Fixes for bug #2416: added proper name format in gtk tree model, and update on canceled edit

svn: r11583
This commit is contained in:
Doug Blank 2009-01-08 02:00:31 +00:00
parent d5177c4b8c
commit 1b25cd8b47
3 changed files with 33 additions and 6 deletions

View File

@ -360,14 +360,37 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
"%s %s, %s" % (_("Given"), _("SURNAME"), _("Suffix")),
"%s /%s/" % (_("Given"), _("SURNAME")),
]
f = lyst[int(random.random() * len(lyst))]
i = _nd.add_name_format(f, f.lower())
node = self.fmt_model.append(row=[i, f, f.lower(),
_nd.format_str(self.examplename, f)])
fmtlyst = ["%s, %s %s (%s)" % ("Surname", "Given", "Suffix",
"Common"),
"%s, %s %s (%s)" % ("Surname", "Given", "Suffix",
"Call"),
"%s, %s %s (%s)" % ("SURNAME", "Given", "Suffix",
"Call"),
"%s, %s (%s)" % ("Surname", "Given", "Common"),
"%s, %s (%s)" % ("Surname", "Given", "Call"),
"%s %s" % ("Given", "Surname"),
"%s %s, %s" % ("Given", "Surname", "Suffix"),
"%s %s %s" % ("Given", "Surname", "Patronymic"),
"%s, %s %s (%s)" % ("SURNAME", "Given", "Suffix",
"Common"),
"%s, %s (%s)" % ("SURNAME", "Given", "Common"),
"%s, %s (%s)" % ("SURNAME", "Given", "Call"),
"%s %s" % ("Given", "SURNAME"),
"%s %s, %s" % ("Given", "SURNAME", "Suffix"),
"%s /%s/" % ("Given", "SURNAME"),
]
rand = int(random.random() * len(lyst))
f = lyst[rand]
fmt = fmtlyst[rand]
i = _nd.add_name_format(f, fmt)
node = self.fmt_model.append(row=[i, f, fmt,
_nd.format_str(self.examplename, fmt)])
path = self.fmt_model.get_path(node)
self.format_list.set_cursor(path,
focus_column=self.name_column,
start_editing=True)
self.__current_path = path
self.__current_text = f
def __edit_name(self, obj):
store, node = self.format_list.get_selection().get_selected()
@ -395,6 +418,9 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
iter = model.iter_next(iter)
return False
def __cancel_change(self, obj):
self.__change_name("", self.__current_path, self.__current_text)
def __change_name(self, text, path, new_text):
"""
If the new string is empty, do nothing. Otherwise, renaming the
@ -457,6 +483,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
text=COL_NAME)
name_renderer.set_property('editable', False)
name_renderer.connect('edited', self.__change_name)
name_renderer.connect('editing-canceled', self.__cancel_change)
self.name_renderer = name_renderer
format_tree.append_column(name_column)
example_renderer = gtk.CellRendererText()

View File

@ -377,7 +377,7 @@ class GrampsDbXmlWriter(UpdateCallback):
for number, name,fmt_str,active in self.db.name_formats:
self.g.write('%s<format number="%d" name="%s" '
'fmt_str="%s" active="%d"/>\n'
% (' ', number, fmt_str, fmt_str, int(active)))
% (' ', number, name, fmt_str, int(active)))
self.g.write(" </name-formats>\n")
def fix(self,line):

View File

@ -1054,7 +1054,7 @@ class GrampsParser(UpdateCallback):
if number in self.taken_name_format_numbers:
number = self.remap_name_format(number)
self.name_formats.append((number, fmt_str, fmt_str, active))
self.name_formats.append((number, name, fmt_str, active))
def remap_name_format(self, old_number):
if self.name_formats_map.has_key(old_number): # This should not happen