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

gEDA-user: pcb: Some code-cleanup-patches



 Hello,

today I am trying to make patches from my recent days work. I am new to git, so it takes much more time than I expected...
But, here are two more patches.

The first one (0002...) removes some unused functions from the gtk-gui-code.
The second one (0004...) introduces the gtk-default-dialog for 'overwrite-existing-file - confirmation'. For this reason, the pcb-dialog 'ghid_dialog_confirm()' is not needed any more and will be removed by this patch, too. This patch also does some other modifications to the file open/save dialogs:
- replace OK-button by OPEN/SAVE
- remove 'gtk_dialog_set_default_response()', because the OK/OPEN/SAVE - Button will be the default button even without this declaration


It is needed, that you apply patch 0002... before 0004.

Perhaps, someone of you can check this patches before they are sent to the patch-tracker.

Thanks and good bye,
Felix
From b66809056891c138ceec8a5a4963b7e5263a7dfd Mon Sep 17 00:00:00 2001
From: Felix Ruoff <Felix@xxxxxxxxxxxxxxxxxx>
Date: Sat, 9 Oct 2010 23:09:25 +0200
Subject: [PATCH] gtk-gui code-cleanup

Removes some unused functions
---
 src/hid/gtk/gtkhid-main.c |   27 +----
 src/hid/gtk/gui-dialog.c  |  268 ---------------------------------------------
 src/hid/gtk/gui.h         |    4 -
 3 files changed, 2 insertions(+), 297 deletions(-)

diff --git a/src/hid/gtk/gtkhid-main.c b/src/hid/gtk/gtkhid-main.c
index 7d59672..6b7c6ab 100644
--- a/src/hid/gtk/gtkhid-main.c
+++ b/src/hid/gtk/gtkhid-main.c
@@ -866,29 +866,6 @@ ghid_report_dialog (char *title, char *msg)
   ghid_dialog_report (title, msg);
 }
 
