dia r3973 - in trunk: . app data lib samples/Self



Author: hans
Date: Thu May  1 18:10:03 2008
New Revision: 3973
URL: http://svn.gnome.org/viewvc/dia?rev=3973&view=rev

Log:
2008-05-01  Hans Breuer  <hans breuer org>

	* app/find-and-replace.[hc] : inital version of find&replace showing 
	the ui and printing what it found (unfinished, to be continued)
	* app/Makefile.am app/makefile.msc : build find-and-replace.c
	* lib/diagramdata.[hc] : new function data_foreach_object() to simplify
	the iteration over objects
	* data/display-ui.xml data/popup-ui.xml app/menus.c : Find&Replace 
	in the menus



Added:
   trunk/app/find-and-replace.c
   trunk/app/find-and-replace.h
Modified:
   trunk/ChangeLog
   trunk/app/Makefile.am
   trunk/app/makefile.msc
   trunk/app/menus.c
   trunk/data/display-ui.xml
   trunk/data/popup-ui.xml
   trunk/lib/diagramdata.c
   trunk/lib/diagramdata.h
   trunk/samples/Self/dia-renderer.dia

Modified: trunk/app/Makefile.am
==============================================================================
--- trunk/app/Makefile.am	(original)
+++ trunk/app/Makefile.am	Thu May  1 18:10:03 2008
@@ -161,6 +161,8 @@
 	    pagesetup.h \
 	    filedlg.c \
 	    filedlg.h \
+	    find-and-replace.c \
+	    find-and-replace.h \
 	    plugin-manager.c \
 	    plugin-manager.h \
 	    dia-props.c \

