mirror of
https://github.com/gryf/pygtktalog.git
synced 2025-12-17 19:40:21 +01:00
* Added recent in config class.
* Added read/write recent menu with correct order into configuration file.
This commit is contained in:
@@ -90,6 +90,9 @@ class ConfigModel(Model):
|
|||||||
'showstatusbar',
|
'showstatusbar',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
recent = []
|
||||||
|
RECENT_MAX = 10
|
||||||
|
|
||||||
dstring = ('cd','ejectapp')
|
dstring = ('cd','ejectapp')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -107,17 +110,28 @@ class ConfigModel(Model):
|
|||||||
os.lstat("%s/.pygtktalog" % self.path)
|
os.lstat("%s/.pygtktalog" % self.path)
|
||||||
except:
|
except:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
print "Saving preferences to %s/.pygtktalog" % self.path
|
print "m_config.py: save() Saving preferences to %s/.pygtktalog" % self.path
|
||||||
newIni = Ini()
|
newIni = Ini()
|
||||||
newIni.add_section("pyGTKtalog conf")
|
newIni.add_section("pyGTKtalog conf")
|
||||||
for opt in self.dictconf:
|
for opt in self.dictconf:
|
||||||
newIni.add_key(opt,self.confd[self.dictconf[opt]])
|
newIni.add_key(opt,self.confd[self.dictconf[opt]])
|
||||||
|
newIni.add_section("pyGTKtalog recent")
|
||||||
|
|
||||||
|
count = 1
|
||||||
|
max_count = self.RECENT_MAX + 1
|
||||||
|
|
||||||
|
for opt in self.recent:
|
||||||
|
if count < max_count:
|
||||||
|
newIni.add_key(count, opt)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
count+=1
|
||||||
try:
|
try:
|
||||||
f = open("%s/.pygtktalog" % self.path,"w")
|
f = open("%s/.pygtktalog" % self.path,"w")
|
||||||
success = True
|
success = True
|
||||||
except:
|
except:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
print "Cannot open config file %s for writing." % (self.path, "/.pygtktalog")
|
print "m_config.py: save() Cannot open config file %s for writing." % (self.path, "/.pygtktalog")
|
||||||
success = False
|
success = False
|
||||||
f.write(newIni.show())
|
f.write(newIni.show())
|
||||||
f.close()
|
f.close()
|
||||||
@@ -128,6 +142,8 @@ class ConfigModel(Model):
|
|||||||
# try to read config file
|
# try to read config file
|
||||||
parser = ConfigParser()
|
parser = ConfigParser()
|
||||||
parser.read("%s/.pygtktalog" % self.path)
|
parser.read("%s/.pygtktalog" % self.path)
|
||||||
|
r = {}
|
||||||
|
self.recent = []
|
||||||
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):
|
||||||
@@ -140,12 +156,39 @@ class ConfigModel(Model):
|
|||||||
self.confd[self.dictconf[opt]] = parser.getint(sec,opt)
|
self.confd[self.dictconf[opt]] = parser.getint(sec,opt)
|
||||||
except:
|
except:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
print "failed to parse option:", opt
|
print "m_config.py: load() failed to parse option:", opt
|
||||||
pass
|
pass
|
||||||
|
elif sec == 'pyGTKtalog recent':
|
||||||
|
|
||||||
|
for opt in parser.options(sec):
|
||||||
|
try:
|
||||||
|
r[int(opt)] = parser.get(sec,opt)
|
||||||
except:
|
except:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
print "load config file failed"
|
print "m_config.py: load() failed to parse option:", opt
|
||||||
pass
|
pass
|
||||||
|
for i in range(1, self.RECENT_MAX + 1):
|
||||||
|
if r.has_key(i):
|
||||||
|
self.recent.append(r[i])
|
||||||
|
|
||||||
|
except:
|
||||||
|
if __debug__:
|
||||||
|
print "m_config.py: load() load config file failed"
|
||||||
|
pass
|
||||||
|
|
||||||
|
def add_recent(self, path):
|
||||||
|
if not path:
|
||||||
|
return
|
||||||
|
|
||||||
|
if path in self.recent:
|
||||||
|
self.recent.remove(path)
|
||||||
|
self.recent.insert(0,path)
|
||||||
|
return
|
||||||
|
|
||||||
|
self.recent.insert(0,path)
|
||||||
|
if len(self.recent) > self.RECENT_MAX:
|
||||||
|
self.recent = self.recent[:self.RECENT_MAX]
|
||||||
|
return
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""show prefs in string way"""
|
"""show prefs in string way"""
|
||||||
|
|||||||
Reference in New Issue
Block a user