-char *
-ghid_prompt_for (char *msg, char *default_string)
-{
-  char *rv;
-
-  rv = ghid_dialog_input (msg, default_string);
-  return rv;
-}
-
-/* FIXME -- implement a proper file select dialog */
-#ifdef FIXME
-char *
-ghid_fileselect (const char *title, const char *descr,
-		 char *default_file, char *default_ext,
-		 const char *history_tag, int flags)
-{
-  char *rv;
-
-  rv = ghid_dialog_input (title, default_file);
-  return rv;
-}
-#endif
-
 void
 ghid_show_item (void *item)
 {
@@ -1187,8 +1164,8 @@ HID ghid_hid = {
   ghid_confirm_dialog,
   ghid_close_confirm_dialog,
   ghid_report_dialog,
-  ghid_prompt_for,
-  ghid_fileselect,
+  0,
+  0,
   ghid_attribute_dialog,
   ghid_show_item,
   ghid_beep,
diff --git a/src/hid/gtk/gui-dialog.c b/src/hid/gtk/gui-dialog.c
index ec91233..f4a2674 100644
--- a/src/hid/gtk/gui-dialog.c
+++ b/src/hid/gtk/gui-dialog.c
@@ -45,50 +45,6 @@
 RCSID ("$Id$");
 
 /* ---------------------------------------------- */
-gchar *
-ghid_dialog_input (gchar * prompt, gchar * initial)
-{
-  GtkWidget *dialog, *vbox, *label, *entry;
-  gchar *string;
-  gboolean response;
-  GHidPort *out = &ghid_port;
-
-  dialog = gtk_dialog_new_with_buttons ("PCB User Input",
-					GTK_WINDOW (out->top_window),
-					GTK_DIALOG_MODAL,
-					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-					GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
-
-  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-  vbox = gtk_vbox_new (FALSE, 4);
-  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
-  label = gtk_label_new ("");
-  gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
-
-  gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
-  gtk_label_set_markup (GTK_LABEL (label),
-			prompt ? prompt : "Enter something");
-
-  entry = gtk_entry_new ();
-  if (initial)
-    gtk_entry_set_text (GTK_ENTRY (entry), initial);
-
-  gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
-  gtk_box_pack_start_defaults (GTK_BOX (vbox), entry);
-  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox);
-  gtk_widget_show_all (dialog);
-
-  response = gtk_dialog_run (GTK_DIALOG (dialog));
-  if (response != GTK_RESPONSE_OK)
-    string = g_strdup (initial ? initial : "");
-  else
-    string = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
-
-  gtk_widget_destroy (dialog);
-  return string;
-}
-
-/* ---------------------------------------------- */
 void
 ghid_dialog_about (void)
 {
@@ -106,35 +62,6 @@ ghid_dialog_about (void)
 }
 
 /* ---------------------------------------------- */
-gint
-ghid_dialog_confirm_all (gchar * all_message)
-{
-  GtkWidget *dialog, *label, *vbox;
-  gint response;
-  GHidPort *out = &ghid_port;
-
-  dialog = gtk_dialog_new_with_buttons ("Confirm",
-					GTK_WINDOW (out->top_window),
-					GTK_DIALOG_MODAL |
-					GTK_DIALOG_DESTROY_WITH_PARENT,
-					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-					GTK_STOCK_OK, GTK_RESPONSE_OK,
-					"Sequence OK",
-					GUI_DIALOG_RESPONSE_ALL, NULL);
-
-  vbox = ghid_framed_vbox (GTK_DIALOG (dialog)->vbox, NULL, 6, FALSE, 4, 6);
-
-  label = gtk_label_new (all_message);
-  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
-  gtk_widget_show_all (dialog);
-
-  response = gtk_dialog_run (GTK_DIALOG (dialog));
-  gtk_widget_destroy (dialog);
-
-  return response;
-}
-
-/* ---------------------------------------------- */
 void
 ghid_dialog_message (gchar * message)
 {
@@ -414,198 +341,3 @@ ghid_dialog_file_select_save (gchar * title, gchar ** path, gchar * file,
   return result;
 }
 
-
-/* ---------------------------------------------- */
-/* how many files and directories to keep for the shortcuts */
-#define NHIST 8
-typedef struct ghid_file_history_struct
-{
-  /* 
-   * an identifier as to which recent files pool this is.  For example
-   * "boards", "eco", "netlists", etc.
-   */
-  char * id;
-
-  /* 
-   * the array of files or directories
-   */
-  char * history[NHIST];
-} ghid_file_history;
-
-static int n_recent_dirs = 0;
-static ghid_file_history * recent_dirs = NULL;
-
-/* ---------------------------------------------- */
-/* Caller must g_free() the returned filename. */
-gchar *
-ghid_fileselect (const char *title, const char *descr,
-                 char *default_file, char *default_ext,
-		 const char *history_tag, int flags)
-{
-  GtkWidget *dialog;
-  gchar *result = NULL;
-  GHidPort *out = &ghid_port;
-  gchar *path = NULL, *base = NULL;
-  int history_pool = -1;
-  int i;
- 
-  if (history_tag && *history_tag)
-    {
-      /* 
-       * I used a simple linear search here because the number of
-       * entries in the array is likely to be quite small (5, maybe 10 at
-       * the absolute most) and this function is used when pulling up
-       * a file dialog box instead of something called over and over
-       * again as part of moving elements or autorouting.  So, keep it
-       * simple....
-       */
-      history_pool = 0;
-      while (history_pool < n_recent_dirs &&
-	     strcmp (recent_dirs[history_pool].id, history_tag) != 0)
-	{
-	  history_pool++;
-	}
-      
-      /*
-       * If we counted all the way to n_recent_dirs, that means we
-       * didn't find our entry
-       */
-      if (history_pool >= n_recent_dirs)
-	{
-	  n_recent_dirs++;
-
-	  recent_dirs = realloc (recent_dirs, 
-				  n_recent_dirs * sizeof (ghid_file_history));
-
-	  if (recent_dirs == NULL)
-	    {
-	      fprintf (stderr, "%s():  realloc failed\n", __FUNCTION__);
-	      exit (1);
-	    }
-	  
-	  recent_dirs[history_pool].id = strdup (history_tag);
-
-	  /* Initialize the entries in our history list to all be NULL */
-	  for (i = 0; i < NHIST; i++)
-	    {
-	      recent_dirs[history_pool].history[i] = NULL;
-	    }
-	}
-    }
-
-  if (default_file && *default_file)
-    {
-      path = g_path_get_dirname (default_file);
-      base = g_path_get_basename (default_file);
-    }
-
-  dialog = gtk_file_chooser_dialog_new (title,
-					GTK_WINDOW (out->top_window),
-					(flags & HID_FILESELECT_READ) ? 
-					GTK_FILE_CHOOSER_ACTION_OPEN : 
-					GTK_FILE_CHOOSER_ACTION_SAVE,
-					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-					GTK_STOCK_OK, GTK_RESPONSE_OK,
-					NULL);
-
-  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-
-  if (path && *path )
-    {
-      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), path);
-      g_free (path);
-    }
-
-  if (base && *base)
-    {
-      /* default file is only supposed to be for writing, not reading */
-      if (!(flags & HID_FILESELECT_READ))
-	{
-	  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), base);
-	}
-      g_free (base);
-    }
-
-  for (i = 0; i < NHIST && recent_dirs[history_pool].history[i] != NULL ; i++)
-    {
-      gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
-					    recent_dirs[history_pool].history[i], 
-					    NULL);
-    }
-
-  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
-    {
-      result = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
-      if (result != NULL)
-	path = g_path_get_dirname (result);
-      else
-	path = NULL;
-
-      /* update the history list */
-      if (path != NULL)
-	{
-	  char *tmps, *tmps2;
-	  int k = 0;
-
-	  /* 
-	   * Put this at the top of the list and bump everything else
-	   * down but skip any old entry of this directory
-	   *
-	   */
-	  while ( k < NHIST &&
-		 recent_dirs[history_pool].history[k] != NULL &&
-		 strcmp ( recent_dirs[history_pool].history[k], path) == 0)
-	    {
-	      k++;
-	    }
-	  tmps = recent_dirs[history_pool].history[k];
-	  recent_dirs[history_pool].history[0] = path;
-	  for (i = 1 ; i < NHIST ; i++)
-	    {
-	      /* store our current entry, but skip duplicates */
-	      while (i + k < NHIST &&
-		     recent_dirs[history_pool].history[i + k] != NULL &&
-		     strcmp ( recent_dirs[history_pool].history[i + k], path) == 0)
-		{
-		  k++;
-		}
-		     
-	      if (i + k < NHIST)
-		tmps2 = recent_dirs[history_pool].history[i + k];
-	      else
-		tmps2 = NULL;
-
-	      /* move down the one we stored last time */
-	      recent_dirs[history_pool].history[i] = tmps;
-
-	      /* and remember the displace entry */
-	      tmps = tmps2;
-	    }
-
-	  /* 
-	   * the last one has fallen off the end of the history list
-	   * so we need to free() it.
-	   */
-	  if (tmps)
-	    {
-	      free (tmps);
-	    }
-	}
-      
-#ifdef DEBUG
-      printf ("\n\n-----\n\n");
-      for (i = 0 ; i < NHIST ; i++)
-	{
-	  printf ("After update recent_dirs[%d].history[%d] = \"%s\"\n",
-		  history_pool, i, recent_dirs[history_pool].history[i] != NULL ?
-		  recent_dirs[history_pool].history[i] : "NULL");
-	}
-#endif
-
-    }
-  gtk_widget_destroy (dialog);
-
-
-  return result;
-}
-
diff --git a/src/hid/gtk/gui.h b/src/hid/gtk/gui.h
index 7686106..996591d 100644
--- a/src/hid/gtk/gui.h
+++ b/src/hid/gtk/gui.h
@@ -331,12 +331,8 @@ int ghid_dialog_close_confirm (void);
 #define GUI_DIALOG_CLOSE_CONFIRM_CANCEL 0
 #define GUI_DIALOG_CLOSE_CONFIRM_NOSAVE 1
 #define GUI_DIALOG_CLOSE_CONFIRM_SAVE   2
