gnobog-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnobog-devel] Patch for 0.4.3 to add X clipboard


From: Detlef Vollmann
Subject: [Gnobog-devel] Patch for 0.4.3 to add X clipboard
Date: Thu, 28 Aug 2003 18:28:03 +0200

Attached is a patch to add an "Copy to X clipboard" to the
popup menu.  Base version for the patch is the 0.4.3 release.

The code is not really production code, it has still some
smaller quirks (though it works fine for me):
 - the value for the clipboard is lazy evaluted when it is used,
   not when the menu entry is selected.
   This can lead to some confusion.
 - the menu entry is active even if nothing is selected, which
   is also confusing.

So, esentially this code is for demonstration only, and will
probably be ported to the current CVS version.

Detlef

-- 
Detlef Vollmann   vollmann engineering gmbh
Linux and C++ for Embedded Systems    http://www.vollmann.ch/
diff -Naur gnobog-0.4.3/src/Makefile.am gnobog-patched/src/Makefile.am
--- gnobog-0.4.3/src/Makefile.am        Sun Oct 22 18:38:10 2000
+++ gnobog-patched/src/Makefile.am      Wed Aug 27 15:58:28 2003
@@ -39,7 +39,9 @@
         gnobog_app.h                    \
         gnobog_app.c                    \
         gnobog_menus.h                  \
-        gnobog_menus.c                          
+        gnobog_menus.c                  \
+        gnobog_selection.h              \
+        gnobog_selection.c  
 
 ##gnobog_LDADD = $(GNOMEUI_LIBS) $(GNOME_LIBDIR) $(INTLLIBS) -lxml -lglade 
-lglade-gnome
 gnobog_LDADD = $(GNOMEUI_LIBS) $(GNOME_LIBDIR) -lxml -lglade -lglade-gnome
diff -Naur gnobog-0.4.3/src/Makefile.in gnobog-patched/src/Makefile.in
--- gnobog-0.4.3/src/Makefile.in        Thu May  3 16:44:54 2001
+++ gnobog-patched/src/Makefile.in      Wed Aug 27 15:59:54 2003
@@ -121,7 +121,7 @@
 
 bin_PROGRAMS = gnobog
 
-gnobog_SOURCES =          glib_addon.h                            glib_addon.c 
                           gnobog_bookmarks-private.h              
gnobog_bookmarks.h                      gnobog_bookmarks.c                      
gnobog_mozilla_backend.h                gnobog_mozilla_backend.c                
gnobog_arborescence.h                   gnobog_arborescence.c                   
gnobog_dnd.h                            gnobog_pixmaps.h                        
gnobog_pixmaps.c                        gnobog_main.c                           
gnobog_popup_menu.h                     gnobog_popup_menu.c                     
gnobog_open_file_dialog.h               gnobog_open_file_dialog.c               
gnobog_save_file_dialog.h               gnobog_save_file_dialog.c               
gnobog_edit.h                           gnobog_edit.c                           
gnobog_app.h                            gnobog_app.c                            
gnobog_menus.h                          gnobog_menus.c                          
+gnobog_SOURCES =          glib_addon.h                            glib_addon.c 
                           gnobog_bookmarks-private.h              
gnobog_bookmarks.h                      gnobog_bookmarks.c                      
gnobog_mozilla_backend.h                gnobog_mozilla_backend.c                
gnobog_arborescence.h                   gnobog_arborescence.c                   
gnobog_dnd.h                            gnobog_pixmaps.h                        
gnobog_pixmaps.c                        gnobog_main.c                           
gnobog_popup_menu.h                     gnobog_popup_menu.c                     
gnobog_open_file_dialog.h               gnobog_open_file_dialog.c               
gnobog_save_file_dialog.h               gnobog_save_file_dialog.c               
gnobog_edit.h                           gnobog_edit.c                           
gnobog_app.h                            gnobog_app.c                            
gnobog_menus.h                          gnobog_menus.c                          
gnobog_selection.h                      gnobog_selection.c  
 
 
 gnobog_LDADD = $(GNOMEUI_LIBS) $(GNOME_LIBDIR) -lxml -lglade -lglade-gnome
