[nautilus-actions] Adapt export assistant to Gtk3
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Adapt export assistant to Gtk3
- Date: Sun, 27 Nov 2011 19:58:56 +0000 (UTC)
commit 54345700b31cf04782dd70bb8b0ee46f522e27c1
Author: Pierre Wieser <pwieser trychlos org>
Date: Sun Nov 27 18:49:03 2011 +0100
Adapt export assistant to Gtk3
As we need to get children widgets from the assistant pages, we also need to wait that
these pages be actually realized.
ChangeLog | 16 +++
src/nact/nact-assistant-export.c | 58 ++++++++----
src/nact/nact-main-window.c | 27 ++++--
src/nact/nact-sort-buttons.c | 6 +-
src/nact/nact-tree-view.c | 192 ++++++++++++++++++++++++++------------
src/nact/nact-tree-view.h | 8 +-
6 files changed, 214 insertions(+), 93 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f307cab..7261061 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2011-11-27 Pierre Wieser <pwieser trychlos org>
+ * nact/nact-tree-view.h:
+ * nact/nact-tree-view.c: Define parent property.
+
+ * nact/nact-tree-view.c (on_tree_view_realized):
+ Delay all signal connection until the widget be actually realized.
+
+ * src/nact/nact-sort-buttons.c (on_base_initialize_buttons):
+ Delay the connection to the NactTreeView signal until we are sure the
+ widget is realized.
+
+ * src/nact/nact-main-window.c (on_base_initialize_gtk_toplevel):
+ Delay the initialization of the NactTreeView until the Gtk toplevel has
+ been loaded from XML Glade file.
+
+ * src/nact/nact-assistant-export.c: Adapt to gtk3.
+
* src/nact/nact-export-format.c (nact_export_format_init_display):
Remove the useless intermediate GtkGrid.
diff --git a/src/nact/nact-assistant-export.c b/src/nact/nact-assistant-export.c
index 3c4ac2f..37cfcea 100644
--- a/src/nact/nact-assistant-export.c
+++ b/src/nact/nact-assistant-export.c
@@ -38,6 +38,7 @@
#include <api/na-core-utils.h>
#include <api/na-object-api.h>
+#include <core/na-gtk-utils.h>
#include <core/na-iprefs.h>
#include <core/na-exporter.h>
@@ -122,6 +123,7 @@ static void on_folder_selection_changed( GtkFileChooser *chooser, gpo
static void assist_initial_load_format( NactAssistantExport *window, GtkAssistant *assistant );
static void assist_runtime_init_format( NactAssistantExport *window, GtkAssistant *assistant );
static NAExportFormat *get_export_format( NactAssistantExport *window );
+static GtkWidget *get_box_container( NactAssistantExport *window );
static void assistant_prepare( BaseAssistant *window, GtkAssistant *assistant, GtkWidget *page );
static void assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, GtkWidget *page );
@@ -291,8 +293,6 @@ nact_assistant_export_run( BaseWindow *main_window )
BASE_PROP_WARN_ON_ESCAPE, esc_confirm,
NULL );
- assistant->private->items_view = nact_tree_view_new( BASE_WINDOW( assistant ), "ActionsList", TREE_MODE_SELECTION );
-
base_window_run( BASE_WINDOW( assistant ));
}
@@ -300,6 +300,7 @@ static void
on_base_initialize_gtk_toplevel( NactAssistantExport *dialog, GtkAssistant *assistant, gpointer user_data )
{
static const gchar *thisfn = "nact_assistant_export_on_base_initialize_gtk_toplevel";
+ GtkWidget *page;
gboolean are_locked, mandatory;
g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( dialog ));
@@ -308,6 +309,11 @@ on_base_initialize_gtk_toplevel( NactAssistantExport *dialog, GtkAssistant *assi
g_debug( "%s: dialog=%p, assistant=%p, user_data=%p",
thisfn, ( void * ) dialog, ( void * ) assistant, ( void * ) user_data );
+ page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_ACTIONS_SELECTION );
+ dialog->private->items_view =
+ nact_tree_view_new( BASE_WINDOW( dialog ),
+ GTK_CONTAINER( page ), "ActionsList", TREE_MODE_SELECTION );
+
are_locked = na_settings_get_boolean( NA_IPREFS_ADMIN_PREFERENCES_LOCKED, NULL, &mandatory );
dialog->private->preferences_locked = are_locked && mandatory;
@@ -327,11 +333,11 @@ on_base_initialize_base_window( NactAssistantExport *dialog, gpointer user_data
if( !dialog->private->dispose_has_run ){
g_debug( "%s: dialog=%p, user_data=%p", thisfn, ( void * ) dialog, ( void * ) user_data );
- assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( dialog )));
-
base_window_signal_connect( BASE_WINDOW( dialog ),
G_OBJECT( dialog ), TREE_SIGNAL_SELECTION_CHANGED, G_CALLBACK( on_tree_view_selection_changed ));
+ assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( dialog )));
+
assist_runtime_init_intro( dialog, assistant );
assist_runtime_init_actions_list( dialog, assistant );
assist_runtime_init_target_folder( dialog, assistant );
@@ -448,7 +454,9 @@ assist_runtime_init_target_folder( NactAssistantExport *window, GtkAssistant *as
static GtkFileChooser *
get_folder_chooser( NactAssistantExport *window )
{
- return( GTK_FILE_CHOOSER( base_window_get_widget( BASE_WINDOW( window ), "ExportFolderChooser" )));
+ GtkAssistant *assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( window )));
+ GtkWidget *page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FOLDER_SELECTION );
+ return( GTK_FILE_CHOOSER( na_gtk_utils_search_for_child_widget( GTK_CONTAINER( page ), "ExportFolderChooser" )));
}
/*
@@ -491,6 +499,8 @@ on_folder_selection_changed( GtkFileChooser *chooser, gpointer user_data )
gtk_assistant_set_page_complete( assistant, content, enabled );
gtk_assistant_update_buttons_state( assistant );
}
+
+ g_debug( "%s: quitting", thisfn );
}
static void
@@ -502,7 +512,8 @@ assist_initial_load_format( NactAssistantExport *window, GtkAssistant *assistant
application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
updater = nact_application_get_updater( application );
- container = base_window_get_widget( BASE_WINDOW( window ), "AssistantExportFormatVBox" );
+ container = get_box_container( window );
+
nact_export_format_init_display( container,
NA_PIVOT( updater ), EXPORT_FORMAT_DISPLAY_ASSISTANT, !window->private->preferences_locked );
}
@@ -510,18 +521,20 @@ assist_initial_load_format( NactAssistantExport *window, GtkAssistant *assistant
static void
assist_runtime_init_format( NactAssistantExport *window, GtkAssistant *assistant )
{
- GtkWidget *content;
GtkWidget *container;
+ GtkWidget *page;
GQuark format;
gboolean mandatory;
format = na_iprefs_get_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, &mandatory );
-
- container = base_window_get_widget( BASE_WINDOW( window ), "AssistantExportFormatVBox" );
+ container = get_box_container( window );
+#ifdef NA_MAINTAINER_MODE
+ na_gtk_utils_dump_children( GTK_CONTAINER( container ));
+#endif
nact_export_format_select( container, !mandatory, format );
- content = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FORMAT_SELECTION );
- gtk_assistant_set_page_complete( assistant, content, TRUE );
+ page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FORMAT_SELECTION );
+ gtk_assistant_set_page_complete( assistant, page, TRUE );
}
static NAExportFormat *
@@ -530,17 +543,26 @@ get_export_format( NactAssistantExport *window )
GtkWidget *container;
NAExportFormat *format;
- container = base_window_get_widget( BASE_WINDOW( window ), "AssistantExportFormatVBox" );
+ container = get_box_container( window );
format = nact_export_format_get_selected( container );
return( format );
}
+static GtkWidget *
+get_box_container( NactAssistantExport *window )
+{
+ GtkAssistant *assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( window )));
+ GtkWidget *page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FORMAT_SELECTION );
+ return( na_gtk_utils_search_for_child_widget( GTK_CONTAINER( page ), "AssistantExportFormatVBox" ));
+}
+
static void
assistant_prepare( BaseAssistant *window, GtkAssistant *assistant, GtkWidget *page )
{
- /*static const gchar *thisfn = "nact_assistant_export_on_prepare";
- g_debug( "%s: window=%p, assistant=%p, page=%p", thisfn, window, assistant, page );*/
+ static const gchar *thisfn = "nact_assistant_export_on_prepare";
+
+ g_debug( "%s: window=%p, assistant=%p, page=%p", thisfn, window, assistant, page );
GtkAssistantPageType type = gtk_assistant_get_page_type( assistant, page );
@@ -587,7 +609,7 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
/* i18n: all exported actions go to one destination folder */
g_string_append_printf( text,
- "\n\n<b>%s</b>\n\n\t%s", _( "Into the destination folder:" ), window->private->uri );
+ "\n<b>%s</b>\n\n\t%s\n", _( "Into the destination folder:" ), window->private->uri );
label11 = NULL;
label21 = NULL;
@@ -597,13 +619,13 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
na_iprefs_set_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, na_export_format_get_quark( format ));
label12 = na_core_utils_str_remove_char( label11, "_" );
label22 = na_core_utils_str_add_prefix( "\t", label21 );
- g_string_append_printf( text, "\n\n<b>%s</b>\n\n%s", label12, label22 );
+ g_string_append_printf( text, "\n<b>%s</b>\n\n%s", label12, label22 );
g_free( label22 );
g_free( label21 );
g_free( label12 );
g_free( label11 );
- confirm_label = GTK_LABEL( base_window_get_widget( BASE_WINDOW( window ), "AssistantExportConfirmLabel" ));
+ confirm_label = GTK_LABEL( na_gtk_utils_search_for_child_widget( GTK_CONTAINER( page ), "AssistantExportConfirmLabel" ));
gtk_label_set_markup( confirm_label, text->str );
g_string_free( text, TRUE );
@@ -729,7 +751,7 @@ assist_prepare_exportdone( NactAssistantExport *window, GtkAssistant *assistant,
text = tmp;
}
- summary_textview = GTK_TEXT_VIEW( base_window_get_widget( BASE_WINDOW( window ), "AssistantExportSummaryTextView" ));
+ summary_textview = GTK_TEXT_VIEW( na_gtk_utils_search_for_child_widget( GTK_CONTAINER( page ), "AssistantExportSummaryTextView" ));
summary_buffer = gtk_text_view_get_buffer( summary_textview );
gtk_text_buffer_set_text( summary_buffer, text, -1 );
g_free( text );
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 33654ce..782004c 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -671,16 +671,6 @@ instance_constructed( GObject *window )
base_window_signal_connect( BASE_WINDOW( window ),
G_OBJECT( window ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, G_CALLBACK( on_tab_updatable_item_updated ));
- /* create the tree view which will create itself its own tree model
- */
- self->private->items_view = nact_tree_view_new( BASE_WINDOW( window ), "ActionsList", TREE_MODE_EDITION );
-
- base_window_signal_connect( BASE_WINDOW( window ),
- G_OBJECT( window ), TREE_SIGNAL_SELECTION_CHANGED, G_CALLBACK( on_tree_view_selection_changed ));
-
- base_window_signal_connect( BASE_WINDOW( window ),
- G_OBJECT( window ), TREE_SIGNAL_MODIFIED_STATUS_CHANGED, G_CALLBACK( on_tree_view_modified_status_changed ));
-
/* create the menubar and other convenience objects
*/
self->private->menubar = nact_menubar_new( BASE_WINDOW( window ));
@@ -790,6 +780,7 @@ static void
on_base_initialize_gtk_toplevel( NactMainWindow *window, GtkWindow *toplevel, gpointer user_data )
{
static const gchar *thisfn = "nact_main_window_on_base_initialize_gtk_toplevel";
+ GtkWidget *tree_parent;
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
@@ -797,6 +788,22 @@ on_base_initialize_gtk_toplevel( NactMainWindow *window, GtkWindow *toplevel, gp
g_debug( "%s: window=%p, toplevel=%p, user_data=%p",
thisfn, ( void * ) window, ( void * ) toplevel, ( void * ) user_data );
+ /* create the tree view which will create itself its own tree model
+ */
+ tree_parent = base_window_get_widget( BASE_WINDOW( window ), "MainVBox" );
+ g_debug( "%s: tree_parent=%p (%s)", thisfn, ( void * ) tree_parent, G_OBJECT_TYPE_NAME( tree_parent ));
+ window->private->items_view = nact_tree_view_new(
+ BASE_WINDOW( window ), GTK_CONTAINER( tree_parent ),
+ "ActionsList", TREE_MODE_EDITION );
+
+ base_window_signal_connect( BASE_WINDOW( window ),
+ G_OBJECT( window ), TREE_SIGNAL_SELECTION_CHANGED, G_CALLBACK( on_tree_view_selection_changed ));
+
+ base_window_signal_connect( BASE_WINDOW( window ),
+ G_OBJECT( window ), TREE_SIGNAL_MODIFIED_STATUS_CHANGED, G_CALLBACK( on_tree_view_modified_status_changed ));
+
+ /* then initialize notebook
+ */
nact_iaction_tab_initial_load_toplevel( NACT_IACTION_TAB( window ));
nact_icommand_tab_initial_load_toplevel( NACT_ICOMMAND_TAB( window ));
nact_ibasenames_tab_initial_load_toplevel( NACT_IBASENAMES_TAB( window ));
diff --git a/src/nact/nact-sort-buttons.c b/src/nact/nact-sort-buttons.c
index 4758707..e833b43 100644
--- a/src/nact/nact-sort-buttons.c
+++ b/src/nact/nact-sort-buttons.c
@@ -223,9 +223,6 @@ nact_sort_buttons_new( BaseWindow *window )
base_window_signal_connect( window,
G_OBJECT( window ), BASE_SIGNAL_INITIALIZE_WINDOW, G_CALLBACK( on_base_initialize_buttons ));
- base_window_signal_connect( window,
- G_OBJECT( window ), TREE_SIGNAL_COUNT_CHANGED, G_CALLBACK( on_tree_view_count_changed ));
-
g_object_set_data( G_OBJECT( window ), WINDOW_DATA_SORT_BUTTONS, obj );
obj->private->window = window;
@@ -258,6 +255,9 @@ on_base_initialize_buttons( BaseWindow *window, gpointer user_data )
g_debug( "%s: window=%p, user_data=%p", thisfn, ( void * ) window, ( void * ) user_data );
+ base_window_signal_connect( window,
+ G_OBJECT( window ), TREE_SIGNAL_COUNT_CHANGED, G_CALLBACK( on_tree_view_count_changed ));
+
sort_buttons = NACT_SORT_BUTTONS( g_object_get_data( G_OBJECT( window ), WINDOW_DATA_SORT_BUTTONS ));
for( i = 0 ; st_toggle_group[i].btn_name ; ++i ){
diff --git a/src/nact/nact-tree-view.c b/src/nact/nact-tree-view.c
index 738cdce..96a7454 100644
--- a/src/nact/nact-tree-view.c
+++ b/src/nact/nact-tree-view.c
@@ -36,6 +36,8 @@
#include <api/na-object-api.h>
+#include <core/na-gtk-utils.h>
+
#include "base-keysyms.h"
#include "base-marshal.h"
#include "nact-application.h"
@@ -52,18 +54,33 @@ struct _NactTreeViewClassPrivate {
/* private instance data
*/
struct _NactTreeViewPrivate {
- gboolean dispose_has_run;
+ gboolean dispose_has_run;
/* properties set at instanciation time
*/
- BaseWindow *window;
- gchar *widget_name;
- guint mode;
+ BaseWindow *window;
+ GtkContainer *parent;
+ gchar *widget_name;
+ guint mode;
/* runtime data
+ *
+ * Rationale:
+ * In Gtk2, we used to nact_tree_view_new() from
+ * nact_main_window:on_instance_constructed().
+ * This let us connect to on-base-initialize-gtk signal before it was
+ * emitted, and so initialize the treeview on the handler.
+ * With Gtk3, we have to wait until the Gtk hierarchy of NactMainWindow
+ * be actually built in order to be able to access to the embedded
+ * GtkTreeView. As a consequence, nact_tree_view_new() has to be delayed
+ * until nact_main_window_on_initialize_gtk().
+ * And so we no more can rely on the on-base-initialize-gtk signal to
+ * initialize the view. So force a call to the handler from
+ * on_base_initialize_view() handler.
*/
- GtkTreeView *tree_view;
- gboolean notify_allowed;
+ GtkTreeView *tree_view;
+ gboolean notify_allowed;
+ gboolean gtk_initialized;
};
/* instance properties
@@ -72,6 +89,7 @@ enum {
TREE_PROP_0,
TREE_PROP_WINDOW_ID,
+ TREE_PROP_PARENT_ID,
TREE_PROP_WIDGET_NAME_ID,
TREE_PROP_MODE_ID,
TREE_PROP_NOTIFY_ALLOWED_ID,
@@ -110,37 +128,39 @@ typedef gboolean ( *FnIterOnSelection )( NactTreeView *, GtkTreeModel *, GtkTree
static gint st_signals[ LAST_SIGNAL ] = { 0 };
static GObjectClass *st_parent_class = NULL;
-static GType register_type( void );
-static void class_init( NactTreeViewClass *klass );
-static void tree_ieditable_iface_init( NactTreeIEditableInterface *iface );
-static void instance_init( GTypeInstance *instance, gpointer klass );
-static void instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
-static void instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
-static void instance_constructed( GObject *object );
-static void instance_dispose( GObject *application );
-static void instance_finalize( GObject *application );
-
-static void on_base_initialize_gtk( BaseWindow *window, GtkWindow *toplevel, gpointer user_data );
-static void on_base_initialize_view( BaseWindow *window, gpointer user_data );
-static void on_base_all_widgets_showed( BaseWindow *window, gpointer user_data );
-static gboolean on_button_press_event( GtkWidget *widget, GdkEventButton *event, BaseWindow *window );
-static gboolean on_focus_in( GtkWidget *widget, GdkEventFocus *event, BaseWindow *window );
-static gboolean on_focus_out( GtkWidget *widget, GdkEventFocus *event, BaseWindow *window );
-static gboolean on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, BaseWindow *window );
-static void on_selection_changed( GtkTreeSelection *selection, BaseWindow *window );
-static void on_selection_changed_cleanup_handler( BaseWindow *window, GList *selected_items );
-static void clear_selection( NactTreeView *view );
-static void display_label( GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, NactTreeView *view );
-static void extend_selection_to_children( NactTreeView *view, GtkTreeModel *model, GtkTreeIter *parent );
-static GList *get_selected_items( NactTreeView *view );
-static void iter_on_selection( NactTreeView *view, FnIterOnSelection fn_iter, gpointer user_data );
-static void navigate_to_child( NactTreeView *view );
-static void navigate_to_parent( NactTreeView *view );
-static void open_popup( BaseWindow *window, GdkEventButton *event );
-static void select_row_at_path_by_string( NactTreeView *view, const gchar *path );
-static void toggle_collapse( NactTreeView *view );
-static gboolean toggle_collapse_iter( NactTreeView *view, GtkTreeModel *model, GtkTreeIter *iter, NAObject *object, gpointer user_data );
-static void toggle_collapse_row( GtkTreeView *treeview, GtkTreePath *path, guint *toggle );
+static GType register_type( void );
+static void class_init( NactTreeViewClass *klass );
+static void tree_ieditable_iface_init( NactTreeIEditableInterface *iface );
+static void instance_init( GTypeInstance *instance, gpointer klass );
+static void instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
+static void instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
+static void instance_constructed( GObject *object );
+static void instance_dispose( GObject *application );
+static void instance_finalize( GObject *application );
+
+static void on_base_initialize_gtk( BaseWindow *window, GtkWindow *toplevel, gpointer user_data );
+static void on_base_initialize_view( BaseWindow *window, gpointer user_data );
+static void on_base_all_widgets_showed( BaseWindow *window, gpointer user_data );
+static gboolean on_button_press_event( GtkWidget *widget, GdkEventButton *event, BaseWindow *window );
+static gboolean on_focus_in( GtkWidget *widget, GdkEventFocus *event, BaseWindow *window );
+static gboolean on_focus_out( GtkWidget *widget, GdkEventFocus *event, BaseWindow *window );
+static gboolean on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, BaseWindow *window );
+static void on_selection_changed( GtkTreeSelection *selection, BaseWindow *window );
+static void on_selection_changed_cleanup_handler( BaseWindow *window, GList *selected_items );
+static void on_tree_view_realized( GtkWidget *treeview, BaseWindow *window );
+static void clear_selection( NactTreeView *view );
+static void display_label( GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, NactTreeView *view );
+static void extend_selection_to_children( NactTreeView *view, GtkTreeModel *model, GtkTreeIter *parent );
+static GList *get_selected_items( NactTreeView *view );
+static GtkWidget *get_tree_view( NactTreeView *items_view );
+static void iter_on_selection( NactTreeView *view, FnIterOnSelection fn_iter, gpointer user_data );
+static void navigate_to_child( NactTreeView *view );
+static void navigate_to_parent( NactTreeView *view );
+static void open_popup( BaseWindow *window, GdkEventButton *event );
+static void select_row_at_path_by_string( NactTreeView *view, const gchar *path );
+static void toggle_collapse( NactTreeView *view );
+static gboolean toggle_collapse_iter( NactTreeView *view, GtkTreeModel *model, GtkTreeIter *iter, NAObject *object, gpointer user_data );
+static void toggle_collapse_row( GtkTreeView *treeview, GtkTreePath *path, guint *toggle );
GType
nact_tree_view_get_type( void )
@@ -209,13 +229,25 @@ class_init( NactTreeViewClass *klass )
TREE_PROP_WINDOW,
/* i18n: this is a class name and should not be translated */
_( "BaseWindow" ),
+ /* i18n: NactTreeView property long description */
_( "The BaseWindow parent" ),
G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
+ g_object_class_install_property( object_class, TREE_PROP_PARENT_ID,
+ g_param_spec_pointer(
+ TREE_PROP_PARENT,
+ /* i18n: NactTreeView property short description */
+ _( "Container" ),
+ /* i18n: NactTreeView property long description */
+ _( "A GtkContainer which contains the GtkTreeView widget" ),
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
+
g_object_class_install_property( object_class, TREE_PROP_WIDGET_NAME_ID,
g_param_spec_string(
TREE_PROP_WIDGET_NAME,
+ /* i18n: NactTreeView property short description */
_( "Widget name" ),
+ /* i18n: NactTreeView property long description */
_( "The name of GtkTreeView widget" ),
"",
G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
@@ -223,7 +255,9 @@ class_init( NactTreeViewClass *klass )
g_object_class_install_property( object_class, TREE_PROP_MODE_ID,
g_param_spec_uint(
TREE_PROP_MODE,
+ /* i18n: NactTreeView property short description */
_( "Management mode" ),
+ /* i18n: NactTreeView property long description */
_( "Management mode of the tree view, selection or edition" ),
0,
TREE_MODE_N_MODES,
@@ -233,7 +267,9 @@ class_init( NactTreeViewClass *klass )
g_object_class_install_property( object_class, TREE_PROP_NOTIFY_ALLOWED_ID,
g_param_spec_boolean(
TREE_PROP_NOTIFY_ALLOWED,
+ /* i18n: NactTreeView property short description */
_( "Allow notify" ),
+ /* i18n: NactTreeView property loong description */
_( "Whether notifications are allowed" ),
FALSE,
G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE ));
@@ -449,6 +485,7 @@ instance_init( GTypeInstance *instance, gpointer klass )
self->private = g_new0( NactTreeViewPrivate, 1 );
self->private->dispose_has_run = FALSE;
+ self->private->gtk_initialized = FALSE;
}
static void
@@ -466,6 +503,10 @@ instance_get_property( GObject *object, guint property_id, GValue *value, GParam
g_value_set_pointer( value, self->private->window );
break;
+ case TREE_PROP_PARENT_ID:
+ g_value_set_pointer( value, self->private->parent );
+ break;
+
case TREE_PROP_WIDGET_NAME_ID:
g_value_set_string( value, self->private->widget_name );
break;
@@ -500,6 +541,10 @@ instance_set_property( GObject *object, guint property_id, const GValue *value,
self->private->window = g_value_get_pointer( value );
break;
+ case TREE_PROP_PARENT_ID:
+ self->private->parent = g_value_get_pointer( value );
+ break;
+
case TREE_PROP_WIDGET_NAME_ID:
g_free( self->private->widget_name );
self->private->widget_name = g_value_dup_string( value );
@@ -608,6 +653,7 @@ instance_finalize( GObject *instance )
/**
* nact_tree_view_new:
* @window: the BaseWindow which embeds the tree view.
+ * @parent: the GtkContainer parent of the tree view.
* @treeview_name: the GtkTreeView widget name.
* @mode: management mode.
*
@@ -616,16 +662,21 @@ instance_finalize( GObject *instance )
* auto-destroys itself at @window finalization.
*/
NactTreeView *
-nact_tree_view_new( BaseWindow *window, const gchar *treeview_name, NactTreeMode mode )
+nact_tree_view_new( BaseWindow *window, GtkContainer *parent, const gchar *treeview_name, NactTreeMode mode )
{
NactTreeView *view;
view = g_object_new( NACT_TREE_VIEW_TYPE,
TREE_PROP_WINDOW, window,
+ TREE_PROP_PARENT, parent,
TREE_PROP_WIDGET_NAME, treeview_name,
TREE_PROP_MODE, mode,
NULL );
+#ifdef NA_MAINTAINER_MODE
+ na_gtk_utils_dump_children( parent );
+#endif
+
return( view );
}
@@ -648,11 +699,11 @@ on_base_initialize_gtk( BaseWindow *window, GtkWindow *toplevel, gpointer user_d
thisfn, ( void * ) window, G_OBJECT_TYPE_NAME( window ),
( void * ) toplevel, G_OBJECT_TYPE_NAME( toplevel ), ( void * ) user_data );
- treeview = GTK_TREE_VIEW( base_window_get_widget( window, items_view->private->widget_name ));
+ treeview = GTK_TREE_VIEW( get_tree_view( items_view ));
nact_tree_model_new( window, treeview, items_view->private->mode );
/* associates the ItemsView to the label */
- label = base_window_get_widget( window, "ActionsListLabel" );
+ label = na_gtk_utils_search_for_child_widget( items_view->private->parent, "ActionsListLabel" );
gtk_label_set_mnemonic_widget( GTK_LABEL( label ), GTK_WIDGET( treeview ));
/* create visible columns on the tree view
@@ -689,6 +740,8 @@ on_base_initialize_gtk( BaseWindow *window, GtkWindow *toplevel, gpointer user_d
gtk_tree_view_column_set_cell_data_func(
column, renderer, ( GtkTreeCellDataFunc ) display_label, items_view, NULL );
}
+
+ items_view->private->gtk_initialized = TRUE;
}
}
@@ -702,11 +755,15 @@ on_base_initialize_view( BaseWindow *window, gpointer user_data )
items_view = NACT_TREE_VIEW( g_object_get_data( G_OBJECT( window ), WINDOW_DATA_TREE_VIEW ));
+ if( !items_view->private->gtk_initialized ){
+ on_base_initialize_gtk( window, base_window_get_gtk_toplevel( window ), NULL );
+ }
+
if( !items_view->private->dispose_has_run ){
g_debug( "%s: window=%p (%s), user_data=%p",
thisfn, ( void * ) window, G_OBJECT_TYPE_NAME( window ), ( void * ) user_data );
- treeview = GTK_TREE_VIEW( base_window_get_widget( window, items_view->private->widget_name ));
+ treeview = GTK_TREE_VIEW( get_tree_view( items_view ));
items_view->private->tree_view = treeview;
/* monitors the selection */
@@ -714,20 +771,10 @@ on_base_initialize_view( BaseWindow *window, gpointer user_data )
base_window_signal_connect( window,
G_OBJECT( selection ), "changed", G_CALLBACK( on_selection_changed ));
- /* expand/collapse with the keyboard */
- base_window_signal_connect( window,
- G_OBJECT( treeview ), "key-press-event", G_CALLBACK( on_key_pressed_event ));
-
- /* monitors whether the focus is on the view */
- base_window_signal_connect( window,
- G_OBJECT( treeview ), "focus-in-event", G_CALLBACK( on_focus_in ));
-
- base_window_signal_connect( window,
- G_OBJECT( treeview ), "focus-out-event", G_CALLBACK( on_focus_out ));
-
- /* monitors mouse events */
+ /* delay all other signal connections until the widget be realized
+ */
base_window_signal_connect( window,
- G_OBJECT( treeview ), "button-press-event", G_CALLBACK( on_button_press_event ));
+ G_OBJECT( treeview ), "realize", G_CALLBACK( on_tree_view_realized ));
if( items_view->private->mode == TREE_MODE_EDITION ){
nact_tree_ieditable_initialize( NACT_TREE_IEDITABLE( items_view ), treeview, window );
@@ -746,11 +793,6 @@ on_base_all_widgets_showed( BaseWindow *window, gpointer user_data )
if( !items_view->private->dispose_has_run ){
g_debug( "%s: window=%p (%s), user_data=%p",
thisfn, ( void * ) window, G_OBJECT_TYPE_NAME( window ), ( void * ) user_data );
-
- /* force the treeview to have the focus at start
- * and select the first row if it exists
- */
- gtk_widget_grab_focus( GTK_WIDGET( items_view->private->tree_view ));
}
}
@@ -858,6 +900,32 @@ on_selection_changed_cleanup_handler( BaseWindow *window, GList *selected_items
na_object_free_items( selected_items );
}
+static void
+on_tree_view_realized( GtkWidget *treeview, BaseWindow *window )
+{
+ g_debug( "nact_tree_view_on_tree_view_realized" );
+
+ /* expand/collapse with the keyboard */
+ base_window_signal_connect( window,
+ G_OBJECT( treeview ), "key-press-event", G_CALLBACK( on_key_pressed_event ));
+
+ /* monitors whether the focus is on the view */
+ base_window_signal_connect( window,
+ G_OBJECT( treeview ), "focus-in-event", G_CALLBACK( on_focus_in ));
+
+ base_window_signal_connect( window,
+ G_OBJECT( treeview ), "focus-out-event", G_CALLBACK( on_focus_out ));
+
+ /* monitors mouse events */
+ base_window_signal_connect( window,
+ G_OBJECT( treeview ), "button-press-event", G_CALLBACK( on_button_press_event ));
+
+ /* force the treeview to have the focus at start
+ * and select the first row if it exists
+ */
+ gtk_widget_grab_focus( treeview );
+}
+
/**
* nact_tree_view_fill:
* @view: this #NactTreeView instance.
@@ -1222,6 +1290,12 @@ get_selected_items( NactTreeView *view )
return( g_list_reverse( items ));
}
+static GtkWidget *
+get_tree_view( NactTreeView *items_view )
+{
+ return( na_gtk_utils_search_for_child_widget( items_view->private->parent, items_view->private->widget_name ));
+}
+
static void
iter_on_selection( NactTreeView *view, FnIterOnSelection fn_iter, gpointer user_data )
{
diff --git a/src/nact/nact-tree-view.h b/src/nact/nact-tree-view.h
index ca90eee..ad38469 100644
--- a/src/nact/nact-tree-view.h
+++ b/src/nact/nact-tree-view.h
@@ -75,12 +75,14 @@ typedef struct {
* Properties defined by the NactTreeView class.
* They should be provided at object instantiation time.
*
- * @TREE_PROP_WINDOW: the BaseWindow parent.
- * @TREE_PROP_WIDGET_NAME: the widget name.
+ * @TREE_PROP_WINDOW: the BaseWindow.
+ * @TREE_PROP_PARENT: the widget which is parent of this tree view.
+ * @TREE_PROP_WIDGET_NAME: the tree view widget name.
* @TREE_PROP_MODE: management mode.
* @TREE_PROP_NOTIFY_ALLOWED: whether notifications are allowed.
*/
#define TREE_PROP_WINDOW "tree-prop-window"
+#define TREE_PROP_PARENT "tree-prop-parent"
#define TREE_PROP_WIDGET_NAME "tree-prop-widget-name"
#define TREE_PROP_MODE "tree-prop-mode"
#define TREE_PROP_NOTIFY_ALLOWED "tree-prop-notify-allowed"
@@ -122,7 +124,7 @@ enum {
GType nact_tree_view_get_type( void );
-NactTreeView *nact_tree_view_new( BaseWindow *window, const gchar *treeview_name, NactTreeMode mode );
+NactTreeView *nact_tree_view_new( BaseWindow *window, GtkContainer *parent, const gchar *treeview_name, NactTreeMode mode );
void nact_tree_view_fill ( NactTreeView *view, GList *items );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]