r16088 - gnucash/trunk/src/gnome - Programmatically generate check file names from the title input by the

David Hampton hampton at cvs.gnucash.org
Mon May 14 22:47:08 EDT 2007


Author: hampton
Date: 2007-05-14 22:47:06 -0400 (Mon, 14 May 2007)
New Revision: 16088
Trac: http://svn.gnucash.org/trac/changeset/16088

Modified:
   gnucash/trunk/src/gnome/dialog-print-check.c
   gnucash/trunk/src/gnome/glade/print.glade
Log:
Programmatically generate check file names from the title input by the
user.  Fixes #436255.  Also reload the check format combobox each time
a custom format is successfully saved.  Fixes #436394.


Modified: gnucash/trunk/src/gnome/dialog-print-check.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-print-check.c	2007-05-14 14:38:46 UTC (rev 16087)
+++ gnucash/trunk/src/gnome/dialog-print-check.c	2007-05-15 02:47:06 UTC (rev 16088)
@@ -74,8 +74,7 @@
 
 #define DEFAULT_FONT            "sans 12"
 #define CHECK_FMT_DIR           "checks"
-#define CUSTOM_CHECK_NAME       "custom.chk"
-#define CHECK_NAME_FILTER       "*.chk"
+#define CHECK_NAME_EXTENSION    ".chk"
 #define DEGREES_TO_RADIANS      (G_PI / 180.0)
 
 #define KF_GROUP_TOP       "Top"
@@ -126,6 +125,7 @@
 void gnc_print_check_save_button_clicked(GtkButton *button, PrintCheckDialog *pcd);
 void gnc_check_format_title_changed (GtkEditable *editable, GtkWidget *ok_button);
 
+static void initialize_format_combobox (PrintCheckDialog * pcd);
 
 /** This enum defines the types of items that gnucash knows how to
  *  print on checks.  Most refer to specific fields from a gnucash
@@ -496,9 +496,7 @@
 /** Save all of the information from the custom check dialog into a check
  *  description file. */
 static void
-pcd_save_custom_data(PrintCheckDialog *pcd,
-                     const gchar *filename,
-                     const gchar *title)
+pcd_save_custom_data(PrintCheckDialog *pcd, const gchar *title)
 {
     GKeyFile *key_file;
     GError *error = NULL;
@@ -507,6 +505,8 @@
     gint i = 1;
     GUID guid;
     char buf[GUID_ENCODING_LENGTH+1];
+    gchar *filename, *pathname;
+    GtkTreeModel *model;
 
     multip = pcd_get_custom_multip(pcd);
 
@@ -533,7 +533,17 @@
     pcd_key_file_save_item_xy(key_file, i++, NOTES, multip,
                               pcd->notes_x, pcd->notes_y);
 
-    if (!gnc_key_file_save_to_file(filename, key_file, &error)) {
+    filename = g_strconcat(title, CHECK_NAME_EXTENSION, NULL);
+    pathname = g_build_filename(gnc_dotgnucash_dir(), CHECK_FMT_DIR, 
+                                filename, NULL);
+
+    if (gnc_key_file_save_to_file(pathname, key_file, &error)) {
+        /* Reload the format combo box and reselect the "custom" entry */
+        initialize_format_combobox(pcd);
+        model = gtk_combo_box_get_model(GTK_COMBO_BOX(pcd->format_combobox));
+        gtk_combo_box_set_active(GTK_COMBO_BOX(pcd->format_combobox),
+                                 pcd->format_max - 1);
+    } else {
         dialog = gtk_message_dialog_new(GTK_WINDOW(pcd->dialog),
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                         GTK_MESSAGE_ERROR,
@@ -545,6 +555,8 @@
         gtk_widget_destroy(dialog);
         g_error_free(error);
     }
+    g_free(pathname);
+    g_free(filename);
 }
 
 
@@ -567,11 +579,9 @@
 void
 gnc_print_check_save_button_clicked(GtkButton *unused, PrintCheckDialog *pcd)
 {
-    GtkFileChooser *chooser;
-    GtkFileFilter *filter;
     GtkWidget *dialog, *entry, *button;
     GladeXML *xml;
-    gchar *check_dir, *filename, *title;
+    gchar *title;
 
     /* Get a title for the new check format. */
     xml = gnc_glade_xml_new ("print.glade", "Format Title Dialog");
@@ -588,42 +598,11 @@
         return;
     }
 
-    /* Now get the filename. */
     title = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
     gtk_widget_destroy (dialog);
     g_object_unref(xml);
 
-    dialog = gtk_file_chooser_dialog_new(_("Save Check Description"),
-                                         GTK_WINDOW(pcd->dialog),
-                                         GTK_FILE_CHOOSER_ACTION_SAVE,
-                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                                         GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
-                                         NULL);
-    chooser = GTK_FILE_CHOOSER(dialog);
-
-    check_dir = g_build_filename(gnc_dotgnucash_dir(), CHECK_FMT_DIR, NULL);
-    gtk_file_chooser_set_current_folder(chooser, check_dir);
-    gtk_file_chooser_set_current_name(chooser, CUSTOM_CHECK_NAME);
-    g_free(check_dir);
-
-    filter = gtk_file_filter_new();
-    gtk_file_filter_set_name(filter, CHECK_NAME_FILTER);
-    gtk_file_filter_add_pattern(filter, CHECK_NAME_FILTER);
-    gtk_file_chooser_add_filter(chooser, filter);
-
-    filter = gtk_file_filter_new();
-    gtk_file_filter_set_name(filter, _("All Files"));
-    gtk_file_filter_add_pattern(filter, "*");
-    gtk_file_chooser_add_filter(chooser, filter);
-
-    gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(pcd->dialog));
-    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
-        filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
-        pcd_save_custom_data(pcd, filename, title);
-        g_free(filename);
-    }
-
-    gtk_widget_destroy (dialog);
+    pcd_save_custom_data(pcd, title);
     g_free(title);
 }
 
