4599: regression from 3.2.5 - name format preference doesn't persist across reloads

svn: r16565
This commit is contained in:
Benny Malengier 2011-02-04 10:51:28 +00:00
parent ded1c7ea29
commit ebe5229822
2 changed files with 23 additions and 11 deletions

View File

@ -266,8 +266,7 @@ class CLIManager(object):
name_displayer.set_name_format(self.dbstate.db.name_formats) name_displayer.set_name_format(self.dbstate.db.name_formats)
fmt_default = config.get('preferences.name-format') fmt_default = config.get('preferences.name-format')
if fmt_default < 0: name_displayer.set_default_format(fmt_default)
name_displayer.set_default_format(fmt_default)
self.dbstate.db.enable_signals() self.dbstate.db.enable_signals()
self.dbstate.signal_change() self.dbstate.signal_change()

View File

@ -222,17 +222,22 @@ class NameDisplay(object):
def __init__(self): def __init__(self):
global WITH_GRAMP_CONFIG global WITH_GRAMP_CONFIG
self.name_formats = {} self.name_formats = {}
#preinit the name formats, this should be updated with the data
#in the database once a database is loaded
self.set_name_format(self.STANDARD_FORMATS) self.set_name_format(self.STANDARD_FORMATS)
if WITH_GRAMPS_CONFIG: if WITH_GRAMPS_CONFIG:
self.default_format = config.get('preferences.name-format') self.default_format = config.get('preferences.name-format')
if self.default_format == 0 \ if self.default_format == 0:
or self.default_format not in Name.NAMEFORMATS :
self.default_format = Name.LNFN self.default_format = Name.LNFN
config.set('preferences.name-format', self.default_format) config.set('preferences.name-format', self.default_format)
else: else:
self.default_format = Name.LNFN self.default_format = Name.LNFN
#following has little sense as the database name formats are not
#loaded yet, but we do it to set up everything
#when loading a database, name formats must be loaded and
#default format set again!
self.set_default_format(self.default_format) self.set_default_format(self.default_format)
def _format_fn(self, fmt_str): def _format_fn(self, fmt_str):
@ -258,18 +263,22 @@ class NameDisplay(object):
return ' '.join(result.split()) return ' '.join(result.split())
def set_name_format(self, formats): def set_name_format(self, formats):
raw_func_dict = { raw_func_dict = {
Name.LNFN : self._raw_lnfn, Name.LNFN : self._raw_lnfn,
Name.FNLN : self._raw_fnln, Name.FNLN : self._raw_fnln,
Name.FN : self._raw_fn, Name.FN : self._raw_fn,
} }
for (num, name, fmt_str, act) in formats: #remove data from previous database
func = self._format_fn(fmt_str) self.name_formats = {}
func_raw = raw_func_dict.get(num) for tformats in [self.STANDARD_FORMATS, formats]:
if func_raw is None: for (num, name, fmt_str, act) in tformats:
func_raw = self._format_raw_fn(fmt_str) func = self._format_fn(fmt_str)
self.name_formats[num] = (name, fmt_str, act, func, func_raw) func_raw = raw_func_dict.get(num)
if func_raw is None:
func_raw = self._format_raw_fn(fmt_str)
self.name_formats[num] = (name, fmt_str, act, func, func_raw)
def add_name_format(self, name, fmt_str): def add_name_format(self, name, fmt_str):
num = -1 num = -1
@ -292,6 +301,10 @@ class NameDisplay(object):
def set_default_format(self, num): def set_default_format(self, num):
if num not in self.name_formats: if num not in self.name_formats:
num = Name.LNFN num = Name.LNFN
# if user sets default format to the Gramps default format,
# then we select LNFN as format.
if num == Name.DEF:
num = Name.LNFN
self.default_format = num self.default_format = num