r23082 - gnucash/trunk/src/report - Require custom report template names to be unique (among other custom report templates)
Geert Janssens
gjanssens at code.gnucash.org
Tue Jul 2 07:18:04 EDT 2013
Author: gjanssens
Date: 2013-07-02 07:18:04 -0400 (Tue, 02 Jul 2013)
New Revision: 23082
Trac: http://svn.gnucash.org/trac/changeset/23082
Modified:
gnucash/trunk/src/report/report-gnome/dialog-custom-report.c
gnucash/trunk/src/report/report-system/report-system.scm
gnucash/trunk/src/report/report-system/report.scm
Log:
Require custom report template names to be unique (among other custom report templates)
Modified: gnucash/trunk/src/report/report-gnome/dialog-custom-report.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/dialog-custom-report.c 2013-07-02 11:17:47 UTC (rev 23081)
+++ gnucash/trunk/src/report/report-gnome/dialog-custom-report.c 2013-07-02 11:18:04 UTC (rev 23082)
@@ -410,10 +410,20 @@
{
CustomReportDialog *crd = data;
SCM guid = get_custom_report_selection(crd, _("Unable to change report name."));
- custom_report_edit_report_name (guid, crd, new_text);
+ SCM unique_name_func = scm_c_eval_string("gnc:report-template-has-unique-name?");
+ SCM new_name_scm = scm_from_locale_string(new_text);
g_object_set(G_OBJECT(crd->namerenderer), "editable", FALSE, NULL);
+ if (scm_is_null (guid))
+ return;
+ if (scm_is_true (scm_call_2 (unique_name_func, guid, new_name_scm)))
+ custom_report_edit_report_name (guid, crd, new_text);
+ else
+ gnc_error_dialog(crd->dialog, "%s",
+ _("A custom report with this name already exists, please choose another name.") );
+
+
}
void custom_report_query_tooltip_cb (GtkTreeView *view,
gint x,
Modified: gnucash/trunk/src/report/report-system/report-system.scm
===================================================================
--- gnucash/trunk/src/report/report-system/report-system.scm 2013-07-02 11:17:47 UTC (rev 23081)
+++ gnucash/trunk/src/report/report-system/report-system.scm 2013-07-02 11:18:04 UTC (rev 23082)
@@ -134,6 +134,7 @@
(export gnc:report-template-menu-tip)
(export gnc:report-template-export-types)
(export gnc:report-template-export-thunk)
+(export gnc:report-template-has-unique-name?)
(export gnc:report-type)
(export gnc:report-set-type!)
(export gnc:report-id)
Modified: gnucash/trunk/src/report/report-system/report.scm
===================================================================
--- gnucash/trunk/src/report/report-system/report.scm 2013-07-02 11:17:47 UTC (rev 23081)
+++ gnucash/trunk/src/report/report-system/report.scm 2013-07-02 11:18:04 UTC (rev 23082)
@@ -474,7 +474,23 @@
(define (gnc:is-custom-report-type report)
(gnc:report-template-is-custom/template-guid? (gnc:report-custom-template report)))
+;; This function should be called right before changing a custom-template's name
+;; to test if the new name is unique among the existting custom reports.
+;; If not the calling function can prevent the name from being updated.
+(define (gnc:report-template-has-unique-name? templ-guid new-name)
+ (let* ((unique? #t))
+ (if new-name
+ (hash-for-each
+ (lambda (id rec)
+ (if (and (not (equal? templ-guid id))
+ (gnc:report-template-is-custom/template-guid? id)
+ (equal? new-name (gnc:report-template-name rec)))
+ (set! unique? #f)))
+ *gnc:_report-templates_*))
+ unique?))
+
+
;; Load and save functions
(define (gnc:report-generate-restore-forms report)
More information about the gnucash-changes
mailing list