From 1fc9e88816691e4ceeb0108d1a30017eef1e7210 Mon Sep 17 00:00:00 2001 From: Carlos Soriano Date: Thu, 9 Jul 2015 17:15:25 +0200 Subject: [PATCH 1/3] general: add nautilus delete notification So in the next patch we will able to change the delete shortcut to just del. --- .../nautilus-file-undo-operations.c | 8 +- .../nautilus-file-undo-operations.h | 4 + src/nautilus-notification.ui | 82 +++++++++++ src/nautilus-window-private.h | 7 + src/nautilus-window.c | 164 +++++++++++++++++++-- src/nautilus.gresource.xml | 1 + 6 files changed, 251 insertions(+), 15 deletions(-) create mode 100644 src/nautilus-notification.ui diff --git a/libnautilus-private/nautilus-file-undo-operations.c b/libnautilus-private/nautilus-file-undo-operations.c index 717f6f8..c1e9dab 100644 --- a/libnautilus-private/nautilus-file-undo-operations.c +++ b/libnautilus-private/nautilus-file-undo-operations.c @@ -186,7 +186,7 @@ nautilus_file_undo_info_class_init (NautilusFileUndoInfoClass *klass) g_object_class_install_properties (oclass, N_PROPERTIES, properties); } -static NautilusFileUndoOp +NautilusFileUndoOp nautilus_file_undo_info_get_op_type (NautilusFileUndoInfo *self) { return self->priv->op_type; @@ -965,6 +965,12 @@ struct _NautilusFileUndoInfoTrashDetails { GHashTable *trashed; }; +GList * +nautilus_file_undo_info_trash_get_files (NautilusFileUndoInfoTrash *self) +{ + return g_hash_table_get_keys (self->priv->trashed); +} + static void trash_strings_func (NautilusFileUndoInfo *info, gchar **undo_label, diff --git a/libnautilus-private/nautilus-file-undo-operations.h b/libnautilus-private/nautilus-file-undo-operations.h index 5a3953f..06db117 100644 --- a/libnautilus-private/nautilus-file-undo-operations.h +++ b/libnautilus-private/nautilus-file-undo-operations.h @@ -95,6 +95,8 @@ void nautilus_file_undo_info_get_strings (NautilusFileUndoInfo *self, gchar **undo_description, gchar **redo_label, gchar **redo_description); +NautilusFileUndoOp nautilus_file_undo_info_get_op_type (NautilusFileUndoInfo *self); + /* copy/move/duplicate/link/restore from trash */ #define NAUTILUS_TYPE_FILE_UNDO_INFO_EXT (nautilus_file_undo_info_ext_get_type ()) @@ -206,6 +208,8 @@ GType nautilus_file_undo_info_trash_get_type (void) G_GNUC_CONST; NautilusFileUndoInfo *nautilus_file_undo_info_trash_new (gint item_count); void nautilus_file_undo_info_trash_add_file (NautilusFileUndoInfoTrash *self, GFile *file); +GList *nautilus_file_undo_info_trash_get_files (NautilusFileUndoInfoTrash *self); + /* recursive permissions */ #define NAUTILUS_TYPE_FILE_UNDO_INFO_REC_PERMISSIONS (nautilus_file_undo_info_rec_permissions_get_type ()) diff --git a/src/nautilus-notification.ui b/src/nautilus-notification.ui new file mode 100644 index 0000000..bef7a0b --- /dev/null +++ b/src/nautilus-notification.ui @@ -0,0 +1,82 @@ + + + + True + + + True + False + False + + + + + True + False + center + start + 100 + + + True + False + + + True + False + 12 + 4 + + + True + False + 50 + middle + 30 + + + + + Undo + True + True + True + True + 6 + + + + + + True + True + True + none + False + + + True + False + window-close-symbolic + 2 + + + + + + + + + + + + + + + diff --git a/src/nautilus-window-private.h b/src/nautilus-window-private.h index 5531d8e..050c021 100644 --- a/src/nautilus-window-private.h +++ b/src/nautilus-window-private.h @@ -72,6 +72,13 @@ struct NautilusWindowDetails guint sidebar_width_handler_id; guint bookmarks_id; + + /* Notifications */ + GtkWidget *notification_delete; + GtkWidget *notification_delete_label; + GtkWidget *notification_delete_close; + GtkWidget *notification_delete_undo; + guint notification_delete_timeout_id; }; /* window geometry */ diff --git a/src/nautilus-window.c b/src/nautilus-window.c index 38dea35..7b4d864 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -59,6 +59,8 @@ #include #include #include +#include +#include #include #include #include @@ -90,6 +92,8 @@ static void use_extra_mouse_buttons_changed (gpointer */ #define UPPER_MOUSE_LIMIT 14 +#define NOTIFICATION_TIMEOUT 6 //s + enum { PROP_DISABLE_CHROME = 1, NUM_PROPERTIES, @@ -1392,12 +1396,12 @@ notebook_create_window_cb (GtkNotebook *notebook, return GTK_NOTEBOOK (new_window->details->notebook); } -static GtkWidget * -create_notebook (NautilusWindow *window) +static void +connect_notebook (NautilusWindow *window) { GtkWidget *notebook; - notebook = g_object_new (NAUTILUS_TYPE_NOTEBOOK, NULL); + notebook = window->details->notebook; g_signal_connect (notebook, "tab-close-request", G_CALLBACK (notebook_tab_close_requested), window); @@ -1419,17 +1423,124 @@ create_notebook (NautilusWindow *window) g_signal_connect_after (notebook, "button-press-event", G_CALLBACK (notebook_button_press_cb), window); +} + +static void +nautilus_window_on_notification_delete_undo_clicked (GtkWidget *notification, + gpointer user_data) +{ + NautilusWindow *window; + + window = NAUTILUS_WINDOW (user_data); + + if (window->details->notification_delete_timeout_id != 0) { + g_source_remove (window->details->notification_delete_timeout_id); + window->details->notification_delete_timeout_id = 0; + } + + gtk_revealer_set_reveal_child (GTK_REVEALER (window->details->notification_delete), FALSE); + nautilus_file_undo_manager_undo (GTK_WINDOW (window)); +} + +static void +nautilus_window_on_notification_delete_close_clicked (GtkWidget *notification, + gpointer user_data) +{ + NautilusWindow *window; + + window = NAUTILUS_WINDOW (user_data); + + if (window->details->notification_delete_timeout_id != 0) { + g_source_remove (window->details->notification_delete_timeout_id); + window->details->notification_delete_timeout_id = 0; + } + + gtk_revealer_set_reveal_child (GTK_REVEALER (window->details->notification_delete), FALSE); +} + +static gboolean +nautilus_window_on_notification_delete_timeout (gpointer user_data) +{ + NautilusWindow *window; + + window = NAUTILUS_WINDOW (user_data); + + if (window->details->notification_delete_timeout_id != 0) { + g_source_remove (window->details->notification_delete_timeout_id); + window->details->notification_delete_timeout_id = 0; + } + + gtk_revealer_set_reveal_child (GTK_REVEALER (window->details->notification_delete), FALSE); - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE); - gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE); - gtk_widget_show (notebook); - gtk_container_set_border_width (GTK_CONTAINER (notebook), 0); + return FALSE; +} + +static char * +nautilus_window_notification_delete_get_label (NautilusFileUndoInfo *undo_info, + GList *files) +{ + gchar *file_label; + gchar *label; + gint length; + + length = g_list_length (files); + if (length == 1) { + file_label = g_file_get_basename (files->data); + /* Translators: only one item has been deleted and %s is its name. */ + label = g_strdup_printf (_("“%s” deleted"), file_label); + g_free (file_label); + } else { + /* Translators: one or more items might have been deleted, and %d + * is the count. */ + label = g_strdup_printf (ngettext ("%d file deleted", "%d files deleted", length), length); + } - gtk_box_pack_start (GTK_BOX (window->details->main_view), - notebook, - TRUE, TRUE, 0); + return label; +} - return notebook; +static void +nautilus_window_on_undo_changed (NautilusFileUndoManager *manager, + NautilusWindow *window) +{ + NautilusFileUndoInfo *undo_info; + NautilusFileUndoManagerState state; + int transition_durantion; + gchar *label; + GList *files; + + /* Hide it inmediatily so we can animate the new notification. */ + transition_durantion = gtk_revealer_get_transition_duration (GTK_REVEALER (window->details->notification_delete)); + gtk_revealer_set_transition_duration (GTK_REVEALER (window->details->notification_delete), 0); + gtk_revealer_set_reveal_child (GTK_REVEALER (window->details->notification_delete), FALSE); + gtk_revealer_set_transition_duration (GTK_REVEALER (window->details->notification_delete), transition_durantion); + if (window->details->notification_delete_timeout_id != 0) { + g_source_remove (window->details->notification_delete_timeout_id); + window->details->notification_delete_timeout_id = 0; + } + + undo_info = nautilus_file_undo_manager_get_action (); + state = nautilus_file_undo_manager_get_state (); + + if (undo_info != NULL && + state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO && + nautilus_file_undo_info_get_op_type (undo_info) == NAUTILUS_FILE_UNDO_OP_MOVE_TO_TRASH && + !NAUTILUS_IS_DESKTOP_WINDOW (window)) { + files = nautilus_file_undo_info_trash_get_files (NAUTILUS_FILE_UNDO_INFO_TRASH (undo_info)); + + /* Don't pop up a notification if user canceled the operation or the focus + * is not in the this window. This is an easy way to know from which window + * was the delete operation made */ + if (g_list_length (files) > 0 && gtk_window_has_toplevel_focus (GTK_WINDOW (window))) { + label = nautilus_window_notification_delete_get_label (undo_info, files); + gtk_label_set_markup (GTK_LABEL (window->details->notification_delete_label), label); + gtk_revealer_set_reveal_child (GTK_REVEALER (window->details->notification_delete), TRUE); + window->details->notification_delete_timeout_id = g_timeout_add_seconds (NOTIFICATION_TIMEOUT, + nautilus_window_on_notification_delete_timeout, + window); + g_free (label); + } + g_list_free (files); + } } static void @@ -1439,6 +1550,7 @@ nautilus_window_constructed (GObject *self) GtkWidget *grid; NautilusWindowSlot *slot; NautilusApplication *application; + GtkBuilder *builder; window = NAUTILUS_WINDOW (self); @@ -1476,13 +1588,30 @@ nautilus_window_constructed (GObject *self) gtk_container_add (GTK_CONTAINER (grid), window->details->content_paned); gtk_widget_show (window->details->content_paned); - window->details->main_view = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + g_type_ensure (NAUTILUS_TYPE_NOTEBOOK); + builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/nautilus-notification.ui"); + + window->details->main_view = GTK_WIDGET (gtk_builder_get_object (builder, "main_view")); gtk_paned_pack2 (GTK_PANED (window->details->content_paned), window->details->main_view, TRUE, FALSE); gtk_widget_show (window->details->main_view); - window->details->notebook = create_notebook (window); - nautilus_window_set_initial_window_geometry (window); + window->details->notebook = GTK_WIDGET (gtk_builder_get_object (builder, "notebook")); + connect_notebook (window); + window->details->notification_delete = GTK_WIDGET (gtk_builder_get_object (builder, "notification_delete")); + window->details->notification_delete_label = GTK_WIDGET (gtk_builder_get_object (builder, "notification_delete_label")); + window->details->notification_delete_undo = GTK_WIDGET (gtk_builder_get_object (builder, "notification_delete_undo")); + window->details->notification_delete_close = GTK_WIDGET (gtk_builder_get_object (builder, "notification_delete_close")); + + g_object_unref (builder); + + g_signal_connect_object (window->details->notification_delete_close, "clicked", + G_CALLBACK (nautilus_window_on_notification_delete_close_clicked), window, 0); + g_signal_connect_object (window->details->notification_delete_undo, "clicked", + G_CALLBACK (nautilus_window_on_notification_delete_undo_clicked), window, 0);nautilus_window_set_initial_window_geometry (window); + + g_signal_connect_after (nautilus_file_undo_manager_get (), "undo-changed", + G_CALLBACK (nautilus_window_on_undo_changed), self); slot = nautilus_window_open_slot (window, 0); nautilus_window_set_active_slot (window, slot); @@ -1604,6 +1733,13 @@ nautilus_window_finalize (GObject *object) window->details->sidebar_width_handler_id = 0; } + if (window->details->notification_delete_timeout_id != 0) { + g_source_remove (window->details->notification_delete_timeout_id); + window->details->notification_delete_timeout_id = 0; + } + + g_signal_handlers_disconnect_by_data (nautilus_file_undo_manager_get (), window); + g_clear_object (&window->details->ui_manager); /* nautilus_window_close() should have run */ diff --git a/src/nautilus.gresource.xml b/src/nautilus.gresource.xml index 37a5bbf..0abdeb0 100644 --- a/src/nautilus.gresource.xml +++ b/src/nautilus.gresource.xml @@ -8,6 +8,7 @@ nautilus-directory-view-ui.xml nautilus-list-view-ui.xml nautilus-shell-ui.xml + nautilus-notification.ui nautilus-app-menu.ui ../icons/thumbnail_frame.png ../icons/filmholes.png -- 2.5.0 From 32608e0ea470cdbe05bd3d2e3b3588cbe9ba39bc Mon Sep 17 00:00:00 2001 From: Carlos Soriano Date: Thu, 9 Jul 2015 17:18:28 +0200 Subject: [PATCH 2/3] view: change delete shortcut To just the del key. --- src/nautilus-view.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nautilus-view.c b/src/nautilus-view.c index 20590c4..b729339 100644 --- a/src/nautilus-view.c +++ b/src/nautilus-view.c @@ -7208,7 +7208,7 @@ static const GtkActionEntry directory_view_entries[] = { /* tooltip */ NULL, G_CALLBACK (action_rename_select_all_callback) }, /* name, stock id */ { NAUTILUS_ACTION_TRASH, NULL, - /* label, accelerator */ N_("Mo_ve to Trash"), "Delete", + /* label, accelerator */ N_("Mo_ve to Trash"), "Delete", /* tooltip */ N_("Move each selected item to the Trash"), G_CALLBACK (action_trash_callback) }, /* name, stock id */ { NAUTILUS_ACTION_DELETE, NULL, -- 2.5.0 From 10bc4b82d158ba93ee179bbb0f7231fa44299876 Mon Sep 17 00:00:00 2001 From: Carlos Soriano Date: Fri, 10 Jul 2015 17:14:27 +0200 Subject: [PATCH 3/3] application: add a warning for the move to trash shortcut Since we changed it, better so warn the user in case he use the old shortcut. --- libnautilus-private/nautilus-global-preferences.h | 3 ++ .../org.gnome.nautilus.gschema.xml.in | 5 +++ src/nautilus-application-actions.c | 46 ++++++++++++++++++++++ src/nautilus-move-to-trash-shortcut-changed.ui | 24 +++++++++++ src/nautilus-view.c | 4 -- src/nautilus.gresource.xml | 1 + 6 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 src/nautilus-move-to-trash-shortcut-changed.ui diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h index 5ec3e08..3cef2a3 100644 --- a/libnautilus-private/nautilus-global-preferences.h +++ b/libnautilus-private/nautilus-global-preferences.h @@ -159,6 +159,9 @@ typedef enum /* Recent files */ #define NAUTILUS_PREFERENCES_RECENT_FILES_ENABLED "remember-recent-files" +/* Move to trash shorcut changed dialog */ +#define NAUTILUS_PREFERENCES_SHOW_MOVE_TO_TRASH_SHORTCUT_CHANGED_DIALOG "show-move-to-trash-shortcut-changed-dialog" + void nautilus_global_preferences_init (void); char *nautilus_global_preferences_get_default_folder_viewer_preference_as_iid (void); diff --git a/libnautilus-private/org.gnome.nautilus.gschema.xml.in b/libnautilus-private/org.gnome.nautilus.gschema.xml.in index ba344a2..71d94b8 100644 --- a/libnautilus-private/org.gnome.nautilus.gschema.xml.in +++ b/libnautilus-private/org.gnome.nautilus.gschema.xml.in @@ -104,6 +104,11 @@ <_summary>Use extra mouse button events in Nautilus' browser window <_description>For users with mice that have "Forward" and "Back" buttons, this key will determine if any action is taken inside of Nautilus when either is pressed. + + true + <_summary>Show a warning dialog for the change of the shorcut for move to trash + <_description>Show a warning dialog for the change of the shorcut for move to trash from control + delete to just delete. + 9 <_summary>Mouse button to activate the "Forward" command in browser window diff --git a/src/nautilus-application-actions.c b/src/nautilus-application-actions.c index e346d61..b759b7a 100644 --- a/src/nautilus-application-actions.c +++ b/src/nautilus-application-actions.c @@ -21,6 +21,7 @@ #include "nautilus-application-actions.h" +#include "nautilus-global-preferences.h" #include "nautilus-desktop-window.h" #include "nautilus-file-management-properties.h" @@ -233,6 +234,49 @@ action_search (GSimpleAction *action, g_object_unref (location); } +static void +got_it_clicked (GtkDialog *dialog, + gint response_id, + gpointer user_data) +{ + g_settings_set_boolean (nautilus_preferences, + NAUTILUS_PREFERENCES_SHOW_MOVE_TO_TRASH_SHORTCUT_CHANGED_DIALOG, + FALSE); +} + +static void +action_show_move_to_trash_shortcut_changed_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GtkApplication *app; + GtkWindow *window; + GtkWindow *dialog; + GtkBuilder *builder; + gboolean show_dialog_preference; + + app = GTK_APPLICATION (user_data); + show_dialog_preference = g_settings_get_boolean (nautilus_preferences, + NAUTILUS_PREFERENCES_SHOW_MOVE_TO_TRASH_SHORTCUT_CHANGED_DIALOG); + if (show_dialog_preference) { + builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/nautilus-move-to-trash-shortcut-changed.ui"); + dialog = GTK_WINDOW (gtk_builder_get_object (builder, "move_to_trash_shortcut_changed_dialog")); + + window = gtk_application_get_active_window (app); + gtk_window_set_transient_for (dialog, window); + g_signal_connect (dialog, "response", + G_CALLBACK (got_it_clicked), + window); + + gtk_widget_show (GTK_WIDGET (dialog)); + gtk_dialog_run(GTK_DIALOG (dialog)); + gtk_widget_destroy (GTK_WIDGET (dialog)); + + g_object_unref (builder); + } +} + + static GActionEntry app_entries[] = { { "new-window", action_new_window, NULL, NULL, NULL }, { "connect-to-server", action_connect_to_server, NULL, NULL, NULL }, @@ -246,6 +290,7 @@ static GActionEntry app_entries[] = { { "kill", action_kill, NULL, NULL, NULL }, { "open-desktop", action_open_desktop, NULL, NULL, NULL }, { "close-desktop", action_close_desktop, NULL, NULL, NULL }, + { "show-move-to-trash-shortcut-changed-dialog", action_show_move_to_trash_shortcut_changed_dialog, NULL, NULL, NULL }, }; void @@ -259,6 +304,7 @@ nautilus_init_application_actions (NautilusApplication *app) app_entries, G_N_ELEMENTS (app_entries), app); gtk_application_add_accelerator (GTK_APPLICATION (app), "F10", "win.gear-menu", NULL); + gtk_application_add_accelerator (GTK_APPLICATION (app), "Delete", "app.show-move-to-trash-shortcut-changed-dialog", NULL); builder = gtk_builder_new (); gtk_builder_add_from_resource (builder, "/org/gnome/nautilus/nautilus-app-menu.ui", &error); diff --git a/src/nautilus-move-to-trash-shortcut-changed.ui b/src/nautilus-move-to-trash-shortcut-changed.ui new file mode 100644 index 0000000..7074b41 --- /dev/null +++ b/src/nautilus-move-to-trash-shortcut-changed.ui @@ -0,0 +1,24 @@ + + + + + + False + True + center-on-parent + True + dialog + Delete Shortcuts Have Changed + With the latest version of Files, you no longer need to hold Ctrl to delete—the Delete key will work when pressed on its own. + + + Got it + True + + + + button_got_it + + + + diff --git a/src/nautilus-view.c b/src/nautilus-view.c index b729339..60eb29e 100644 --- a/src/nautilus-view.c +++ b/src/nautilus-view.c @@ -9851,10 +9851,6 @@ nautilus_view_class_init (NautilusViewClass *klass) g_object_class_install_properties (oclass, NUM_PROPERTIES, properties); binding_set = gtk_binding_set_by_class (klass); - gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK, - "trash", 0); - gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK, - "trash", 0); gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_SHIFT_MASK, "delete", 0); } diff --git a/src/nautilus.gresource.xml b/src/nautilus.gresource.xml index 0abdeb0..c6f42dc 100644 --- a/src/nautilus.gresource.xml +++ b/src/nautilus.gresource.xml @@ -10,6 +10,7 @@ nautilus-shell-ui.xml nautilus-notification.ui nautilus-app-menu.ui + nautilus-move-to-trash-shortcut-changed.ui ../icons/thumbnail_frame.png ../icons/filmholes.png ../icons/knob.png -- 2.5.0