-gint ghid_dialog_confirm_all (gchar * message);
-gchar *ghid_dialog_input (gchar * prompt, gchar * initial);
 void ghid_dialog_about (void);
 
-char * ghid_fileselect (const char *, const char *, char *, char *, const char *, int);
-
 
 /* gui-dialog-print.c */
 void ghid_dialog_export (void);
-- 
1.7.1

From ff721473fa3aa39247b52106e91874f45fcaf279 Mon Sep 17 00:00:00 2001
From: Felix Ruoff <Felix@xxxxxxxxxxxxxxxxxx>
Date: Sat, 9 Oct 2010 22:11:19 +0200
Subject: [PATCH] Use gtk-default-window for confirmation of overwriting files

This patch introduces the gtk_file_chooser_get_do_overwrite_confirmation() - function to ghid_dialog_file_select_save() which makes the pcb - confirm-dialog useless.
This patch also changes the 'OK'-Button of the file-chooser dialogs from GTK_STOCK_OK to GTK_STOCK_OPEN or GTK_STOCK_SAVE and removes the gtk_dialog_set_default_response() function, because the OPEN/SAVE button will be the default-button by default.
---
 src/hid/gtk/gtkhid-main.c |   19 +---------------
 src/hid/gtk/gui-dialog.c  |   54 ++++----------------------------------------
 src/hid/gtk/gui.h         |    1 -
 3 files changed, 6 insertions(+), 68 deletions(-)

diff --git a/src/hid/gtk/gtkhid-main.c b/src/hid/gtk/gtkhid-main.c
index 6b7c6ab..fdccdce 100644
--- a/src/hid/gtk/gtkhid-main.c
+++ b/src/hid/gtk/gtkhid-main.c
@@ -1403,24 +1403,7 @@ Save (int argc, char **argv, int x, int y)
 				       PCB->Filename, Settings.FilePath);
   
   if (name)
