From 769e117e901dce718915b863209fc58c218ca3c6 Mon Sep 17 00:00:00 2001 From: Ettore Perazzoli Date: Tue, 25 Sep 2001 21:27:00 +0000 Subject: New helper function. (command_move_folder): Pass the @folder_path argument * e-shell-view-menu.c (get_path_for_folder_op): New helper function. (command_move_folder): Pass the @folder_path argument to `e_shell_command_move_folder' by using it. (command_copy_folder): Pass the @folder_path argument to `e_shell_command_copy_folder' by using it. (command_delete_folder): Pass the @folder_path argument to `e_shell_command_delete_folder()' by using it. (command_add_folder_to_shortcut_bar): Pass the @folder_path argument to `e_shell_command_add_to_shortcut_bar()' by using it. (command_create_folder): Pass the @parent_folder_path argument to `e_shell_command_create_new_folder()' by using it. (command_new_folder): Use `get_path_for_folder_op()'. * e-shell-folder-commands.c (e_shell_command_add_to_shortcut_bar): New arg @folder_path. (e_shell_command_copy_folder): New arg @folder_path. (e_shell_command_move_folder): New arg @folder_path. (e_shell_command_open_folder_in_other_window): New arg @folder_path. (e_shell_command_create_new_folder): New arg @parent_folder_path. (e_shell_command_delete_folder): New arg @folder_path. * e-shell-view.c (e_shell_view_get_folder_bar_right_click_path): New. * e-storage-set-view.c: New member `right_click_row_path'. (init): Init to NULL. (destroy): Free. (right_click): Set. (popup_folder_menu): Use `gnome_popup_menu_do_popup_modal()' so we are stuck in here until the menu disappears. After that, destroy the menu and call `e_tree_right_click_up()'. (e_storage_set_view_get_right_click_path): New. svn path=/trunk/; revision=13124 --- shell/ChangeLog | 35 +++++++++++++ shell/e-shell-folder-commands.c | 112 +++++++++++++++++++++++++--------------- shell/e-shell-folder-commands.h | 14 ++--- shell/e-shell-view-menu.c | 49 +++++++++++------- shell/e-shell-view.c | 14 +++++ shell/e-shell-view.h | 2 + shell/e-storage-set-view.c | 71 +++++++++++-------------- shell/e-storage-set-view.h | 2 + 8 files changed, 190 insertions(+), 109 deletions(-) (limited to 'shell') diff --git a/shell/ChangeLog b/shell/ChangeLog index 8d1c31e301..8a7f377401 100644 --- a/shell/ChangeLog +++ b/shell/ChangeLog @@ -1,3 +1,38 @@ +2001-09-25 Ettore Perazzoli + + * e-shell-view-menu.c (get_path_for_folder_op): New helper + function. + (command_move_folder): Pass the @folder_path argument to + `e_shell_command_move_folder' by using it. + (command_copy_folder): Pass the @folder_path argument to + `e_shell_command_copy_folder' by using it. + (command_delete_folder): Pass the @folder_path argument to + `e_shell_command_delete_folder()' by using it. + (command_add_folder_to_shortcut_bar): Pass the @folder_path + argument to `e_shell_command_add_to_shortcut_bar()' by using it. + (command_create_folder): Pass the @parent_folder_path argument to + `e_shell_command_create_new_folder()' by using it. + (command_new_folder): Use `get_path_for_folder_op()'. + + * e-shell-folder-commands.c (e_shell_command_add_to_shortcut_bar): + New arg @folder_path. + (e_shell_command_copy_folder): New arg @folder_path. + (e_shell_command_move_folder): New arg @folder_path. + (e_shell_command_open_folder_in_other_window): New arg @folder_path. + (e_shell_command_create_new_folder): New arg @parent_folder_path. + (e_shell_command_delete_folder): New arg @folder_path. + + * e-shell-view.c (e_shell_view_get_folder_bar_right_click_path): New. + + * e-storage-set-view.c: New member `right_click_row_path'. + (init): Init to NULL. + (destroy): Free. + (right_click): Set. + (popup_folder_menu): Use `gnome_popup_menu_do_popup_modal()' so we + are stuck in here until the menu disappears. After that, destroy + the menu and call `e_tree_right_click_up()'. + (e_storage_set_view_get_right_click_path): New. + 2001-09-21 Iain Holmes * e-shell-importer.c (folder_selected): Use GNOME functions to get diff --git a/shell/e-shell-folder-commands.c b/shell/e-shell-folder-commands.c index a9bc540ca3..f3c6a540cc 100644 --- a/shell/e-shell-folder-commands.c +++ b/shell/e-shell-folder-commands.c @@ -236,11 +236,17 @@ connect_folder_selection_dialog_signals (EShellFolderSelectionDialog *folder_sel void e_shell_command_create_new_folder (EShell *shell, - EShellView *shell_view) + EShellView *shell_view, + const char *parent_folder_path) { g_return_if_fail (shell != NULL); g_return_if_fail (E_IS_SHELL (shell)); + g_return_if_fail (shell_view != NULL || parent_folder_path != NULL); g_return_if_fail (shell_view != NULL && E_IS_SHELL_VIEW (shell_view)); + g_return_if_fail (parent_folder_path != NULL || g_path_is_absolute (parent_folder_path)); + + if (parent_folder_path == NULL) + parent_folder_path = e_shell_view_get_current_path (shell_view); /* FIXME: Should handle the result stuff. */ e_shell_show_folder_creation_dialog (shell, GTK_WINDOW (shell_view), @@ -254,15 +260,22 @@ e_shell_command_create_new_folder (EShell *shell, void e_shell_command_open_folder_in_other_window (EShell *shell, - EShellView *shell_view) + EShellView *shell_view, + const char *folder_path) { EShellView *view; + char *uri; g_return_if_fail (shell != NULL); g_return_if_fail (E_IS_SHELL (shell)); g_return_if_fail (shell_view != NULL && E_IS_SHELL_VIEW (shell_view)); - view = e_shell_create_view (shell, e_shell_view_get_current_uri (shell_view)); + if (folder_path == NULL) + folder_path = e_shell_view_get_current_path (shell_view); + + uri = g_strconcat (E_SHELL_URI_PREFIX, folder_path, NULL); + view = e_shell_create_view (shell, uri); + g_free (uri); gtk_widget_show (GTK_WIDGET (view)); } @@ -272,38 +285,41 @@ e_shell_command_open_folder_in_other_window (EShell *shell, void e_shell_command_copy_folder (EShell *shell, - EShellView *shell_view) + EShellView *shell_view, + const char *folder_path) { GtkWidget *folder_selection_dialog; FolderCommandData *data; - const char *current_path; - const char *current_uri; + char *uri; char *caption; g_return_if_fail (shell != NULL); g_return_if_fail (E_IS_SHELL (shell)); g_return_if_fail (shell_view != NULL && E_IS_SHELL_VIEW (shell_view)); + g_return_if_fail (folder_path == NULL || g_path_is_absolute (folder_path)); - current_path = e_shell_view_get_current_path (shell_view); + if (folder_path == NULL) + folder_path = e_shell_view_get_current_path (shell_view); - if (current_path == NULL) { + if (folder_path == NULL) { g_warning ("Called `e_shell_command_copy_folder()' without a valid displayed folder"); return; } caption = g_strdup_printf (_("Specify a folder to copy folder \"%s\" into:"), - get_folder_name (shell, current_path)); + get_folder_name (shell, folder_path)); - current_uri = e_shell_view_get_current_uri (shell_view); + uri = g_strconcat (E_SHELL_URI_PREFIX, folder_path, NULL); folder_selection_dialog = e_shell_folder_selection_dialog_new (shell, _("Copy folder"), caption, - current_uri, + uri, NULL); g_free (caption); + g_free (uri); - data = folder_command_data_new (shell, shell_view, FOLDER_COMMAND_COPY, current_path, NULL); + data = folder_command_data_new (shell, shell_view, FOLDER_COMMAND_COPY, folder_path, NULL); connect_folder_selection_dialog_signals (E_SHELL_FOLDER_SELECTION_DIALOG (folder_selection_dialog), data); @@ -315,38 +331,42 @@ e_shell_command_copy_folder (EShell *shell, void e_shell_command_move_folder (EShell *shell, - EShellView *shell_view) + EShellView *shell_view, + const char *folder_path) { GtkWidget *folder_selection_dialog; FolderCommandData *data; - const char *current_path; - const char *current_uri; + char *uri; char *caption; g_return_if_fail (shell != NULL); g_return_if_fail (E_IS_SHELL (shell)); g_return_if_fail (shell_view != NULL); g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); + g_return_if_fail (folder_path == NULL || g_path_is_absolute (folder_path)); - current_path = e_shell_view_get_current_path (shell_view); - if (current_path == NULL) { + if (folder_path == NULL) + folder_path = e_shell_view_get_current_path (shell_view); + + if (folder_path == NULL) { g_warning ("Called `e_shell_command_move_folder()' without a valid displayed folder"); return; } caption = g_strdup_printf (_("Specify a folder to move folder \"%s\" into:"), - get_folder_name (shell, current_path)); + get_folder_name (shell, folder_path)); - current_uri = e_shell_view_get_current_uri (shell_view); + uri = g_strconcat (E_SHELL_URI_PREFIX, folder_path, NULL); folder_selection_dialog = e_shell_folder_selection_dialog_new (shell, _("Move folder"), caption, - current_uri, + uri, NULL); g_free (caption); + g_free (uri); - data = folder_command_data_new (shell, shell_view, FOLDER_COMMAND_MOVE, current_path, NULL); + data = folder_command_data_new (shell, shell_view, FOLDER_COMMAND_MOVE, folder_path, NULL); connect_folder_selection_dialog_signals (E_SHELL_FOLDER_SELECTION_DIALOG (folder_selection_dialog), data); @@ -406,35 +426,33 @@ delete_dialog (EShellView *shell_view, const char *utf8_folder) void e_shell_command_delete_folder (EShell *shell, - EShellView *shell_view) + EShellView *shell_view, + const char *folder_path) { EStorageSet *storage_set; - char *path; g_return_if_fail (shell != NULL); g_return_if_fail (E_IS_SHELL (shell)); - g_return_if_fail (shell_view != NULL); + g_return_if_fail (shell_view != NULL || folder_path != NULL); g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); + g_return_if_fail (folder_path != NULL || g_path_is_absolute (folder_path)); storage_set = e_shell_get_storage_set (shell); - path = g_strdup (e_shell_view_get_current_path (shell_view)); - - if (delete_dialog (shell_view, get_folder_name (shell, path)) == 0) { - /* Remove and destroy the control */ - e_shell_view_remove_control_for_uri (shell_view, - e_shell_view_get_current_uri (shell_view)); - - /* Remove the folder */ - e_storage_set_async_remove_folder (storage_set, - path, - delete_cb, - shell_view); - - /* Select another folder to prevent bad things from happening */ + + if (folder_path == NULL) + folder_path = e_shell_view_get_current_path (shell_view); + + if (delete_dialog (shell_view, get_folder_name (shell, folder_path)) == 0) { + char *uri; + + uri = g_strconcat (E_SHELL_URI_PREFIX, folder_path, NULL); + e_shell_view_remove_control_for_uri (shell_view, uri); + g_free (uri); + + e_storage_set_async_remove_folder (storage_set, folder_path, delete_cb, shell_view); + e_shell_view_display_uri (shell_view, E_SHELL_VIEW_DEFAULT_URI); } - - g_free (path); } #if 0 @@ -572,23 +590,29 @@ e_shell_command_rename_folder (EShell *shell, void e_shell_command_add_to_shortcut_bar (EShell *shell, - EShellView *shell_view) + EShellView *shell_view, + const char *folder_path) { EShortcuts *shortcuts; EStorageSet *storage_set; EFolder *folder; int group_num; - const char *uri; + char *uri; int unread_count; g_return_if_fail (shell != NULL); g_return_if_fail (E_IS_SHELL (shell)); g_return_if_fail (shell_view != NULL); g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); + g_return_if_fail (folder_path == NULL || g_path_is_absolute (folder_path)); shortcuts = e_shell_get_shortcuts (shell); group_num = e_shell_view_get_current_shortcuts_group_num (shell_view); - uri = e_shell_view_get_current_uri (shell_view); + + if (folder_path == NULL) + uri = g_strdup (e_shell_view_get_current_uri (shell_view)); + else + uri = g_strconcat (E_SHELL_URI_PREFIX, folder_path, NULL); unread_count = get_folder_unread (shell, e_shell_view_get_current_path (shell_view)); @@ -596,4 +620,6 @@ e_shell_command_add_to_shortcut_bar (EShell *shell, folder = e_storage_set_get_folder (storage_set, e_shell_view_get_current_path (shell_view)); e_shortcuts_add_shortcut (shortcuts, group_num, -1, uri, NULL, unread_count, e_folder_get_type_string (folder)); + + g_free (uri); } diff --git a/shell/e-shell-folder-commands.h b/shell/e-shell-folder-commands.h index 2a3f61d863..87652df4b9 100644 --- a/shell/e-shell-folder-commands.h +++ b/shell/e-shell-folder-commands.h @@ -27,15 +27,15 @@ #include "e-shell.h" #include "e-shell-view.h" -void e_shell_command_create_new_folder (EShell *shell, EShellView *shell_view); +void e_shell_command_open_folder_in_other_window (EShell *shell, EShellView *shell_view, const char *folder_path); -void e_shell_command_open_folder_in_other_window (EShell *shell, EShellView *shell_view); +void e_shell_command_create_new_folder (EShell *shell, EShellView *shell_view, const char *parent_folder_path); -void e_shell_command_copy_folder (EShell *shell, EShellView *shell_view); -void e_shell_command_move_folder (EShell *shell, EShellView *shell_view); -void e_shell_command_delete_folder (EShell *shell, EShellView *shell_view); -void e_shell_command_rename_folder (EShell *shell, EShellView *shell_view); +void e_shell_command_copy_folder (EShell *shell, EShellView *shell_view, const char *folder_path); +void e_shell_command_move_folder (EShell *shell, EShellView *shell_view, const char *folder_path); +void e_shell_command_delete_folder (EShell *shell, EShellView *shell_view, const char *folder_path); +void e_shell_command_rename_folder (EShell *shell, EShellView *shell_view, const char *folder_path); -void e_shell_command_add_to_shortcut_bar (EShell *shell, EShellView *shell_view); +void e_shell_command_add_to_shortcut_bar (EShell *shell, EShellView *shell_view, const char *folder_path); #endif diff --git a/shell/e-shell-view-menu.c b/shell/e-shell-view-menu.c index 5f3520993f..3049bc93e1 100644 --- a/shell/e-shell-view-menu.c +++ b/shell/e-shell-view-menu.c @@ -92,6 +92,21 @@ const char *authors[] = { NULL }; + +/* Utility functions. */ + +static const char * +get_path_for_folder_op (EShellView *shell_view) +{ + const char *path; + + path = e_shell_view_get_folder_bar_right_click_path (shell_view); + if (path != NULL) + return path; + + return e_shell_view_get_current_path (shell_view); +} + /* EShellView callbacks. */ @@ -285,20 +300,12 @@ command_new_folder (BonoboUIComponent *uih, { EShellView *shell_view; EShell *shell; - const char *current_uri; - const char *default_parent_folder; shell_view = E_SHELL_VIEW (data); shell = e_shell_view_get_shell (shell_view); - current_uri = e_shell_view_get_current_uri (shell_view); - - if (current_uri && strncmp (current_uri, E_SHELL_URI_PREFIX, E_SHELL_URI_PREFIX_LEN) == 0) - default_parent_folder = current_uri + E_SHELL_URI_PREFIX_LEN; - else - default_parent_folder = NULL; - + e_shell_show_folder_creation_dialog (shell, GTK_WINDOW (shell_view), - default_parent_folder, + get_path_for_folder_op (shell_view), NULL /* result_callback */, NULL /* result_callback_data */); } @@ -310,13 +317,15 @@ command_open_folder_in_new_window (BonoboUIComponent *uih, { EShellView *shell_view, *new_view; EShell *shell; - const char *current_uri; + char *uri; shell_view = E_SHELL_VIEW (data); shell = e_shell_view_get_shell (shell_view); - current_uri = e_shell_view_get_current_uri (shell_view); - new_view = e_shell_create_view (shell, current_uri); + uri = g_strconcat (E_SHELL_URI_PREFIX, get_path_for_folder_op (shell_view), NULL); + new_view = e_shell_create_view (shell, uri); + g_free (uri); + gtk_widget_show (GTK_WIDGET (new_view)); } @@ -331,7 +340,8 @@ command_move_folder (BonoboUIComponent *uih, EShellView *shell_view; shell_view = E_SHELL_VIEW (data); - e_shell_command_move_folder (e_shell_view_get_shell (shell_view), shell_view); + e_shell_command_move_folder (e_shell_view_get_shell (shell_view), shell_view, + get_path_for_folder_op (shell_view)); } static void @@ -342,7 +352,8 @@ command_copy_folder (BonoboUIComponent *uih, EShellView *shell_view; shell_view = E_SHELL_VIEW (data); - e_shell_command_copy_folder (e_shell_view_get_shell (shell_view), shell_view); + e_shell_command_copy_folder (e_shell_view_get_shell (shell_view), shell_view, + get_path_for_folder_op (shell_view)); } static void @@ -353,7 +364,8 @@ command_delete_folder (BonoboUIComponent *uih, EShellView *shell_view; shell_view = E_SHELL_VIEW (data); - e_shell_command_delete_folder (e_shell_view_get_shell (shell_view), shell_view); + e_shell_command_delete_folder (e_shell_view_get_shell (shell_view), shell_view, + get_path_for_folder_op (shell_view)); } static void @@ -375,7 +387,8 @@ command_add_folder_to_shortcut_bar (BonoboUIComponent *uih, EShellView *shell_view; shell_view = E_SHELL_VIEW (data); - e_shell_command_add_to_shortcut_bar (e_shell_view_get_shell (shell_view), shell_view); + e_shell_command_add_to_shortcut_bar (e_shell_view_get_shell (shell_view), shell_view, + get_path_for_folder_op (shell_view)); } @@ -447,7 +460,7 @@ command_create_folder (BonoboUIComponent *uih, shell_view = E_SHELL_VIEW (data); shell = e_shell_view_get_shell (shell_view); - e_shell_command_create_new_folder (shell, shell_view); + e_shell_command_create_new_folder (shell, shell_view, get_path_for_folder_op (shell_view)); } static void diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c index 11f0025d16..1e632a912b 100644 --- a/shell/e-shell-view.c +++ b/shell/e-shell-view.c @@ -2493,5 +2493,19 @@ e_shell_view_get_current_shortcuts_group_num (EShellView *shell_view) return group; } + +const char * +e_shell_view_get_folder_bar_right_click_path (EShellView *shell_view) +{ + EShellViewPrivate *priv; + + g_return_val_if_fail (shell_view != NULL, NULL); + g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); + + priv = shell_view->priv; + + return e_storage_set_view_get_right_click_path (priv->storage_set_view); +} + E_MAKE_TYPE (e_shell_view, "EShellView", EShellView, class_init, init, BONOBO_TYPE_WINDOW) diff --git a/shell/e-shell-view.h b/shell/e-shell-view.h index 8fbdd199df..ab83de2bc6 100644 --- a/shell/e-shell-view.h +++ b/shell/e-shell-view.h @@ -107,6 +107,8 @@ int e_shell_view_get_current_shortcuts_group_num (EShellView *shell_view); void e_shell_view_set_current_shortcuts_group_num (EShellView *shell_view, int group_num); +/* Private -- */ +const char *e_shell_view_get_folder_bar_right_click_path (EShellView *shell_view); #ifdef __cplusplus } diff --git a/shell/e-storage-set-view.c b/shell/e-storage-set-view.c index 73c73f940f..2a86048185 100644 --- a/shell/e-storage-set-view.c +++ b/shell/e-storage-set-view.c @@ -82,6 +82,9 @@ struct _EStorageSetViewPrivate { /* Path of the row selected by the latest "cursor_activated" signal. */ char *selected_row_path; + /* Path of the row selected by a right click. */ + char *right_click_row_path; + unsigned int show_folders : 1; unsigned int allow_dnd : 1; @@ -634,46 +637,6 @@ folder_xfer_callback (EStorageSet *storage_set, /* Folder context menu. */ -/* FIXME: This should be moved somewhere else, so that also the shortcut code - can share it. */ - -#if 0 -static void -folder_context_menu_activate_cb (BonoboUIComponent *uih, - void *data, - const char *path) -{ - EStorageSetView *storage_set_view; - EStorageSetViewPrivate *priv; - - storage_set_view = E_STORAGE_SET_VIEW (data); - priv = storage_set_view->priv; - - gtk_signal_emit (GTK_OBJECT (storage_set_view), signals[FOLDER_SELECTED], - priv->selected_row_path); -} - -static void -remove_cb(EStorageSet *storage_set, EStorageResult result, void *data) -{ - g_print ("remove_cb: %d\n", result); -} - -static void -folder_context_menu_remove_cb (BonoboUIComponent *uih, - void *data, - const char *path) -{ - EStorageSetView *storage_set_view; - EStorageSetViewPrivate *priv; - - storage_set_view = E_STORAGE_SET_VIEW (data); - priv = storage_set_view->priv; - - e_storage_set_async_remove_folder (priv->storage_set, priv->selected_row_path, - remove_cb, storage_set_view); -} -#endif static void popup_folder_menu (EStorageSetView *storage_set_view, @@ -711,7 +674,12 @@ popup_folder_menu (EStorageSetView *storage_set_view, e_folder_get_type_string (folder)); gtk_widget_show (GTK_WIDGET (menu)); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 3, event->time); + + gnome_popup_menu_do_popup_modal (GTK_WIDGET (menu), NULL, NULL, event, NULL); + + gtk_widget_destroy (GTK_WIDGET (menu)); + + e_tree_right_click_up (E_TREE (storage_set_view)); } @@ -771,6 +739,7 @@ destroy (GtkObject *object) CORBA_free (priv->drag_corba_data); g_free (priv->selected_row_path); + g_free (priv->right_click_row_path); g_free (priv); @@ -1265,9 +1234,17 @@ right_click (ETree *etree, storage_set_view = E_STORAGE_SET_VIEW (etree); priv = storage_set_view->priv; + /* This should never happen, but you never know with ETree. */ + if (priv->right_click_row_path != NULL) + g_free (priv->right_click_row_path); + priv->right_click_row_path = g_strdup (e_tree_memory_node_get_data (E_TREE_MEMORY(priv->etree_model), path)); + if (priv->container) popup_folder_menu (storage_set_view, (GdkEventButton *) event); + g_free (priv->right_click_row_path); + priv->right_click_row_path = NULL; + return TRUE; } @@ -1698,7 +1675,10 @@ init (EStorageSetView *storage_set_view) priv->storage_set = NULL; priv->path_to_etree_node = g_hash_table_new (g_str_hash, g_str_equal); priv->type_name_to_pixbuf = g_hash_table_new (g_str_hash, g_str_equal); + priv->selected_row_path = NULL; + priv->right_click_row_path = NULL; + priv->show_folders = TRUE; priv->allow_dnd = TRUE; @@ -2054,5 +2034,14 @@ e_storage_set_view_get_allow_dnd (EStorageSetView *storage_set_view) return storage_set_view->priv->allow_dnd; } +const char * +e_storage_set_view_get_right_click_path (EStorageSetView *storage_set_view) +{ + g_return_val_if_fail (storage_set_view != NULL, NULL); + g_return_val_if_fail (E_IS_STORAGE_SET_VIEW (storage_set_view), NULL); + + return storage_set_view->priv->right_click_row_path; +} + E_MAKE_TYPE (e_storage_set_view, "EStorageSetView", EStorageSetView, class_init, init, PARENT_TYPE) diff --git a/shell/e-storage-set-view.h b/shell/e-storage-set-view.h index 9e00c0e678..d70d09e89b 100644 --- a/shell/e-storage-set-view.h +++ b/shell/e-storage-set-view.h @@ -88,6 +88,8 @@ void e_storage_set_view_set_allow_dnd (EStorageSetView *storage_set gboolean allow_dnd); gboolean e_storage_set_view_get_allow_dnd (EStorageSetView *storage_set_view); +const char *e_storage_set_view_get_right_click_path (EStorageSetView *storage_set_view); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit v1.2.3