@@ -136,7 +136,8 @@
 gnobog_OBJECTS =  glib_addon.o gnobog_bookmarks.o \
 gnobog_mozilla_backend.o gnobog_arborescence.o gnobog_pixmaps.o \
 gnobog_main.o gnobog_popup_menu.o gnobog_open_file_dialog.o \
-gnobog_save_file_dialog.o gnobog_edit.o gnobog_app.o gnobog_menus.o
+gnobog_save_file_dialog.o gnobog_edit.o gnobog_app.o gnobog_menus.o \
+gnobog_selection.o
 gnobog_DEPENDENCIES = 
 gnobog_LDFLAGS = 
 COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS)
diff -Naur gnobog-0.4.3/src/gnobog_app.c gnobog-patched/src/gnobog_app.c
--- gnobog-0.4.3/src/gnobog_app.c       Sun Dec  3 22:45:56 2000
+++ gnobog-patched/src/gnobog_app.c     Wed Aug 27 16:16:48 2003
@@ -29,6 +29,7 @@
 #include "gnobog_popup_menu.h"
 #include "gnobog_app.h"
 #include "gnobog_menus.h"
+#include "gnobog_selection.h"
 
 #define LOCK_FILENAME  "lock"
 #define LOCK_ERROR "Lock file %s exist !\n\
@@ -328,6 +329,7 @@
   gnobog_popup_menu_set (gnobog_app);
 
   /* gnobog-widgets ***/
