diff options
author | Darin Adler <darin@src.gnome.org> | 2002-03-08 09:29:57 +0000 |
---|---|---|
committer | Darin Adler <darin@src.gnome.org> | 2002-03-08 09:29:57 +0000 |
commit | 76c700136247c1463d16e51d2b4de6cafc247106 (patch) | |
tree | 4dcef86fe1bcc98f508c45b53880df71c6cf4977 /components | |
parent | 71c2d7efb3355dca7eb3165007c55250aacbdd8b (diff) | |
download | nautilus-76c700136247c1463d16e51d2b4de6cafc247106.tar.gz |
Rename old stop_monitoring_directory function.
* components/tree/nautilus-tree-model.h:
* components/tree/nautilus-tree-model.c:
(stop_monitoring_directory_without_reporting): Rename old
stop_monitoring_directory function.
(stop_monitoring_directory): New function that handles changes
caused by stopping monitoring.
(destroy_children_by_function): New.
(destroy_by_function): New.
(should_show_file): New.
(update_node): Call should_show_file instead of
nautilus_file_is_gone to decide whether a given file should show
up.
(process_file_change): Ditto.
(start_monitoring_directory): Pass through flags for whether to
monitor invisible or backup files, rather than just TRUE, TRUE.
(nautilus_tree_model_get_value): Use PANGO_STYLE_ITALIC instead of
PANGO_STYLE_OBLIQUE. Both will fall back to the other if not
available, but if we have both, we'd prefer italic.
(stop_monitoring_directory_and_children): New.
(stop_monitoring): New.
(nautilus_tree_model_set_show_hidden_files): New.
(nautilus_tree_model_set_show_backup_files): New.
(file_is_not_directory): New.
(nautilus_tree_model_set_show_only_directories): New.
* components/tree/nautilus-tree-view.c:
(update_filtering_from_preferences): Call functions to change
settings on model rather than storing these settings here.
(tree_activate_callback),
(filtering_changed_callback): Call
update_filtering_from_preferences to set filtering for the newly
created tree.
(nautilus_tree_view_instance_init): Don't call
update_filtering_from_preferences here, because we don't have a
tree model yet.
* libnautilus-private/nautilus-theme.c: Formatting tweaks.
* libnautilus/nautilus-view-standard-main.c: Formatting tweak.
* src/nautilus-window-toolbars.c: Formatting tweaks, and remove
some unnecessary localized strings.
* src/nautilus-zoom-control.h: Remove extern "C" stuff. If we need
this, we'll do G_BEGIN_DECLS, and it's silly to use it for private
headers that are never going to be used from C++.
* libnautilus-private/nautilus-bonobo-extensions.c:
(nautilus_bonobo_activation_register_for_display): Temporarily
re-disable per-display registration since it doesn't work at all
on my machine. I'll turn it back on after talking to Michael
Meeks.
Diffstat (limited to 'components')
-rw-r--r-- | components/tree/nautilus-tree-model.c | 187 | ||||
-rw-r--r-- | components/tree/nautilus-tree-model.h | 3 | ||||
-rw-r--r-- | components/tree/nautilus-tree-view.c | 65 |
3 files changed, 195 insertions, 60 deletions
diff --git a/components/tree/nautilus-tree-model.c b/components/tree/nautilus-tree-model.c index cf063b7d5..18a1f816e 100644 --- a/components/tree/nautilus-tree-model.c +++ b/components/tree/nautilus-tree-model.c @@ -37,6 +37,8 @@ #include <libnautilus-private/nautilus-icon-factory.h> #include <string.h> +typedef gboolean (* FilePredicate) (NautilusFile *); + /* The user_data of the GtkTreeIter is the TreeNode pointer. * It's NULL for the dummy node. If it's NULL, then user_data2 * is the TreeNode pointer to the parent. @@ -81,6 +83,10 @@ struct NautilusTreeModelDetails { gboolean root_node_parented; guint monitoring_update_idle_id; + + gboolean show_hidden_files; + gboolean show_backup_files; + gboolean show_only_directories; }; typedef struct { @@ -554,7 +560,7 @@ report_dummy_row_contents_changed (NautilusTreeModel *model, TreeNode *parent) } static void -stop_monitoring_directory (NautilusTreeModel *model, TreeNode *node) +stop_monitoring_directory_without_reporting (NautilusTreeModel *model, TreeNode *node) { NautilusDirectory *directory; @@ -580,6 +586,25 @@ stop_monitoring_directory (NautilusTreeModel *model, TreeNode *node) } static void +stop_monitoring_directory (NautilusTreeModel *model, TreeNode *node) +{ + gboolean had_dummy, has_dummy; + + had_dummy = tree_node_has_dummy_child (node); + stop_monitoring_directory_without_reporting (model, node); + has_dummy = tree_node_has_dummy_child (node); + + if (had_dummy) { + g_assert (has_dummy); + report_dummy_row_contents_changed (model, node); + } else { + if (has_dummy) { + report_dummy_row_inserted (model, node); + } + } +} + +static void destroy_children_without_reporting (NautilusTreeModel *model, TreeNode *parent) { while (parent->first_child != NULL) { @@ -591,7 +616,7 @@ static void destroy_node_without_reporting (NautilusTreeModel *model, TreeNode *node) { abandon_node_ref_count (model, node); - stop_monitoring_directory (model, node); + stop_monitoring_directory_without_reporting (model, node); node->inserted = FALSE; destroy_children_without_reporting (model, node); g_hash_table_remove (model->details->file_to_node_map, node->file); @@ -632,6 +657,27 @@ destroy_children (NautilusTreeModel *model, TreeNode *parent) } } +static void +destroy_children_by_function (NautilusTreeModel *model, TreeNode *parent, FilePredicate f) +{ + TreeNode *child, *next; + + for (child = parent->first_child; child != NULL; child = next) { + next = child->next; + if (f (child->file)) { + destroy_node (model, child); + } else { + destroy_children_by_function (model, child, f); + } + } +} + +static void +destroy_by_function (NautilusTreeModel *model, FilePredicate f) +{ + destroy_children_by_function (model, model->details->root_node, f); +} + static gboolean update_node_without_reporting (NautilusTreeModel *model, TreeNode *node) { @@ -642,7 +688,7 @@ update_node_without_reporting (NautilusTreeModel *model, TreeNode *node) if (node->directory == NULL && nautilus_file_is_directory (node->file)) { node->directory = nautilus_directory_get_for_file (node->file); } else if (node->directory != NULL && !nautilus_file_is_directory (node->file)) { - stop_monitoring_directory (model, node); + stop_monitoring_directory_without_reporting (model, node); destroy_children (model, node); nautilus_directory_unref (node->directory); node->directory = NULL; @@ -686,6 +732,33 @@ reparent_node (NautilusTreeModel *model, TreeNode *node) insert_node (model, new_parent, node); } +static gboolean +should_show_file (NautilusTreeModel *model, NautilusFile *file) +{ + gboolean should; + + should = nautilus_file_should_show (file, + model->details->show_hidden_files, + model->details->show_backup_files); + + if (should + && model->details->show_only_directories + &&! nautilus_file_is_directory (file)) { + should = FALSE; + } + + if (should && nautilus_file_is_gone (file)) { + should = FALSE; + } + + if (!should && model->details->root_node != NULL + && file == model->details->root_node->file) { + should = TRUE; + } + + return should; +} + static void update_node (NautilusTreeModel *model, TreeNode *node) { @@ -693,7 +766,7 @@ update_node (NautilusTreeModel *model, TreeNode *node) gboolean had_directory, has_directory; gboolean changed; - if (nautilus_file_is_gone (node->file)) { + if (!should_show_file (model, node->file)) { destroy_node (model, node); return; } @@ -740,7 +813,7 @@ process_file_change (NautilusTreeModel *model, return; } - if (nautilus_file_is_gone (file)) { + if (!should_show_file (model, file)) { return; } @@ -838,18 +911,18 @@ start_monitoring_directory (NautilusTreeModel *model, TreeNode *node) node->done_loading_id = g_signal_connect (directory, "done_loading", G_CALLBACK (done_loading_callback), model); - node->files_added_id = g_signal_connect (directory, "files_added", G_CALLBACK (files_changed_callback), model); - node->files_changed_id = g_signal_connect (directory, "files_changed", G_CALLBACK (files_changed_callback), model); attrs = get_tree_monitor_attributes (); - nautilus_directory_file_monitor_add (directory, model, TRUE, TRUE, attrs, - files_changed_callback, model); + nautilus_directory_file_monitor_add (directory, model, + model->details->show_hidden_files, + model->details->show_backup_files, + attrs, files_changed_callback, model); g_list_free (attrs); if (nautilus_directory_are_all_files_seen (directory)) { @@ -993,7 +1066,6 @@ static void nautilus_tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, int column, GValue *value) { TreeNode *node, *parent; - const char *dummy_node_str; g_return_if_fail (NAUTILUS_IS_TREE_MODEL (model)); g_return_if_fail (iter_is_valid (NAUTILUS_TREE_MODEL (model), iter)); @@ -1005,8 +1077,8 @@ nautilus_tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, int colum g_value_init (value, G_TYPE_STRING); if (node == NULL) { parent = iter->user_data2; - dummy_node_str = parent->done_loading ? _("(Empty)") : _("Loading..."); - g_value_set_static_string (value, dummy_node_str); + g_value_set_static_string (value, parent->done_loading + ? _("(Empty)") : _("Loading...")); } else { g_value_set_string (value, tree_node_get_display_name (node)); } @@ -1022,9 +1094,8 @@ nautilus_tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, int colum case NAUTILUS_TREE_MODEL_FONT_STYLE_COLUMN: g_value_init (value, PANGO_TYPE_STYLE); if (node == NULL) { - g_value_set_enum (value, PANGO_STYLE_OBLIQUE); - } - else { + g_value_set_enum (value, PANGO_STYLE_ITALIC); + } else { g_value_set_enum (value, PANGO_STYLE_NORMAL); } break; @@ -1151,7 +1222,7 @@ nautilus_tree_model_iter_nth_child (GtkTreeModel *model, GtkTreeIter *iter, return make_iter_invalid (iter); } return make_iter_for_node (tree_model->details->root_node, - iter, tree_model->details->stamp); + iter, tree_model->details->stamp); } parent = parent_iter->user_data; @@ -1178,7 +1249,7 @@ update_monitoring (NautilusTreeModel *model, TreeNode *node) TreeNode *child; if (node->all_children_ref_count == 0) { - stop_monitoring_directory (model, node); + stop_monitoring_directory_without_reporting (model, node); destroy_children (model, node); } else { for (child = node->first_child; child != NULL; child = child->next) { @@ -1209,6 +1280,23 @@ schedule_monitoring_update (NautilusTreeModel *model) } static void +stop_monitoring_directory_and_children (NautilusTreeModel *model, TreeNode *node) +{ + TreeNode *child; + + stop_monitoring_directory (model, node); + for (child = node->first_child; child != NULL; child = child->next) { + stop_monitoring_directory_and_children (model, child); + } +} + +static void +stop_monitoring (NautilusTreeModel *model) +{ + stop_monitoring_directory_and_children (model, model->details->root_node); +} + +static void nautilus_tree_model_ref_node (GtkTreeModel *model, GtkTreeIter *iter) { TreeNode *node, *parent; @@ -1328,6 +1416,69 @@ nautilus_tree_model_new (const char *root_uri) return model; } +void +nautilus_tree_model_set_show_hidden_files (NautilusTreeModel *model, + gboolean show_hidden_files) +{ + g_return_if_fail (NAUTILUS_IS_TREE_MODEL (model)); + g_return_if_fail (show_hidden_files == FALSE || show_hidden_files == TRUE); + + show_hidden_files = show_hidden_files != FALSE; + if (model->details->show_hidden_files == show_hidden_files) { + return; + } + model->details->show_hidden_files = show_hidden_files; + stop_monitoring (model); + schedule_monitoring_update (model); + if (!show_hidden_files) { + destroy_by_function (model, nautilus_file_is_hidden_file); + } +} + +void +nautilus_tree_model_set_show_backup_files (NautilusTreeModel *model, + gboolean show_backup_files) +{ + g_return_if_fail (NAUTILUS_IS_TREE_MODEL (model)); + g_return_if_fail (show_backup_files == FALSE || show_backup_files == TRUE); + + show_backup_files = show_backup_files != FALSE; + if (model->details->show_backup_files == show_backup_files) { + return; + } + model->details->show_backup_files = show_backup_files; + stop_monitoring (model); + schedule_monitoring_update (model); + if (!show_backup_files) { + destroy_by_function (model, nautilus_file_is_backup_file); + } +} + +static gboolean +file_is_not_directory (NautilusFile *file) +{ + return !nautilus_file_is_directory (file); +} + +void +nautilus_tree_model_set_show_only_directories (NautilusTreeModel *model, + gboolean show_only_directories) +{ + g_return_if_fail (NAUTILUS_IS_TREE_MODEL (model)); + g_return_if_fail (show_only_directories == FALSE || show_only_directories == TRUE); + + show_only_directories = show_only_directories != FALSE; + if (model->details->show_only_directories == show_only_directories) { + return; + } + model->details->show_only_directories = show_only_directories; + stop_monitoring (model); + schedule_monitoring_update (model); + if (show_only_directories) { + destroy_by_function (model, file_is_not_directory); + } +} + NautilusFile * nautilus_tree_model_iter_get_file (NautilusTreeModel *model, GtkTreeIter *iter) { @@ -1372,7 +1523,7 @@ nautilus_tree_model_finalize (GObject *object) g_free (model->details); - G_OBJECT_CLASS (parent_class)->finalize (object); + parent_class->finalize (object); } static void diff --git a/components/tree/nautilus-tree-model.h b/components/tree/nautilus-tree-model.h index abb933385..3afc0c6d7 100644 --- a/components/tree/nautilus-tree-model.h +++ b/components/tree/nautilus-tree-model.h @@ -58,11 +58,10 @@ typedef struct { GType nautilus_tree_model_get_type (void); NautilusTreeModel *nautilus_tree_model_new (const char *root_uri); -gboolean nautilus_tree_model_would_include_uri (const char *uri); void nautilus_tree_model_set_show_hidden_files (NautilusTreeModel *model, gboolean show_hidden_files); void nautilus_tree_model_set_show_backup_files (NautilusTreeModel *model, - gboolean show_hidden_files); + gboolean show_backup_files); void nautilus_tree_model_set_show_only_directories (NautilusTreeModel *model, gboolean show_only_directories); NautilusFile * nautilus_tree_model_iter_get_file (NautilusTreeModel *model, diff --git a/components/tree/nautilus-tree-view.c b/components/tree/nautilus-tree-view.c index b46387acd..3e555e6e5 100644 --- a/components/tree/nautilus-tree-view.c +++ b/components/tree/nautilus-tree-view.c @@ -53,10 +53,6 @@ struct NautilusTreeViewDetails { GtkTreeModelSort *sort_model; NautilusTreeModel *child_model; - gboolean show_hidden_files; - gboolean show_backup_files; - gboolean show_only_directories; - NautilusFile *activation_file; guint save_expansion_state_idle_id; }; @@ -251,9 +247,11 @@ create_tree (NautilusTreeView *view) GtkCellRenderer *cell; view->details->child_model = nautilus_tree_model_new ("file:///"); - view->details->sort_model = GTK_TREE_MODEL_SORT (gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (view->details->child_model))); + view->details->sort_model = GTK_TREE_MODEL_SORT + (gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (view->details->child_model))); g_object_unref (view->details->child_model); - view->details->tree_widget = GTK_TREE_VIEW (gtk_tree_view_new_with_model (GTK_TREE_MODEL (view->details->sort_model))); + view->details->tree_widget = GTK_TREE_VIEW + (gtk_tree_view_new_with_model (GTK_TREE_MODEL (view->details->sort_model))); g_object_unref (view->details->sort_model); gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (view->details->sort_model), @@ -296,6 +294,24 @@ create_tree (NautilusTreeView *view) } static void +update_filtering_from_preferences (NautilusTreeView *view) +{ + if (view->details->child_model == NULL) { + return; + } + + nautilus_tree_model_set_show_hidden_files + (view->details->child_model, + eel_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES)); + nautilus_tree_model_set_show_backup_files + (view->details->child_model, + eel_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES)); + nautilus_tree_model_set_show_only_directories + (view->details->child_model, + eel_preferences_get_boolean (NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES)); +} + +static void tree_activate_callback (BonoboControl *control, gboolean activating, gpointer user_data) { NautilusTreeView *view; @@ -303,45 +319,16 @@ tree_activate_callback (BonoboControl *control, gboolean activating, gpointer us view = NAUTILUS_TREE_VIEW (user_data); if (activating && view->details->tree_widget == NULL) { - create_tree (view); load_expansion_state (view); + create_tree (view); + update_filtering_from_preferences (view); } } -static int -get_filtering_as_integer (NautilusTreeView *view) -{ - return (((view->details->show_hidden_files << 1) - | view->details->show_backup_files) << 1) - | view->details->show_only_directories; -} - -static void -update_filtering_from_preferences (NautilusTreeView *view) -{ - view->details->show_hidden_files = - eel_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES); - view->details->show_backup_files = - eel_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES); - view->details->show_only_directories = - eel_preferences_get_boolean (NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES); -} - static void filtering_changed_callback (gpointer callback_data) { - NautilusTreeView *view; - int filtering_before; - - view = NAUTILUS_TREE_VIEW (callback_data); - - filtering_before = get_filtering_as_integer (view); - update_filtering_from_preferences (view); - if (filtering_before == get_filtering_as_integer (view)) { - return; - } - - /* FIXME: reload the whole tree */ + update_filtering_from_preferences (NAUTILUS_TREE_VIEW (callback_data)); } static void @@ -371,8 +358,6 @@ nautilus_tree_view_instance_init (NautilusTreeView *view) filtering_changed_callback, view); eel_preferences_add_callback (NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES, filtering_changed_callback, view); - - update_filtering_from_preferences (view); } static void |