Added: trunk/app/find-and-replace.c
==============================================================================
--- (empty file)
+++ trunk/app/find-and-replace.c	Thu May  1 18:10:03 2008
@@ -0,0 +1,202 @@
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * find-and-replace.c - common functionality applied to diagram
+ *
+ * Copyright (C) 2008 Hans Breuer
+ *
+ * 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 "intl.h"
+
+#include "diagram.h"
+#include "display.h"
+#include "object.h"
+
+#include "find-and-replace.h"
+
+enum {
+  RESPONSE_FIND = -20,
+  RESPONSE_REPLACE = -21,
+  RESPONSE_REPLACE_ALL = -23
+};
+
+typedef struct _SearchData {
+  const gchar *key;
+} SearchData;
+
+static void
+find_func (DiaObject *obj, gpointer user_data)
+{
+  SearchData *data = (SearchData *)user_data;
+
+  gchar* name = object_get_displayname (obj);
+  if (strstr (name, data->key) != NULL)
+    g_print ("%s\n", name);
+  g_free (name);
+}
+
+static gint
+fnr_respond (GtkWidget *widget, gint response_id, gpointer data)
+{
+  const gchar *search = gtk_entry_get_text (g_object_get_data (G_OBJECT (widget), "search-entry")); 
+  const gchar *replace;
+  DDisplay *ddisp = (DDisplay*)data;
+  GList *list;
+  SearchData sd;
+
+  switch (response_id) {
+  case RESPONSE_FIND :
+    sd.key = search;
+    data_foreach_object (ddisp->diagram->data, find_func, &sd);
+    break;
+  case RESPONSE_REPLACE :
+    replace = gtk_entry_get_text (g_object_get_data (G_OBJECT (widget), "replace-entry"));
+    g_print ("Replace: %s\n", replace);
+    break;
+  case RESPONSE_REPLACE_ALL :
+    break;
+  default:
+    gtk_widget_hide (widget);
+  }
+  return 0;
+}
+
+static void
+fnr_dialog_setup_common (GtkWidget *dialog, gboolean is_replace, DDisplay *ddisp)
+{
+  GtkWidget *vbox;
+  GtkWidget *hbox;
+  GtkWidget *label;
+  GtkWidget *search_entry;
+  GtkWidget *match_case;
+  GtkWidget *match_word;
+
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), RESPONSE_FIND);
+
+  /* don't destroy dialog when window manager close button pressed */
+  g_signal_connect(G_OBJECT (dialog), "response",
+		   G_CALLBACK(fnr_respond), ddisp);
+  g_signal_connect(G_OBJECT(dialog), "delete_event",
+		   G_CALLBACK(gtk_widget_hide), NULL);
+  g_signal_connect(GTK_OBJECT(dialog), "delete_event",
+		   G_CALLBACK(gtk_true), NULL);
+  g_signal_connect(GTK_OBJECT(dialog), "destroy",
+		   G_CALLBACK(gtk_widget_destroyed), &dialog);
+
+  vbox = GTK_DIALOG(dialog)->vbox;
+
+  hbox = gtk_hbox_new (FALSE, 12);
+  label = gtk_label_new_with_mnemonic (_("_Search for:"));
+  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+  search_entry = gtk_entry_new ();
+  g_object_set_data (G_OBJECT (dialog), "search-entry", search_entry);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), search_entry);
+  gtk_entry_set_width_chars (GTK_ENTRY (search_entry), 30);
+  gtk_box_pack_start (GTK_BOX (hbox), search_entry, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 6);
+  
+  if (is_replace) {
+    GtkWidget *replace_entry;
+
+    hbox = gtk_hbox_new (FALSE, 12);
+    label = gtk_label_new_with_mnemonic (_("Replace _with:"));
+    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+    replace_entry = gtk_entry_new ();
+    g_object_set_data (G_OBJECT (dialog), "replace-entry", replace_entry);
+    gtk_label_set_mnemonic_widget (GTK_LABEL (label), replace_entry);
+    gtk_entry_set_width_chars (GTK_ENTRY (replace_entry), 30);
+    gtk_box_pack_start (GTK_BOX (hbox), replace_entry, TRUE, TRUE, 0);
+    gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 6);
+  }
+
+  match_case = gtk_check_button_new_with_mnemonic (_("_Match case"));
+  gtk_box_pack_start (GTK_BOX (vbox), match_case, FALSE, FALSE, 6);
+
+  match_word = gtk_check_button_new_with_mnemonic (_("Match _entire word only"));
+  gtk_box_pack_start (GTK_BOX (vbox), match_word, FALSE, FALSE, 6);
+
+  gtk_widget_show_all (vbox);
+}
+
+/**
+ * React to <Display>/Edit/Find
+ */
+void
+edit_find_callback(gpointer data, guint action, GtkWidget *widget)
+{
+  DDisplay *ddisp;
+  Diagram *dia;
+  GtkWidget *dialog;
+
+  ddisp = ddisplay_active();
+  if (!ddisp) return;
+  dia = ddisp->diagram;
+
+  /* no static var, instead we are attaching the dialog to the diplay shell */
+  dialog = g_object_get_data (G_OBJECT (ddisp->shell), "edit-find-dialog");
+  if (!dialog) {
+    dialog = gtk_dialog_new_with_buttons (
+		_("Find"), 
+		GTK_WINDOW (ddisp->shell), GTK_DIALOG_DESTROY_WITH_PARENT,
+		GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+		GTK_STOCK_FIND, RESPONSE_FIND,
+		NULL);
+
+    fnr_dialog_setup_common (dialog, FALSE, ddisp);
+  }
+  g_object_set_data (G_OBJECT (ddisp->shell), "edit-find-dialog", dialog);
+
+  gtk_dialog_run (GTK_DIALOG (dialog));  
+}
+
+/**
+ * React to <Display>/Edit/Replace
+ */
+void
+edit_replace_callback(gpointer data, guint action, GtkWidget *widget)
+{
+  DDisplay *ddisp;
+  Diagram *dia;
+  GtkWidget *dialog;
+
+  ddisp = ddisplay_active();
+  if (!ddisp) return;
+  dia = ddisp->diagram;
+
+  /* no static var, instead we are attaching the dialog to the diplay shell */
+  dialog = g_object_get_data (G_OBJECT (ddisp->shell), "edit-replace-dialog");
+  if (!dialog) {
+    dialog = gtk_dialog_new_with_buttons (
+		_("Replace"), 
+		GTK_WINDOW (ddisp->shell), GTK_DIALOG_DESTROY_WITH_PARENT,
+		GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+		_("Replace _All"), RESPONSE_REPLACE_ALL,
+		GTK_STOCK_FIND_AND_REPLACE, RESPONSE_REPLACE,
+		GTK_STOCK_FIND, RESPONSE_FIND,
+		NULL);
+    
+    fnr_dialog_setup_common (dialog, TRUE, ddisp);
+  }
+  g_object_set_data (G_OBJECT (ddisp->shell), "edit-replace-dialog", dialog);
+
+  gtk_dialog_run (GTK_DIALOG (dialog));  
+}
+

Added: trunk/app/find-and-replace.h
==============================================================================
--- (empty file)
+++ trunk/app/find-and-replace.h	Thu May  1 18:10:03 2008
@@ -0,0 +1,30 @@
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * find-and-replace.h - common functionality applied to diagram
+ *
+ * Copyright (C) 2008 Hans Breuer
+ *
+ * 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 FIND_AND_REPLACE_H
+#define FIND_AND_REPLACE_H
+
+void edit_find_callback (gpointer data, guint action, GtkWidget *widget);
+void edit_replace_callback (gpointer data, guint action, GtkWidget *widget);
+
+#endif /* FIND_AND_REPLACE_H */
+

Modified: trunk/app/makefile.msc
==============================================================================
--- trunk/app/makefile.msc	(original)
+++ trunk/app/makefile.msc	Thu May  1 18:10:03 2008
@@ -51,6 +51,7 @@
 	exit_dialog.obj \
 	export_png.obj \
 	filedlg.obj \
+	find-and-replace.obj \
 	grid.obj \
 	gtkhwrapbox.obj \
 	gtkvwrapbox.obj \

