Commits

Iñigo Serna  committed 56d098f

Implemented: EntryLine: Ctrl-G not PowerCLI: select historic. Refactor "add text to history".

* lfm/messages.py (EntryLine.manage_keys): Ctrl-G not PowerCLI: select historic
* REDME (Key bindings): update documentation

* lfm/messages.py (Entry.run): refactor "add text to history" code
* lfm/messages.py (DoubleEntry.run):
* lfm/messages.py (add_to_history): new function

  • Participants
  • Parent commits 32443ab

Comments (0)

Files changed (3)

+Fri May 20 23:08:20 2011  Iñigo Serna  <inigoserna@gmail.com>
+
+	* lfm/messages.py (EntryLine.manage_keys): Ctrl-G not PowerCLI: select historic
+	* README (Key bindings): update documentation
+
+Fri May 20 22:52:24 2011  Iñigo Serna  <inigoserna@gmail.com>
+
+	* lfm/messages.py (Entry.run): refactor "add text to history" code
+	* lfm/messages.py (DoubleEntry.run):
+	* lfm/messages.py (add_to_history): new function
+
 Fri May 20 22:32:42 2011  Iñigo Serna  <inigoserna@gmail.com>
 
 	* lfm/lfm.py (Vfs.get_fileinfo_str_long): fixed bug: crash when filenane
 
           There is NO WARRANTY.
 
-:Last update: Fri May 20 21:04:13 2011
+:Last update: Fri May 20 23:06:48 2011
 
 .. contents:: Table of Contents
 
         - Ctrl-V: insert filename at position
         - Ctrl-S: insert path at position
         - Ctrl-O: insert other pane path at position
-        - Ctrl-D, Ctrl-\: insert bookmark at position
-        - Ctrl-Y: insert previous path at position
-        - Ctrl-G: insert PowerCLI stored (from config) or history command (only PowerCLI)
+        - Ctrl-D, Ctrl-\: select bookmark at position
+        - Ctrl-Y: select previous path at position
+        - Ctrl-G: select historic (not PowerCLI)
+        - Ctrl-G: select PowerCLI stored (from config) or history command (PowerCLI)
 
 + ***SelectItem* window**
     - up, k, K

File lfm/messages.py

 ######################################################################
 ##### module variables
 app = None
+
+
+######################################################################
+##### history stuff
 HISTORY_FILE = os.path.abspath(os.path.expanduser('~/.lfm_history'))
 DEFAULT_HISTORY = {'path': [], 'file': [], 'glob': [], 'grep': [], 'exec': [], 'cli': []}
 MAX_HISTORY = 100
 history = DEFAULT_HISTORY.copy()
 
+def add_to_history(hist, text):
+    if text and text != '*':
+        if text in hist:
+            hist.remove(text)
+        if len(hist) >= MAX_HISTORY:
+            hist.remove(hist[0])
+        hist.append(text)
+
 
 ######################################################################
 class BaseWindow(object):
     except UnicodeError:
         return unichr(first_byte)
 
-# EntryLine
+
+######################################################################
 class EntryLine(object):
     """An entry line to enter a dir. or file, a pattern, etc"""
 
                         else:
                             self.text, self.pos = selected, len(selected)
                     return 0x19 # hack, to update screen
-            elif ch == 0x07 and self.cli:        # Ctr-G
+            elif ch == 0x07 and not self.cli:    # Ctr-G, not CLI
+                selected = __select_item(self.history[::-1], 0, 'Historic', False)
+                if selected not in (None, -1, ''):
+                    self.text, self.pos = selected, len(selected)
+                return 0x07 # hack, to update screen
+            elif ch == 0x07 and self.cli:        # Ctr-G, in CLI
                 BOOKMARKS_STR, HISTORY_STR = '----- Stored:  -----', '----- History: -----'
                 entries = [BOOKMARKS_STR]
                 entries.extend([c for c in app.prefs.powercli_favs if c])
         cursor_hide()
         if answer:
             answer = os.path.expanduser(answer)
-            # save new history entries
             if self.with_history in history.keys():
-                if self.entry.text and self.entry.text != '*':
-                    hist = history[self.with_history]
-                    if len(hist) >= MAX_HISTORY:
-                        hist.remove(hist[0])
-                    if hist.count(self.entry.text) >= 1:
-                        hist.remove(self.entry.text)
-                    hist.append(self.entry.text)
+                add_to_history(history[self.with_history], self.entry.text)
         self.pwin.hide()
         return answer
 
 
         cursor_hide()
         if answer:
-            # save new history entries
             if self.with_history1 in history.keys():
-                if self.entry1.text and self.entry1.text != '*':
-                    hist = history[self.with_history1]
-                    if len(hist) >= MAX_HISTORY:
-                        hist.remove(hist[0])
-                    if hist.count(self.entry1.text) >= 1:
-                        hist.remove(self.entry1.text)
-                    hist.append(self.entry1.text)
+                add_to_history(history[self.with_history1], self.entry1.text)
             if self.with_history2 in history.keys():
-                if self.entry2.text and self.entry2.text != '*':
-                    hist = history[self.with_history2]
-                    if len(hist) >= MAX_HISTORY:
-                        hist.remove(hist[0])
-                    if hist.count(self.entry2.text) >= 1:
-                        hist.remove(self.entry2.text)
-                    hist.append(self.entry2.text)
+                add_to_history(history[self.with_history2], self.entry2.text)
             ans1 = os.path.expanduser(self.entry1.text)
             ans2 = os.path.expanduser(self.entry2.text)
         else: