summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2012-08-31 22:42:55 -0400
committerCosimo Cecchi <cosimoc@gnome.org>2012-08-31 23:00:48 -0400
commit215f9cff6846297788dc81fdb563988f38ec8ff5 (patch)
tree11d8aedba6844f3932566bcbebdea855a6268780 /src
parent0de1d3fe1099f7221c846bdbdaec90be29644c88 (diff)
downloadnautilus-215f9cff6846297788dc81fdb563988f38ec8ff5.tar.gz
view: don't connect to NautilusWindow signals
Since the window of the slot can change, we don't want to connect signals from the view to the window. We only connect to NautilusWindow signals for two reasons: - updating the shadow type of the content view when the number of tabs in the notebook changes - following the hidden-files-changed signal Since the first is really a hack, it can live in NautilusWindow itself To implement the second, move the Show Hidden Files action to the view action group, and handle hidden files action changes completely in the view.
Diffstat (limited to 'src')
-rw-r--r--src/nautilus-view.c135
-rw-r--r--src/nautilus-view.h2
-rw-r--r--src/nautilus-window-menus.c63
-rw-r--r--src/nautilus-window-private.h2
-rw-r--r--src/nautilus-window.c70
-rw-r--r--src/nautilus-window.h10
6 files changed, 88 insertions, 194 deletions
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index 53fec5965..801dce8e5 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -284,7 +284,8 @@ static void load_directory (NautilusView
NautilusDirectory *directory);
static void nautilus_view_merge_menus (NautilusView *view);
static void nautilus_view_unmerge_menus (NautilusView *view);
-static void nautilus_view_init_show_hidden_files (NautilusView *view);
+static void nautilus_view_set_show_hidden_files (NautilusView *view,
+ gboolean show_hidden);
static void clipboard_changed_callback (NautilusClipboardMonitor *monitor,
NautilusView *view);
static void open_one_in_new_window (gpointer data,
@@ -467,19 +468,12 @@ nautilus_view_reveal_selection (NautilusView *view)
static void
nautilus_view_reset_to_defaults (NautilusView *view)
{
- NautilusWindowShowHiddenFilesMode mode;
- NautilusWindow *window;
-
- g_return_if_fail (NAUTILUS_IS_VIEW (view));
-
- NAUTILUS_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->reset_to_defaults (view);
+ GtkAction *action;
- window = nautilus_window_slot_get_window (view->details->slot);
- mode = nautilus_window_get_hidden_files_mode (window);
- if (mode != NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_DEFAULT) {
- nautilus_window_set_hidden_files_mode (window,
- NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_DEFAULT);
- }
+ action = gtk_action_group_get_action (view->details->dir_action_group,
+ NAUTILUS_ACTION_SHOW_HIDDEN_FILES);
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
+ g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES));
}
static gboolean
@@ -1536,18 +1530,6 @@ action_reset_to_defaults_callback (GtkAction *action,
nautilus_view_reset_to_defaults (callback_data);
}
-
-static void
-hidden_files_mode_changed (NautilusWindow *window,
- gpointer callback_data)
-{
- NautilusView *directory_view;
-
- directory_view = NAUTILUS_VIEW (callback_data);
-
- nautilus_view_init_show_hidden_files (directory_view);
-}
-
static void
action_save_search_callback (GtkAction *action,
gpointer callback_data)
@@ -2205,6 +2187,18 @@ all_selected_items_in_trash (NautilusView *view)
}
static void
+action_show_hidden_files_callback (GtkAction *action,
+ gpointer callback_data)
+{
+ NautilusView *view;
+
+ view = NAUTILUS_VIEW (callback_data);
+
+ nautilus_view_set_show_hidden_files
+ (view, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+}
+
+static void
click_policy_changed_callback (gpointer callback_data)
{
NautilusView *view;
@@ -2663,6 +2657,8 @@ nautilus_view_init (NautilusView *view)
view->details->sort_directories_first =
g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST);
+ view->details->show_hidden_files =
+ g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES);
g_signal_connect_object (nautilus_trash_monitor_get (), "trash_state_changed",
G_CALLBACK (nautilus_view_trash_state_changed_callback), view, 0);
@@ -7108,40 +7104,26 @@ action_location_restore_from_trash_callback (GtkAction *action,
nautilus_view_get_containing_window (view));
}
-static void
-nautilus_view_init_show_hidden_files (NautilusView *view)
+gboolean
+nautilus_view_get_show_hidden_files (NautilusView *view)
{
- NautilusWindowShowHiddenFilesMode mode;
- gboolean show_hidden_changed;
- gboolean show_hidden_default_setting;
+ return view->details->show_hidden_files;
+}
+static void
+nautilus_view_set_show_hidden_files (NautilusView *view,
+ gboolean show_hidden)
+{
if (view->details->ignore_hidden_file_preferences) {
return;
}
- show_hidden_changed = FALSE;
- mode = nautilus_window_get_hidden_files_mode (nautilus_view_get_window (view));
-
- if (mode == NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_DEFAULT) {
- show_hidden_default_setting = g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES);
- if (show_hidden_default_setting != view->details->show_hidden_files) {
- view->details->show_hidden_files = show_hidden_default_setting;
- show_hidden_changed = TRUE;
- }
- } else {
- if (mode == NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_ENABLE) {
- show_hidden_changed = !view->details->show_hidden_files;
- view->details->show_hidden_files = TRUE;
- } else {
- show_hidden_changed = view->details->show_hidden_files;
- view->details->show_hidden_files = FALSE;
+ if (show_hidden != view->details->show_hidden_files) {
+ view->details->show_hidden_files = show_hidden;
+ if (view->details->model != NULL) {
+ load_directory (view, view->details->model);
}
}
-
- if (show_hidden_changed && (view->details->model != NULL)) {
- load_directory (view, view->details->model);
- }
-
}
static const GtkActionEntry directory_view_entries[] = {
@@ -7412,6 +7394,14 @@ static const GtkActionEntry directory_view_entries[] = {
G_CALLBACK (action_location_properties_callback) },
};
+static const GtkToggleActionEntry directory_view_toggle_entries[] = {
+ /* name, stock id */ { NAUTILUS_ACTION_SHOW_HIDDEN_FILES, NULL,
+ /* label, accelerator */ N_("Show _Hidden Files"), "<control>H",
+ /* tooltip */ N_("Toggle the display of hidden files in the current window"),
+ G_CALLBACK (action_show_hidden_files_callback),
+ TRUE },
+};
+
static void
connect_proxy (NautilusView *view,
GtkAction *action,
@@ -7485,6 +7475,9 @@ real_merge_menus (NautilusView *view)
gtk_action_group_add_actions (action_group,
directory_view_entries, G_N_ELEMENTS (directory_view_entries),
view);
+ gtk_action_group_add_toggle_actions (action_group,
+ directory_view_toggle_entries, G_N_ELEMENTS (directory_view_toggle_entries),
+ view);
tooltip = g_strdup (_("Run or manage scripts"));
/* Create a script action here specially because its tooltip is dynamic */
@@ -8808,6 +8801,9 @@ real_update_menus (NautilusView *view)
NAUTILUS_ACTION_MOVE_TO);
gtk_action_set_sensitive (action, can_delete_files);
gtk_action_set_visible (action, !selection_contains_recent);
+
+ action = gtk_action_group_get_action (view->details->dir_action_group, NAUTILUS_ACTION_SHOW_HIDDEN_FILES);
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), view->details->show_hidden_files);
}
/**
@@ -9600,27 +9596,6 @@ real_get_selected_icon_locations (NautilusView *view)
}
static void
-window_slots_changed (NautilusWindow *window,
- NautilusWindowSlot *slot,
- NautilusView *view)
-{
- GList *slots;
-
- slots = nautilus_window_get_slots (window);
-
- /* Only add a shadow to the scrolled window when we're in a tabless
- * notebook, since when the notebook has tabs, it will draw its own
- * border.
- */
- if (g_list_length (slots) > 1 ||
- NAUTILUS_IS_DESKTOP_CANVAS_VIEW (view)) {
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view), GTK_SHADOW_NONE);
- } else {
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view), GTK_SHADOW_IN);
- }
-}
-
-static void
nautilus_view_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -9628,7 +9603,6 @@ nautilus_view_set_property (GObject *object,
{
NautilusView *directory_view;
NautilusWindowSlot *slot;
- NautilusWindow *window;
directory_view = NAUTILUS_VIEW (object);
@@ -9637,8 +9611,6 @@ nautilus_view_set_property (GObject *object,
g_assert (directory_view->details->slot == NULL);
slot = NAUTILUS_WINDOW_SLOT (g_value_get_object (value));
- window = nautilus_window_slot_get_window (slot);
-
directory_view->details->slot = slot;
g_signal_connect_object (directory_view->details->slot,
@@ -9647,19 +9619,6 @@ nautilus_view_set_property (GObject *object,
g_signal_connect_object (directory_view->details->slot,
"inactive", G_CALLBACK (slot_inactive),
directory_view, 0);
-
- g_signal_connect_object (window,
- "slot-added", G_CALLBACK (window_slots_changed),
- directory_view, 0);
- g_signal_connect_object (window,
- "slot-removed", G_CALLBACK (window_slots_changed),
- directory_view, 0);
- window_slots_changed (window, slot, directory_view);
-
- g_signal_connect_object (window,
- "hidden-files-mode-changed", G_CALLBACK (hidden_files_mode_changed),
- directory_view, 0);
- nautilus_view_init_show_hidden_files (directory_view);
break;
case PROP_SUPPORTS_ZOOMING:
directory_view->details->supports_zooming = g_value_get_boolean (value);
diff --git a/src/nautilus-view.h b/src/nautilus-view.h
index 04b79c243..ff21058d4 100644
--- a/src/nautilus-view.h
+++ b/src/nautilus-view.h
@@ -410,4 +410,6 @@ void nautilus_view_pop_up_location_context_menu (NautilusView *v
void nautilus_view_grab_focus (NautilusView *view);
void nautilus_view_update_menus (NautilusView *view);
+gboolean nautilus_view_get_show_hidden_files (NautilusView *view);
+
#endif /* NAUTILUS_VIEW_H */
diff --git a/src/nautilus-window-menus.c b/src/nautilus-window-menus.c
index 76bc3bee2..c8d06e55d 100644
--- a/src/nautilus-window-menus.c
+++ b/src/nautilus-window-menus.c
@@ -187,48 +187,6 @@ action_zoom_normal_callback (GtkAction *action,
}
static void
-action_show_hidden_files_callback (GtkAction *action,
- gpointer callback_data)
-{
- NautilusWindow *window;
- NautilusWindowShowHiddenFilesMode mode;
-
- window = NAUTILUS_WINDOW (callback_data);
-
- if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
- mode = NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_ENABLE;
- } else {
- mode = NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_DISABLE;
- }
-
- nautilus_window_set_hidden_files_mode (window, mode);
-}
-
-static void
-show_hidden_files_preference_callback (gpointer callback_data)
-{
- NautilusWindow *window;
- GtkAction *action;
-
- window = NAUTILUS_WINDOW (callback_data);
-
- if (window->details->show_hidden_files_mode == NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_DEFAULT) {
- action = gtk_action_group_get_action (nautilus_window_get_main_action_group (window),
- NAUTILUS_ACTION_SHOW_HIDDEN_FILES);
-
- /* update button */
- g_signal_handlers_block_by_func (action, action_show_hidden_files_callback, window);
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
- g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES));
- g_signal_handlers_unblock_by_func (action, action_show_hidden_files_callback, window);
-
- /* inform views */
- nautilus_window_set_hidden_files_mode (window, NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_DEFAULT);
-
- }
-}
-
-static void
action_preferences_callback (GtkAction *action,
gpointer user_data)
{
@@ -609,11 +567,6 @@ static const GtkActionEntry main_entries[] = {
};
static const GtkToggleActionEntry main_toggle_entries[] = {
- /* name, stock id */ { NAUTILUS_ACTION_SHOW_HIDDEN_FILES, NULL,
- /* label, accelerator */ N_("Show _Hidden Files"), "<control>H",
- /* tooltip */ N_("Toggle the display of hidden files in the current window"),
- G_CALLBACK (action_show_hidden_files_callback),
- TRUE },
/* name, stock id */ { NAUTILUS_ACTION_SHOW_HIDE_SIDEBAR, NULL,
/* label, accelerator */ N_("_Show Sidebar"), "F9",
/* tooltip */ N_("Change the visibility of this window's side pane"),
@@ -734,7 +687,7 @@ nautilus_window_initialize_menus (NautilusWindow *window)
action_group = gtk_action_group_new ("ShellActions");
gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
window->details->main_action_group = action_group;
- gtk_action_group_add_actions (action_group,
+ gtk_action_group_add_actions (action_group,
main_entries, G_N_ELEMENTS (main_entries),
window);
gtk_action_group_add_toggle_actions (action_group,
@@ -757,17 +710,6 @@ nautilus_window_initialize_menus (NautilusWindow *window)
action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_HOME);
g_object_set (action, "short_label", _("_Home"), NULL);
- action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_SHOW_HIDDEN_FILES);
- g_signal_handlers_block_by_func (action, action_show_hidden_files_callback, window);
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
- g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES));
- g_signal_handlers_unblock_by_func (action, action_show_hidden_files_callback, window);
-
-
- g_signal_connect_swapped (nautilus_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
- G_CALLBACK(show_hidden_files_preference_callback),
- window);
-
/* Alt+N for the first 10 tabs */
for (i = 0; i < 10; ++i) {
gchar action_name[80];
@@ -807,9 +749,6 @@ nautilus_window_initialize_menus (NautilusWindow *window)
void
nautilus_window_finalize_menus (NautilusWindow *window)
{
- g_signal_handlers_disconnect_by_func (nautilus_preferences,
- show_hidden_files_preference_callback, window);
-
if (window->details->app_menu_visibility_id != 0) {
g_signal_handler_disconnect (gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))),
window->details->app_menu_visibility_id);
diff --git a/src/nautilus-window-private.h b/src/nautilus-window-private.h
index fce6e9f24..e1cdd5e77 100644
--- a/src/nautilus-window-private.h
+++ b/src/nautilus-window-private.h
@@ -44,8 +44,6 @@ struct NautilusWindowDetails
guint extensions_menu_merge_id;
GtkActionGroup *extensions_menu_action_group;
- NautilusWindowShowHiddenFilesMode show_hidden_files_mode;
-
/* Ensures that we do not react on signals of a
* view that is re-used as new view when its loading
* is cancelled
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 3327a4c6a..843b0dcb6 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -34,6 +34,7 @@
#include "nautilus-actions.h"
#include "nautilus-application.h"
#include "nautilus-bookmarks-window.h"
+#include "nautilus-desktop-window.h"
#include "nautilus-location-bar.h"
#include "nautilus-mime-actions.h"
#include "nautilus-notebook.h"
@@ -102,7 +103,6 @@ enum {
RELOAD,
PROMPT_FOR_LOCATION,
LOADING_URI,
- HIDDEN_FILES_MODE_CHANGED,
SLOT_ADDED,
SLOT_REMOVED,
LAST_SIGNAL
@@ -332,14 +332,8 @@ close_slot (NautilusWindow *window,
page_num = gtk_notebook_page_num (notebook, GTK_WIDGET (slot));
g_assert (page_num >= 0);
- g_signal_handlers_block_by_func (notebook,
- G_CALLBACK (notebook_switch_page_cb),
- window);
/* this will call gtk_widget_destroy on the slot */
gtk_notebook_remove_page (notebook, page_num);
- g_signal_handlers_unblock_by_func (notebook,
- G_CALLBACK (notebook_switch_page_cb),
- window);
}
}
@@ -1025,6 +1019,33 @@ create_toolbar (NautilusWindow *window)
}
static void
+notebook_num_pages_changed (NautilusWindow *window)
+{
+ NautilusView *view;
+ NautilusWindowSlot *active_slot;
+
+ active_slot = nautilus_window_get_active_slot (window);
+ if (active_slot == NULL) {
+ return;
+ }
+ view = nautilus_window_slot_get_current_view (active_slot);
+ if (view == NULL) {
+ return;
+ }
+
+ /* Only add a shadow to the scrolled window when we're in a tabless
+ * notebook, since when the notebook has tabs, it will draw its own
+ * border.
+ */
+ if (g_list_length (window->details->slots) > 1 ||
+ NAUTILUS_IS_DESKTOP_WINDOW (window)) {
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view), GTK_SHADOW_NONE);
+ } else {
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view), GTK_SHADOW_IN);
+ }
+}
+
+static void
notebook_page_removed_cb (GtkNotebook *notebook,
GtkWidget *page,
guint page_num,
@@ -1034,6 +1055,8 @@ notebook_page_removed_cb (GtkNotebook *notebook,
NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (page), *next_slot;
gboolean dnd_slot;
+ notebook_num_pages_changed (window);
+
dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
if (!dnd_slot) {
return;
@@ -1058,6 +1081,11 @@ notebook_page_added_cb (GtkNotebook *notebook,
NautilusWindowSlot *dummy_slot;
gboolean dnd_slot;
+ /* It's too early here to call notebook_num_pages_changed(),
+ * since the view might not be associagted to the slot yet.
+ * Defer the call to nautilus_window_connect_content_view().
+ */
+
dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
if (!dnd_slot) {
return;
@@ -1710,6 +1738,9 @@ nautilus_window_connect_content_view (NautilusWindow *window,
G_CALLBACK (zoom_level_changed_callback),
window);
+ /* See the comment in notebook_page_added_cb() */
+ notebook_num_pages_changed (window);
+
/* Update displayed view in menu. Only do this if we're not switching
* locations though, because if we are switching locations we'll
* install a whole new set of views in the menu later (the current
@@ -1835,21 +1866,6 @@ nautilus_window_get_slot_for_view (NautilusWindow *window,
return slot;
}
-NautilusWindowShowHiddenFilesMode
-nautilus_window_get_hidden_files_mode (NautilusWindow *window)
-{
- return window->details->show_hidden_files_mode;
-}
-
-void
-nautilus_window_set_hidden_files_mode (NautilusWindow *window,
- NautilusWindowShowHiddenFilesMode mode)
-{
- window->details->show_hidden_files_mode = mode;
-
- g_signal_emit_by_name (window, "hidden_files_mode_changed");
-}
-
NautilusWindowSlot *
nautilus_window_get_active_slot (NautilusWindow *window)
{
@@ -1971,8 +1987,6 @@ nautilus_window_init (NautilusWindow *window)
window->details->slots = NULL;
window->details->active_slot = NULL;
- window->details->show_hidden_files_mode = NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_DEFAULT;
-
window_group = gtk_window_group_new ();
gtk_window_group_add_window (window_group, GTK_WINDOW (window));
g_object_unref (window_group);
@@ -2060,14 +2074,6 @@ nautilus_window_class_init (NautilusWindowClass *class)
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
- signals[HIDDEN_FILES_MODE_CHANGED] =
- g_signal_new ("hidden_files_mode_changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
signals[LOADING_URI] =
g_signal_new ("loading_uri",
G_TYPE_FROM_CLASS (class),
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index ecc200f86..6e7ed6349 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -50,12 +50,6 @@
(G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_WINDOW, NautilusWindowClass))
typedef enum {
- NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_DEFAULT,
- NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_ENABLE,
- NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_DISABLE
-} NautilusWindowShowHiddenFilesMode;
-
-typedef enum {
NAUTILUS_WINDOW_NOT_SHOWN,
NAUTILUS_WINDOW_POSITION_SET,
NAUTILUS_WINDOW_SHOULD_SHOW
@@ -120,10 +114,6 @@ GtkActionGroup * nautilus_window_get_main_action_group (NautilusWindow *window
void nautilus_window_report_load_complete (NautilusWindow *window,
NautilusView *view);
-NautilusWindowShowHiddenFilesMode
- nautilus_window_get_hidden_files_mode (NautilusWindow *window);
-void nautilus_window_set_hidden_files_mode (NautilusWindow *window,
- NautilusWindowShowHiddenFilesMode mode);
void nautilus_window_report_load_underway (NautilusWindow *window,
NautilusView *view);
void nautilus_window_view_visible (NautilusWindow *window,