[nautilus/wip/gaction] Add selection menu
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/gaction] Add selection menu
- Date: Thu, 13 Nov 2014 15:54:27 +0000 (UTC)
commit ff8a4f2e694e9a2e8b2cf28e1cccb2ccc043d213
Author: Carlos Soriano <carlos sorian89 gmail com>
Date: Thu Nov 13 16:54:12 2014 +0100
Add selection menu
src/nautilus-view-right-click-menus.xml | 63 ++++++-
src/nautilus-view.c | 312 +++++++++++++++++++++++++++----
2 files changed, 335 insertions(+), 40 deletions(-)
---
diff --git a/src/nautilus-view-right-click-menus.xml b/src/nautilus-view-right-click-menus.xml
index 116aa30..dd33565 100755
--- a/src/nautilus-view-right-click-menus.xml
+++ b/src/nautilus-view-right-click-menus.xml
@@ -75,17 +75,15 @@
</menu>
<menu id="selection-menu">
<section>
+ <attribute name="id">open-with-default-application-section</attribute>
+ </section>
+ <section>
<item>
<attribute name="label" translatable="yes">Open Item Location</attribute>
<attribute name="action">view.open-item-location</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
<item>
- <attribute name="label" translatable="yes">Open</attribute>
- <attribute name="action">view.open-item</attribute>
- <attribute name="hidden-when">action-disabled</attribute>
- </item>
- <item>
<attribute name="label" translatable="yes">Open In New Window</attribute>
<attribute name="action">view.open-item-new-window</attribute>
<attribute name="hidden-when">action-disabled</attribute>
@@ -97,7 +95,60 @@
</item>
</section>
<section>
-
+ <item>
+ <attribute name="label" translatable="yes">Open With Other Application</attribute>
+ <attribute name="action">view.open-with-other-application</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Cut</attribute>
+ <attribute name="action">view.cut</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Copy</attribute>
+ <attribute name="action">view.copy</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Move to…</attribute>
+ <attribute name="action">view.move-to</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Copy to…</attribute>
+ <attribute name="action">view.copy-to</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Send to…</attribute>
+ <attribute name="action">view.send-to</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Move to Trash</attribute>
+ <attribute name="action">view.move-to-trash</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Rename</attribute>
+ <attribute name="action">view.rename</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Properties</attribute>
+ <attribute name="action">view.properties</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
</section>
</menu>
</interface>
\ No newline at end of file
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index 120c81d..df13c1f 100755
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -319,7 +319,7 @@ static void unschedule_pop_up_location_context_menu (NautilusView *view);
static void action_new_folder (GSimpleAction *action,
GVariant *state,
gpointer user_data);
-static void action_new_tab (GSimpleAction *action,
+static void action_new_item_tab (GSimpleAction *action,
GVariant *state,
gpointer user_data);
static void action_undo (GSimpleAction *action,
@@ -1131,9 +1131,9 @@ action_open_callback (GtkAction *action,
}
static void
-action_open_item (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+action_open_with_default_application (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
{
NautilusView *view;
@@ -1357,8 +1357,9 @@ open_with_other_program (NautilusView *view)
g_assert (NAUTILUS_IS_VIEW (view));
selection = nautilus_view_get_selection (view);
-
+ g_print ("open with other program\n");
if (selection_contains_one_item_in_menu_callback (view, selection)) {
+ g_print ("one item in election open with other program\n");
choose_program (view, NAUTILUS_FILE (selection->data));
}
@@ -1375,6 +1376,16 @@ action_other_application_callback (GtkAction *action,
}
static void
+action_open_with_other_application (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ g_assert (NAUTILUS_IS_VIEW (user_data));
+
+ open_with_other_program (NAUTILUS_VIEW (user_data));
+}
+
+static void
trash_or_delete_selected_files (NautilusView *view)
{
GList *selection;
@@ -1416,6 +1427,14 @@ action_trash_callback (GtkAction *action,
}
static void
+action_move_to_trash (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ trash_or_delete_selected_files (NAUTILUS_VIEW (user_data));
+}
+
+static void
delete_selected_files (NautilusView *view)
{
GList *selection;
@@ -2255,6 +2274,33 @@ action_properties_callback (GtkAction *action,
}
static void
+action_properties (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ NautilusView *view;
+ GList *selection;
+ GList *files;
+
+ g_assert (NAUTILUS_IS_VIEW (user_data));
+
+ view = NAUTILUS_VIEW (user_data);
+ selection = nautilus_view_get_selection (view);
+ if (g_list_length (selection) == 0) {
+ if (view->details->directory_as_file != NULL) {
+ files = g_list_append (NULL, nautilus_file_ref (view->details->directory_as_file));
+
+ nautilus_properties_window_present (files, GTK_WIDGET (view), NULL);
+
+ nautilus_file_list_free (files);
+ }
+ } else {
+ nautilus_properties_window_present (selection, GTK_WIDGET (view), NULL);
+ }
+ nautilus_file_list_free (selection);
+}
+
+static void
action_location_properties_callback (GtkAction *action,
gpointer callback_data)
{
@@ -2350,31 +2396,6 @@ action_show_hidden_files (GSimpleAction *action,
}
static void
-action_new_tab (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
-{
- GList *selection;
- GtkWindow *window;
-
- g_assert (NAUTILUS_IS_VIEW (user_data));
-
-
- selection = nautilus_view_get_selection (user_data);
-
- window = nautilus_view_get_containing_window (user_data);
-
- if (nautilus_view_confirm_multiple (window, g_list_length (selection), TRUE)) {
- nautilus_view_activate_files (user_data,
- selection,
- NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB,
- FALSE);
- }
-
- nautilus_file_list_free (selection);
-}
-
-static void
action_undo (GSimpleAction *action,
GVariant *state,
gpointer user_data)
@@ -3157,6 +3178,7 @@ nautilus_view_display_selection_info (NautilusView *view)
char *detail_status;
NautilusFile *file;
+ g_print ("display select info %s\n", G_OBJECT_TYPE_NAME (view));
g_return_if_fail (NAUTILUS_IS_VIEW (view));
selection = nautilus_view_get_selection (view);
@@ -6332,6 +6354,21 @@ action_copy_files_callback (GtkAction *action,
}
static void
+action_copy(GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ NautilusView *view;
+ GList *selection;
+
+ view = NAUTILUS_VIEW (user_data);
+
+ selection = nautilus_view_get_selection_for_file_transfer (view);
+ copy_or_cut_files (view, selection, FALSE);
+ nautilus_file_list_free (selection);
+}
+
+static void
action_cut_files_callback (GtkAction *action,
gpointer callback_data)
{
@@ -6346,6 +6383,21 @@ action_cut_files_callback (GtkAction *action,
}
static void
+action_cut (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ NautilusView *view;
+ GList *selection;
+
+ view = NAUTILUS_VIEW (user_data);
+
+ selection = nautilus_view_get_selection_for_file_transfer (view);
+ copy_or_cut_files (view, selection, TRUE);
+ nautilus_file_list_free (selection);
+}
+
+static void
action_copy_to_callback (GtkAction *action,
gpointer callback_data)
{
@@ -6356,6 +6408,17 @@ action_copy_to_callback (GtkAction *action,
}
static void
+action_copy_to (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ NautilusView *view;
+
+ view = NAUTILUS_VIEW (user_data);
+ copy_or_move_selection (view, FALSE);
+}
+
+static void
action_move_to_callback (GtkAction *action,
gpointer callback_data)
{
@@ -6365,6 +6428,17 @@ action_move_to_callback (GtkAction *action,
copy_or_move_selection (view, TRUE);
}
+static void
+action_move_to (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ NautilusView *view;
+
+ view = NAUTILUS_VIEW (user_data);
+ copy_or_move_selection (view, TRUE);
+}
+
typedef struct {
NautilusView *view;
NautilusFile *target;
@@ -6534,6 +6608,15 @@ action_rename_callback (GtkAction *action,
}
static void
+action_rename (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ real_action_rename (NAUTILUS_VIEW (user_data), FALSE);
+}
+
+
+static void
action_rename_select_all_callback (GtkAction *action,
gpointer callback_data)
{
@@ -7315,9 +7398,17 @@ const GActionEntry view_entries[] = {
{ "show-hidden-files", NULL, NULL, "true", action_show_hidden_files },
/* Selection menu */
{ "open-item-location", action_open_item_location },
- { "open-item", action_open_item },
+ { "open-with-default-application", action_open_with_default_application },
{ "open-item-new-window", action_open_item_new_window },
{ "open-item-new-tab", action_open_item_new_tab },
+ { "cut", action_cut},
+ { "copy", action_copy},
+ { "move-to", action_move_to},
+ { "copy-to", action_copy_to},
+ { "move-to-trash", action_move_to_trash},
+ { "rename", action_rename},
+ { "properties", action_properties},
+ { "open-with-other-application", action_open_with_other_application }
};
static const GtkActionEntry directory_view_entries[] = {
@@ -9016,15 +9107,168 @@ nautilus_view_get_action_group (NautilusView *view)
static void
real_update_actions_state (NautilusView *view)
{
+ GList *selection, *l;
+ gint selection_count;
+ const char *tip, *label;
+ char *label_with_underscore;
+ gboolean selection_contains_special_link;
+ gboolean selection_contains_desktop_or_home_dir;
+ gboolean selection_contains_recent;
+ gboolean selection_contains_search;
+ gboolean selection_all_in_trash;
+ gboolean can_create_files;
+ gboolean can_delete_files;
+ gboolean can_move_files;
+ gboolean can_trash_files;
+ gboolean can_copy_files;
+ gboolean can_link_files;
+ gboolean show_separate_delete_command;
+ gboolean show_open_alternate;
+ gboolean show_open_in_new_tab;
+ gboolean can_open;
+ gboolean show_app, show_run;
+ gboolean show_save_search;
+ gboolean save_search_sensitive;
+ gboolean show_save_search_as;
+ gboolean item_opens_in_view;
+ GAction *action;
+ GAppInfo *app;
+ GIcon *app_icon;
+ GtkWidget *menuitem;
+ gboolean show_properties;
GActionGroup *view_action_group;
+ gchar *detailed_action;
+ GMenuItem *open_menu_item;
view_action_group = view->details->view_action_group;
- GAction *action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "show-hidden-files");
+ g_print ("entering update actions state\n");
+
+ selection = nautilus_view_get_selection (view);
+ selection_count = g_list_length (selection);
+ selection_contains_special_link = special_link_in_selection (selection);
+ selection_contains_desktop_or_home_dir = desktop_or_home_dir_in_selection (selection);
+ selection_contains_recent = showing_recent_directory (view);
+ selection_contains_search = view->details->model &&
+ NAUTILUS_IS_SEARCH_DIRECTORY (view->details->model);
+ selection_all_in_trash = all_selected_items_in_trash (selection);
+ can_create_files = nautilus_view_supports_creating_files (view);
+ can_delete_files =
+ can_delete_all (selection) &&
+ selection_count != 0 &&
+ !selection_contains_special_link &&
+ !selection_contains_desktop_or_home_dir;
+ can_trash_files =
+ can_trash_all (selection) &&
+ selection_count != 0 &&
+ !selection_contains_special_link &&
+ !selection_contains_desktop_or_home_dir;
+ can_copy_files = selection_count != 0
+ && !selection_contains_special_link;
+ can_move_files = can_delete_files && !selection_contains_recent;
+ can_link_files = can_create_files && can_copy_files;
+
+ /* Right click actions */
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "rename");
+ if (selection_count > 1) {
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ have_bulk_rename_tool ());
+ } else {
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ selection_count == 1 &&
+ nautilus_view_can_rename_file (view, selection->data));
+ }
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "open-item-location");
+
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ selection_count == 1 &&
+ (selection_contains_recent || selection_contains_search));
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "new-folder");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_create_files);
+
+
+ /* If selection is only one item and it's a folder or
+ * some item that shows in the view, we show the
+ * "open" menu item */
+ item_opens_in_view = selection_count == 1 &&
+ nautilus_mime_file_opens_in_view (NAUTILUS_FILE (selection->data));
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "open-item-new-tab");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), item_opens_in_view);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "open-item-new-window");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), item_opens_in_view);
+
+ /* Open With <App> menu item */
+ can_open = show_app = show_run = selection_count == 1;
+ for (l = selection; l != NULL; l = l->next) {
+ NautilusFile *file;
+
+ file = NAUTILUS_FILE (selection->data);
+
+ if (!nautilus_mime_file_opens_in_external_app (file)) {
+ show_app = FALSE;
+ }
+
+ if (!nautilus_mime_file_launches (file)) {
+ show_run = FALSE;
+ }
+
+ if (!show_app && !show_run) {
+ break;
+ }
+ }
+
+ label_with_underscore = NULL;
+ app = NULL;
+
+ if (show_app) {
+ app = nautilus_mime_get_default_application_for_files (selection);
+ }
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "open-with-default-application");
+ if (app != NULL || show_run || item_opens_in_view) {
+ char *escaped_app;
+
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ if (app != NULL) {
+ /* Allow to select a different application to open the item */
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "open-with-other-application");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+
+ escaped_app = eel_str_double_underscores (g_app_info_get_name (app));
+ label_with_underscore = g_strdup_printf (_("Open With %s"),
+ escaped_app);
+ g_free (escaped_app);
+ g_object_unref (app);
+ } else if (show_run) {
+ label_with_underscore = g_strdup (_("Run"));
+ } else {
+ label_with_underscore = g_strdup (_("Open"));
+ }
+ open_menu_item = g_menu_item_new (label_with_underscore, "open-with-default-application");
+
+ g_free (label_with_underscore);
+ } else {
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+ }
+
+ /* Toolbar menu actions */
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "show-hidden-files");
g_action_change_state (action,
- g_variant_new_boolean (view->details->show_hidden_files));
+ g_variant_new_boolean (view->details->show_hidden_files));
+
+ g_print ("exiting update actions state\n");
+
}
/* Convenience function to be called when updating menus,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]