summaryrefslogtreecommitdiff
path: root/libnautilus
diff options
context:
space:
mode:
authorRebecca Schulman <rebecka@eazel.com>2000-10-12 02:09:20 +0000
committerRebecca Schulman <rebecka@src.gnome.org>2000-10-12 02:09:20 +0000
commit4cd6570fd52838f52cb462dce8a53995e06a5c9f (patch)
treed685927857f9fc37edfa50eab486d4684407ae4c /libnautilus
parent27226688b5dd302365743baa08003d16a0347049 (diff)
downloadnautilus-4cd6570fd52838f52cb462dce8a53995e06a5c9f.tar.gz
First part of the bug fix for 3514. We still need to add a local clipboard
2000-10-11 Rebecca Schulman <rebecka@eazel.com> First part of the bug fix for 3514. We still need to add a local clipboard interface, and set up the clipboard to work with the location bar. * components/notes/nautilus-notes.c: (make_notes_view): Use the new clipboard api call * libnautilus/nautilus-clipboard-ui.xml: * libnautilus/Makefile.am: Define DATADIR so we can install the new bonobo ui xml file for the clipboard * libnautilus/nautilus-clipboard.c: (cut_callback), (copy_callback), (paste_callback), (clear_callback), (add_menu_items_callback), (remove_menu_items_callback), (ui_component_remove_container_and_unref), (finish_setting_up_editable_from_bonobo_control), (nautilus_clipboard_set_up_editable_from_bonobo_control): Gutted the bonobo code from the old functions and added new code where appropriate that should approximate the functionality we had before the ui handler change * src/nautilus-shell-ui.xml: Declare the cut copy and paste menu items insensitive by default. Maintain cmd/widget separation by creating separate commands for them. * src/nautilus-window-menus.c: (nautilus_window_initialize_menus): Remove unused cut, copy and paste callbacks Removed ui verbs relating to these that we don't need.
Diffstat (limited to 'libnautilus')
-rw-r--r--libnautilus/Makefile.am10
-rw-r--r--libnautilus/nautilus-clipboard-ui.xml29
-rw-r--r--libnautilus/nautilus-clipboard.c215
3 files changed, 154 insertions, 100 deletions
diff --git a/libnautilus/Makefile.am b/libnautilus/Makefile.am
index 5e8de7809..32fcf25c1 100644
--- a/libnautilus/Makefile.am
+++ b/libnautilus/Makefile.am
@@ -9,6 +9,7 @@ INCLUDES=-I$(top_srcdir) -I$(top_builddir) -I. \
$(OAF_CFLAGS) \
$(VFS_CFLAGS) \
$(XML_CFLAGS) \
+ -DDATADIR=\""$(datadir)"\" \
-D_REENTRANT
libnautilus_la_LDFLAGS=\
@@ -51,7 +52,6 @@ libnautilusinclude_HEADERS= \
nautilus-zoomable.h \
$(NULL)
-
libnautilus_la_SOURCES= \
$(nautilus_view_component_idl_sources) \
$(nautilus_distributed_undo_idl_sources) \
@@ -80,9 +80,15 @@ CLEANFILES = \
$(nautilus_distributed_undo_idl_sources) \
nautilus_distributed_undo_idl_stamp
+uidir = $(datadir)/gnome/ui
+ui_DATA = \
+ nautilus-clipboard-ui.xml \
+ $(NULL)
+
+
EXTRA_DIST = \
+ $(ui_DATA) \
nautilus-view-component.idl \
nautilus-distributed-undo.idl \
$(NULL)
-
diff --git a/libnautilus/nautilus-clipboard-ui.xml b/libnautilus/nautilus-clipboard-ui.xml
new file mode 100644
index 000000000..ca47efba2
--- /dev/null
+++ b/libnautilus/nautilus-clipboard-ui.xml
@@ -0,0 +1,29 @@
+<Root>
+<commands>
+ <cmd name="Cut" accel="*Control*x" sensitive="1"/>
+ <cmd name="Copy" accel="*Control*c" sensitive="1"/>
+ <cmd name="Paste" accel="*Control*v" sensitive="1"/>
+ <cmd name="Clear" sensitive="1"/>
+</commands>
+
+<menu>
+ <submenu name="Edit" _label="_Edit">
+ <menuitem name="Cut"
+ _label="_Cut"
+ _tip="Cut the selected text to the clipboard"
+ verb="Cut"/>
+ <menuitem name="Copy"
+ _label="_Copy"
+ _tip="Copy the selected text to the clipboard"
+ verb="Copy"/>
+ <menuitem name="Paste"
+ _label="_Paste"
+ _tip="Paste the text stored on the clipboard"
+ verb="Paste"/>
+ <menuitem name="Clear"
+ _label="C_lear"
+ _tip="Remove the selected text without putting it on the clipboard"
+ verb="Clear"/>
+ </submenu>
+</menu>
+</Root>
diff --git a/libnautilus/nautilus-clipboard.c b/libnautilus/nautilus-clipboard.c
index 3d5ce6bc4..1bde2d044 100644
--- a/libnautilus/nautilus-clipboard.c
+++ b/libnautilus/nautilus-clipboard.c
@@ -35,70 +35,67 @@
#include <gtk/gtk.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
+#include <bonobo/bonobo-ui-util.h>
+
-#ifdef UIH
static void
-cut_callback (BonoboUIHandler *ui_handler,
+cut_callback (BonoboUIComponent *ui_component,
gpointer callback_data,
- const char *path)
+ const char *cname)
{
- g_assert (BONOBO_IS_UI_HANDLER (ui_handler));
- g_assert (strcmp (path, NAUTILUS_MENU_PATH_CUT_ITEM) == 0);
+ GtkEditable *editable_widget;
+
+ g_assert (BONOBO_IS_UI_COMPONENT (ui_component));
+ g_assert (strcmp (cname, "Cut") == 0);
- gtk_editable_cut_clipboard (GTK_EDITABLE (callback_data));
+ editable_widget = GTK_EDITABLE (callback_data);
+ gtk_editable_cut_clipboard (editable_widget);
}
static void
-copy_callback (BonoboUIHandler *ui_handler,
+copy_callback (BonoboUIComponent *ui_component,
gpointer callback_data,
- const char *path)
+ const char *cname)
{
- g_assert (BONOBO_IS_UI_HANDLER (ui_handler));
- g_assert (strcmp (path, NAUTILUS_MENU_PATH_COPY_ITEM) == 0);
+ GtkEditable *editable_widget;
- gtk_editable_copy_clipboard (GTK_EDITABLE (callback_data));
+ g_assert (BONOBO_IS_UI_COMPONENT (ui_component));
+ g_assert (strcmp (cname, "Copy") == 0);
+
+ editable_widget = GTK_EDITABLE (callback_data);
+ gtk_editable_copy_clipboard (editable_widget);
}
static void
-paste_callback (BonoboUIHandler *ui_handler,
+paste_callback (BonoboUIComponent *ui_component,
gpointer callback_data,
- const char *path)
+ const char *cname)
{
- g_assert (BONOBO_IS_UI_HANDLER (ui_handler));
- g_assert (strcmp (path, NAUTILUS_MENU_PATH_PASTE_ITEM) == 0);
-
- gtk_editable_paste_clipboard (GTK_EDITABLE (callback_data));
+ GtkEditable *editable_widget;
+
+ g_assert (BONOBO_IS_UI_COMPONENT (ui_component));
+ g_assert (strcmp (cname, "Paste") == 0);
+
+ editable_widget = GTK_EDITABLE (callback_data);
+ gtk_editable_paste_clipboard (editable_widget);
}
static void
-clear_callback (BonoboUIHandler *ui_handler,
+clear_callback (BonoboUIComponent *ui_component,
gpointer callback_data,
- const char *path)
+ const char *cname)
{
- g_assert (BONOBO_IS_UI_HANDLER (ui_handler));
- g_assert (strcmp (path, NAUTILUS_MENU_PATH_CLEAR_ITEM) == 0);
-
- /* A negative index deletes until the end of the string */
- gtk_editable_delete_text (GTK_EDITABLE (callback_data), 0, -1);
-}
+ GtkEditable *editable_widget;
-static void
-add_menu_item (BonoboUIHandler *ui_handler,
- const char *path,
- const char *title,
- const char *description,
- BonoboUIHandlerCallback callback,
- gpointer callback_data)
-{
- bonobo_ui_handler_menu_new_item
- (ui_handler, path, title, description,
- bonobo_ui_handler_menu_get_pos (ui_handler, path),
- BONOBO_UI_HANDLER_PIXMAP_NONE, NULL, 0, 0,
- callback, callback_data);
+ g_assert (BONOBO_IS_UI_COMPONENT (ui_component));
+ g_assert (strcmp (cname, "Clear") == 0);
+
+
+ editable_widget = GTK_EDITABLE (callback_data);
+ gtk_editable_delete_selection (editable_widget);
}
-#endif /* UIH */
-/*
+#ifdef N0
static void
set_paste_sensitive_if_clipboard_contains_data (BonoboUIHandler *ui_handler)
{
@@ -111,46 +108,29 @@ set_paste_sensitive_if_clipboard_contains_data (BonoboUIHandler *ui_handler)
NAUTILUS_MENU_PATH_PASTE_ITEM,
clipboard_contains_data);
}
-*/
+#endif
+
static void
add_menu_items_callback (GtkWidget *widget,
GdkEventAny *event,
gpointer callback_data)
{
-#ifdef UIH
+ BonoboUIComponent *ui_component;
+ BonoboUIVerb verbs [] = {
+ BONOBO_UI_VERB ("Cut", (BonoboUIVerbFn) cut_callback),
+ BONOBO_UI_VERB ("Copy", (BonoboUIVerbFn) copy_callback),
+ BONOBO_UI_VERB ("Paste", (BonoboUIVerbFn) paste_callback),
+ BONOBO_UI_VERB ("Clear", (BonoboUIVerbFn) clear_callback),
+ BONOBO_UI_VERB_END
+ };
- BonoboUIHandler *local_ui_handler;
- Bonobo_UIHandler remote_ui_handler;
+ ui_component = gtk_object_get_data (GTK_OBJECT (widget), "clipboard_ui_component");
+ g_assert (BONOBO_IS_UI_COMPONENT (ui_component));
- g_assert (GTK_IS_EDITABLE (widget));
+ /* Add the verbs */
+ bonobo_ui_component_add_verb_list_with_data (ui_component, verbs, widget);
- local_ui_handler = bonobo_control_get_ui_handler (BONOBO_CONTROL (callback_data));
-
- remote_ui_handler = bonobo_control_get_remote_ui_handler (BONOBO_CONTROL (callback_data));
- bonobo_ui_handler_set_container (local_ui_handler, remote_ui_handler);
- bonobo_object_release_unref (remote_ui_handler, NULL);
-
- add_menu_item (local_ui_handler,
- NAUTILUS_MENU_PATH_CUT_ITEM,
- _("_Cut Text"),
- _("Cuts the selected text to the clipboard"),
- cut_callback, widget);
- add_menu_item (local_ui_handler,
- NAUTILUS_MENU_PATH_COPY_ITEM,
- _("_Copy Text"),
- _("Copies the selected text to the clipboard"),
- copy_callback, widget);
- add_menu_item (local_ui_handler,
- NAUTILUS_MENU_PATH_PASTE_ITEM,
- _("_Paste Text"),
- _("Pastes the text stored on the clipboard"),
- paste_callback, widget);
- add_menu_item (local_ui_handler,
- NAUTILUS_MENU_PATH_CLEAR_ITEM,
- _("C_lear Text"),
- _("Removes the selected text without putting it on the clipboard"),
- clear_callback, widget);
-#endif
+ /* FIXME bugzilla.eazel.com 733: Update the sensitivities */
}
static void
@@ -158,25 +138,15 @@ remove_menu_items_callback (GtkWidget *widget,
GdkEventAny *event,
gpointer callback_data)
{
-#ifdef UIH
- BonoboUIHandler *ui_handler;
-
- g_assert (GTK_IS_EDITABLE (widget));
+ BonoboUIComponent *ui_component;
- ui_handler = bonobo_control_get_ui_handler (BONOBO_CONTROL (callback_data));
+ ui_component = gtk_object_get_data (GTK_OBJECT (widget), "clipboard_ui_component");
+ bonobo_ui_component_unset_container (ui_component);
- bonobo_ui_handler_menu_remove (ui_handler,
- NAUTILUS_MENU_PATH_CUT_ITEM);
- bonobo_ui_handler_menu_remove (ui_handler,
- NAUTILUS_MENU_PATH_COPY_ITEM);
- bonobo_ui_handler_menu_remove (ui_handler,
- NAUTILUS_MENU_PATH_PASTE_ITEM);
- bonobo_ui_handler_menu_remove (ui_handler,
- NAUTILUS_MENU_PATH_CLEAR_ITEM);
-#endif
}
-/*
+
+#ifdef N0
static void
set_clipboard_menu_items_sensitive (BonoboUIHandler *ui_handler)
{
@@ -217,25 +187,74 @@ set_clipboard_menu_items_insensitive (BonoboUIHandler *ui_handler,
FALSE);
}
}
-*/
+#endif
+
+static void
+ui_component_remove_container_and_unref (gpointer data)
+{
+ BonoboUIComponent *ui;
+
+ ui = BONOBO_UI_COMPONENT (data);
+
+ bonobo_ui_component_unset_container (ui);
+ bonobo_object_unref (BONOBO_OBJECT (ui));
+}
+
+static void
+finish_setting_up_editable_from_bonobo_control (gpointer data,
+ GdkEventAny *event,
+ gpointer user_data)
+{
+ BonoboUIComponent *ui;
+ GtkEditable *target;
+ BonoboControl *control;
+
+ target = GTK_EDITABLE (data);
+ control = BONOBO_CONTROL (user_data);
+
+ /* Don't set up the clipboard again on future focus_in's */
+ gtk_signal_disconnect_by_func (GTK_OBJECT (data),
+ GTK_SIGNAL_FUNC (finish_setting_up_editable_from_bonobo_control),
+ user_data);
+
+ ui = bonobo_ui_component_new ("Clipboard");
+ bonobo_ui_component_set_container (ui,
+ bonobo_control_get_remote_ui_container (control));
+
+ bonobo_ui_util_set_ui (ui,
+ DATADIR,
+ "nautilus-clipboard-ui.xml",
+ "nautilus");
+
+ /* Free the ui component when we get rid of the widget */
+ gtk_object_set_data_full (GTK_OBJECT (target), "clipboard_ui_component",
+ ui, ui_component_remove_container_and_unref);
+
+ gtk_signal_connect (GTK_OBJECT (target), "focus_in_event",
+ GTK_SIGNAL_FUNC (add_menu_items_callback),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (target), "focus_out_event",
+ GTK_SIGNAL_FUNC (remove_menu_items_callback),
+ NULL);
+}
void
nautilus_clipboard_set_up_editable_from_bonobo_control (GtkEditable *target,
BonoboControl *control)
{
+
+
g_return_if_fail (GTK_IS_EDITABLE (target));
g_return_if_fail (BONOBO_IS_CONTROL (control));
- /* Attach code to add menus when it gets the focus. */
- gtk_signal_connect_while_alive
- (GTK_OBJECT (target), "focus_in_event",
- GTK_SIGNAL_FUNC (add_menu_items_callback),
- control, GTK_OBJECT (control));
- /* Attach code to remove menus when it loses the focus. */
- gtk_signal_connect_while_alive
- (GTK_OBJECT (target), "focus_out_event",
- GTK_SIGNAL_FUNC (remove_menu_items_callback),
- control, GTK_OBJECT (control));
+ /* Use lazy initialization, so that we wait until after
+ embedding, and thus for the ability to get the remote
+ ui container */
+ gtk_signal_connect_while_alive (GTK_OBJECT (target),
+ "focus_in_event",
+ finish_setting_up_editable_from_bonobo_control,
+ control, GTK_OBJECT (control));
}
+