+  gnobog_selection_init();
 
   /*** gnobog-signals */
   gtk_signal_connect (GTK_OBJECT (gnobog_app),
diff -Naur gnobog-0.4.3/src/gnobog_popup_menu.c 
gnobog-patched/src/gnobog_popup_menu.c
--- gnobog-0.4.3/src/gnobog_popup_menu.c        Thu May  3 16:07:11 2001
+++ gnobog-patched/src/gnobog_popup_menu.c      Wed Aug 27 16:13:18 2003
@@ -28,6 +28,7 @@
 #include "gnobog_open_file_dialog.h"
 #include "gnobog_app.h"
 #include "gnobog_menus.h"
+#include "gnobog_selection.h"
 #include "pixmaps/title.xpm"
 
 static GtkWidget* popup = NULL;
@@ -143,6 +144,9 @@
   GNOMEUIINFO_ITEM_NONE (N_("Edit"),
                          N_("Edit bookmark properties"),
                          gnobog_popup_cb_edit),
+  GNOMEUIINFO_ITEM_NONE (N_("Copy to clipboard"),
+                         N_("Copy link URL to X clipboard"),
+                         gnobog_selection_provide),
   GNOMEUIINFO_SEPARATOR,
   GNOMEUIINFO_ITEM_NONE (N_("Set as root"),
                          N_("Show only this folder content"),
diff -Naur gnobog-0.4.3/src/gnobog_selection.c 
gnobog-patched/src/gnobog_selection.c
--- gnobog-0.4.3/src/gnobog_selection.c Thu Jan  1 01:00:00 1970
+++ gnobog-patched/src/gnobog_selection.c       Wed Aug 27 17:17:52 2003
@@ -0,0 +1,162 @@
+/* gnobog_selection.c
+ *
+ * Copyright (C) 2003 Detlef Vollmann
+ *
+ * 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
+ */
+
+#include <config.h>
+#include <gtk/gtk.h>
+#include "gnobog_arborescence.h"
+#include "gnobog_app.h"
+
+static void 
+gnobog_selection_copy_cb(GtkWidget        *widget, 
+                         GtkSelectionData *selection_data,
+                         guint             info,
+                         guint             time_stamp,
+                         gpointer data);
+static gint
+gnobog_selection_clear(GtkWidget         *widget,
+                       GdkEventSelection *event,
+                       gpointer          data);
+
+
+static GtkWidget *selection_widget = NULL;
+static int have_selection = FALSE;
+static GnobogArborescence*  arborescence;
+
+
+
+
+
+/*****************************************************************************/
+/* Widget creation                                                           */
+/*****************************************************************************/
+
+/* creates (invisible) widget for selection and registers callbacks */
+void 
+gnobog_selection_init(void)
+{
+    selection_widget = gtk_invisible_new();
+
+
+    gtk_selection_add_target (selection_widget,
+                              GDK_SELECTION_PRIMARY,
+                              GDK_SELECTION_TYPE_STRING,
+                              1);
+    gtk_signal_connect (GTK_OBJECT(selection_widget),
+                        "selection_get",
+                        GTK_SIGNAL_FUNC (gnobog_selection_copy_cb),
+                        &have_selection);
+    gtk_signal_connect (GTK_OBJECT(selection_widget),
+                        "selection_clear_event",
+                        GTK_SIGNAL_FUNC (gnobog_selection_clear),
+                        &have_selection);
+}
+
+
+
+
+
+
+
+/*****************************************************************************/
+/* Menus callbacks                                                           */
+/*****************************************************************************/
+
+/* provides the currently selected link to the X clipboard */
+/* actually, just claims the selection */
+void 
+gnobog_selection_provide(GtkWidget* widget, 
+                         gpointer data)
+{
+    if (!have_selection)
+    {
+        have_selection = gtk_selection_owner_set(selection_widget,
+                                                 GDK_SELECTION_PRIMARY,
+                                                 GDK_CURRENT_TIME);
+    }
+
+    if (have_selection)
+    {
+        arborescence = GNOBOG_ARBORESCENCE (gnobog_app_get_active_view ());
+    }
+}
+
+
+
+
+/*****************************************************************************/
+/* Selection callbacks                                                       */
+/*****************************************************************************/
+
+/* provides the currently selected link to the X clipboard */
+/* actually provides the data when somebody else wants it */
+/* we have an asynchronicy here: the selection might be changed
+ * between the "Copy to clipboard" and this request.
+ * There might even nothing be selected anymore.
+ * Simple fix: put the location in a local buffer in gnobog_selection_provide.
+ * I(dv) don't do the fix here as I like the current (problematic) behaviour.
+ */
+static void 
+gnobog_selection_copy_cb(GtkWidget* widget, 
+                         GtkSelectionData *selection_data,
+                         guint             info,
+                         guint             time_stamp,
+                         gpointer data)
+{
+    GList*               selection;
+    GnobogBookmarksNode  bookmarks_node;
+    gchar*               location;
+
+    /* Find the bookmark selected */
+    selection = gnobog_arborescence_get_sorted_bookmarks_node_selection 
(arborescence);
+    if ( NULL == selection )
+    {
+        location = "";
+        g_warning("nothing selected");
+    }
+    else
+    {
+        bookmarks_node = (GnobogBookmarksNode) (selection->data);
+
+        /* Set the url of the selected bookmark as the dragged data */
+        location = gnobog_bookmarks_node_get_location (bookmarks_node);
+    }
+
+    gtk_selection_data_set(selection_data,
+                           GDK_SELECTION_TYPE_STRING,
+                           8 /* format : num bits/unit */,
+                           location /* data pointer */,
+                           strlen(location) /* length w/o trailing null */);
+}
+
+/* Called when another application claims the selection */
+static gint
+gnobog_selection_clear(GtkWidget         *widget,
+                       GdkEventSelection *event,
+                       gpointer data)
+{
+    have_selection = FALSE;
+
+    return TRUE;
+}
+
+
+
+
+/* gnobog-selection ***/
diff -Naur gnobog-0.4.3/src/gnobog_selection.h 
gnobog-patched/src/gnobog_selection.h
--- gnobog-0.4.3/src/gnobog_selection.h Thu Jan  1 01:00:00 1970
+++ gnobog-patched/src/gnobog_selection.h       Wed Aug 27 15:00:27 2003
@@ -0,0 +1,35 @@
+/* gnobog_selection.h
+ *
+ * Copyright (C) 2003 Detlef Vollmann
+ *
+ * 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
+ */
+
+#ifndef GNOBOG_SELECTION_H
+#define GNOBOG_SELECTION_H
+
+#include <gnome.h>
+
+void gnobog_selection_init
+         (void);
+void gnobog_selection_provide
+         (GtkWidget* menu,
+          const gpointer data);
+      
+#endif
+
+/* gnometest-selectionh ***/
+

reply via email to

[Prev in Thread] Current Thread [Next in Thread]