Skip to content

Commit

Permalink
Rename *_click callbacks to *_mouse_down
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolaus Wittenstein committed Jun 27, 2012
1 parent ad8fce3 commit 436202d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ MouseEventListener adds two new callbacks to Sublime Text 2's plugin API:
* `on_pre_click({'event': {'x': screen_x, 'y': screen_y, 'button': button}})`
* `on_post_click(text_point)`

An important thing to note is that the selection is modified not once but twice in between on_pre_click and on_post_click—this is done to determine the text_point of the click, as Sublime Text 2 has no API to translate a screen x and y into a text_point other than by calling "drag_select" and seeing where the selection ends up.
An important thing to note is that the selection is modified not once but twice in between `on_pre_mouse_down` and `on_post_mouse_down`—this is done to determine the `text_point` of the click, as Sublime Text 2 has no API to translate a screen x and y into a `text_point` other than by calling `drag_select` and seeing where the selection ends up.

A second important thing to note is that mouse-up currently cannot be captured using Sublime Text 2's API. Hopefully this will be added in the future. However, this means that drags cannot be detected! other than perhaps by carefully monitoring the selection as it changes and just guessing. Additionally, `on_selection_modified` fires on mouse up in most cases.

Install
-------
Expand Down
16 changes: 8 additions & 8 deletions mouse_event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class DragSelectCallbackCommand(sublime_plugin.TextCommand):
def run_(self, args):
for c in sublime_plugin.all_callbacks.setdefault('on_pre_click',[]):
c.on_pre_click(args)
for c in sublime_plugin.all_callbacks.setdefault('on_pre_mouse_down',[]):
c.on_pre_mouse_down(args)

#We have to make a copy of the selection, otherwise we'll just have
#a *reference* to the selection which is useless if we're trying to
Expand All @@ -25,22 +25,22 @@ def run_(self, args):
#This is the "real" drag_select that alters the selection for real.
self.view.run_command("drag_select", args)

for c in sublime_plugin.all_callbacks.setdefault('on_post_click',[]):
c.on_post_click(click_point)
for c in sublime_plugin.all_callbacks.setdefault('on_post_mouse_down',[]):
c.on_post_mouse_down(click_point)

class MouseEventListener(sublime_plugin.EventListener):
#If we add the callback names to the list of all callbacks, Sublime
#Text will automatically search for them in future imported classes.
#You don't actually *need* to inherit from MouseEventListener, but
#doing so forces you to import this file and therefore forces Sublime
#to add these to its callback list.
sublime_plugin.all_callbacks.setdefault('on_pre_click', [])
sublime_plugin.all_callbacks.setdefault('on_post_click', [])
sublime_plugin.all_callbacks.setdefault('on_pre_mouse_down', [])
sublime_plugin.all_callbacks.setdefault('on_post_mouse_down', [])


class MouseEventProcessor(MouseEventListener):
def on_pre_click(self, args):
def on_pre_mouse_down(self, args):
print "on pre-click!", args
def on_post_click(self, point):
def on_post_mouse_down(self, point):
print "on post-click!", point

0 comments on commit 436202d

Please sign in to comment.