New function. (create_directory_tree): New function. (create_file_list):
2003-09-05 Federico Mena Quintero <federico@ximian.com> * gtkfilechooserimpldefault.c (create_filter): New function. (create_directory_tree): New function. (create_file_list): New function. (create_filename_entry): New function. (gtk_file_chooser_impl_default_constructor): Use the functions above rather than creating the whole file chooser megawidget here, for readability. This will also let us rearrange the user interface more easily.
This commit is contained in:
committed by
Federico Mena Quintero
parent
c725b0671b
commit
a9eaa49d88
@ -292,45 +292,16 @@ set_preview_widget (GtkFileChooserImplDefault *impl,
|
|||||||
update_preview_widget_visibility (impl);
|
update_preview_widget_visibility (impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GObject*
|
/* Creates the widgets for the filter option menu */
|
||||||
gtk_file_chooser_impl_default_constructor (GType type,
|
static GtkWidget *
|
||||||
guint n_construct_properties,
|
create_filter (GtkFileChooserImplDefault *impl)
|
||||||
GObjectConstructParam *construct_params)
|
|
||||||
{
|
{
|
||||||
GtkFileChooserImplDefault *impl;
|
|
||||||
GtkTreeViewColumn *column;
|
|
||||||
GtkCellRenderer *renderer;
|
|
||||||
GObject *object;
|
|
||||||
GtkWidget *table;
|
|
||||||
GtkWidget *hpaned;
|
|
||||||
GtkWidget *hbox;
|
GtkWidget *hbox;
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
GtkTreeSelection *selection;
|
|
||||||
#if 0
|
|
||||||
GList *focus_chain;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
object = parent_class->constructor (type,
|
|
||||||
n_construct_properties,
|
|
||||||
construct_params);
|
|
||||||
impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (object);
|
|
||||||
|
|
||||||
g_assert (impl->file_system);
|
|
||||||
|
|
||||||
gtk_widget_push_composite_child ();
|
|
||||||
|
|
||||||
table = gtk_table_new (3, 2, FALSE);
|
|
||||||
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
|
||||||
gtk_box_pack_start (GTK_BOX (impl), table, TRUE, TRUE, 0);
|
|
||||||
gtk_widget_show (table);
|
|
||||||
|
|
||||||
impl->filter_alignment = gtk_alignment_new (0.0, 0.5, 0.0, 1.0);
|
impl->filter_alignment = gtk_alignment_new (0.0, 0.5, 0.0, 1.0);
|
||||||
gtk_alignment_set_padding (GTK_ALIGNMENT (impl->filter_alignment), 0, 6, 0, 0);
|
gtk_alignment_set_padding (GTK_ALIGNMENT (impl->filter_alignment), 0, 6, 0, 0);
|
||||||
gtk_table_attach (GTK_TABLE (table), impl->filter_alignment,
|
/* Don't show filter initially -- don't gtk_widget_show() the filter_alignment here */
|
||||||
0, 1, 0, 1,
|
|
||||||
GTK_EXPAND | GTK_FILL, 0,
|
|
||||||
0, 0);
|
|
||||||
/* Don't show filter initially */
|
|
||||||
|
|
||||||
hbox = gtk_hbox_new (FALSE, 6);
|
hbox = gtk_hbox_new (FALSE, 6);
|
||||||
gtk_container_add (GTK_CONTAINER (impl->filter_alignment), hbox);
|
gtk_container_add (GTK_CONTAINER (impl->filter_alignment), hbox);
|
||||||
@ -351,21 +322,26 @@ gtk_file_chooser_impl_default_constructor (GType type,
|
|||||||
g_signal_connect (impl->filter_option_menu, "changed",
|
g_signal_connect (impl->filter_option_menu, "changed",
|
||||||
G_CALLBACK (filter_option_menu_changed), impl);
|
G_CALLBACK (filter_option_menu_changed), impl);
|
||||||
|
|
||||||
hpaned = gtk_hpaned_new ();
|
return impl->filter_alignment;
|
||||||
gtk_table_attach (GTK_TABLE (table), hpaned,
|
}
|
||||||
0, 1, 1, 2,
|
|
||||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
|
/* Creates the widgets for the directory tree */
|
||||||
0, 0);
|
static GtkWidget *
|
||||||
gtk_widget_show (hpaned);
|
create_directory_tree (GtkFileChooserImplDefault *impl)
|
||||||
|
{
|
||||||
|
GtkTreeSelection *selection;
|
||||||
|
|
||||||
|
/* Scrolled window */
|
||||||
|
|
||||||
impl->tree_scrollwin = gtk_scrolled_window_new (NULL, NULL);
|
impl->tree_scrollwin = gtk_scrolled_window_new (NULL, NULL);
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
|
||||||
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
|
||||||
GTK_SHADOW_IN);
|
GTK_SHADOW_IN);
|
||||||
gtk_paned_add1 (GTK_PANED (hpaned), impl->tree_scrollwin);
|
|
||||||
gtk_widget_show (impl->tree_scrollwin);
|
gtk_widget_show (impl->tree_scrollwin);
|
||||||
|
|
||||||
|
/* Tree */
|
||||||
|
|
||||||
impl->tree = gtk_tree_view_new ();
|
impl->tree = gtk_tree_view_new ();
|
||||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->tree), FALSE);
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->tree), FALSE);
|
||||||
|
|
||||||
@ -373,65 +349,10 @@ gtk_file_chooser_impl_default_constructor (GType type,
|
|||||||
g_signal_connect (selection, "changed",
|
g_signal_connect (selection, "changed",
|
||||||
G_CALLBACK (tree_selection_changed), impl);
|
G_CALLBACK (tree_selection_changed), impl);
|
||||||
|
|
||||||
gtk_paned_set_position (GTK_PANED (hpaned), 200);
|
|
||||||
|
|
||||||
gtk_container_add (GTK_CONTAINER (impl->tree_scrollwin), impl->tree);
|
gtk_container_add (GTK_CONTAINER (impl->tree_scrollwin), impl->tree);
|
||||||
gtk_widget_show (impl->tree);
|
gtk_widget_show (impl->tree);
|
||||||
|
|
||||||
impl->list_scrollwin = gtk_scrolled_window_new (NULL, NULL);
|
/* Model */
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
|
|
||||||
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
||||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
|
|
||||||
GTK_SHADOW_IN);
|
|
||||||
gtk_paned_add2 (GTK_PANED (hpaned), impl->list_scrollwin);
|
|
||||||
gtk_widget_show (impl->list_scrollwin);
|
|
||||||
|
|
||||||
impl->list = gtk_tree_view_new ();
|
|
||||||
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->list), TRUE);
|
|
||||||
gtk_container_add (GTK_CONTAINER (impl->list_scrollwin), impl->list);
|
|
||||||
gtk_widget_show (impl->list);
|
|
||||||
|
|
||||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
|
|
||||||
g_signal_connect (selection, "changed",
|
|
||||||
G_CALLBACK (list_selection_changed), impl);
|
|
||||||
|
|
||||||
hbox = gtk_hbox_new (FALSE, 6);
|
|
||||||
gtk_table_attach (GTK_TABLE (table), hbox,
|
|
||||||
0, 2, 2, 3,
|
|
||||||
GTK_EXPAND | GTK_FILL, 0,
|
|
||||||
0, 6);
|
|
||||||
gtk_widget_show (hbox);
|
|
||||||
|
|
||||||
label = gtk_label_new_with_mnemonic ("_Location:");
|
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
||||||
gtk_widget_show (label);
|
|
||||||
|
|
||||||
impl->entry = _gtk_file_chooser_entry_new ();
|
|
||||||
gtk_entry_set_activates_default (GTK_ENTRY (impl->entry), TRUE);
|
|
||||||
g_signal_connect (impl->entry, "activate",
|
|
||||||
G_CALLBACK (entry_activate), impl);
|
|
||||||
|
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), impl->entry, TRUE, TRUE, 0);
|
|
||||||
gtk_widget_show (impl->entry);
|
|
||||||
|
|
||||||
gtk_label_set_mnemonic_widget (GTK_LABEL (label), impl->entry);
|
|
||||||
|
|
||||||
impl->preview_frame = gtk_frame_new ("Preview");
|
|
||||||
gtk_table_attach (GTK_TABLE (table), impl->preview_frame,
|
|
||||||
1, 2, 0, 2,
|
|
||||||
0, GTK_EXPAND | GTK_FILL,
|
|
||||||
0, 0);
|
|
||||||
/* Don't show preview frame initially */
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
focus_chain = g_list_append (NULL, impl->entry);
|
|
||||||
focus_chain = g_list_append (focus_chain, impl->tree);
|
|
||||||
focus_chain = g_list_append (focus_chain, impl->list);
|
|
||||||
gtk_container_set_focus_chain (GTK_CONTAINER (impl), focus_chain);
|
|
||||||
g_list_free (focus_chain);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gtk_widget_pop_composite_child ();
|
|
||||||
|
|
||||||
impl->tree_model = _gtk_file_system_model_new (impl->file_system, NULL, -1,
|
impl->tree_model = _gtk_file_system_model_new (impl->file_system, NULL, -1,
|
||||||
GTK_FILE_INFO_DISPLAY_NAME);
|
GTK_FILE_INFO_DISPLAY_NAME);
|
||||||
@ -440,6 +361,8 @@ gtk_file_chooser_impl_default_constructor (GType type,
|
|||||||
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->tree),
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->tree),
|
||||||
GTK_TREE_MODEL (impl->tree_model));
|
GTK_TREE_MODEL (impl->tree_model));
|
||||||
|
|
||||||
|
/* Column */
|
||||||
|
|
||||||
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (impl->tree), 0,
|
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (impl->tree), 0,
|
||||||
"File name",
|
"File name",
|
||||||
gtk_cell_renderer_text_new (),
|
gtk_cell_renderer_text_new (),
|
||||||
@ -447,6 +370,40 @@ gtk_file_chooser_impl_default_constructor (GType type,
|
|||||||
gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->tree),
|
gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->tree),
|
||||||
GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
|
GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
|
||||||
|
|
||||||
|
return impl->tree_scrollwin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Creates the widgets for the directory tree */
|
||||||
|
static GtkWidget *
|
||||||
|
create_file_list (GtkFileChooserImplDefault *impl)
|
||||||
|
{
|
||||||
|
GtkTreeSelection *selection;
|
||||||
|
GtkTreeViewColumn *column;
|
||||||
|
GtkCellRenderer *renderer;
|
||||||
|
|
||||||
|
/* Scrolled window */
|
||||||
|
|
||||||
|
impl->list_scrollwin = gtk_scrolled_window_new (NULL, NULL);
|
||||||
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
|
||||||
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||||
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
|
||||||
|
GTK_SHADOW_IN);
|
||||||
|
gtk_widget_show (impl->list_scrollwin);
|
||||||
|
|
||||||
|
/* Tree/list view */
|
||||||
|
|
||||||
|
impl->list = gtk_tree_view_new ();
|
||||||
|
/* FIXME: hide the headers; look at create_directory_tree() */
|
||||||
|
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->list), TRUE);
|
||||||
|
gtk_container_add (GTK_CONTAINER (impl->list_scrollwin), impl->list);
|
||||||
|
gtk_widget_show (impl->list);
|
||||||
|
|
||||||
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
|
||||||
|
g_signal_connect (selection, "changed",
|
||||||
|
G_CALLBACK (list_selection_changed), impl);
|
||||||
|
|
||||||
|
/* Filename column */
|
||||||
|
|
||||||
column = gtk_tree_view_column_new ();
|
column = gtk_tree_view_column_new ();
|
||||||
gtk_tree_view_column_set_title (column, "File name");
|
gtk_tree_view_column_set_title (column, "File name");
|
||||||
|
|
||||||
@ -464,8 +421,11 @@ gtk_file_chooser_impl_default_constructor (GType type,
|
|||||||
|
|
||||||
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
|
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
|
||||||
|
|
||||||
|
/* Size column */
|
||||||
|
|
||||||
column = gtk_tree_view_column_new ();
|
column = gtk_tree_view_column_new ();
|
||||||
gtk_tree_view_column_set_title (column, "Size");
|
gtk_tree_view_column_set_title (column, "Size");
|
||||||
|
|
||||||
renderer = gtk_cell_renderer_text_new ();
|
renderer = gtk_cell_renderer_text_new ();
|
||||||
gtk_tree_view_column_pack_start (column, renderer, TRUE);
|
gtk_tree_view_column_pack_start (column, renderer, TRUE);
|
||||||
gtk_tree_view_column_set_cell_data_func (column, renderer,
|
gtk_tree_view_column_set_cell_data_func (column, renderer,
|
||||||
@ -473,8 +433,122 @@ gtk_file_chooser_impl_default_constructor (GType type,
|
|||||||
gtk_tree_view_column_set_sort_column_id (column, 1);
|
gtk_tree_view_column_set_sort_column_id (column, 1);
|
||||||
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
|
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
|
||||||
|
|
||||||
|
return impl->list_scrollwin;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GtkWidget *
|
||||||
|
create_filename_entry (GtkFileChooserImplDefault *impl)
|
||||||
|
{
|
||||||
|
GtkWidget *hbox;
|
||||||
|
GtkWidget *label;
|
||||||
|
|
||||||
|
hbox = gtk_hbox_new (FALSE, 6);
|
||||||
|
gtk_widget_show (hbox);
|
||||||
|
|
||||||
|
label = gtk_label_new_with_mnemonic ("_Location:");
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
||||||
|
gtk_widget_show (label);
|
||||||
|
|
||||||
|
impl->entry = _gtk_file_chooser_entry_new ();
|
||||||
|
gtk_entry_set_activates_default (GTK_ENTRY (impl->entry), TRUE);
|
||||||
|
g_signal_connect (impl->entry, "activate",
|
||||||
|
G_CALLBACK (entry_activate), impl);
|
||||||
_gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->entry),
|
_gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->entry),
|
||||||
impl->file_system);
|
impl->file_system);
|
||||||
|
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox), impl->entry, TRUE, TRUE, 0);
|
||||||
|
gtk_widget_show (impl->entry);
|
||||||
|
|
||||||
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), impl->entry);
|
||||||
|
|
||||||
|
return hbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GObject*
|
||||||
|
gtk_file_chooser_impl_default_constructor (GType type,
|
||||||
|
guint n_construct_properties,
|
||||||
|
GObjectConstructParam *construct_params)
|
||||||
|
{
|
||||||
|
GtkFileChooserImplDefault *impl;
|
||||||
|
GObject *object;
|
||||||
|
GtkWidget *table;
|
||||||
|
GtkWidget *hpaned;
|
||||||
|
GtkWidget *widget;
|
||||||
|
#if 0
|
||||||
|
GList *focus_chain;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
object = parent_class->constructor (type,
|
||||||
|
n_construct_properties,
|
||||||
|
construct_params);
|
||||||
|
impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (object);
|
||||||
|
|
||||||
|
g_assert (impl->file_system);
|
||||||
|
|
||||||
|
gtk_widget_push_composite_child ();
|
||||||
|
|
||||||
|
/* Basic table */
|
||||||
|
|
||||||
|
table = gtk_table_new (3, 2, FALSE);
|
||||||
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
||||||
|
gtk_box_pack_start (GTK_BOX (impl), table, TRUE, TRUE, 0);
|
||||||
|
gtk_widget_show (table);
|
||||||
|
|
||||||
|
/* Filter */
|
||||||
|
|
||||||
|
widget = create_filter (impl);
|
||||||
|
gtk_table_attach (GTK_TABLE (table), widget,
|
||||||
|
0, 1, 0, 1,
|
||||||
|
GTK_EXPAND | GTK_FILL, 0,
|
||||||
|
0, 0);
|
||||||
|
|
||||||
|
/* Paned widget */
|
||||||
|
|
||||||
|
hpaned = gtk_hpaned_new ();
|
||||||
|
gtk_table_attach (GTK_TABLE (table), hpaned,
|
||||||
|
0, 1, 1, 2,
|
||||||
|
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
|
||||||
|
0, 0);
|
||||||
|
gtk_paned_set_position (GTK_PANED (hpaned), 200); /* FIXME: this sucks */
|
||||||
|
gtk_widget_show (hpaned);
|
||||||
|
|
||||||
|
/* Directory tree */
|
||||||
|
|
||||||
|
widget = create_directory_tree (impl);
|
||||||
|
gtk_paned_add1 (GTK_PANED (hpaned), widget);
|
||||||
|
|
||||||
|
/* File list */
|
||||||
|
|
||||||
|
widget = create_file_list (impl);
|
||||||
|
gtk_paned_add2 (GTK_PANED (hpaned), widget);
|
||||||
|
|
||||||
|
/* Location/filename entry */
|
||||||
|
|
||||||
|
widget = create_filename_entry (impl);
|
||||||
|
gtk_table_attach (GTK_TABLE (table), widget,
|
||||||
|
0, 2, 2, 3,
|
||||||
|
GTK_EXPAND | GTK_FILL, 0,
|
||||||
|
0, 6);
|
||||||
|
|
||||||
|
/* Preview */
|
||||||
|
|
||||||
|
impl->preview_frame = gtk_frame_new ("Preview");
|
||||||
|
gtk_table_attach (GTK_TABLE (table), impl->preview_frame,
|
||||||
|
1, 2, 0, 2,
|
||||||
|
0, GTK_EXPAND | GTK_FILL,
|
||||||
|
0, 0);
|
||||||
|
/* Don't show preview frame initially */
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
focus_chain = g_list_append (NULL, impl->entry);
|
||||||
|
focus_chain = g_list_append (focus_chain, impl->tree);
|
||||||
|
focus_chain = g_list_append (focus_chain, impl->list);
|
||||||
|
gtk_container_set_focus_chain (GTK_CONTAINER (impl), focus_chain);
|
||||||
|
g_list_free (focus_chain);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gtk_widget_pop_composite_child ();
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user