Commit b24d331f authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Tell the clipboard monitor of changes. Update paste menus on clipboard

2004-02-10  Alexander Larsson  <alexl@redhat.com>

	* src/file-manager/fm-tree-view.c (copy_or_cut_files):
	* src/file-manager/fm-directory-view.c:
	Tell the clipboard monitor of changes.
	Update paste menus on clipboard changes.

	* libnautilus-private/Makefile.am:
	* libnautilus-private/nautilus-clipboard-monitor.[ch]
	New files.
parent 56405cf4
2004-02-10 Alexander Larsson <alexl@redhat.com>
* src/file-manager/fm-tree-view.c (copy_or_cut_files):
* src/file-manager/fm-directory-view.c:
Tell the clipboard monitor of changes.
Update paste menus on clipboard changes.
* libnautilus-private/Makefile.am:
* libnautilus-private/nautilus-clipboard-monitor.[ch]
New files.
2004-02-10 Balamurali Viswanathan <balamurali.viswanathan@wipro.com>
* src/file-manager/fm-icon-view.c (play_file): Use the AUDIODEV env,
......
......@@ -55,6 +55,8 @@ libnautilus_private_la_SOURCES = \
nautilus-cell-renderer-pixbuf-emblem.c \
nautilus-cell-renderer-pixbuf-emblem.h \
nautilus-cdrom-extensions.h \
nautilus-clipboard-monitor.c \
nautilus-clipboard-monitor.h \
nautilus-column-chooser.c \
nautilus-column-chooser.h \
nautilus-column-utilities.c \
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
nautilus-clipboard-monitor.c: catch clipboard changes.
Copyright (C) 2004 Red Hat, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Alexander Larsson <alexl@redhat.com>
*/
#include <config.h>
#include "nautilus-clipboard-monitor.h"
#include <eel/eel-debug.h>
#include <eel/eel-gtk-macros.h>
#include <eel/eel-glib-extensions.h>
/* X11 has a weakness when it comes to clipboard handling,
* there is no way to get told when the owner of the clipboard
* changes. This is often needed, for instance to set the
* sensitivity of the paste menu item. We work around this
* internally in an app by telling the clipboard monitor when
* we changed the clipboard. Unfortunately this doesn't give
* us perfect results, we still don't catch changes made by
* other clients. The solution to that is to use the XFIXES
* extension, which isn't availible yet.
*/
enum {
CLIPBOARD_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
static void nautilus_clipboard_monitor_init (gpointer object,
gpointer klass);
static void nautilus_clipboard_monitor_class_init (gpointer klass);
EEL_CLASS_BOILERPLATE (NautilusClipboardMonitor,
nautilus_clipboard_monitor,
G_TYPE_OBJECT)
static NautilusClipboardMonitor *clipboard_monitor = NULL;
static void
destroy_clipboard_monitor (void)
{
if (clipboard_monitor != NULL) {
g_object_unref (clipboard_monitor);
}
}
NautilusClipboardMonitor *
nautilus_clipboard_monitor_get (void)
{
if (clipboard_monitor == NULL) {
clipboard_monitor = NAUTILUS_CLIPBOARD_MONITOR (g_object_new (NAUTILUS_TYPE_CLIPBOARD_MONITOR, NULL));
eel_debug_call_at_shutdown (destroy_clipboard_monitor);
}
return clipboard_monitor;
}
void
nautilus_clipboard_monitor_emit_changed (void)
{
NautilusClipboardMonitor *monitor;
monitor = nautilus_clipboard_monitor_get ();
g_signal_emit (monitor, signals[CLIPBOARD_CHANGED], 0);
}
static void
nautilus_clipboard_monitor_init (gpointer object, gpointer klass)
{
NautilusClipboardMonitor *monitor;
monitor = NAUTILUS_CLIPBOARD_MONITOR (object);
}
static void
clipboard_monitor_finalize (GObject *object)
{
NautilusClipboardMonitor *monitor;
monitor = NAUTILUS_CLIPBOARD_MONITOR (object);
EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
}
static void
nautilus_clipboard_monitor_class_init (gpointer klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = clipboard_monitor_finalize;
signals[CLIPBOARD_CHANGED] =
g_signal_new ("clipboard_changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusClipboardMonitorClass, clipboard_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
nautilus-clipboard-monitor.h: lets you notice clipboard changes.
Copyright (C) 2004 Red Hat, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Alexander Larsson <alexl@redhat.com>
*/
#ifndef NAUTILUS_CLIPBOARD_MONITOR_H
#define NAUTILUS_CLIPBOARD_MONITOR_H
#include <gtk/gtkobject.h>
#define NAUTILUS_TYPE_CLIPBOARD_MONITOR \
(nautilus_clipboard_monitor_get_type ())
#define NAUTILUS_CLIPBOARD_MONITOR(obj) \
(GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_CLIPBOARD_MONITOR, NautilusClipboardMonitor))
#define NAUTILUS_CLIPBOARD_MONITOR_CLASS(klass) \
(GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_CLIPBOARD_MONITOR, NautilusClipboardMonitor))
#define NAUTILUS_IS_CLIPBOARD_MONITOR(obj) \
(GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_CLIPBOARD_MONITOR))
#define NAUTILUS_IS_CLIPBOARD_MONITOR_CLASS(klass) \
(GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_CLIPBOARD_MONITOR))
typedef struct NautilusClipboardMonitorDetails NautilusClipboardMonitorDetails;
typedef struct {
GObject parent_slot;
} NautilusClipboardMonitor;
typedef struct {
GObjectClass parent_slot;
void (* clipboard_changed) (NautilusClipboardMonitor *monitor);
} NautilusClipboardMonitorClass;
GType nautilus_clipboard_monitor_get_type (void);
NautilusClipboardMonitor * nautilus_clipboard_monitor_get (void);
void nautilus_clipboard_monitor_emit_changed (void);
#endif /* NAUTILUS_CLIPBOARD_MONITOR_H */
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
nautilus-desktop-link-monitor.h: singleton thatn manages the links
nautilus-desktop-link-monitor.h: singleton that manages the desktop links
Copyright (C) 2003 Red Hat, Inc.
......
......@@ -71,6 +71,7 @@
#include <libegg/egg-screen-exec.h>
#include <libnautilus-extension/nautilus-menu-provider.h>
#include <libnautilus-private/nautilus-bonobo-extensions.h>
#include <libnautilus-private/nautilus-clipboard-monitor.h>
#include <libnautilus-private/nautilus-desktop-icon-file.h>
#include <libnautilus-private/nautilus-desktop-directory.h>
#include <libnautilus-private/nautilus-directory-background.h>
......@@ -322,6 +323,8 @@ static void stop_loading_callback (NautilusView
static void load_location_callback (NautilusView *nautilus_view,
const char *location,
FMDirectoryView *directory_view);
static void clipboard_changed_callback (NautilusClipboardMonitor *monitor,
FMDirectoryView *view);
static void selection_changed_callback (NautilusView *nautilus_view,
GList *selection,
FMDirectoryView *directory_view);
......@@ -1566,6 +1569,10 @@ fm_directory_view_init (FMDirectoryView *view)
G_CALLBACK (icons_changed_callback),
view, G_CONNECT_SWAPPED);
/* React to clipboard changes */
g_signal_connect_object (nautilus_clipboard_monitor_get (), "clipboard_changed",
G_CALLBACK (clipboard_changed_callback), view, 0);
gtk_widget_show (GTK_WIDGET (view));
filtering_changed_callback (view);
......@@ -4618,6 +4625,7 @@ copy_or_cut_files (FMDirectoryView *view,
clipboard_targets, G_N_ELEMENTS (clipboard_targets),
get_clipboard_callback, clear_clipboard_callback,
clipboard_string);
nautilus_clipboard_monitor_emit_changed ();
count = g_list_length (clipboard_contents);
......@@ -5129,6 +5137,65 @@ real_update_menus_volumes (FMDirectoryView *view,
!show_properties);
}
static void
real_update_paste_menu (FMDirectoryView *view,
GList *selection,
gint selection_count)
{
selection_count = g_list_length (selection);
gboolean can_paste_files_into;
gboolean selection_is_read_only;
gboolean is_read_only;
selection_is_read_only = selection_count == 1
&& !nautilus_file_can_write (NAUTILUS_FILE (selection->data));
is_read_only = fm_directory_view_is_read_only (view);
can_paste_files_into = selection_count == 1 &&
nautilus_file_is_directory (NAUTILUS_FILE (selection->data));
nautilus_bonobo_set_hidden (view->details->ui,
FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES_INTO,
!can_paste_files_into);
nautilus_bonobo_set_sensitive (view->details->ui,
FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES_INTO,
!selection_is_read_only);
nautilus_bonobo_set_sensitive (view->details->ui,
FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES,
is_read_only);
if (!selection_is_read_only || !is_read_only) {
/* Ask the clipboard */
g_object_ref (view); /* Need to keep the object alive until we get the reply */
gtk_clipboard_request_contents (get_clipboard (view),
gdk_atom_intern ("TARGETS", FALSE),
clipboard_targets_received,
view);
}
}
static void
clipboard_changed_callback (NautilusClipboardMonitor *monitor, FMDirectoryView *view)
{
GList *selection;
gint selection_count;
if (view->details->ui == NULL) {
return;
}
selection = fm_directory_view_get_selection (view);
selection_count = g_list_length (selection);
bonobo_ui_component_freeze (view->details->ui, NULL);
real_update_paste_menu (view, selection, selection_count);
bonobo_ui_component_thaw (view->details->ui, NULL);
nautilus_file_list_free (selection);
}
static void
real_update_menus (FMDirectoryView *view)
{
......@@ -5138,11 +5205,9 @@ real_update_menus (FMDirectoryView *view)
char *label_with_underscore;
gboolean selection_contains_special_link;
gboolean is_read_only;
gboolean selection_is_read_only;
gboolean can_create_files;
gboolean can_delete_files;
gboolean can_copy_files;
gboolean can_paste_files_into;
gboolean can_link_files;
gboolean can_duplicate_files;
gboolean show_separate_delete_command;
......@@ -5160,17 +5225,12 @@ real_update_menus (FMDirectoryView *view)
selection_contains_special_link = special_link_in_selection (view);
is_read_only = fm_directory_view_is_read_only (view);
selection_is_read_only = selection_count == 1
&& !nautilus_file_can_write (NAUTILUS_FILE (selection->data));
can_create_files = fm_directory_view_supports_creating_files (view);
can_delete_files = !is_read_only
&& selection_count != 0
&& !selection_contains_special_link;
can_copy_files = selection_count != 0
&& !selection_contains_special_link;
can_paste_files_into = selection_count == 1 &&
nautilus_file_is_directory (NAUTILUS_FILE (selection->data));
can_duplicate_files = can_create_files && can_copy_files;
can_link_files = can_create_files && can_copy_files;
......@@ -5324,23 +5384,7 @@ real_update_menus (FMDirectoryView *view)
FM_DIRECTORY_VIEW_COMMAND_COPY_FILES,
can_copy_files);
nautilus_bonobo_set_hidden (view->details->ui,
FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES_INTO,
!can_paste_files_into);
nautilus_bonobo_set_sensitive (view->details->ui,
FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES_INTO,
!selection_is_read_only);
nautilus_bonobo_set_sensitive (view->details->ui,
FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES,
is_read_only);
if (!selection_is_read_only || !is_read_only) {
/* Ask the clipboard */
g_object_ref (view); /* Need to keep the object alive until we get the reply */
gtk_clipboard_request_contents (get_clipboard (view),
gdk_atom_intern ("TARGETS", FALSE),
clipboard_targets_received,
view);
}
real_update_paste_menu (view, selection, selection_count);
nautilus_bonobo_set_hidden (view->details->ui,
FM_DIRECTORY_VIEW_COMMAND_NEW_LAUNCHER,
......
......@@ -56,6 +56,7 @@
#include <libgnomeui/gnome-popup-menu.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <libgnomevfs/gnome-vfs-volume-monitor.h>
#include <libnautilus-private/nautilus-clipboard-monitor.h>
#include <libnautilus-private/nautilus-file-attributes.h>
#include <libnautilus-private/nautilus-file-operations.h>
#include <libnautilus-private/nautilus-global-preferences.h>
......@@ -780,6 +781,7 @@ copy_or_cut_files (FMTreeView *view,
clipboard_targets, G_N_ELEMENTS (clipboard_targets),
get_clipboard_callback, clear_clipboard_callback,
clipboard_string);
nautilus_clipboard_monitor_emit_changed ();
name = nautilus_file_get_display_name (view->details->popup_file);
if (cut) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment