[tepl] WindowActionsFile: move code to update actions sensitivity



commit d1a219584f51329a5c5f3fbc918d81a40964e860
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun May 3 22:46:35 2020 +0200

    WindowActionsFile: move code to update actions sensitivity

 tepl/tepl-application-window.c  | 22 ----------------------
 tepl/tepl-window-actions-file.c | 36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 23 deletions(-)
---
diff --git a/tepl/tepl-application-window.c b/tepl/tepl-application-window.c
index f1903ed..38ad6cb 100644
--- a/tepl/tepl-application-window.c
+++ b/tepl/tepl-application-window.c
@@ -376,26 +376,6 @@ goto_line_change_state_cb (GSimpleAction *action,
        update_goto_line (tepl_window);
 }
 
-static void
-update_save_actions_sensitivity (TeplApplicationWindow *tepl_window)
-{
-       TeplBuffer *buffer;
-       GActionMap *action_map;
-       GAction *action;
-
-       buffer = tepl_tab_group_get_active_buffer (TEPL_TAB_GROUP (tepl_window));
-
-       action_map = G_ACTION_MAP (tepl_window->priv->gtk_window);
-
-       action = g_action_map_lookup_action (action_map, "tepl-save");
-       g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
-                                    buffer != NULL);
-
-       action = g_action_map_lookup_action (action_map, "tepl-save-as");
-       g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
-                                    buffer != NULL);
-}
-
 static void
 update_undo_redo_actions_sensitivity (TeplApplicationWindow *tepl_window)
 {
@@ -589,7 +569,6 @@ update_basic_edit_actions_sensitivity (TeplApplicationWindow *tepl_window)
 static void
 update_actions_sensitivity (TeplApplicationWindow *tepl_window)
 {
-       update_save_actions_sensitivity (tepl_window);
        update_undo_redo_actions_sensitivity (tepl_window);
        update_basic_edit_actions_sensitivity (tepl_window);
        update_paste_action_sensitivity (tepl_window);
@@ -1098,7 +1077,6 @@ active_buffer_changed (TeplApplicationWindow *tepl_window)
                                                  tepl_window));
 
 end:
-       update_save_actions_sensitivity (tepl_window);
        update_undo_redo_actions_sensitivity (tepl_window);
        update_basic_edit_actions_sensitivity (tepl_window);
 
diff --git a/tepl/tepl-window-actions-file.c b/tepl/tepl-window-actions-file.c
index 21c651c..5e47a96 100644
--- a/tepl/tepl-window-actions-file.c
+++ b/tepl/tepl-window-actions-file.c
@@ -162,6 +162,34 @@ save_as_activate_cb (GSimpleAction *save_as_action,
        tepl_tab_save_as_async_simple (tab);
 }
 
+static void
+update_actions_sensitivity (TeplApplicationWindow *tepl_window)
+{
+       TeplBuffer *buffer;
+       GActionMap *action_map;
+       GAction *action;
+
+       buffer = tepl_tab_group_get_active_buffer (TEPL_TAB_GROUP (tepl_window));
+
+       action_map = G_ACTION_MAP (tepl_application_window_get_application_window (tepl_window));
+
+       action = g_action_map_lookup_action (action_map, "tepl-save");
+       g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+                                    buffer != NULL);
+
+       action = g_action_map_lookup_action (action_map, "tepl-save-as");
+       g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+                                    buffer != NULL);
+}
+
+static void
+active_buffer_notify_cb (TeplApplicationWindow *tepl_window,
+                        GParamSpec            *pspec,
+                        gpointer               user_data)
+{
+       update_actions_sensitivity (tepl_window);
+}
+
 void
 _tepl_window_actions_file_add_actions (TeplApplicationWindow *tepl_window)
 {
@@ -177,9 +205,15 @@ _tepl_window_actions_file_add_actions (TeplApplicationWindow *tepl_window)
        g_return_if_fail (TEPL_IS_APPLICATION_WINDOW (tepl_window));
 
        gtk_window = tepl_application_window_get_application_window (tepl_window);
-
        amtk_action_map_add_action_entries_check_dups (G_ACTION_MAP (gtk_window),
                                                       entries,
                                                       G_N_ELEMENTS (entries),
                                                       tepl_window);
+
+       update_actions_sensitivity (tepl_window);
+
+       g_signal_connect (tepl_window,
+                         "notify::active-buffer",
+                         G_CALLBACK (active_buffer_notify_cb),
+                         NULL);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]