-    {
-      FILE *exist;
-      exist = fopen (name, "r");
-      if (exist)
-	{
-	  fclose (exist);
-	  if (ghid_dialog_confirm (_("File exists!  Ok to overwrite?"), NULL, NULL))
-	    {
-	      if (Settings.verbose)
-		fprintf (stderr, _("Overwriting %s\n"), name);
-	    }
-	  else
-	    {
-	      g_free (name);
-	      return 1;
-	    }
-	}
-      
+    {      
       if (Settings.verbose)
 	fprintf (stderr, "%s:  Calling SaveTo(%s, %s)\n", 
 		 __FUNCTION__, function, name);
diff --git a/src/hid/gtk/gui-dialog.c b/src/hid/gtk/gui-dialog.c
index 57148e4..81a0865 100644
--- a/src/hid/gtk/gui-dialog.c
+++ b/src/hid/gtk/gui-dialog.c
@@ -79,48 +79,6 @@ ghid_dialog_message (gchar * message)
 }
 
 /* ---------------------------------------------- */
-gboolean
-ghid_dialog_confirm (gchar * message, gchar * cancelmsg, gchar * okmsg)
-{
-  static gint x = -1, y = -1;
-  GtkWidget *dialog;
-  gboolean confirm = FALSE;
-  GHidPort *out = &ghid_port;
-
-  if (cancelmsg == NULL)
-    {
-      cancelmsg = _("_Cancel");
-    }
-  if (okmsg == NULL)
-    {
-      okmsg = _("_OK");
-    }
-
-  dialog = gtk_message_dialog_new (GTK_WINDOW (out->top_window),
-				   GTK_DIALOG_MODAL |
-				   GTK_DIALOG_DESTROY_WITH_PARENT,
-				   GTK_MESSAGE_QUESTION,
-				   GTK_BUTTONS_NONE,
-				   "%s", message);
-  gtk_dialog_add_buttons (GTK_DIALOG (dialog), 
-			  cancelmsg, GTK_RESPONSE_CANCEL,
-			  okmsg, GTK_RESPONSE_OK,
-			  NULL);
-
-  if(x != -1) {
-  	gtk_window_move(GTK_WINDOW (dialog), x, y);
-  }
-
-  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
-    confirm = TRUE;
-
-  gtk_window_get_position(GTK_WINDOW (dialog), &x, &y);
-
-  gtk_widget_destroy (dialog);
-  return confirm;
-}
-
-/* ---------------------------------------------- */
 gint
 ghid_dialog_close_confirm ()
 {
@@ -203,11 +161,9 @@ ghid_dialog_file_select_open (gchar * title, gchar ** path, gchar * shortcuts)
 					GTK_WINDOW (out->top_window),
 					GTK_FILE_CHOOSER_ACTION_OPEN,
 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-					GTK_STOCK_OK, GTK_RESPONSE_OK,
+					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
 					NULL);
 
-  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-
   /* add a default filter for not filtering files */
   no_filter = gtk_file_filter_new ();
   gtk_file_filter_set_name (no_filter, "all");
@@ -280,7 +236,7 @@ ghid_dialog_file_select_open (gchar * title, gchar ** path, gchar * shortcuts)
       g_free (folder);
     }
 
-  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
     {
       result = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
       folder =
@@ -335,10 +291,10 @@ ghid_dialog_file_select_save (gchar * title, gchar ** path, gchar * file,
 					GTK_WINDOW (out->top_window),
 					GTK_FILE_CHOOSER_ACTION_SAVE,
 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-					GTK_STOCK_OK, GTK_RESPONSE_OK,
+					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
 					NULL);
 
-  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+  gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
 
   if (path && *path && **path)
     gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), *path);
@@ -358,7 +314,7 @@ ghid_dialog_file_select_save (gchar * title, gchar ** path, gchar * file,
 	}
       g_free (folder);
     }
-  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
     {
       result = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
       folder =
diff --git a/src/hid/gtk/gui.h b/src/hid/gtk/gui.h
index d365b97..7e97f9b 100644
--- a/src/hid/gtk/gui.h
+++ b/src/hid/gtk/gui.h
@@ -328,7 +328,6 @@ gchar *ghid_dialog_file_select_open (gchar * title, gchar ** path,
 gchar *ghid_dialog_file_select_save (gchar * title, gchar ** path,
 				     gchar * file, gchar * shortcuts);
 void ghid_dialog_message (gchar * message);
-gboolean ghid_dialog_confirm (gchar * message, gchar *cancelmsg, gchar *okmsg);
 int ghid_dialog_close_confirm (void);
 #define GUI_DIALOG_CLOSE_CONFIRM_CANCEL 0
 #define GUI_DIALOG_CLOSE_CONFIRM_NOSAVE 1
-- 
1.7.1


_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user