Skip to content

Commit

Permalink
Improve toolbar appearence with GTK+ 3
Browse files Browse the repository at this point in the history
Use symbolic icons for the toolbar. Also mark it as primary toolbar to
have appearance consistent with other applications, particularly on
Ubuntu.
  • Loading branch information
vslavik committed Oct 6, 2018
1 parent f2be20f commit 7cd752a
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 6 deletions.
7 changes: 7 additions & 0 deletions artwork/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions artwork/linux/poedit-sync-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions artwork/linux/poedit-update-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions artwork/linux/poedit-validate-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions artwork/linux/sidebar-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 25 additions & 6 deletions src/icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

#include <set>

#ifdef __WXGTK__
#include <gtk/gtk.h>
#endif

#include "icons.h"

#include "colorscheme.h"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions src/wx/main_toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#include <wx/msw/uxtheme.h>
#endif

#ifdef __WXGTK__
#include <gtk/gtk.h>
#endif


class WXMainToolbar : public MainToolbar
{
Expand All @@ -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())
Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 7cd752a

Please sign in to comment.