Modified: trunk/app/menus.c
==============================================================================
--- trunk/app/menus.c	(original)
+++ trunk/app/menus.c	Thu May  1 18:10:03 2008
@@ -33,6 +33,7 @@
 #include "interface.h"
 #include "display.h"
 #include "filedlg.h"
+#include "find-and-replace.h"
 #include "plugin-manager.h"
 #include "select.h"
 #include "dia_dirs.h"
@@ -122,6 +123,9 @@
     { "EditDuplicate", NULL, N_("_Duplicate"), "<control>D", NULL, G_CALLBACK (edit_duplicate_callback) },
     { "EditDelete", GTK_STOCK_DELETE, NULL, "Delete", NULL, G_CALLBACK (edit_delete_callback) },
 
+    { "EditFind", GTK_STOCK_FIND, NULL, "<control>F", NULL, G_CALLBACK (edit_find_callback) },
+    { "EditReplace", GTK_STOCK_FIND_AND_REPLACE, NULL, "<control>F", NULL, G_CALLBACK (edit_replace_callback) },
+
     /* the following used to bind to <control><shift>C which collides with Unicode input. 
      * <control>>alt> doesn't work either */
     { "EditCopytext", NULL, N_("Copy Text"), NULL, NULL, G_CALLBACK (edit_copy_text_callback) },
@@ -794,6 +798,7 @@
       if (tooltip)
         {
 	  gtk_tooltips_set_tip (tool_tips, proxy, tooltip, NULL);
+	  g_free (tooltip);
 	}
     }
 }

Modified: trunk/data/display-ui.xml
==============================================================================
--- trunk/data/display-ui.xml	(original)
+++ trunk/data/display-ui.xml	Thu May  1 18:10:03 2008
@@ -27,10 +27,13 @@
 			<menuitem name="EditDuplicate" action="EditDuplicate" />
 			<menuitem name="EditDelete" action="EditDelete" />
 			<separator name="EditSep2" />
+			<menuitem name="EditFind" action="EditFind" />
+			<menuitem name="EditReplace" action="EditReplace" />
+			<separator name="EditSep3" />
 			<menuitem name="EditCopytext" action="EditCopytext" />
 			<menuitem name="EditCuttext" action="EditCuttext" />
 			<menuitem name="EditPastetext" action="EditPastetext" />
-			<separator name="EditSep3" />
+			<separator name="EditSep4" />
 			<separator name="EditExtensionStart" />
 		</menu>
 		<menu name="Diagram" action="Diagram">

Modified: trunk/data/popup-ui.xml
==============================================================================
--- trunk/data/popup-ui.xml	(original)
+++ trunk/data/popup-ui.xml	Thu May  1 18:10:03 2008
@@ -27,10 +27,13 @@
 			<menuitem name="EditDuplicate" action="EditDuplicate" />
 			<menuitem name="EditDelete" action="EditDelete" />
 			<separator name="EditSep2" />
+			<menuitem name="EditFind" action="EditFind" />
+			<menuitem name="EditReplace" action="EditReplace" />
+			<separator name="EditSep3" />
 			<menuitem name="EditCopytext" action="EditCopytext" />
 			<menuitem name="EditCuttext" action="EditCuttext" />
 			<menuitem name="EditPastetext" action="EditPastetext" />
-			<separator name="EditSep3" />
+			<separator name="EditSep4" />
 			<separator name="EditExtensionStart" />
 		</menu>
 		<menu name="Diagram" action="Diagram">

Modified: trunk/lib/diagramdata.c
==============================================================================
--- trunk/lib/diagramdata.c	(original)
+++ trunk/lib/diagramdata.c	Thu May  1 18:10:03 2008
@@ -630,6 +630,17 @@
   if (!renderer->is_interactive) (DIA_RENDERER_GET_CLASS(renderer)->end_render)(renderer);
 }
 
+void 
+data_foreach_object (DiagramData *data, GFunc func, gpointer user_data)
+{
+  Layer *layer;
+  int i;
+  for (i=0; i<data->layers->len; i++) {
+    layer = (Layer *) g_ptr_array_index(data->layers, i);
+    g_list_foreach (layer->objects, func, user_data);
+  }  
+}
+
 /** The default object renderer.
  * @param obj An object to render.
  * @param renderer The renderer to render on.

Modified: trunk/lib/diagramdata.h
==============================================================================
--- trunk/lib/diagramdata.h	(original)
+++ trunk/lib/diagramdata.h	Thu May  1 18:10:03 2008
@@ -144,6 +144,7 @@
 float data_get_font_unit_multiplier(DiagramData *data);
 void data_emit(DiagramData *data,Layer *layer,DiaObject* obj,const char *signal_name);
 
+void data_foreach_object (DiagramData *data, GFunc func, gpointer user_data);
 
 
 typedef void (*ObjectRenderer)(DiaObject *obj, DiaRenderer *renderer,

Modified: trunk/samples/Self/dia-renderer.dia
==============================================================================
Binary files. No diff available.



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