toolbar: Revamp the main toolbar style

Get rid of the text and switch all icons to slightly smaller symoblic icons.
This will allow it to behave much better with dark gtk themes. Replace the
recent documents button with a button for file open. Changing the style of
the buttons on the main toolbar also effects the fullscreen toolbar so
update this as well to use a matching layout.
This commit is contained in:
JosephMcc 2016-10-03 23:48:20 -07:00
parent bafaeaca98
commit 94dae95b95
4 changed files with 172 additions and 157 deletions

View File

@ -1328,19 +1328,9 @@ xed_prefs_manager_max_recents_changed (GSettings *settings,
max = g_settings_get_int (settings, key);
if (max < 0) {
max = GPM_DEFAULT_MAX_RECENTS;
}
windows = xed_app_get_windows (xed_app_get_default ());
while (windows != NULL)
if (max < 0)
{
XedWindow *w = windows->data;
gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (w->priv->toolbar_recent_menu),
max);
windows = g_list_next (windows);
max = GPM_DEFAULT_MAX_RECENTS;
}
/* FIXME: we have no way at the moment to trigger the

View File

@ -53,9 +53,9 @@ static const GtkActionEntry xed_always_sensitive_menu_entries[] =
{ "Help", NULL, N_("_Help") },
/* File menu */
{ "FileNew", GTK_STOCK_NEW, NULL, "<control>N",
{ "FileNew", "document-new-symbolic", N_("_New"), "<control>N",
N_("Create a new document"), G_CALLBACK (_xed_cmd_file_new) },
{ "FileOpen", GTK_STOCK_OPEN, N_("_Open..."), "<control>O",
{ "FileOpen", "document-open-symbolic", N_("_Open..."), "<control>O",
N_("Open a file"), G_CALLBACK (_xed_cmd_file_open) },
/* Edit menu */
@ -69,7 +69,7 @@ static const GtkActionEntry xed_always_sensitive_menu_entries[] =
N_("About this application"), G_CALLBACK (_xed_cmd_help_about) },
/* Fullscreen toolbar */
{ "LeaveFullscreen", GTK_STOCK_LEAVE_FULLSCREEN, NULL,
{ "LeaveFullscreen", "view-restore-symbolic", NULL,
NULL, N_("Leave fullscreen mode"),
G_CALLBACK (_xed_cmd_view_leave_fullscreen_mode) }
};
@ -77,7 +77,7 @@ static const GtkActionEntry xed_always_sensitive_menu_entries[] =
static const GtkActionEntry xed_menu_entries[] =
{
/* File menu */
{ "FileSave", GTK_STOCK_SAVE, NULL, "<control>S",
{ "FileSave", "document-save-symbolic", N_("_Save"), "<control>S",
N_("Save the current file"), G_CALLBACK (_xed_cmd_file_save) },
{ "FileSaveAs", GTK_STOCK_SAVE_AS, N_("Save _As..."), "<shift><control>S",
N_("Save the current file with a different name"), G_CALLBACK (_xed_cmd_file_save_as) },
@ -89,15 +89,15 @@ static const GtkActionEntry xed_menu_entries[] =
N_("Print the current page"), G_CALLBACK (_xed_cmd_file_print) },
/* Edit menu */
{ "EditUndo", GTK_STOCK_UNDO, NULL, "<control>Z",
{ "EditUndo", "edit-undo-symbolic", N_("Undo"), "<control>Z",
N_("Undo the last action"), G_CALLBACK (_xed_cmd_edit_undo) },
{ "EditRedo", GTK_STOCK_REDO, NULL, "<control>Y",
{ "EditRedo", "edit-redo-symbolic", N_("Redo"), "<control>Y",
N_("Redo the last undone action"), G_CALLBACK (_xed_cmd_edit_redo) },
{ "EditCut", GTK_STOCK_CUT, NULL, "<control>X",
{ "EditCut", "edit-cut-symbolic", N_("Cut"), "<control>X",
N_("Cut the selection"), G_CALLBACK (_xed_cmd_edit_cut) },
{ "EditCopy", GTK_STOCK_COPY, NULL, "<control>C",
{ "EditCopy", "edit-copy-symbolic", N_("Copy"), "<control>C",
N_("Copy the selection"), G_CALLBACK (_xed_cmd_edit_copy) },
{ "EditPaste", GTK_STOCK_PASTE, NULL, "<control>V",
{ "EditPaste", "edit-paste-symbolic", N_("Paste"), "<control>V",
N_("Paste the clipboard"), G_CALLBACK (_xed_cmd_edit_paste) },
{ "EditDelete", GTK_STOCK_DELETE, NULL, NULL,
N_("Delete the selected text"), G_CALLBACK (_xed_cmd_edit_delete) },
@ -108,13 +108,13 @@ static const GtkActionEntry xed_menu_entries[] =
{ "ViewHighlightMode", NULL, N_("_Highlight Mode") },
/* Search menu */
{ "SearchFind", GTK_STOCK_FIND, N_("_Find..."), "<control>F",
{ "SearchFind", "edit-find-symbolic", N_("_Find"), "<control>F",
N_("Search for text"), G_CALLBACK (_xed_cmd_search_find) },
{ "SearchFindNext", NULL, N_("Find Ne_xt"), "<control>G",
N_("Search forwards for the same text"), G_CALLBACK (_xed_cmd_search_find_next) },
{ "SearchFindPrevious", NULL, N_("Find Pre_vious"), "<shift><control>G",
N_("Search backwards for the same text"), G_CALLBACK (_xed_cmd_search_find_prev) },
{ "SearchReplace", GTK_STOCK_FIND_AND_REPLACE, N_("_Replace..."), "<control>H",
{ "SearchReplace", "edit-find-replace-symbolic", N_("_Replace"), "<control>H",
N_("Search for and replace text"), G_CALLBACK (_xed_cmd_search_replace) },
{ "SearchGoToLine", GTK_STOCK_JUMP_TO, N_("Go to _Line..."), "<control>I",
N_("Go to a specific line"), G_CALLBACK (_xed_cmd_search_goto_line) },

View File

@ -56,6 +56,7 @@ struct _XedWindowPrivate
/* Widgets for fullscreen mode */
GtkWidget *fullscreen_controls;
GtkWidget *fullscreen_controls_container;
guint fullscreen_animation_timeout_id;
gboolean fullscreen_animation_enter;
@ -79,9 +80,7 @@ struct _XedWindowPrivate
GtkActionGroup *documents_list_action_group;
guint documents_list_menu_ui_id;
GtkWidget *toolbar;
GtkWidget *toolbar_recent_menu;
GtkWidget *menubar;
XedToolbarSetting toolbar_style;
/* recent files */
GtkActionGroup *recents_action_group;

View File

@ -393,34 +393,6 @@ disconnect_proxy_cb (GtkUIManager *manager,
}
}
static void
apply_toolbar_style (XedWindow *window,
GtkWidget *toolbar)
{
switch (window->priv->toolbar_style)
{
case XED_TOOLBAR_SYSTEM:
xed_debug_message (DEBUG_WINDOW, "XED: SYSTEM");
gtk_toolbar_unset_style (GTK_TOOLBAR(toolbar));
break;
case XED_TOOLBAR_ICONS:
xed_debug_message (DEBUG_WINDOW, "XED: ICONS");
gtk_toolbar_set_style (GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);
break;
case XED_TOOLBAR_ICONS_AND_TEXT:
xed_debug_message (DEBUG_WINDOW, "XED: ICONS_AND_TEXT");
gtk_toolbar_set_style (GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
break;
case XED_TOOLBAR_ICONS_BOTH_HORIZ:
xed_debug_message (DEBUG_WINDOW, "XED: ICONS_BOTH_HORIZ");
gtk_toolbar_set_style (GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH_HORIZ);
break;
}
}
/* Returns TRUE if toolbar is visible */
static gboolean
set_toolbar_style (XedWindow *window,
@ -456,20 +428,6 @@ set_toolbar_style (XedWindow *window,
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(action), visible);
}
/* Set style */
if (origin == NULL)
{
style = xed_prefs_manager_get_toolbar_buttons_style ();
}
else
{
style = origin->priv->toolbar_style;
}
window->priv->toolbar_style = style;
apply_toolbar_style (window, window->priv->toolbar);
return visible;
}
@ -950,19 +908,6 @@ open_recent_file (const gchar *uri,
g_slist_free (uris);
}
static void
recent_chooser_item_activated (GtkRecentChooser *chooser,
XedWindow *window)
{
gchar *uri;
uri = gtk_recent_chooser_get_current_uri (chooser);
open_recent_file (uri, window);
g_free (uri);
}
static void
recents_menu_activate (GtkAction *action,
XedWindow *window)
@ -1116,13 +1061,6 @@ update_recent_files_menu (XedWindow *window)
g_list_free (items);
}
static void
set_non_homogeneus (GtkWidget *widget,
gpointer data)
{
gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM(widget), FALSE);
}
static void
toolbar_visibility_changed (GtkWidget *toolbar,
XedWindow *window)
@ -1146,45 +1084,21 @@ toolbar_visibility_changed (GtkWidget *toolbar,
}
static GtkWidget *
setup_toolbar_open_button (XedWindow *window,
GtkWidget *toolbar)
create_toolbar_button (GtkAction *action)
{
GtkRecentManager *recent_manager;
GtkRecentFilter *filter;
GtkWidget *toolbar_recent_menu;
GtkToolItem *open_button;
GtkAction *action;
GtkWidget *button;
GtkWidget *image;
recent_manager = gtk_recent_manager_get_default ();
button = gtk_button_new ();
image = gtk_image_new ();
/* recent files menu tool button */
toolbar_recent_menu = gtk_recent_chooser_menu_new_for_manager (recent_manager);
gtk_button_set_image (GTK_BUTTON (button), image);
gtk_style_context_add_class (gtk_widget_get_style_context (button), "flat");
gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action);
gtk_button_set_label (GTK_BUTTON (button), NULL);
gtk_widget_set_tooltip_text (button, gtk_action_get_tooltip (action));
gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER(toolbar_recent_menu),
FALSE);
gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER(toolbar_recent_menu), GTK_RECENT_SORT_MRU);
gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER(toolbar_recent_menu), xed_prefs_manager_get_max_recents ());
filter = gtk_recent_filter_new ();
gtk_recent_filter_add_group (filter, "xed");
gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER(toolbar_recent_menu), filter);
g_signal_connect(toolbar_recent_menu, "item_activated", G_CALLBACK (recent_chooser_item_activated), window);
/* add the custom Open button to the toolbar */
open_button = gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN);
gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON(open_button), toolbar_recent_menu);
gtk_tool_item_set_tooltip_text (open_button, _("Open a file"));
gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON(open_button), _("Open a recently used file"));
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "FileOpen");
g_object_set (action, "short_label", _("Open"), NULL);
gtk_activatable_set_related_action (GTK_ACTIVATABLE(open_button), action);
gtk_toolbar_insert (GTK_TOOLBAR(toolbar), open_button, 1);
return toolbar_recent_menu;
return button;
}
static void
@ -1197,6 +1111,11 @@ create_menu_bar_and_toolbar (XedWindow *window,
GtkRecentManager *recent_manager;
GError *error = NULL;
gchar *ui_file;
GtkWidget *tool_item;
GtkWidget *tool_box;
GtkWidget *box;
GtkWidget *separator;
GtkWidget *button;
xed_debug (DEBUG_WINDOW);
@ -1223,16 +1142,6 @@ create_menu_bar_and_toolbar (XedWindow *window,
g_object_unref (action_group);
window->priv->action_group = action_group;
/* set short labels to use in the toolbar */
action = gtk_action_group_get_action (action_group, "FileSave");
g_object_set (action, "short_label", _("Save"), NULL);
action = gtk_action_group_get_action (action_group, "FilePrint");
g_object_set (action, "short_label", _("Print"), NULL);
action = gtk_action_group_get_action (action_group, "SearchFind");
g_object_set (action, "short_label", _("Find"), NULL);
action = gtk_action_group_get_action (action_group, "SearchReplace");
g_object_set (action, "short_label", _("Replace"), NULL);
action_group = gtk_action_group_new ("XedQuitWindowActions");
gtk_action_group_set_translation_domain (action_group, NULL);
gtk_action_group_add_actions (action_group, xed_quit_menu_entries, G_N_ELEMENTS(xed_quit_menu_entries), window);
@ -1302,17 +1211,82 @@ create_menu_bar_and_toolbar (XedWindow *window,
window->priv->menubar = gtk_ui_manager_get_widget (manager, "/MenuBar");
gtk_box_pack_start (GTK_BOX(main_box), window->priv->menubar, FALSE, FALSE, 0);
window->priv->toolbar = gtk_ui_manager_get_widget (manager, "/ToolBar");
gtk_style_context_add_class (gtk_widget_get_style_context (window->priv->toolbar),
GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
window->priv->toolbar = gtk_toolbar_new ();
gtk_style_context_add_class (gtk_widget_get_style_context (window->priv->toolbar), GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
gtk_box_pack_start (GTK_BOX(main_box), window->priv->toolbar, FALSE, FALSE, 0);
tool_item = gtk_tool_item_new ();
gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
gtk_toolbar_insert (GTK_TOOLBAR (window->priv->toolbar), GTK_TOOL_ITEM (tool_item), 0);
tool_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_container_add (GTK_CONTAINER (tool_item), tool_box);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (tool_box), box, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "FileNew");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "FileOpen");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "FileSave");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
gtk_box_pack_start (GTK_BOX (tool_box), separator, FALSE, FALSE, 0);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (tool_box), box, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "EditUndo");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "EditRedo");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
gtk_box_pack_start (GTK_BOX (tool_box), separator, FALSE, FALSE, 0);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (tool_box), box, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "EditCut");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "EditCopy");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "EditPaste");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
gtk_box_pack_start (GTK_BOX (tool_box), separator, FALSE, FALSE, 0);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (tool_box), box, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "SearchFind");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "SearchReplace");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
gtk_widget_show_all (GTK_WIDGET (window->priv->toolbar));
set_toolbar_style (window, NULL);
window->priv->toolbar_recent_menu = setup_toolbar_open_button (window, window->priv->toolbar);
gtk_container_foreach (GTK_CONTAINER(window->priv->toolbar), (GtkCallback) set_non_homogeneus, NULL);
g_signal_connect_after(G_OBJECT (window->priv->toolbar), "show", G_CALLBACK (toolbar_visibility_changed), window);
g_signal_connect_after(G_OBJECT (window->priv->toolbar), "hide", G_CALLBACK (toolbar_visibility_changed), window);
}
@ -2404,16 +2378,16 @@ fullscreen_controls_show (XedWindow *window)
{
GdkScreen *screen;
GdkRectangle fs_rect;
gint w, h;
gint min_h, nat_h;
screen = gtk_window_get_screen (GTK_WINDOW (window));
gdk_screen_get_monitor_geometry (
screen, gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (GTK_WIDGET(window))),
&fs_rect);
gtk_window_get_size (GTK_WINDOW(window->priv->fullscreen_controls), &w, &h);
gtk_window_resize (GTK_WINDOW(window->priv->fullscreen_controls), fs_rect.width, h);
gtk_window_move (GTK_WINDOW(window->priv->fullscreen_controls), fs_rect.x, fs_rect.y - h + 1);
gtk_widget_get_preferred_height (window->priv->fullscreen_controls_container, &min_h, &nat_h);
gtk_window_resize (GTK_WINDOW (window->priv->fullscreen_controls), fs_rect.width, nat_h);
gtk_window_move (GTK_WINDOW (window->priv->fullscreen_controls), fs_rect.x, fs_rect.y - nat_h + 1);
gtk_widget_show_all (window->priv->fullscreen_controls);
}
@ -2544,9 +2518,11 @@ static void
fullscreen_controls_build (XedWindow *window)
{
XedWindowPrivate *priv = window->priv;
GtkWidget *toolbar;
GtkWidget *toolbar_recent_menu;
GtkAction *action;
GtkWidget *box;
GtkWidget *fullscreen_btn;
GtkWidget *separator;
GtkWidget *button;
if (priv->fullscreen_controls != NULL)
{
@ -2557,19 +2533,69 @@ fullscreen_controls_build (XedWindow *window)
gtk_window_set_transient_for (GTK_WINDOW(priv->fullscreen_controls), &window->window);
/* popup toolbar */
toolbar = gtk_ui_manager_get_widget (priv->manager, "/FullscreenToolBar");
gtk_container_add (GTK_CONTAINER(priv->fullscreen_controls), toolbar);
window->priv->fullscreen_controls_container = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_set_border_width (GTK_CONTAINER (window->priv->fullscreen_controls_container), 6);
gtk_container_add (GTK_CONTAINER (priv->fullscreen_controls), window->priv->fullscreen_controls_container);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_vexpand (box, FALSE);
gtk_box_pack_start (GTK_BOX (window->priv->fullscreen_controls_container), box, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "FileNew");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "FileOpen");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "FileSave");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 6);
action = gtk_action_group_get_action (window->priv->action_group, "EditUndo");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "EditRedo");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 6);
action = gtk_action_group_get_action (window->priv->action_group, "EditCut");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "EditCopy");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "EditPaste");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 6);
action = gtk_action_group_get_action (window->priv->action_group, "SearchFind");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (window->priv->action_group, "SearchReplace");
button = create_toolbar_button (action);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
action = gtk_action_group_get_action (priv->always_sensitive_action_group, "LeaveFullscreen");
g_object_set (action, "is-important", TRUE, NULL);
fullscreen_btn = create_toolbar_button (action);
gtk_box_pack_end (GTK_BOX (box), fullscreen_btn, FALSE, FALSE, 0);
toolbar_recent_menu = setup_toolbar_open_button (window, toolbar);
gtk_container_foreach (GTK_CONTAINER(toolbar), (GtkCallback) set_non_homogeneus, NULL);
/* Set the toolbar style */
gtk_toolbar_set_style (GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH_HORIZ);
gtk_widget_show_all (window->priv->fullscreen_controls_container);
g_signal_connect(priv->fullscreen_controls, "enter-notify-event",
G_CALLBACK (on_fullscreen_controls_enter_notify_event), window);