3 * A file-manager extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009-2015 Pierre Wieser and others (see AUTHORS)
9 * FileManager-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.
14 * FileManager-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.
19 * You should have received a copy of the GNU General Public License
20 * along with FileManager-Actions; see the file COPYING. If not, see
21 * <http://www.gnu.org/licenses/>.
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)
34 #include <glib/gi18n.h>
36 #include "api/fma-object-api.h"
38 #include "core/fma-gtk-utils.h"
40 #include "base-gtk-utils.h"
41 #include "fma-ibasenames-tab.h"
42 #include "fma-main-tab.h"
43 #include "fma-main-window.h"
44 #include "fma-match-list.h"
46 /* private interface data
48 struct _FMAIBasenamesTabInterfacePrivate
{
49 void *empty
; /* so that gcc -pedantic is happy */
52 /* the identifier of this notebook page in the Match dialog
54 #define ITAB_NAME "basenames"
56 /* data set against the instance
59 gboolean on_selection_change
;
63 #define IBASENAMES_TAB_PROP_DATA "fma-ibasenames-tab-data"
65 static guint st_initializations
= 0; /* interface initialization count */
67 static GType
register_type( void );
68 static void interface_base_init( FMAIBasenamesTabInterface
*klass
);
69 static void interface_base_finalize( FMAIBasenamesTabInterface
*klass
);
70 static void initialize_gtk( FMAIBasenamesTab
*instance
);
71 static void initialize_window( FMAIBasenamesTab
*instance
);
72 static void on_tree_selection_changed( FMATreeView
*tview
, GList
*selected_items
, FMAIBasenamesTab
*instance
);
73 static void on_matchcase_toggled( GtkToggleButton
*button
, FMAIBasenamesTab
*instance
);
74 static GSList
*get_basenames( void *context
);
75 static void set_basenames( void *context
, GSList
*filters
);
76 static IBasenamesData
*get_ibasenames_data( FMAIBasenamesTab
*instance
);
77 static void on_instance_finalized( gpointer user_data
, FMAIBasenamesTab
*instance
);
80 fma_ibasenames_tab_get_type( void )
82 static GType iface_type
= 0;
85 iface_type
= register_type();
94 static const gchar
*thisfn
= "fma_ibasenames_tab_register_type";
97 static const GTypeInfo info
= {
98 sizeof( FMAIBasenamesTabInterface
),
99 ( GBaseInitFunc
) interface_base_init
,
100 ( GBaseFinalizeFunc
) interface_base_finalize
,
109 g_debug( "%s", thisfn
);
111 type
= g_type_register_static( G_TYPE_INTERFACE
, "FMAIBasenamesTab", &info
, 0 );
113 g_type_interface_add_prerequisite( type
, GTK_TYPE_APPLICATION_WINDOW
);
119 interface_base_init( FMAIBasenamesTabInterface
*klass
)
121 static const gchar
*thisfn
= "fma_ibasenames_tab_interface_base_init";
123 if( !st_initializations
){
125 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
127 klass
->private = g_new0( FMAIBasenamesTabInterfacePrivate
, 1 );
130 st_initializations
+= 1;
134 interface_base_finalize( FMAIBasenamesTabInterface
*klass
)
136 static const gchar
*thisfn
= "fma_ibasenames_tab_interface_base_finalize";
138 st_initializations
-= 1;
140 if( !st_initializations
){
142 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
144 g_free( klass
->private );
149 * fma_ibasenames_tab_init:
150 * @instance: this #FMAIBasenamesTab instance.
152 * Initialize the interface
153 * Connect to #BaseWindow signals
156 fma_ibasenames_tab_init( FMAIBasenamesTab
*instance
)
158 static const gchar
*thisfn
= "fma_ibasenames_tab_init";
159 IBasenamesData
*data
;
161 g_return_if_fail( FMA_IS_IBASENAMES_TAB( instance
));
163 g_debug( "%s: instance=%p (%s)",
165 ( void * ) instance
, G_OBJECT_TYPE_NAME( instance
));
167 fma_main_tab_init( FMA_MAIN_WINDOW( instance
), TAB_BASENAMES
);
168 initialize_gtk( instance
);
169 initialize_window( instance
);
171 data
= get_ibasenames_data( instance
);
172 data
->on_selection_change
= FALSE
;
174 g_object_weak_ref( G_OBJECT( instance
), ( GWeakNotify
) on_instance_finalized
, NULL
);
178 * on_base_initialize_gtk:
179 * @window: this #FMAIBasenamesTab instance.
181 * Initializes the tab widget at initial load.
184 initialize_gtk( FMAIBasenamesTab
*instance
)
186 static const gchar
*thisfn
= "fma_ibasenames_tab_initialize_gtk";
188 g_return_if_fail( instance
&& FMA_IS_IBASENAMES_TAB( instance
));
190 g_debug( "%s: instance=%p (%s)",
191 thisfn
, ( void * ) instance
, G_OBJECT_TYPE_NAME( instance
));
193 fma_match_list_init_with_args(
194 FMA_MAIN_WINDOW( instance
),
197 fma_gtk_utils_find_widget_by_name( GTK_CONTAINER( instance
), "BasenamesTreeView" ),
198 fma_gtk_utils_find_widget_by_name( GTK_CONTAINER( instance
), "AddBasenameButton" ),
199 fma_gtk_utils_find_widget_by_name( GTK_CONTAINER( instance
), "RemoveBasenameButton" ),
200 ( pget_filters
) get_basenames
,
201 ( pset_filters
) set_basenames
,
204 MATCH_LIST_MUST_MATCH_ONE_OF
,
205 _( "Basename filter" ),
210 * on_base_initialize_window:
211 * @window: this #FMAIBasenamesTab instance.
213 * Initializes the tab widget at each time the widget will be displayed.
214 * Connect signals and setup runtime values.
217 initialize_window( FMAIBasenamesTab
*instance
)
219 static const gchar
*thisfn
= "fma_ibasenames_tab_initialize_window";
222 g_return_if_fail( instance
&& FMA_IS_IBASENAMES_TAB( instance
));
224 g_debug( "%s: instance=%p (%s)",
225 thisfn
, ( void * ) instance
, G_OBJECT_TYPE_NAME( instance
));
227 tview
= fma_main_window_get_items_view( FMA_MAIN_WINDOW( instance
));
229 tview
, TREE_SIGNAL_SELECTION_CHANGED
,
230 G_CALLBACK( on_tree_selection_changed
), instance
);
232 fma_gtk_utils_connect_widget_by_name(
233 GTK_CONTAINER( instance
), "BasenamesMatchcaseButton",
234 "toggled", G_CALLBACK( on_matchcase_toggled
), instance
);
238 on_tree_selection_changed( FMATreeView
*tview
, GList
*selected_items
, FMAIBasenamesTab
*instance
)
240 FMAIContext
*context
;
243 GtkToggleButton
*matchcase_button
;
245 IBasenamesData
*data
;
247 g_object_get( G_OBJECT( instance
),
248 MAIN_PROP_CONTEXT
, &context
, MAIN_PROP_EDITABLE
, &editable
,
251 enable_tab
= ( context
!= NULL
);
252 fma_main_tab_enable_page( FMA_MAIN_WINDOW( instance
), TAB_BASENAMES
, enable_tab
);
254 data
= get_ibasenames_data( FMA_IBASENAMES_TAB( instance
));
255 data
->on_selection_change
= TRUE
;
257 matchcase_button
= GTK_TOGGLE_BUTTON( fma_gtk_utils_find_widget_by_name( GTK_CONTAINER( instance
), "BasenamesMatchcaseButton" ));
258 matchcase
= context
? fma_object_get_matchcase( context
) : FALSE
;
259 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( matchcase_button
), matchcase
);
260 base_gtk_utils_set_editable( G_OBJECT( matchcase_button
), editable
);
262 data
->on_selection_change
= FALSE
;
266 on_matchcase_toggled( GtkToggleButton
*button
, FMAIBasenamesTab
*instance
)
268 FMAIContext
*context
;
271 IBasenamesData
*data
;
273 data
= get_ibasenames_data( FMA_IBASENAMES_TAB( instance
));
275 if( !data
->on_selection_change
){
276 g_object_get( G_OBJECT( instance
),
277 MAIN_PROP_CONTEXT
, &context
, MAIN_PROP_EDITABLE
, &editable
,
281 matchcase
= gtk_toggle_button_get_active( button
);
284 fma_object_set_matchcase( context
, matchcase
);
285 g_signal_emit_by_name( G_OBJECT( instance
), MAIN_SIGNAL_ITEM_UPDATED
, context
, 0 );
288 g_signal_handlers_block_by_func(( gpointer
) button
, on_matchcase_toggled
, instance
);
289 gtk_toggle_button_set_active( button
, !matchcase
);
290 g_signal_handlers_unblock_by_func(( gpointer
) button
, on_matchcase_toggled
, instance
);
297 get_basenames( void *context
)
299 return( fma_object_get_basenames( context
));
303 set_basenames( void *context
, GSList
*filters
)
305 fma_object_set_basenames( context
, filters
);
308 static IBasenamesData
*
309 get_ibasenames_data( FMAIBasenamesTab
*instance
)
311 IBasenamesData
*data
;
313 data
= ( IBasenamesData
* ) g_object_get_data( G_OBJECT( instance
), IBASENAMES_TAB_PROP_DATA
);
316 data
= g_new0( IBasenamesData
, 1 );
317 g_object_set_data( G_OBJECT( instance
), IBASENAMES_TAB_PROP_DATA
, data
);
324 on_instance_finalized( gpointer user_data
, FMAIBasenamesTab
*instance
)
326 static const gchar
*thisfn
= "fma_ibasenames_tab_on_instance_finalized";
327 IBasenamesData
*data
;
329 g_debug( "%s: instance=%p, user_data=%p", thisfn
, ( void * ) instance
, ( void * ) user_data
);
331 data
= get_ibasenames_data( instance
);