[nautilus] toolbar: don't explicitly call to update the view mode
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] toolbar: don't explicitly call to update the view mode
- Date: Sun, 25 Jan 2015 15:22:50 +0000 (UTC)
commit a8bfc0a748f7ab76f9ac795ebd640e9edde4de10
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sun Jan 25 12:51:55 2015 +0000
toolbar: don't explicitly call to update the view mode
The toolbar can just listen to changes in the action state.
src/nautilus-toolbar.c | 59 ++++++++++++++++++++++++++---------------------
src/nautilus-toolbar.h | 2 -
src/nautilus-window.c | 4 ---
3 files changed, 33 insertions(+), 32 deletions(-)
---
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index ff2169d..03ccd96 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -87,32 +87,6 @@ G_DEFINE_TYPE_WITH_PRIVATE(NautilusToolbar, nautilus_toolbar, GTK_TYPE_HEADER_BA
static void unschedule_menu_popup_timeout (NautilusToolbar *self);
-void
-nautilus_toolbar_update_view_mode (NautilusToolbar *self,
- const gchar *view_mode)
-{
- gchar *name;
- GtkWidget *image;
-
- if (g_strcmp0 (view_mode, "list") == 0) {
- name = "view-list-symbolic";
- self->priv->active_zoom_adjustment = self->priv->zoom_adjustment_list;
- } else if (g_strcmp0 (view_mode, "grid") == 0) {
- name = "view-grid-symbolic";
- self->priv->active_zoom_adjustment = self->priv->zoom_adjustment_grid;
- } else {
- g_assert_not_reached ();
- }
-
- gtk_range_set_adjustment (GTK_RANGE (self->priv->zoom_level_scale),
- self->priv->active_zoom_adjustment);
-
- image = gtk_image_new ();
- gtk_button_set_image (GTK_BUTTON (self->priv->view_button), image);
- gtk_image_set_from_icon_name (GTK_IMAGE (image), name,
- GTK_ICON_SIZE_MENU);
-}
-
static void
toolbar_update_appearance (NautilusToolbar *self)
{
@@ -294,6 +268,36 @@ show_menu (NautilusToolbar *self,
}
static void
+action_view_mode_state_changed (GActionGroup *action_group,
+ gchar *action_name,
+ GVariant *value,
+ gpointer user_data)
+{
+ NautilusToolbar *self = user_data;
+ const gchar *view_mode = g_variant_get_string (value, NULL);
+ gchar *name;
+ GtkWidget *image;
+
+ if (g_strcmp0 (view_mode, "list") == 0) {
+ name = "view-list-symbolic";
+ self->priv->active_zoom_adjustment = self->priv->zoom_adjustment_list;
+ } else if (g_strcmp0 (view_mode, "grid") == 0) {
+ name = "view-grid-symbolic";
+ self->priv->active_zoom_adjustment = self->priv->zoom_adjustment_grid;
+ } else {
+ g_assert_not_reached ();
+ }
+
+ gtk_range_set_adjustment (GTK_RANGE (self->priv->zoom_level_scale),
+ self->priv->active_zoom_adjustment);
+
+ image = gtk_image_new ();
+ gtk_button_set_image (GTK_BUTTON (self->priv->view_button), image);
+ gtk_image_set_from_icon_name (GTK_IMAGE (image), name,
+ GTK_ICON_SIZE_MENU);
+}
+
+static void
action_reload_enabled_changed (GActionGroup *action_group,
gchar *action_name,
gboolean enabled,
@@ -319,10 +323,13 @@ nautilus_toolbar_set_window (NautilusToolbar *self,
{
self->priv->window = window;
+
g_signal_connect (self->priv->window, "action-enabled-changed::stop",
G_CALLBACK (action_stop_enabled_changed), self);
g_signal_connect (self->priv->window, "action-enabled-changed::reload",
G_CALLBACK (action_reload_enabled_changed), self);
+ g_signal_connect (self->priv->window, "action-state-changed::view-mode",
+ G_CALLBACK (action_view_mode_state_changed), self);
}
#define MENU_POPUP_TIMEOUT 1200
diff --git a/src/nautilus-toolbar.h b/src/nautilus-toolbar.h
index 4a8411d..cea8042 100644
--- a/src/nautilus-toolbar.h
+++ b/src/nautilus-toolbar.h
@@ -80,8 +80,6 @@ void nautilus_toolbar_reset_menus (NautilusToolbar *self);
void nautilus_toolbar_sync_navigation_buttons (NautilusToolbar *self);
void nautilus_toolbar_view_menu_widget_set_zoom_level (NautilusToolbar *self,
gdouble level);
-void nautilus_toolbar_update_view_mode (NautilusToolbar *self,
- const gchar *view_mode);
void nautilus_toolbar_show_sort_trash_time (NautilusToolbar *self);
void nautilus_toolbar_show_sort_search_relevance (NautilusToolbar *self);
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 3b5dd81..d252b64 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -371,11 +371,9 @@ action_view_mode (GSimpleAction *action,
{
const gchar *name;
NautilusWindowSlot *slot;
- NautilusToolbar *toolbar;
name = g_variant_get_string (value, NULL);
slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (user_data));
- toolbar = NAUTILUS_TOOLBAR (nautilus_window_get_toolbar (NAUTILUS_WINDOW (user_data)));
if (g_strcmp0 (name, "list") == 0) {
nautilus_window_slot_set_content_view (slot, NAUTILUS_LIST_VIEW_ID);
@@ -385,8 +383,6 @@ action_view_mode (GSimpleAction *action,
g_assert_not_reached ();
}
- nautilus_toolbar_update_view_mode (toolbar, name);
-
g_simple_action_set_state (action, value);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]