[gedit/wip/redesign2] Manage sensitivity in tab context menu



commit 9b224dfc2ff1129f6c8ddc1ac82c53d945306eb0
Author: Paolo Borelli <pborelli gnome org>
Date:   Mon Jan 6 09:14:14 2014 +0100

    Manage sensitivity in tab context menu

 gedit/gedit-notebook-popup-menu.c |   47 +++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)
---
diff --git a/gedit/gedit-notebook-popup-menu.c b/gedit/gedit-notebook-popup-menu.c
index 3e69e85..a252a1e 100644
--- a/gedit/gedit-notebook-popup-menu.c
+++ b/gedit/gedit-notebook-popup-menu.c
@@ -28,6 +28,10 @@ struct _GeditNotebookPopupMenuPrivate
 {
        GeditWindow *window;
        GeditTab *tab;
+
+       GtkWidget *move_left_item;
+       GtkWidget *move_right_item;
+       GtkWidget *close_item;
 };
 
 enum
@@ -94,12 +98,52 @@ gedit_notebook_popup_menu_finalize (GObject *object)
 }
 
 static void
+update_sensitivity (GeditNotebookPopupMenu *menu)
+{
+       GeditTabState state;
+       GeditMultiNotebook *mnb;
+       GtkNotebook *notebook;
+       gint page_num;
+       gint n_pages;
+
+       state = gedit_tab_get_state (menu->priv->tab);
+
+       mnb = GEDIT_MULTI_NOTEBOOK (_gedit_window_get_multi_notebook (menu->priv->window));
+
+       notebook = GTK_NOTEBOOK (gedit_multi_notebook_get_notebook_for_tab (mnb, menu->priv->tab));
+       n_pages = gtk_notebook_get_n_pages (notebook);
+       page_num = gtk_notebook_page_num (notebook, GTK_WIDGET (menu->priv->tab));
+
+       gtk_widget_set_sensitive (menu->priv->close_item,
+                                 (state != GEDIT_TAB_STATE_CLOSING) &&
+                                 (state != GEDIT_TAB_STATE_SAVING) &&
+                                 (state != GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW) &&
+                                 (state != GEDIT_TAB_STATE_PRINTING) &&
+                                 (state != GEDIT_TAB_STATE_PRINT_PREVIEWING) &&
+                                 (state != GEDIT_TAB_STATE_SAVING_ERROR));
+
+       gtk_widget_set_sensitive (menu->priv->move_left_item, page_num > 0);
+       gtk_widget_set_sensitive (menu->priv->move_right_item, page_num < n_pages - 1);
+}
+
+static void
+gedit_notebook_popup_menu_constructed (GObject *object)
+{
+       GeditNotebookPopupMenu *menu = GEDIT_NOTEBOOK_POPUP_MENU (object);
+
+       update_sensitivity (menu);
+
+       G_OBJECT_CLASS (gedit_notebook_popup_menu_parent_class)->constructed (object);
+}
+
+static void
 gedit_notebook_popup_menu_class_init (GeditNotebookPopupMenuClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
        object_class->get_property = gedit_notebook_popup_menu_get_property;
        object_class->set_property = gedit_notebook_popup_menu_set_property;
+       object_class->constructed = gedit_notebook_popup_menu_constructed;
        object_class->finalize = gedit_notebook_popup_menu_finalize;
 
        g_object_class_install_property (object_class,
@@ -200,6 +244,7 @@ gedit_notebook_popup_menu_init (GeditNotebookPopupMenu *menu)
                          menu);
        gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
        gtk_widget_show (menu_item);
+       menu->priv->close_item = menu_item;
 
        menu_item = gtk_separator_menu_item_new ();
        gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
@@ -229,6 +274,7 @@ gedit_notebook_popup_menu_init (GeditNotebookPopupMenu *menu)
                          menu);
        gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
        gtk_widget_show (menu_item);
+       menu->priv->move_right_item = menu_item;
 
        menu_item = gtk_menu_item_new_with_mnemonic (_("_Move Left"));
        g_signal_connect (menu_item, "activate",
@@ -236,6 +282,7 @@ gedit_notebook_popup_menu_init (GeditNotebookPopupMenu *menu)
                          menu);
        gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
        gtk_widget_show (menu_item);
+       menu->priv->move_left_item = menu_item;
 }
 
 GtkWidget *


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