I start to work on plugin that must help me with "TODO" in my projects. This is my first plugin and work with python and github. [url="https://github.com/SDemonUA/sublime-text2"]Source[/url].
I faced with leak of documentation
def isView(view_id):
# check that they are in a View, rather than some panel, etc.
if not view_id: return False
window = sublime.active_window()
view = window.active_view() if window != None else None
return (view is not None and view.id() == view_id)
def showRegion(view, reg):
view.sel().clear()
view.sel().add(reg)
view.show(reg)
class QuickEditsCommand(sublime_plugin.TextCommand):
# Shows a quick panel to jump to edit lines.
def run(self, edit):
self.vid = self.view.id()
if not isView(self.vid):
sublime.status_message('Click into the view/tab first.')
return
edited = adjustEdits(self.view)
if not edited:
sublime.status_message('No edits to list.')
return
the_edits = getEditList(self.view, edited)
if the_edits:
sublime.active_window().show_quick_panel(the_edits, self.on_chosen)
def on_chosen(self, index):
if index == -1: return
if not isView(self.vid):
sublime.status_message('You are in a different view.')
return
edited = self.view.get_regions("edited_rgns") or []
for reg in [r for i, r in enumerate(edited) if i == index]:
showRegion(self.view, reg)
breakdef getEditList(view, edited):
the_edits = []
curr_edit = view.get_regions("edited_rgn") or []
curr_edit = curr_edit[0] if curr_edit else None
for i, r in enumerate(edited):
curr_line, _ = view.rowcol(r.begin())
curr_text = view.substr(r).strip()[:50]
if not len(curr_text):
curr_text = view.substr(view.line(r)).strip()[:50] + " (line)"
if curr_edit and r.intersects(curr_edit):
display_line = "*%03d %s" % (curr_line + 1, curr_text)
else:
display_line = " %03d %s" % (curr_line + 1, curr_text)
the_edits.append(display_line)
return the_editsSDemonUA wrote:Thanks. But this part I already have. I interested in some onfocus event for show_quick_panel, not only onselect.
I'd like to do it like goto_anithing : when you focus list item it scrolls the view to that item.
def isPanel(view):
(group, index) = view.window().get_view_index(view)
if group is -1 and index is -1:
return True
return Falseimport sublime
import sublime_plugin
import sublime_lib
quick_panel_active = False
quick_panel_id = 0
def quick_panel(w, items, callback, flags=0):
global quick_panel_active
timeout = 2000
def find_quick_panel_id(w, current_id, time=0):
global quick_panel_active, quick_panel_id
vid = w.active_view().id()
print("checking panel", vid)
if vid != current_id:
quick_panel_active = True
print("panel found")
quick_panel_id = vid
if time >= timeout:
print("timeout")
return
# recall recursively
wait = 10
sublime.set_timeout(lambda: find_quick_panel_id(w, current_id, time + wait), wait)
quick_panel_active = False # what if there's still a quick paneL active?
current_id = w.active_view().id()
print("cid", current_id)
sublime.set_timeout(lambda: find_quick_panel_id(w, current_id), 0)
w.show_quick_panel(items, callback, flags)
class TestCommandCommand(sublime_plugin.WindowCommand):
string = "abcdefghijklmnopqrstuvwxyz"
choose = [c * 3 for c in string]
def is_checked(self):
return True
def run(self):
quick_panel(self.window, self.choose, self.on_done)
def on_done(self, result):
print("result", result, self.choose[result] if result != -1 else None)
class ActiveViewCommand(sublime_lib.WindowAndTextCommand):
def run(self, param=None):
print("window command", self._window_command, "param", param)
print(" view", self.view, self.view.id())
print(" aview", self.window.active_view(), self.window.active_view().id())
print("aaview", sublime.active_window().active_view(), sublime.active_window().active_view().id())
import sublime_plugin
import sublime_lib
vlib = sublime_lib.view
last_view_id = 0
quick_panel_waiting = False
quick_panel_active = False
quick_panel_id = 0
class TestCommandCommand(sublime_lib.WindowAndTextCommand):
string = "abcdefghijklmnopqrstuvwxyz"
choose = [c * 3 for c in string]
def is_checked(self):
return True
def run(self, param=None):
global last_view_id, quick_panel_waiting
last_view_id = self.view.id()
quick_panel_waiting = True
self.window.show_quick_panel(self.choose, self.on_done)
def on_done(self, result):
print("result", result, self.choose[result] if result != -1 else None)
class QuickPanelListener(sublime_plugin.EventListener):
def on_modified(self, view):
global quick_panel_active, quick_panel_waiting, quick_panel_id
if quick_panel_waiting and view.id() != last_view_id:
quick_panel_active = True
quick_panel_waiting = False
quick_panel_id = view.id()
if quick_panel_active and view.id() != quick_panel_id:
quick_panel_active = False
if quick_panel_active:
print("text in panel", vlib.get_text(view))
[
{ "keys": ["down"], "command": "dummy",
"context": [
{"key": "panel", "operand": "console"},
{"key": "panel_has_focus"}
]
},
{ "keys": ["up"], "command": "dummy",
"context": [
{ "key": "overlay_visible", "operator": "equal", "operand": true }
]
}
]
{ "keys": ["escape"], "command": "hide_panel", "args": {"cancel": true},
"context":
[
{ "key": "panel_visible", "operator": "equal", "operand": true }
]
},
{ "keys": ["escape"], "command": "hide_overlay", "context":
[
{ "key": "overlay_visible", "operator": "equal", "operand": true }
]
}API: show_quick_panel() accepts an on_highlighted callback
Users browsing this forum: No registered users and 5 guests