Commits

Iñigo Serna committed c3db985

EntryLine: added insert bookmark at pos (Ctrl-D, Ctrl-\) and insert previous path at pos (Ctrl-Y). Changed insert path at pos (Ctrl-S). Clean code.

* lfm/messages.py (EntryLine.manage_keys): added insert bookmark at pos,
key shortcuts Ctrl-D, Ctrl-\
* lfm/messages.py (EntryLine.manage_keys): added insert previous path at pos,
key shortcut Ctrl-Y
* lfm/messages.py (EntryLine.manage_keys): change insert path at pos, now Ctrl-S
* lfm/messages.py (EntryLine.manage_keys): clean code
* README: update documentation

  • Participants
  • Parent commits 3965326

Comments (0)

Files changed (4)

+Sun May 15 18:41:46 2011  Iñigo Serna  <inigoserna@gmail.com>
+
+	* lfm/messages.py (EntryLine.manage_keys): added insert bookmark at pos,
+	key shortcuts Ctrl-D, Ctrl-\
+	* lfm/messages.py (EntryLine.manage_keys): added insert previous path at pos,
+	key shortcut Ctrl-Y
+	* lfm/messages.py (EntryLine.manage_keys): change insert path at pos, now Ctrl-S
+	* lfm/messages.py (EntryLine.manage_keys): clean code
+	* README: update documentation
+
 Sat May 14 19:08:53 2011  Iñigo Serna  <inigoserna@gmail.com>
 
 	* lfm/actions.py (keytable): change PowerCLI key shortcut, now Ctrl-X
     - insertion
         - Ctrl-Z: restore original content (undo)
         - Ctrl-V: insert filename at position
-        - Ctrl-D: insert path 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
 
 + ***SelectItem* window**
     - up, k, K
 ============================================================================
-Last update:	Time-stamp: <2011-05-14 18:50:06 inigo>
+Last update:	Time-stamp: <2011-05-15 18:44:17 inigo>
 ============================================================================
 
 
 - F11: PowerCLI
   . Stored commands
   . History
-- messages.EntryLine
-  . ? accept $b[0-9]: bookmarks
-  . Ctrl-D?: open bookmarks selection list
-  . Ctrl-Y: open history selection list
 - history
   . s/historic/history/g
   . per edit type

File lfm/messages.py

                 pos +=1
             return pos if pos < l  else l
 
+        def __select_item(entries, pos0, cli=False):
+            if not entries:
+                curses.beep()
+                return
+            elif len(entries) == 1:
+                return entries.pop()
+            else:
+                y, x0 = self.entry.getbegyx()
+                x = x0 + pos0
+                if x > 2*app.maxw/3 - 4:
+                    x = x0 + 2
+                if cli:
+                    y = app.maxh / 2
+                selected = SelectItem(entries, y+1, x-2).run()
+                if cli:
+                    app.lpane.display()
+                    app.rpane.display()
+                else:
+                    app.display()
+                cursor_show2()
+                return selected
+
+        def __insert_item(title, entries):
+            ret = MenuWin(title, entries).run()
+            if ret != -1:
+                if self.cli:
+                    ret = '"' + ret + '"'
+                self.text = self.text[:self.pos] + ret + self.text[self.pos:]
+                self.pos += len(ret)
+            cursor_show2()
+            if self.cli:
+                app.lpane.display()
+                app.rpane.display()
+                return False
+            else:
+                app.display()
+                return True
+
         while True:
             self.show()
             ch = self.entry.getch()
             elif ch == 0x14 and not self.cli:             # Ctrl-T, no CLI
                 if self.with_complete:
                     base, entries = files.complete(self.text, self.panelpath)
-                    if not entries:
-                        curses.beep()
-                        continue
-                    elif len(entries) == 1:
-                        selected = entries.pop()
-                    else:
-                        y, x0 = self.entry.getbegyx()
-                        x = x0 + len(self.text)
-                        if x > 2*app.maxw/3 - 4:
-                            x = x0 + 2
-                        selected = SelectItem(entries, y+1, x-2).run()
-                        app.display()
-                        cursor_show2()
-                    if selected != -1:
+                    selected = __select_item(entries, len(self.text), False)
+                    if selected is not None and selected != -1:
                         self.text = os.path.join(base, selected)
                         self.pos = len(self.text)
                     return 0x14
                     continue
             elif ch in (ord('\t'), 0x14) and self.cli:    # tab or Ctrl-T, in CLI
                 if self.text.rfind(' "', 0, self.pos) != -1:
-                    if self.text[self.pos-1] == '"':
-                        pos1 = self.pos -1
-                    else:
-                        pos1 = self.pos
+                    pos1 = self.pos-1 if self.text[self.pos-1]=='"' else self.pos
                     pos0 = self.text.rfind(' "', 0, pos1) + 2
                 else:
                     pos0 = self.text.rfind(' ', 0, self.pos) + 1
                 if pos0 == 0 or not entries:
                     base = None
                     entries = files.complete_programs(text)
-                if not entries:
-                    curses.beep()
-                    continue
-                elif len(entries) == 1:
-                    selected = entries.pop()
-                else:
-                    y, x0 = self.entry.getbegyx()
-                    y, x, = app.maxh/2, x0+pos0
-                    if x > 2*app.maxw/3 - 4:
-                        x = x0 + 2
-                    selected = SelectItem(entries, y+1, x-2).run()
-                    app.lpane.display()
-                    app.rpane.display()
-                    cursor_show2()
-                if selected != -1:
+                selected = __select_item(entries, pos0, True)
+                if selected is not None and selected != -1:
                     if base is None: # system program
                         selected += ' '
-                        self.text = self.text[:pos0] + selected + self.text[pos1:]
-                        self.pos = len(self.text[:pos0]+selected)
                     else:            # file
-                        self.text = self.text[:pos0] + os.path.join(base, selected) + self.text[pos1:]
-                        self.pos = len(self.text[:pos0]+ os.path.join(base, selected))
+                        selected = os.path.join(base, selected)
+                    self.text = self.text[:pos0] + selected + self.text[pos1:]
+                    self.pos = len(self.text[:pos0]+selected)
             elif ch in (10, 13):         # enter
                 return 10
             # movement
                 buf = app.act_pane.act_tab.get_file()
                 self.text = self.text[:self.pos] + buf + self.text[self.pos:]
                 self.pos += len(buf)
-            elif ch == 0x04:                     # Ctrl-D
+            elif ch == 0x13:                     # Ctrl-S
                 buf = app.act_pane.act_tab.path + os.sep
                 self.text = self.text[:self.pos] + buf + self.text[self.pos:]
                 self.pos += len(buf)
             elif ch == 0x0F:                     # Ctrl-O
                 buf = app.noact_pane.act_tab.path + os.sep
                 if self.cli:
-                    self.text = self.text[:self.pos] + '"%s"' % buf + self.text[self.pos:]
-                    self.pos += len(buf)+2
-                else:
-                    self.text = self.text[:self.pos] + buf + self.text[self.pos:]
-                    self.pos += len(buf)
+                    buf = '"' + buf + '"'
+                self.text = self.text[:self.pos] + buf + self.text[self.pos:]
+                self.pos += len(buf)
+            elif ch in (0x04, 0x1C):            # Ctrl-D, Ctrl-\
+                if __insert_item('Insert Bookmark', app.prefs.bookmarks):
+                    return 0x1C # hack, to update screen
+            elif ch == 0x19:                    # Ctrl-Y
+                items = app.act_pane.act_tab.historic[::-1]
+                items.extend(app.noact_pane.act_tab.historic[::-1])
+                if items:
+                    if __insert_item('Insert previous path', items):
+                        return 0x19 # hack, to update screen
             # chars and edit keys
             elif ch == curses.KEY_IC:            # insert
                 self.ins = not self.ins
                     self.active_widget = self.entry
                     self.btns.active = 0
                     cursor_show2()
-            elif ans == 0x14:            # Ctrl-T
+            elif ans in (0x14, 0x19, 0x1C):    # Ctrl-T, Ctrl-Y, Ctrl-\
                 # this is a hack, we need to return to refresh Entry
                 return [self.entry.text]
             elif ans == 10:              # return values
                     self.btns.active = 2
                     cursor_hide()
                     answer = False
-            elif ans == 0x14:            # Ctrl-T
+            elif ans in (0x14, 0x19, 0x1C):    # Ctrl-T, Ctrl-Y, Ctrl-\
                 # this is a hack, we need to return to refresh Entry
                 return [self.entry1.text, self.entry2.text, self.active_entry_i]
             elif ans == 10:    # return values