Home Download Buy Blog Forum Support

Can I make double click do normal behaviour + my own

Can I make double click do normal behaviour + my own

Postby deanflick on Tue Aug 21, 2012 9:07 am

Hi,
Default behavior on double clicking is highlighting the word and it's other instances in the file (and I use it a lot) and would not want to be without it.
BUT, now I'm creating a plugin where I want the double click behave differently, but only in one special buffer.

So I have a plugin like:
Code: Select all
class MySpecialDoubleclickCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    if self.view.name() == "mySpecialBuffer":
      self.doMyStuff()

which runs fine....

But when I assign it to the double click it just calls my code. Is there a way to make it call my plugin and also the default behavior one?

This is how I assign the double click in the Default (Windows).sublime-mousemap :
Code: Select all
{
  "button": "button1", "count": 2,
  "command": "my_special_doubleclick"
}


I know I can assign modifiers like ctrl+alt, but I rather just have the double click...

thanks in advance
Dean
deanflick
 
Posts: 2
Joined: Tue Aug 21, 2012 8:47 am

Re: Can I make double click do normal behaviour + my own

Postby xeno.by on Tue Aug 21, 2012 9:36 am

Theoretically (I haven't checked that yet for double click) by making use of run_ you can get hold of the mouse click event and then pass it to the default handler (drag_select - see the default mousemap for the details).

Here's an example: [1] custom command that overrides run_, [2] mousemap for subclasses of that command, which specifies the system command that gets overriden and its arguments, so that the custom command can call it.

By the way, please, let me know how it goes. I'm also going to override double-click to navigate the stack trace during debugging. Would be great if this sketch works.

[1] https://github.com/sublimescala/sublime ... me.py#L190
[2] https://github.com/sublimescala/sublime ... e-mousemap
xeno.by
 
Posts: 106
Joined: Mon Jan 30, 2012 10:03 am
Location: Lausanne, Switzerland

Re: Can I make double click do normal behaviour + my own

Postby deanflick on Tue Aug 21, 2012 9:54 am

Thanks, this worked like a charm! :)

The mouse overwrite ended as:
Code: Select all
{
  "button": "button1", "count": 2,
  "press_command": "my_special_doubleclick",
  "press_args": {"command": "drag_select", "args": {"by": "words"}}
}


And my plugin is:
Code: Select all
class MySpecialDoubleclickCommand(sublime_plugin.TextCommand):
  def run_(self, args):
    if self.view.name() == "mySpecialBuffer":
      self.doMyStuff()
    else:
      system_command = args["command"] if "command" in args else None
      if system_command:
        system_args = dict({"event": args["event"]}.items() + args["args"].items())
        self.view.run_command(system_command, system_args)


thanks again for your quick reply
Dean
deanflick
 
Posts: 2
Joined: Tue Aug 21, 2012 8:47 am

Re: Can I make double click do normal behaviour + my own

Postby Scam on Mon Nov 18, 2013 1:45 pm

Aforementioned code apparently works only in ST2. I would like to get this functionality working in ST3 as well. Python 3.x treats dictionaries differently than 2.x so I changed the addition to union to achieve the same dictionary as a result.

However, my attempts to call the run_command(system_command, system_args) have been unsuccessful. I keep getting the following error:

Code: Select all
  File "C:\Program Files\Sublime Text 3\sublime.py", line 607, in run_command
    sublime_api.view_run_command(self.view_id, cmd, args)
TypeError: Value required


Any help would be appreciated.
Scam
 
Posts: 12
Joined: Fri Oct 25, 2013 1:15 pm

Re: Can I make double click do normal behaviour + my own

Postby Saucebergenstein on Tue Aug 19, 2014 8:30 pm

Scam, I did a little digging on bringing that broken dictionary syntax into Python 3, and here's what I got:

http://stackoverflow.com/questions/1336 ... dict-items

Turns out we need to replace the + operator with <dictionary name>.update(<other dictionary name>)

To put it in context, here's what it looks like, using the example from earlier in this thread:

Code: Select all
class MySpecialDoubleclickCommand(sublime_plugin.TextCommand):
    def run_(self, view, args):
        if self.view.name() == "mySpecialBuffer":
            self.doMyStuff()
        else:
            system_command = args["command"] if "command" in args else None
            if system_command:
                system_args = dict({"event": args["event"]}.items())
                system_args.update(dict(args["args"].items()))
                self.view.run_command(system_command, system_args)


Thanks to everyone in this thread for the springboard - I hope the fix I found works for you too.
Saucebergenstein
 
Posts: 4
Joined: Mon Aug 18, 2014 8:31 pm


Return to Plugin Development

Who is online

Users browsing this forum: Majestic-12 [Bot] and 4 guests