diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-02-27 16:45:44 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-02-28 21:25:51 +0100 |
commit | c456ce855ac1ee4775489485f9107bd43a0f1371 (patch) | |
tree | 696e4e7deb93d5cd112c2a5a081b081bdf018824 /vcl/unx | |
parent | dc10b663a50adf4c9ea268f123169c7caf0b75c4 (diff) |
use ok, cancel under kde vs cancel, ok under gnome
for the native welded dialogs
Change-Id: I34663616826c1eb084262ea1c830f8580785d50c
Reviewed-on: https://gerrit.libreoffice.org/50458
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index e31606fffbad..c36895fffce1 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -1378,6 +1378,79 @@ public: } }; +namespace +{ + struct ButtonOrder + { + OString m_aType; + int m_nPriority; + }; + + int getButtonPriority(const OString &rType) + { + static const size_t N_TYPES = 6; + static const ButtonOrder aDiscardCancelSave[N_TYPES] = + { + { "/discard", 0 }, + { "/no", 0 }, + { "/cancel", 1 }, + { "/save", 2 }, + { "/yes", 2 }, + { "/ok", 2 } + }; + + static const ButtonOrder aSaveDiscardCancel[N_TYPES] = + { + { "/save", 0 }, + { "/yes", 0 }, + { "/ok", 0 }, + { "/discard", 1 }, + { "/no", 1 }, + { "/cancel", 2 } + }; + + const ButtonOrder* pOrder = &aDiscardCancelSave[0]; + + const OUString &rEnv = Application::GetDesktopEnvironment(); + + if (rEnv.equalsIgnoreAsciiCase("windows") || + rEnv.equalsIgnoreAsciiCase("tde") || + rEnv.startsWithIgnoreAsciiCase("kde")) + { + pOrder = &aSaveDiscardCancel[0]; + } + + for (size_t i = 0; i < N_TYPES; ++i, ++pOrder) + { + if (rType.endsWith(pOrder->m_aType)) + return pOrder->m_nPriority; + } + + return -1; + } + + bool sortButtons(const GtkWidget* pA, const GtkWidget* pB) + { + //order within groups according to platform rules + return getButtonPriority(::get_help_id(pA)) < getButtonPriority(::get_help_id(pB)); + } + + void sort_native_button_order(GtkBox* pContainer) + { + std::vector<GtkWidget*> aChildren; + GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pContainer)); + for (GList* pChild = g_list_first(pChildren); pChild; pChild = g_list_next(pChild)) + aChildren.push_back(static_cast<GtkWidget*>(pChild->data)); + g_list_free(pChildren); + + //sort child order within parent so that we match the platform button order + std::stable_sort(aChildren.begin(), aChildren.end(), sortButtons); + + for (size_t pos = 0; pos < aChildren.size(); ++pos) + gtk_box_reorder_child(pContainer, aChildren[pos], pos); + } +} + class GtkInstanceDialog : public GtkInstanceWindow, public virtual weld::Dialog { private: @@ -1399,6 +1472,7 @@ public: virtual int run() override { + sort_native_button_order(GTK_BOX(gtk_dialog_get_action_area(m_pDialog))); int ret; while (true) { |