Permalink
Browse files

recent file list

  • Loading branch information...
1 parent 3f94a82 commit 67df76594a6cb48e20632bd40c5150039bc00986 @baverman committed Jan 31, 2011
Showing with 33 additions and 2 deletions.
  1. +18 −1 typetrainer/config.py
  2. +1 −0 typetrainer/run.py
  3. +14 −1 typetrainer/ui/main.py
View
@@ -11,4 +11,21 @@ class Config(PySettings):
TUTOR_DOC = 'Tutor generator. One of (en.basic, en.advanced, ru.basic)'
FILE = None
- FILE_DOC = 'Last opened file with words'
+ FILE_DOC = 'Last opened file with words'
+
+ RECENT_FILES = None
+ RECENT_FILES_DOC = 'Last opened file list'
+
+ def add_recent_file(self, filename, limit=5):
+ if 'RECENT_FILES' not in self:
+ rf = self['RECENT_FILES'] = []
+ else:
+ rf = self['RECENT_FILES']
+
+ try:
+ rf.remove(filename)
+ except ValueError:
+ pass
+
+ rf.insert(0, filename)
+ rf[:] = rf[:limit]
View
@@ -30,6 +30,7 @@ def run():
from typetrainer.tutors import get_filler
try:
filler = get_filler(config['TUTOR'], config['FILE'])
+ config.add_recent_file(config['FILE'])
except ImportError:
parser.error(_("Can't find [%s] tutor") % config['TUTOR'])
except IOError:
View
@@ -1,4 +1,3 @@
-import os.path
import time
from collections import defaultdict
@@ -226,6 +225,16 @@ def on_window_button_press_event(self, window, event):
menu.append(gtk.SeparatorMenuItem())
+ if 'RECENT_FILES' in self.config and self.config['RECENT_FILES']:
+ item = None
+ for fname in self.config['RECENT_FILES']:
+ item = gtk.MenuItem(fname)
+ item.connect('activate', self.on_filename_activate, fname)
+ menu.append(item)
+
+ menu.append(gtk.SeparatorMenuItem())
+
+
item = gtk.ImageMenuItem(gtk.STOCK_OPEN)
item.connect('activate', self.on_open_file_activate)
menu.append(item)
@@ -259,6 +268,7 @@ def update_filler(self, tutor, filename):
self.filler = get_filler(tutor, filename)
self.fill()
+ self.config.add_recent_file(filename)
self.update_title()
self.config['TUTOR'] = tutor
@@ -268,6 +278,9 @@ def on_tutor_activate(self, item, tutor):
if item.get_active():
idle(self.update_filler, tutor, self.filler.filename)
+ def on_filename_activate(self, item, filename):
+ idle(self.update_filler, self.filler.name, filename)
+
def on_keyboard_activate(self, item, kbd):
if item.get_active():
for k, label, name in available_keyboards:

0 comments on commit 67df765

Please sign in to comment.