Changeset 896539c063a7…
Parent 8dd7ec3f5bce…
by
Changes to 6 files · Browse files at 896539c063a7 Showing diff from parent 8dd7ec3f5bce Diff from another changeset...
|
@@ -39,7 +39,9 @@ self._src_path = ''
self._dest_path = ''
self._settings = shlib.Settings('clone')
-
+ self._recent_src = self._settings.mrul('src_paths')
+ self._recent_dest = self._settings.mrul('dest_paths')
+
try:
self._src_path = repos[0]
self._dest_path = repos[1]
@@ -108,10 +110,10 @@
# add pre-defined src paths to pull-down list
sympaths = [x[1] for x in ui.ui().configitems('paths')]
- recentsrc = self._settings.get('src_paths', [])
- paths = list(set(sympaths + recentsrc))
+ paths = list(set(sympaths + [x for x in self._recent_src]))
paths.sort()
- for p in paths: self._srclist.append([p])
+ for p in paths:
+ self._srclist.append([p])
# clone destination
destbox = gtk.HBox()
@@ -138,9 +140,10 @@ destbox.pack_end(self._btn_dest_browse, False, False, 5)
vbox.pack_start(destbox, False, False, 2)
- # add pre-defined dest paths to pull-down list
- recentdest = self._settings.get('dest_paths', [])
- for p in recentdest:
+ # add most-recent dest paths to pull-down list
+ paths = list(self._recent_dest)
+ paths.sort()
+ for p in paths:
self._destlist.append([p])
# revision input
@@ -225,51 +228,37 @@ if rev is not None:
self._rev_input.set_text(rev)
- def _update_setting_list(self, key, path):
- paths = self._settings.get(key, [])
- if path in paths:
- paths.remove(path)
- paths.append(path)
- while len(paths) > HistorySize:
- del paths[0]
- self._settings[key] = paths
-
def _add_src_to_recent(self, src):
if os.path.exists(src):
src = os.path.abspath(src)
- srclist = [x[0] for x in self._srclist]
-
+ # save path to recent list in history
+ self._recent_src.add(src)
+ self._settings.write()
+
# update drop-down list
- if src not in srclist:
- srclist.append(src)
- srclist.sort()
self._srclist.clear()
- for p in srclist:
+ sympaths = [x[1] for x in ui.ui().configitems('paths')]
+ paths = list(set(sympaths + [x for x in self._recent_src]))
+ paths.sort()
+ for p in paths:
self._srclist.append([p])
-
- # save path to recent list in history
- self._update_setting_list('src_paths', src)
- self._settings.write()
def _add_dest_to_recent(self, dest):
if os.path.exists(dest):
dest = os.path.abspath(dest)
- destlist = [x[0] for x in self._destlist]
-
- # update drop-down list
- if dest not in destlist:
- destlist.append(dest)
- destlist.sort()
+ # save path to recent list in history
+ self._recent_dest.add(dest)
+ self._settings.write()
+
+ # update drop down list
+ paths = list(self._recent_dest)
+ paths.sort()
self._destlist.clear()
- for p in destlist:
+ for p in paths:
self._destlist.append([p])
- # save path to recent list in history
- self._update_setting_list('dest_paths', dest)
- self._settings.write()
-
def _btn_clone_clicked(self, toolbutton, data=None):
# gather input data
src = self._src_input.get_text()
|
@@ -314,8 +314,8 @@ def _destroying(self, gtkobj):
try:
settings = self.save_settings()
- self.settings['settings_version'] = GDialog.settings_version
- self.settings['dialogs'] = settings
+ self.settings.set_value('settings_version', GDialog.settings_version)
+ self.settings.set_value('dialogs', settings)
self.settings.write()
finally:
if self.main:
@@ -324,9 +324,9 @@
def _load_settings(self):
settings = {}
- version = self.settings.get('settings_version', None)
+ version = self.settings.get_value('settings_version', None)
if version == GDialog.settings_version:
- settings = self.settings.get('dialogs', {})
+ settings = self.settings.get_value('dialogs', {})
self.load_settings(settings)
|
@@ -189,9 +189,9 @@ def _refresh(self, initial):
def fill_history(history, vlist, cpath):
vlist.clear()
- if cpath not in history:
+ if cpath not in history.get_keys():
return
- for v in history[cpath]:
+ for v in history.get_value(cpath):
vlist.append([v])
history = shlib.Settings('config_history')
@@ -248,11 +248,11 @@ def _on_send_clicked(self, button):
def record_new_value(cpath, history, newvalue):
if not newvalue: return
- if cpath not in history:
- history[cpath] = []
- elif newvalue in history[cpath]:
- history[cpath].remove(newvalue)
- history[cpath].insert(0, newvalue)
+ if cpath not in history.get_keys():
+ history.set_value(cpath, [])
+ elif newvalue in history.get_value(cpath):
+ history.get_value(cpath).remove(newvalue)
+ history.get_value(cpath).insert(0, newvalue)
totext = self._tobox.child.get_text()
cctext = self._ccbox.child.get_text()
|
|
@@ -11,25 +11,105 @@ import shelve
import time
-class Settings(dict):
- def __init__(self, key):
- self.key = key
- self.path = os.path.join(os.path.expanduser('~'), '.hgext', 'tortoisehg')
- if not os.path.exists(os.path.dirname(self.path)):
- os.makedirs(os.path.dirname(self.path))
+class SimpleMRUList(object):
+ def __init__(self, size=10, reflist=[]):
+ self._size = size
+ self._list = reflist
+
+ def __iter__(self):
+ for elem in self._list:
+ yield elem
+
+ def add(self, val):
+ if val in self._list:
+ self._list.remove(val)
+ self._list.append(val)
+ self.flush()
+
+ def get_size(self):
+ return self._size
+
+ def set_size(self, size):
+ self._size = size
+ self.flush()
+
+ def flush(self):
+ while len(self._list) > self._size:
+ del self._list[0]
+
+class Settings(object):
+ version = 1.0
+
+ def __init__(self, appname, path=None):
+ self._appname = appname
+ self._data = {}
+ self._path = path and path or self._get_path(appname)
+ self._audit()
self.read()
-
+
+ def get_value(self, key, default=None, create=False):
+ if key in self._data:
+ return self._data[key]
+ elif create == True:
+ self._data[key] = default
+ return default
+
+ def set_value(self, key, value):
+ self._data[key] = value
+
+ def mrul(self, key, size=10):
+ ''' wrapper method to create a most-recently-used (MRU) list '''
+ ls = self.get_value(key, [], True)
+ ml = SimpleMRUList(size=size, reflist=ls)
+ return ml
+
+ def get_keys(self):
+ return self._data.keys()
+
+ def get_appname(self):
+ return self._appname
+
def read(self):
- self.clear()
- dbase = shelve.open(self.path)
- self.update(dbase.get(self.key, {}))
+ self._data.clear()
+ if not os.path.exists(self._path):
+ return
+
+ dbase = shelve.open(self._path)
+ self._dbappname = dbase['APPNAME']
+ self.version = dbase['VERSION']
+ self._data.update(dbase.get('DATA', {}))
dbase.close()
def write(self):
- dbase = shelve.open(self.path)
- dbase[self.key] = dict(self)
+ self._write(self._path, self._data)
+
+ def _write(self, appname, data):
+ dbase = shelve.open(self._get_path(appname))
+ dbase['VERSION'] = Settings.version
+ dbase['APPNAME'] = appname
+ dbase['DATA'] = data
dbase.close()
+ def _get_path(self, appname):
+ return os.path.join(os.path.expanduser('~'), '.tortoisehg',
+ 'settings', appname)
+
+ def _audit(self):
+ if os.path.exists(os.path.dirname(self._path)):
+ return
+ os.makedirs(os.path.dirname(self._path))
+ self._import()
+
+ def _import(self):
+ # import old settings data (TortoiseHg <= 0.3)
+ old_path = os.path.join(os.path.expanduser('~'), '.hgext', 'tortoisehg')
+ if os.path.isfile(old_path):
+ print "converting old history..."
+ olddb = shelve.open(old_path)
+ for key in olddb.keys():
+ self._write(key, olddb[key])
+ olddb.close()
+
def get_system_times():
t = os.times()
if t[4] == 0.0: # Windows leaves this as zero, so use time.clock()
|
@@ -37,7 +37,8 @@
# persistent app data
self._settings = shlib.Settings('synch')
-
+ self._recent_src = self._settings.mrul('src_paths')
+
self.set_default_size(610, 400)
self.paths = self._get_paths()
@@ -129,7 +130,7 @@ self._pathbox.set_active(defpushrow)
sympaths = [x[1] for x in self.paths]
- for p in self._settings.get('src_paths', []):
+ for p in self._recent_src:
if p not in sympaths:
self.pathlist.append([p])
@@ -425,34 +426,21 @@
self._add_src_to_recent(remote_path)
- def _update_setting_list(self, key, path):
- paths = self._settings.get(key, [])
- if path in paths:
- paths.remove(path)
- paths.append(path)
- while len(paths) > HistorySize:
- del paths[0]
- self._settings[key] = paths
-
def _add_src_to_recent(self, src):
if os.path.exists(src):
src = os.path.abspath(src)
- srclist = [x[0] for x in self.pathlist]
-
+ # save path to recent list in history
+ self._recent_src.add(src)
+ self._settings.write()
+
# update drop-down list
- if src not in srclist:
- srclist.append(src)
- srclist.sort()
self.pathlist.clear()
- for p in srclist:
+ sympaths = [x[1] for x in ui.ui().configitems('paths')]
+ paths = list(set(sympaths + [x for x in self._recent_src]))
+ paths.sort()
+ for p in paths:
self.pathlist.append([p])
-
- # save path to recent list in history
- sympaths = [x[1] for x in self.paths]
- if src not in sympaths:
- self._update_setting_list('src_paths', src)
- self._settings.write()
def write(self, msg, append=True):
msg = unicode(msg, 'iso-8859-1')
|
@@ -453,9 +453,9 @@ vlist.append([v, False])
if v == curvalue:
currow = len(vlist) - 1
- if cpath in self.history:
+ if cpath in self.history.get_keys():
separator = False
- for v in self.history[cpath]:
+ for v in self.history.get_value(cpath):
if v in values: continue
if not separator:
vlist.append(['History', True])
@@ -527,11 +527,11 @@ self.ini[section][key] = newvalue
if not keephistory:
return
- if cpath not in self.history:
- self.history[cpath] = []
- elif newvalue in self.history[cpath]:
- self.history[cpath].remove(newvalue)
- self.history[cpath].insert(0, newvalue)
+ if cpath not in self.history.get_keys():
+ self.history.set_value(cpath, [])
+ elif newvalue in self.history.get_keys():
+ self.history.get_value(cpath).remove(newvalue)
+ self.history.get_value(cpath).insert(0, newvalue)
def _apply_clicked(self, *args):
# Reload history, since it may have been modified externally
|
Loading...