From 7cd752add85d0dbfe6c6fb00cd556ab9d1f9caaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Sat, 6 Oct 2018 18:03:37 +0200 Subject: [PATCH] Improve toolbar appearence with GTK+ 3 Use symbolic icons for the toolbar. Also mark it as primary toolbar to have appearance consistent with other applications, particularly on Ubuntu. --- artwork/Makefile.am | 7 ++++ artwork/linux/poedit-sync-symbolic.svg | 1 + artwork/linux/poedit-update-symbolic.svg | 1 + artwork/linux/poedit-validate-symbolic.svg | 1 + artwork/linux/sidebar-symbolic.svg | 1 + src/icons.cpp | 31 +++++++++++++---- src/icons.h | 5 +++ src/wx/main_toolbar.cpp | 40 ++++++++++++++++++++++ 8 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 artwork/linux/poedit-sync-symbolic.svg create mode 100644 artwork/linux/poedit-update-symbolic.svg create mode 100644 artwork/linux/poedit-validate-symbolic.svg create mode 100644 artwork/linux/sidebar-symbolic.svg diff --git a/artwork/Makefile.am b/artwork/Makefile.am index 02c5a99bdf..81c150592e 100644 --- a/artwork/Makefile.am +++ b/artwork/Makefile.am @@ -9,6 +9,7 @@ appicons512dir=$(iconsdir)/512x512/apps pixmapsdir=$(datadir)/pixmaps uiiconsdir=$(datadir)/poedit/icons +uiiconssymbolicdir=$(uiiconsdir)/hicolor/scalable/actions dist_appicons16_DATA = linux/appicon/16x16/apps/poedit.png dist_appicons24_DATA = linux/appicon/24x24/apps/poedit.png @@ -19,6 +20,12 @@ dist_appicons512_DATA = linux/appicon/512x512/apps/poedit.png dist_pixmaps_DATA = linux/appicon/48x48/apps/poedit.png +dist_uiiconssymbolic_DATA = \ + linux/poedit-sync-symbolic.svg \ + linux/poedit-update-symbolic.svg \ + linux/poedit-validate-symbolic.svg \ + linux/sidebar-symbolic.svg + dist_uiicons_DATA = \ linux/document-new.png \ linux/document-open.png \ diff --git a/artwork/linux/poedit-sync-symbolic.svg b/artwork/linux/poedit-sync-symbolic.svg new file mode 100644 index 0000000000..b79c20af9f --- /dev/null +++ b/artwork/linux/poedit-sync-symbolic.svg @@ -0,0 +1 @@ +Sync \ No newline at end of file diff --git a/artwork/linux/poedit-update-symbolic.svg b/artwork/linux/poedit-update-symbolic.svg new file mode 100644 index 0000000000..b79c20af9f --- /dev/null +++ b/artwork/linux/poedit-update-symbolic.svg @@ -0,0 +1 @@ +Sync \ No newline at end of file diff --git a/artwork/linux/poedit-validate-symbolic.svg b/artwork/linux/poedit-validate-symbolic.svg new file mode 100644 index 0000000000..c7ed16492c --- /dev/null +++ b/artwork/linux/poedit-validate-symbolic.svg @@ -0,0 +1 @@ +Validate \ No newline at end of file diff --git a/artwork/linux/sidebar-symbolic.svg b/artwork/linux/sidebar-symbolic.svg new file mode 100644 index 0000000000..4feb8574f3 --- /dev/null +++ b/artwork/linux/sidebar-symbolic.svg @@ -0,0 +1 @@ +Sidebar \ No newline at end of file diff --git a/src/icons.cpp b/src/icons.cpp index ddeafd11e3..169f5e0657 100644 --- a/src/icons.cpp +++ b/src/icons.cpp @@ -29,6 +29,10 @@ #include +#ifdef __WXGTK__ +#include +#endif + #include "icons.h" #include "colorscheme.h" @@ -112,6 +116,26 @@ void ProcessTemplateImage(wxImage& img, bool keepOpaque, bool inverted) } // anonymous namespace + + +PoeditArtProvider::PoeditArtProvider() +{ +#ifdef __WXGTK3__ + gtk_icon_theme_prepend_search_path(gtk_icon_theme_get_default(), GetIconsDir().fn_str()); +#endif +} + + +wxString PoeditArtProvider::GetIconsDir() +{ +#if defined(__WXMSW__) + return wxStandardPaths::Get().GetResourcesDir() + "\\Resources"; +#else + return wxStandardPaths::Get().GetInstallPrefix() + "/share/poedit/icons"; +#endif +} + + wxBitmap PoeditArtProvider::CreateBitmap(const wxArtID& id_, const wxArtClient& client, const wxSize& size) @@ -147,12 +171,7 @@ wxBitmap PoeditArtProvider::CreateBitmap(const wxArtID& id_, } #endif // __WXGTK20__ - wxString iconsdir = -#if defined(__WXMSW__) - wxStandardPaths::Get().GetResourcesDir() + "\\Resources"; -#else - wxStandardPaths::Get().GetInstallPrefix() + "/share/poedit/icons"; -#endif + auto iconsdir = GetIconsDir(); if ( !wxDirExists(iconsdir) ) { wxLogTrace("poedit.icons", diff --git a/src/icons.h b/src/icons.h index 76c88d4ac5..7422ba2876 100644 --- a/src/icons.h +++ b/src/icons.h @@ -35,7 +35,12 @@ #ifndef __WXOSX__ class PoeditArtProvider : public wxArtProvider { +public: + PoeditArtProvider(); + protected: + static wxString GetIconsDir(); + virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size); diff --git a/src/wx/main_toolbar.cpp b/src/wx/main_toolbar.cpp index 3b85c235a1..d318e1af01 100644 --- a/src/wx/main_toolbar.cpp +++ b/src/wx/main_toolbar.cpp @@ -38,6 +38,10 @@ #include #endif +#ifdef __WXGTK__ +#include +#endif + class WXMainToolbar : public MainToolbar { @@ -47,6 +51,15 @@ class WXMainToolbar : public MainToolbar m_tb = wxXmlResource::Get()->LoadToolBar(parent, "toolbar"); m_idUpdate = XRCID("toolbar_update"); +#ifdef __WXGTK3__ + gtk_style_context_add_class(gtk_widget_get_style_context(GTK_WIDGET(Toolbar())), GTK_STYLE_CLASS_PRIMARY_TOOLBAR); + SetIcon(0 , "document-open-symbolic"); + SetIcon(1 , "document-save-symbolic"); + SetIcon(3 , "poedit-validate-symbolic"); + SetIcon(4 , "poedit-update-symbolic"); + SetIcon(6 , "sidebar-symbolic"); +#endif + #ifdef __WXMSW__ // De-uglify the toolbar a bit on Windows 10: if (IsWindows10OrGreater()) @@ -72,7 +85,11 @@ class WXMainToolbar : public MainToolbar { tool->SetLabel(_("Sync")); tool->SetShortHelp(_("Synchronize the translation with Crowdin")); + #ifdef __WXGTK3__ + SetIcon(4 , "poedit-sync-symbolic"); + #else m_tb->SetToolNormalBitmap(m_idUpdate, wxArtProvider::GetBitmap("poedit-sync", wxART_TOOLBAR)); + #endif #ifdef __WXMSW__ m_tb->SetToolDisabledBitmap(m_idUpdate, wxArtProvider::GetBitmap("poedit-sync@disabled", wxART_TOOLBAR)); #endif @@ -81,13 +98,36 @@ class WXMainToolbar : public MainToolbar { tool->SetLabel(MSW_OR_OTHER(_("Update from code"), _("Update from Code"))); tool->SetShortHelp(_("Update catalog - synchronize it with sources")); + #ifdef __WXGTK3__ + SetIcon(4 , "poedit-update-symbolic"); + #else m_tb->SetToolNormalBitmap(m_idUpdate, wxArtProvider::GetBitmap("poedit-update", wxART_TOOLBAR)); + #endif #ifdef __WXMSW__ m_tb->SetToolDisabledBitmap(m_idUpdate, wxArtProvider::GetBitmap("poedit-update@disabled", wxART_TOOLBAR)); #endif } } +#ifdef __WXGTK3__ +private: + GtkToolbar *Toolbar() + { + #ifdef __WXGTK4__ + return GTK_TOOLBAR(m_tb->GetHandle()); + #else + return GTK_TOOLBAR(gtk_bin_get_child(GTK_BIN(m_tb->GetHandle()))); + #endif + } + + void SetIcon(int index, const char *name) + { + GtkToolItem *i = gtk_toolbar_get_nth_item(Toolbar(), index); + gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(i), NULL); + gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(i), name); + } +#endif + private: wxToolBar *m_tb; int m_idUpdate;