1
0
mirror of https://github.com/gryf/pygtktalog.git synced 2025-12-17 19:40:21 +01:00

* Added support for history of searches.

This commit is contained in:
2008-05-08 08:46:23 +00:00
parent 9f03954433
commit 1a4bbbb653

View File

@@ -150,7 +150,9 @@ class ConfigModel(Model):
) )
recent = [] recent = []
search_history = []
RECENT_MAX = 10 RECENT_MAX = 10
HISTORY_MAX = 20
dstring = ('cd','ejectapp','imgprog') dstring = ('cd','ejectapp','imgprog')
@@ -202,6 +204,17 @@ class ConfigModel(Model):
break break
count+=1 count+=1
# search history section
newIni.add_section("search history")
count = 1
max_count = self.HISTORY_MAX + 1
for opt in self.search_history:
if count < max_count:
newIni.add_key(count, opt)
else:
break
count+=1
# extensions sections # extensions sections
newIni.add_section("extensions") newIni.add_section("extensions")
count = 1 count = 1
@@ -228,18 +241,20 @@ class ConfigModel(Model):
parser = ConfigParser() parser = ConfigParser()
parser.read("%s/.pygtktalog" % self.path) parser.read("%s/.pygtktalog" % self.path)
r = {} r = {}
h = {}
self.recent = [] self.recent = []
self.search_history = []
for sec in parser.sections(): for sec in parser.sections():
if sec == 'pyGTKtalog conf': if sec == 'pyGTKtalog conf':
for opt in parser.options(sec): for opt in parser.options(sec):
i = self.dictconf[opt] i = self.dictconf[opt]
try: try:
if self.dictconf[opt] in self.dbool: if self.dictconf[opt] in self.dbool:
self.confd[i] = parser.getboolean(sec,opt) self.confd[i] = parser.getboolean(sec, opt)
elif self.dictconf[opt] in self.dstring: elif self.dictconf[opt] in self.dstring:
self.confd[i] = parser.get(sec,opt) self.confd[i] = parser.get(sec, opt)
else: else:
self.confd[i] = parser.getint(sec,opt) self.confd[i] = parser.getint(sec, opt)
except: except:
if __debug__: if __debug__:
print "m_config.py: load() failed to parse", print "m_config.py: load() failed to parse",
@@ -248,7 +263,16 @@ class ConfigModel(Model):
elif sec == 'pyGTKtalog recent': elif sec == 'pyGTKtalog recent':
for opt in parser.options(sec): for opt in parser.options(sec):
try: try:
r[int(opt)] = parser.get(sec,opt) r[int(opt)] = parser.get(sec, opt)
except:
if __debug__:
print "m_config.py: load() failed to parse",
print "option:", opt
pass
elif sec == 'search history':
for opt in parser.options(sec):
try:
h[int(opt)] = parser.get(sec, opt)
except: except:
if __debug__: if __debug__:
print "m_config.py: load() failed to parse", print "m_config.py: load() failed to parse",
@@ -269,6 +293,9 @@ class ConfigModel(Model):
for i in range(1, self.RECENT_MAX + 1): for i in range(1, self.RECENT_MAX + 1):
if i in r: if i in r:
self.recent.append(r[i]) self.recent.append(r[i])
for i in range(1, self.HISTORY_MAX + 1):
if i in h:
self.search_history.append(h[i])
except: except:
if __debug__: if __debug__:
@@ -289,6 +316,20 @@ class ConfigModel(Model):
self.recent = self.recent[:self.RECENT_MAX] self.recent = self.recent[:self.RECENT_MAX]
return return
def add_search_history(self, text):
if not text:
return
if text in self.search_history:
self.search_history.remove(text)
self.search_history.insert(0, text)
return
self.search_history.insert(0, text)
if len(self.search_history) > self.HISTORY_MAX:
self.search_history = self.search_history[:self.HISTORY_MAX]
return
def __str__(self): def __str__(self):
"""show prefs in string way""" """show prefs in string way"""
string = "[varname]\tvalue\n" string = "[varname]\tvalue\n"