-
Notifications
You must be signed in to change notification settings - Fork 15
/
orguniqueview.py
94 lines (83 loc) · 2.8 KB
/
orguniqueview.py
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
import sublime, sublime_plugin
import logging
log = logging.getLogger(__name__)
ViewMappings = {}
def CreateUniqueViewNamed(name, syntax):
# Close the view if it exists
win = sublime.active_window()
for view in win.views():
if view.name() == name:
win.focus_view(view)
win.run_command('close')
win.run_command('new_file')
view = win.active_view()
view.set_name(name)
view.set_syntax_file("Packages/OrgExtended/{}.sublime-syntax".format(syntax))
return view
def CreateOrFindUniqueViewNamed(name, syntax):
# Return the view if it exists
win = sublime.active_window()
for view in win.views():
if view.name() == name:
win.focus_view(view)
return view
win.run_command('new_file')
view = win.active_view()
view.set_name(name)
view.set_syntax_file("Packages/OrgExtended/{}.sublime-syntax".format(syntax))
return view
def IsViewActuallyActive(name):
win = sublime.active_window()
for view in win.views():
if view.name() == name:
return True
return False
def MoveViewToOtherGroup(view,myview):
window = sublime.active_window()
if (window.num_groups() < 2):
#self.window.run_command('clone_file')
window.set_layout({
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
})
mygroup = 0
othergroup = 1
else:
window.focus_view(view)
mygroup = 1
othergroup = 0
if (window.get_view_index(myview)[0] == 0):
othergroup = 1
mygroup = 0
window.focus_view(view)
window.run_command('move_to_group', {'group': othergroup})
window.run_command('focus_group', {'group': mygroup})
window.focus_view(myview)
class UniqueView:
def __init__(self, name, syntax, reuse=False,curview=None):
self.name = name
if(reuse):
self._view = CreateOrFindUniqueViewNamed(name,syntax=syntax)
else:
self._view = CreateUniqueViewNamed(name,syntax=syntax)
self._view.set_name(self.name)
if(curview != None):
MoveViewToOtherGroup(self._view,curview)
self._view.set_read_only(True)
self._view.set_scratch(True)
# View mappings is required so we can return the
# UniqueView rather than the view
ViewMappings[name] = self
@property
def view(self):
return self._view
@staticmethod
def Get(name,syntax="OrgExtended",reuse=True,curview=None):
if(name in ViewMappings and IsViewActuallyActive(name)):
return ViewMappings[name]
else:
return UniqueView(name,syntax,reuse,curview)
@staticmethod
def IsShowing(name):
return IsViewActuallyActive(name)