File: yjumpsel.py

package info (click to toggle)
far2l 2.7.0~beta%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,304 kB
  • sloc: cpp: 263,566; ansic: 53,886; python: 7,048; sh: 1,516; perl: 410; javascript: 279; xml: 145; makefile: 31
file content (38 lines) | stat: -rw-r--r-- 1,271 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

"""
First of all this plugin is an example of how easy writing plugins
for FAR should be when having proper pythonic library.

yfar is a work-in-progress attempt to write such library.

This plugin allows to jump between selected files on the panel.
This was very helpful if you have thousands or even tens of thousands 
files in the directory, select some of them by mask and want to figure 
out which files were actually selected. For convenience bind
them to hotkeys likes Alt+Up / Alt+Down.
"""

__author__ = 'Yaroslav Yanovsky'

from yfar import FarPlugin


class Plugin(FarPlugin):
    label = 'Jump Between Selected Files'
    openFrom = ['PLUGINSMENU', 'FILEPANEL']

    def OpenPlugin(self, _):
        panel = self.get_panel()
        option = self.menu(('Jump to &Previous Selected File',
                            'Jump to &Next Selected File'), self.label)
        if option == 0:  # move up
            for f in reversed(panel.selected):
                if f.index < panel.cursor:
                    panel.cursor = f.index
                    break
        elif option == 1:  # move down
            for f in panel.selected:
                if f.index > panel.cursor:
                    panel.cursor = f.index
                    break