Home Download Buy Blog Forum Support

Make a page with outlined links

Make a page with outlined links

Postby CodeEffect on Sat May 18, 2013 2:50 pm

I want to make a page of search results in the same way that existing find-in-files does - with the clickable outlined matches.

Does anyone know if this (or anything similar) is possible please?
CodeEffect
 
Posts: 20
Joined: Mon May 06, 2013 6:18 am

Re: Make a page with outlined links

Postby adzenith on Sat May 18, 2013 5:18 pm

It's possible, but it's very difficult because of the way the mouse handling works.
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: Make a page with outlined links

Postby skuroda on Sat May 18, 2013 6:26 pm

SublimeTODO does this. As adzenith said, it's difficult because of mouse handling works. Essentially, there are no context as there are with key commands. I suppose one possible way to do this is to set everything up to work and include a sample file, then let the user do it. Perhaps have create a mouse map entry with the following

Code: Select all
[
    {
        "button": "button1", "count": 2,
        "command": "mouse_map",
        "press_command": "drag_select",
        "press_args": {"by": "words"}
    }
]


The user would then have to define a mouse_map command to take a particular action based on say...the view's name. Not really sure the best way to go about this with what's built in. But it could be a start.
skuroda
 
Posts: 689
Joined: Fri Oct 05, 2012 8:11 am

Re: Make a page with outlined links

Postby CodeEffect on Mon May 27, 2013 2:34 pm

Cheers for that, the link will be especially useful. It doesn't look like a lot of fun does it!!

I'm not sure what you mean by let the user do it though, could you elaborate please?

Am about to dive into this bit this afternoon so I'll shout if (more likely *when*) I get stuck :)

An unrelated one: Is it possible to "read" the case sensitivity setting from the find panel? Say I wanted my plugin to search case sensitively if it's set and not case sensitive if it's unset. Can I pull that value from somewhere??
CodeEffect
 
Posts: 20
Joined: Mon May 06, 2013 6:18 am

Re: Make a page with outlined links

Postby skuroda on Mon May 27, 2013 8:38 pm

Sure. So to play around, I defined a new plugin with the following...

Code: Select all
class MouseMapCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        if self.view.settings().get("todo_results"):
            self.view.run_command("mouse_goto_comment")
        if self.view.settings().get("_find_key_conflicts"):
            line = self.view.substr(self.view.line(self.view.sel()[0]))
            match = re.match(r"^\s+(.+?)\s+(.+?)\s+", line)
            if match:
                print(match.group(2))
                resource_str = "Packages/%s/Default.sublime-keymap" % match.group(2)
                package_str = "${packages}/%s/Default.sublime-keymap" % match.group(2)
                try:
                    resource = sublime.load_resource(resource_str)
                    self.view.window.open_file(package_str)
                except:

                    package_str = "${packages}/%s/Default (%s).sublime-keymap" % (match.group(2), "Windows")
                    self.view.window().open_file(package_str)


Note the first condition is checking for a "todo_results" setting. This is set on views created by SublimeTODO. Because SublimeTODO already has a command to jump to the results, I don't have to do anything beyond that call that command. Plugins could, theoretically, do something similar. That is, define a command that will give the behavior desired, but require the end user to "activate it". In this case, modifying their mousemap file and creating a custom command to be associated with it. Hope that makes things a little more clear.

I would think there would be a way, but I don't know of it.
skuroda
 
Posts: 689
Joined: Fri Oct 05, 2012 8:11 am


Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests