1 /*
2 * Nautilus-Actions
3 * A Nautilus extension which offers configurable context menu actions.
4 *
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009-2014 Pierre Wieser and others (see AUTHORS)
8 *
9 * Nautilus-Actions is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * Nautilus-Actions is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Nautilus-Actions; see the file COPYING. If not, see
21 * <http://www.gnu.org/licenses/>.
22 *
23 * Authors:
24 * Frederic Ruaudel <grumz@grumz.net>
25 * Rodrigo Moya <rodrigo@gnome-db.org>
26 * Pierre Wieser <pwieser@trychlos.org>
27 * ... and many others (see AUTHORS)
28 */
29
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33
34 #include <api/na-object-profile.h>
35
36 #include "nact-main-tab.h"
37
38 static void on_tab_initialize_window( NactMainWindow *window, gpointer p_page );
39
40 /**
41 * nact_main_tab_init:
42 * @window: the #NactMainWindow.
43 * @num_page: the page number, starting from zero.
44 *
45 * Common initialization of each page of the notebook.
46 */
47 void
nact_main_tab_init(NactMainWindow * window,gint num_page)48 nact_main_tab_init( NactMainWindow *window, gint num_page )
49 {
50 base_window_signal_connect_with_data(
51 BASE_WINDOW( window ),
52 G_OBJECT( window ),
53 BASE_SIGNAL_INITIALIZE_WINDOW,
54 G_CALLBACK( on_tab_initialize_window ),
55 GUINT_TO_POINTER( num_page ));
56 }
57
58 /**
59 * nact_main_tab_enable_page:
60 * @window: the #NactMainWindow.
61 * @num_page: the page number, starting from zero.
62 * @enabled: whether the tab should be set sensitive or not.
63 *
64 * Set the sensitivity of the tab.
65 */
66 void
nact_main_tab_enable_page(NactMainWindow * window,gint num_page,gboolean enabled)67 nact_main_tab_enable_page( NactMainWindow *window, gint num_page, gboolean enabled )
68 {
69 GtkNotebook *notebook;
70 GtkWidget *page, *label;
71
72 notebook = GTK_NOTEBOOK( base_window_get_widget( BASE_WINDOW( window ), "MainNotebook" ));
73 page = gtk_notebook_get_nth_page( notebook, num_page );
74 gtk_widget_set_sensitive( page, enabled );
75
76 label = gtk_notebook_get_tab_label( notebook, page );
77 gtk_widget_set_sensitive( label, enabled );
78 }
79
80 /**
81 * nact_main_tab_is_page_enabled:
82 * @window: the #NactMainWindow.
83 * @num_page: the page number, starting from zero.
84 *
85 * Returns: %TRUE if the tab is sensitive, %FALSE else.
86 */
87 gboolean
nact_main_tab_is_page_enabled(NactMainWindow * window,gint num_page)88 nact_main_tab_is_page_enabled( NactMainWindow *window, gint num_page )
89 {
90 gboolean is_sensitive;
91 GtkNotebook *notebook;
92 GtkWidget *page;
93
94 notebook = GTK_NOTEBOOK( base_window_get_widget( BASE_WINDOW( window ), "MainNotebook" ));
95 page = gtk_notebook_get_nth_page( notebook, num_page );
96
97 is_sensitive = gtk_widget_is_sensitive( page );
98
99 g_debug( "nact_main_tab_is_page_enabled: num_page=%d, is_sensitive=%s", num_page, is_sensitive ? "True":"False" );
100
101 return( is_sensitive );
102 }
103
104 /*
105 * a commoon initialization for each page of the notebook
106 * (provided that the page has itself called nact_main_tab_init()
107 * *before* the BASE_SIGNAL_INITIALIZE_WINDOW has been emitted)
108 */
109 static void
on_tab_initialize_window(NactMainWindow * window,gpointer p_page)110 on_tab_initialize_window( NactMainWindow *window, gpointer p_page )
111 {
112 GtkNotebook *notebook;
113 GtkWidget *page;
114 const gchar *text;
115 guint num_page;
116
117 notebook = GTK_NOTEBOOK( base_window_get_widget( BASE_WINDOW( window ), "MainNotebook" ));
118 num_page = GPOINTER_TO_UINT( p_page );
119 page = gtk_notebook_get_nth_page( notebook, num_page );
120
121 /* popup menu is enabled in NactMainWindow::on_base_initialize_window()
122 * but the displayed labels default to be those of the tab, i.e. embed
123 * an underscore as an accelerator - so get ride of this
124 */
125 text = gtk_notebook_get_tab_label_text( notebook, page );
126 gtk_notebook_set_menu_label_text( notebook, page, text );
127 }
128