Home Download Buy Blog Forum Support

feed edit object into show_quick_panel

feed edit object into show_quick_panel

Postby Binocular222 on Wed Dec 25, 2013 11:16 am

This not work:
Code: Select all
import sublime, sublime_plugin

class examplCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        sublime.active_window().show_quick_panel('Y', self._on_select)

    def _on_select(self, idx):
        for sel in self.view.sel():
            self.view.insert(edit, sel.begin(), 'sample text')

I know that I need to feed edit object into _on_select(), I tried all the ways with _on_select(self, edit, idx); _on_select(self, idx, edit), still not work.?!

Please help.
Binocular222
 
Posts: 55
Joined: Sat May 18, 2013 4:10 pm

Re: feed edit object into show_quick_panel

Postby lechor on Mon Dec 30, 2013 8:21 am

Code: Select all
import sublime, sublime_plugin

class examplCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        sublime.active_window().show_quick_panel('Y', self._on_select)
        def _on_select(self, idx):
            for sel in self.view.sel():
                self.view.insert(edit, sel.begin(), 'sample text')


this works
lechor
 
Posts: 4
Joined: Fri Dec 27, 2013 9:14 am

Re: feed edit object into show_quick_panel

Postby Binocular222 on Tue Dec 31, 2013 7:02 am

You changed indentation level of def _on_select(self, idx) ?
Sorry but not works for me.
Binocular222
 
Posts: 55
Joined: Sat May 18, 2013 4:10 pm

Re: feed edit object into show_quick_panel

Postby jbjornson on Tue Dec 31, 2013 8:45 am

Try this (untested but should work).

Code: Select all
import sublime, sublime_plugin

class examplCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        sublime.active_window().show_quick_panel('Y', lambda idx: self._on_select(idx, edit))

    def _on_select(self, idx, edit):
        for sel in self.view.sel():
            self.view.insert(edit, sel.begin(), 'sample text')
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: feed edit object into show_quick_panel

Postby Binocular222 on Tue Dec 31, 2013 9:28 am

Sorry, but still not work. (Quick panel shown up but self.view.insert(edit, sel.begin(), 'sample text') not do it job).
As far as I know, edit object is destroyed when quick_panel pop up, so the only way to initiate edit object is by calling TextCommand again
Binocular222
 
Posts: 55
Joined: Sat May 18, 2013 4:10 pm

Re: feed edit object into show_quick_panel

Postby jbjornson on Tue Dec 31, 2013 10:30 am

Sorry...I didn't really look at what you were trying to but was trying to solve how to pass the parameter to the callback.

I had a similar problem in one of my plugins that I solved by using the following code:
Code: Select all
    self.view.run_command('append', {'characters': message+'\n', 'force': True, 'scroll_to_end': True})


Maybe you could try something like this to insert the text?
Code: Select all
    self.view.run_command('insert', {'characters': 'sample text'})


Have a look here for more info on the available commands: http://docs.sublimetext.info/en/latest/reference/commands.html
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: feed edit object into show_quick_panel

Postby Binocular222 on Wed Jan 01, 2014 2:43 am

Binocular222
 
Posts: 55
Joined: Sat May 18, 2013 4:10 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests