forked from SublimeText/MoveTab
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.py
More file actions
Latest commit
100 lines (78 loc) · 3.02 KB
/
Copy pathplugin.py
File metadata and controls
100 lines (78 loc) · 3.02 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
fromos.pathimportbasename
importsublime_plugin
__all__= ["MoveToNeighboringIndexCommand", "MoveToIndexCommand"]
defactive_view_group_index(window):
view=window.active_view()
group, index=window.get_view_index(view)
returnview, group, index
classMoveToNeighboringIndexCommand(sublime_plugin.WindowCommand):
defis_enabled(self, forward=True):
returnlen(self.window.views_in_group(self.window.active_group())) >1
defrun(self, forward=True, cycle=False):
view, view_group, view_index=active_view_group_index(self.window)
ifnotview:
return
num_views=len(self.window.views_in_group(view_group))
ifnum_views<2:
return
ifcycle:
ifforward:
index= (view_index+1) %num_views
else:
index= (view_index-1) %num_views
else:
ifforward:
index=min(view_index+1, num_views)
else:
index=max(view_index-1, 0)
ifindex!=view_index:
self.window.set_view_index(view, view_group, index)
self.window.focus_view(view)
classMoveToIndexCommand(sublime_plugin.WindowCommand):
defis_enabled(self, index=None):
ifindexisNone:
returnTrue
_, view_group, view_index=active_view_group_index(self.window)
ifview_indexin (-1, index):
returnFalse
num_views=len(self.window.views_in_group(view_group))
returnnum_views>1andindex<num_views
definput(self, args):
ifargs.get("index") isNone:
returnIndexInputHandler(self.window)
returnNone
definput_description(self):
return"Move View:"
defrun(self, index):
view, view_group, view_index=active_view_group_index(self.window)
ifnotview:
return
num_views=len(self.window.views_in_group(view_group))
ifnum_views>1:
ifindex<0:
index=num_views+index
index=max(0, min(index, num_views-1))
ifindex!=view_index:
self.window.set_view_index(view, view_group, index)
self.window.focus_view(view)
classIndexInputHandler(sublime_plugin.ListInputHandler):
def__init__(self, window):
super().__init__()
self.window=window
deflist_items(self):
_, view_group, view_index=active_view_group_index(self.window)
views=self.window.views_in_group(view_group)
views.pop(view_index)
ifview_index>0:
items= [("First Position\tto position 1", 0)]
else:
items= []
fori, vinenumerate(views, start=1):
ifi==view_index:
continue
try:
title=basename(v.file_name())
exceptTypeError:
title=v.name() or"untitled"
items.append(("{}\tto position {}".format(title, i+1), i))
returnitems