summaryrefslogtreecommitdiff
path: root/src/file-manager/fm-icon-view.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/file-manager/fm-icon-view.c')
-rw-r--r--src/file-manager/fm-icon-view.c133
1 files changed, 132 insertions, 1 deletions
diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c
index 96c8bf578..004225d32 100644
--- a/src/file-manager/fm-icon-view.c
+++ b/src/file-manager/fm-icon-view.c
@@ -25,9 +25,11 @@
#include <config.h>
#include "fm-icon-view.h"
+#include "fm-annotation-window.h"
#include "fm-desktop-icon-view.h"
#include "fm-error-reporting.h"
#include "fm-icon-text-window.h"
+#include <bonobo/bonobo-widget.h>
#include <bonobo/bonobo-ui-util.h>
#include <ctype.h>
#include <errno.h>
@@ -45,6 +47,7 @@
#include <libgnomevfs/gnome-vfs-xfer.h>
#include <libnautilus-extensions/nautilus-audio-player.h>
#include <eel/eel-background.h>
+#include <libnautilus-extensions/nautilus-annotation.h>
#include <libnautilus-extensions/nautilus-bonobo-extensions.h>
#include <libnautilus-extensions/nautilus-directory-background.h>
#include <libnautilus-extensions/nautilus-directory.h>
@@ -73,6 +76,7 @@
/* Paths to use when creating & referring to Bonobo menu items */
#define MENU_PATH_RENAME "/menu/File/File Items Placeholder/Rename"
+#define MENU_PATH_ANNOTATE "/menu/File/File Items Placeholder/Annotate"
#define MENU_PATH_CUSTOMIZE_ICON_TEXT "/menu/Edit/Global Edit Items Placeholder/Icon Text"
#define MENU_PATH_STRETCH_ICON "/menu/Edit/Edit Items Placeholder/Stretch"
#define MENU_PATH_UNSTRETCH_ICONS "/menu/Edit/Edit Items Placeholder/Unstretch"
@@ -86,6 +90,7 @@
#define COMMAND_PREFIX "/commands/"
#define COMMAND_RENAME "/commands/Rename"
+#define COMMAND_ANNOTATE "/commands/Annotate"
#define COMMAND_STRETCH_ICON "/commands/Stretch"
#define COMMAND_UNSTRETCH_ICONS "/commands/Unstretch"
#define COMMAND_TIGHTER_LAYOUT "/commands/Tighter Layout"
@@ -401,6 +406,23 @@ rename_icon_callback (BonoboUIComponent *component, gpointer callback_data, cons
}
static void
+annotate_callback (BonoboUIComponent *component, gpointer callback_data, const char *verb)
+{
+ GList *selected_files;
+ NautilusFile *first_file;
+
+ g_assert (FM_IS_ICON_VIEW (callback_data));
+
+ /* show the annotation window */
+ selected_files = fm_directory_view_get_selection (FM_DIRECTORY_VIEW (callback_data));
+ if (selected_files != NULL) {
+ first_file = NAUTILUS_FILE (selected_files->data);
+ fm_annotation_window_present (first_file, FM_DIRECTORY_VIEW (callback_data));
+ g_list_free (selected_files);
+ }
+}
+
+static void
set_tighter_layout (FMIconView *icon_view, gboolean new_value)
{
fm_icon_view_set_directory_tighter_layout (icon_view,
@@ -1251,6 +1273,7 @@ fm_icon_view_merge_menus (FMDirectoryView *view)
FMIconView *icon_view;
BonoboUIVerb verbs [] = {
BONOBO_UI_VERB ("Rename", rename_icon_callback),
+ BONOBO_UI_VERB ("Annotate", annotate_callback),
BONOBO_UI_VERB ("Icon Text", customize_icon_text_callback),
BONOBO_UI_VERB ("Stretch", show_stretch_handles_callback),
BONOBO_UI_VERB ("Unstretch", unstretch_icons_callback),
@@ -1340,6 +1363,10 @@ fm_icon_view_update_menus (FMDirectoryView *view)
COMMAND_RENAME,
selection_count == 1
&& nautilus_file_can_rename (selection->data));
+
+ nautilus_bonobo_set_sensitive (icon_view->details->ui,
+ COMMAND_ANNOTATE,
+ selection_count == 1);
bonobo_ui_component_thaw (icon_view->details->ui, NULL);
@@ -1420,14 +1447,57 @@ fm_icon_view_set_selection (FMDirectoryView *view, GList *selection)
(get_icon_container (FM_ICON_VIEW (view)), selection);
}
+/* utility routine to return the specified keyword, given a file and emblem index */
+static char *
+get_keyword_by_index (NautilusFile *file, int emblem_index)
+{
+ GList *keyword_list, *selected_keyword;
+ char *keyword;
+
+ keyword_list = nautilus_file_get_emblem_names (file);
+ if (keyword_list == NULL) {
+ return NULL;
+ }
+
+ selected_keyword = g_list_nth (keyword_list, emblem_index - 1);
+ if (selected_keyword == NULL) {
+ eel_g_list_free_deep (keyword_list);
+ return NULL;
+ }
+
+ keyword = g_strdup (selected_keyword->data);
+ eel_g_list_free_deep (keyword_list);
+
+ return keyword;
+}
+
static void
icon_container_activate_callback (NautilusIconContainer *container,
GList *file_list,
+ int emblem_index,
FMIconView *icon_view)
{
+ char *keyword;
+ NautilusFile *file;
+
g_assert (FM_IS_ICON_VIEW (icon_view));
g_assert (container == get_icon_container (icon_view));
+ /* if there is a single file to be activated, and the user clicked on an emblem,
+ * implement the emblem-specific action instead of activation. For now,
+ * we just handle annotations.
+ */
+ if (emblem_index > 0 && file_list != NULL && file_list->next == NULL) {
+ file = NAUTILUS_FILE (file_list->data);
+ keyword = get_keyword_by_index (file, emblem_index);
+ if (eel_strcmp (keyword, "note") == 0) {
+ fm_annotation_window_present (file, FM_DIRECTORY_VIEW (icon_view));
+ g_free (keyword);
+ return;
+ }
+ g_free (keyword);
+ }
+
fm_directory_view_activate_files (FM_DIRECTORY_VIEW (icon_view), file_list);
}
@@ -1833,6 +1903,38 @@ get_icon_images_callback (NautilusIconContainer *container,
return nautilus_icon_factory_get_icon_for_file (file, modifier, smooth_graphics);
}
+/* return the Bonobo control associated with the icon, if any */
+static void
+get_icon_control_callback (NautilusIconContainer *container,
+ NautilusFile *file,
+ GtkWidget **control,
+ FMIconView *icon_view)
+{
+ Bonobo_UIContainer ui_container;
+ char *control_moniker, *control_data;
+ char *uri, *path;
+ *control = NULL;
+
+ if (nautilus_file_is_nautilus_link (file)) {
+ uri = nautilus_file_get_uri (file);
+ path = gnome_vfs_get_local_path_from_uri (uri);
+ if (path != NULL) {
+ nautilus_link_local_get_component_info (path, &control_moniker, &control_data);
+ if (control_moniker && strlen (control_moniker) > 0) {
+ ui_container = fm_directory_view_get_bonobo_ui_container (FM_DIRECTORY_VIEW (icon_view));
+ *control = bonobo_widget_new_control (control_moniker, ui_container);
+ g_free (control_moniker);
+ }
+ if (control_data && strlen (control_data) > 0) {
+ bonobo_widget_set_property (BONOBO_WIDGET (*control), "configuration", control_data, NULL);
+ g_free (control_data);
+ }
+ g_free (path);
+ }
+ g_free (uri);
+ }
+}
+
static char *
get_icon_uri_callback (NautilusIconContainer *container,
NautilusFile *file,
@@ -1897,6 +1999,7 @@ get_icon_text_callback (NautilusIconContainer *container,
g_assert (additional_text != NULL);
g_assert (FM_IS_ICON_VIEW (icon_view));
+
/* In the smallest zoom mode, no text is drawn. */
if (fm_icon_view_get_zoom_level (icon_view) == NAUTILUS_ZOOM_LEVEL_SMALLEST) {
*editable_text = NULL;
@@ -1904,7 +2007,7 @@ get_icon_text_callback (NautilusIconContainer *container,
/* Strip the suffix for nautilus object xml files. */
*editable_text = nautilus_file_get_name (file);
}
-
+
/* Handle link files specially. */
if (nautilus_file_is_nautilus_link (file)) {
/* FIXME bugzilla.eazel.com 2531: Does sync. I/O and works only locally. */
@@ -1955,6 +2058,26 @@ get_icon_text_callback (NautilusIconContainer *container,
g_strfreev (text_array);
}
+/* this callback returns the annotation text associated with the passed-in file and emblem index */
+static char *
+get_icon_annotation_callback (NautilusIconContainer *container,
+ NautilusFile *file,
+ int emblem_index,
+ FMIconView *icon_view)
+{
+ char *keyword;
+
+ keyword = get_keyword_by_index (file, emblem_index);
+
+ /* if the keyword is "note", return the file annotation instead */
+ if (eel_strcmp (keyword, "note") == 0) {
+ g_free (keyword);
+ keyword = nautilus_annotation_get_annotation (file);
+ }
+
+ return keyword;
+}
+
/* Preferences changed callbacks */
static void
fm_icon_view_text_attribute_names_changed (FMDirectoryView *directory_view)
@@ -2446,6 +2569,10 @@ create_icon_container (FMIconView *icon_view)
GTK_SIGNAL_FUNC (get_icon_images_callback),
icon_view);
gtk_signal_connect (GTK_OBJECT (icon_container),
+ "get_icon_control",
+ GTK_SIGNAL_FUNC (get_icon_control_callback),
+ icon_view);
+ gtk_signal_connect (GTK_OBJECT (icon_container),
"get_icon_uri",
GTK_SIGNAL_FUNC (get_icon_uri_callback),
icon_view);
@@ -2458,6 +2585,10 @@ create_icon_container (FMIconView *icon_view)
GTK_SIGNAL_FUNC (get_icon_text_callback),
icon_view);
gtk_signal_connect (GTK_OBJECT (icon_container),
+ "get_icon_annotation",
+ GTK_SIGNAL_FUNC (get_icon_annotation_callback),
+ icon_view);
+ gtk_signal_connect (GTK_OBJECT (icon_container),
"move_copy_items",
GTK_SIGNAL_FUNC (icon_view_move_copy_items),
directory_view);