forked from bollu/sublimeBookmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
64 lines (45 loc) · 1.79 KB
/
ui.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
import sublime
from copy import deepcopy
class OptionsSelector:
def __init__(self, window, panelItems, onDone, onHighlight):
self.window = window
self.panelItems = deepcopy(panelItems)
self.onDone = onDone
self.onHighlight = onHighlight
def start(self):
startIndex = 0
self.window.show_quick_panel(self.panelItems, self.onDone, 0, startIndex, self.onHighlight)
class OptionsInput:
def __init__(self, window, caption, initalText, onDone, onCancel):
self.window = window
self.caption = caption
self.initalText = initalText
self.onDone = onDone
self.onCancel = onCancel
def start(self):
view = self.window.active_view()
inputPanelView = self.window.show_input_panel(self.caption, self.initalText, self.onDone, None, self.onCancel)
#select the text in the view so that when the user types a new name, the old name
#is overwritten
assert (len(inputPanelView.sel()) > 0)
selectionRegion = inputPanelView.full_line(inputPanelView.sel()[0])
inputPanelView.sel().add(selectionRegion)
def createBookmarkPanelItems(window, visibleBookmarks):
def ellipsisStringEnd(string, length):
#I have NO idea why the hell this would happen. But it's happening.
if string is None:
return ""
else:
return string if len(string) <= length else string[ 0 : length - 3] + '...'
def ellipsisStringBegin(string, length):
if string is None:
return ""
else:
return string if len(string) <= length else '...' + string[ len(string) + 3 - (length) : len(string) ]
bookmarkItems = []
for bookmark in visibleBookmarks:
bookmarkName = bookmark.getName()
bookmarkLine = bookmark.getLineStr().lstrip()
bookmarkFile = ellipsisStringBegin(bookmark.getFilePath().lstrip(), 55)
bookmarkItems.append( [bookmarkName, bookmarkLine, bookmarkFile] )
return bookmarkItems