@@ -1165,7 +1144,24 @@
     return separator;
 }
 
+static void
+initialize_format_combobox (PrintCheckDialog * pcd)
+{
+  GtkListStore *store;
+  GtkTreeIter iter;
 
+  store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
+  read_formats(pcd, store);
+  gtk_list_store_append(store, &iter);
+  gtk_list_store_set(store, &iter, COL_NAME, _("Custom"), -1);
+  pcd->format_max = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store),NULL);
+  gtk_combo_box_set_model(GTK_COMBO_BOX(pcd->format_combobox),
+                          GTK_TREE_MODEL(store));
+  gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(pcd->format_combobox),
+                                       format_is_a_separator, NULL, NULL);
+}
+
+
 /********************************************************************\
  * gnc_ui_print_check_dialog_create
  * make a new print check dialog and wait for it.
@@ -1179,8 +1175,6 @@
   GladeXML *xml;
   GtkWidget *table;
   GtkWindow *window;
-  GtkListStore *store;
-  GtkTreeIter iter;
   gchar *font;
 
   pcd = g_new0(PrintCheckDialog, 1);
@@ -1233,15 +1227,7 @@
   pcd->default_font = font ? font : g_strdup(DEFAULT_FONT);
 
   /* Update the combo boxes bases on the available check formats */
-  store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
-  read_formats(pcd, store);
-  gtk_list_store_append(store, &iter);
-  gtk_list_store_set(store, &iter, COL_NAME, _("Custom"), -1);
-  pcd->format_max = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store),NULL);
-  gtk_combo_box_set_model(GTK_COMBO_BOX(pcd->format_combobox),
-                          GTK_TREE_MODEL(store));
-  gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(pcd->format_combobox),
-                                       format_is_a_separator, NULL, NULL);
+  initialize_format_combobox(pcd);
 
 #if USE_GTKPRINT
   gtk_widget_destroy(glade_xml_get_widget (xml, "lower_left"));

Modified: gnucash/trunk/src/gnome/glade/print.glade
===================================================================
--- gnucash/trunk/src/gnome/glade/print.glade	2007-05-14 14:38:46 UTC (rev 16087)
+++ gnucash/trunk/src/gnome/glade/print.glade	2007-05-15 02:47:06 UTC (rev 16088)
@@ -1089,7 +1089,7 @@
 
 <widget class="GtkDialog" id="Format Title Dialog">
   <property name="visible">True</property>
-  <property name="title" translatable="yes">New Check Format Title</property>
+  <property name="title" translatable="yes">Save Custom Check Format</property>
   <property name="type">GTK_WINDOW_TOPLEVEL</property>
   <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
   <property name="modal">False</property>
@@ -1153,7 +1153,7 @@
 	<widget class="GtkLabel" id="label847683">
 	  <property name="visible">True</property>
 	  <property name="can_focus">True</property>
-	  <property name="label" translatable="yes">Please enter a title for the new check format.  This title will appear in the &quot;Check format&quot; selector in the Print Check dialog.</property>
+	  <property name="label" translatable="yes">Enter a title for this custom format.  This title will appear in the &quot;Check format&quot; selector of the Print Check dialog.  Using the title of an exiting custom format will cause that format to be overwritten.</property>
 	  <property name="use_underline">False</property>
 	  <property name="use_markup">False</property>
 	  <property name="justify">GTK_JUSTIFY_LEFT</property>



More information about the gnucash-changes mailing list