def run(self, url): if url: url = utils.strunquote(url) sublime.set_timeout(lambda: self.window.run_command(utils.cmd('page'), { 'action': utils.cmd('show_page'), 'action_params': {'title': self.proto_replacer(url)} }), 1)
def process(self, index): if index == 0: site_active_new = None site_active = utils.get_view_site() sites = utils.props.get_setting('site') host = sites[site_active]['host'] domain_first = '.'.join(host.split('.')[-2:]) # NOTE: only links like lang_prefix.site.com supported.. (like en.wikipedia.org) host_new = '%s.%s' % (self.lang_prefix, domain_first) # if host_new exists in settings we can open page for site in sites: if sites[site]['host'] == host_new: site_active_new = site break if site_active_new: # open page with force site_active_new sublime.active_window().run_command( utils.cmd('page'), { 'action': utils.cmd('show_page'), 'action_params': { 'title': self.page_name, 'site_active': site_active_new } }) else: utils.status_message('Settings not found for host %s.' % (host_new)) elif index == 1: self.view.run_command(utils.cmd('replace_text'), {'text': self.page_name})
def run(self, url): if mw.get_setting('offline_mode'): return if url: url = mw.strunquote(url) sublime.set_timeout(lambda: self.window.run_command(mw.cmd('page'), { 'action': mw.cmd('show_page'), 'action_params': {'title': self.proto_replacer(url)} }), 1)
def on_done(self, index): if index >= 0: title = self.my_pages[index] try: self.window.run_command(utils.cmd('page'), { 'action': utils.cmd('show_page'), 'action_params': {'title': title} }) except ValueError as e: sublime.message_dialog(e)
def on_done(self, index): if index >= 0: title = self.my_pages[index] try: self.window.run_command(mw.cmd('page'), { 'action': mw.cmd('show_page'), 'action_params': {'title': title} }) except ValueError as e: sublime.message_dialog(e)
def edit_item(self): if self.item is not None: sublime.set_timeout( lambda: self.view.window().run_command( utils.cmd('page'), { 'action': utils.cmd('show_page'), 'action_params': { 'title': self.item['open'] } }), 1)
def on_done(self, index): if index >= 0: self.page_name = self.links[index] sublime.active_window().run_command( utils.cmd('page'), { 'action': utils.cmd('show_page'), 'action_params': { 'title': self.page_name } })
def on_navigate(link): page_name = link.split(':', 1)[-1].replace(' ', '_') if link.startswith('open'): view.window().run_command(mw.cmd('page'), { 'action': mw.cmd('show_page'), 'action_params': {'title': page_name} }) elif link.startswith('browse'): url = mw.get_page_url(page_name) webbrowser.open(url) elif link.startswith('get_image'): webbrowser.open(page_name)
def on_done(self, idx): if idx > -1: if idx == 0: url = mw.get_page_url(page_name='Special:Notifications') webbrowser.open(url) else: title = self.msgs[idx - 1].get('title', None) if title: self.window.run_command(mw.cmd('page'), { "action": mw.cmd('show_page'), 'action_params': {"title": title}, "check_notifications": False })
def on_navigate(link): page_name = link.split(':', 1)[-1].replace(' ', '_') if link.startswith('open'): view.window().run_command( utils.cmd('page'), { 'action': utils.cmd('show_page'), 'action_params': { 'title': page_name } }) elif link.startswith('browse'): url = utils.get_page_url(page_name) webbrowser.open(url) elif link.startswith('get_image'): webbrowser.open(page_name)
def show_results(self, search_value=''): # TODO: paging? if search_value: search_result = self.do_search(search_value) if search_result: text = '' while True: try: hit = search_result.next() if hit: text += self.get_block(hit) except StopIteration: break if text: self.view = sublime.active_window().new_file() # TODO: view set attrs in utils.. syntax_file = utils.props.get_setting('syntax') self.view.set_syntax_file(syntax_file) self.view.set_name('Wiki search results: %s' % search_value) self.view.run_command(utils.cmd('insert_text'), { 'position': 0, 'text': text }) elif search_value: sublime.message_dialog('No results for: %s' % search_value)
def on_navigate(link): if link == 'fold': for t in p.templates: if t.region.contains(point): r.fold() return elif link == 'unfold': for t in p.templates: if t.region.contains(point): r.unfold() return else: sublime.active_window().run_command(mw.cmd('page'), { 'action': mw.cmd('show_page'), 'action_params': {'title': link.replace(' ', '_')} })
def on_done(self, idx): if idx > -1: if idx == 0: url = utils.get_page_url(page_name='Special:Notifications') webbrowser.open(url) else: title = self.msgs[idx - 1].get('title', None) if title: self.window.run_command( utils.cmd('page'), { "action": utils.cmd('show_page'), 'action_params': { "title": title }, "check_notifications": False })
def show_results(self, search_value=''): # TODO: paging? if search_value: search_result = self.do_search(search_value) if search_result: text = '' while True: try: hit = search_result.next() if hit: text += self.get_block(hit) except StopIteration: break if text: self.view = sublime.active_window().new_file() # TODO: view set attrs in utils.. syntax_file = mw.get_setting('syntax') self.view.set_syntax_file(syntax_file) self.view.set_name('Wiki search results: %s' % search_value) self.view.run_command(mw.cmd('insert_text'), {'position': 0, 'text': text}) elif search_value: sublime.message_dialog('No results for: %s' % search_value)
def set_category(self, category): index_of_textend = self.view.size() self.view.run_command(utils.cmd('insert_text'), { 'position': index_of_textend, 'text': '[[%s]]' % category }) self.view.show(self.view.size())
def get_page(self, index): if index >= 0: # escape from quick panel return -1 page_name = self.category_strip_special_prefix(self.pages_names[index]) if self.pages[page_name] == mw.api.CATEGORY_NAMESPACE: self.update_category_path(page_name) self.show_list(page_name) else: try: sublime.active_window().run_command(mw.cmd('page'), { 'action': mw.cmd('show_page'), 'action_params': { 'title': page_name } }) except ValueError as e: sublime.message_dialog(e)
def on_done(self, idx): if idx >= 0: index_of_cursor = self.view.sel()[0].begin() self.view.run_command( utils.cmd('insert_text'), { 'position': index_of_cursor, 'text': '[[Image:%s]]' % self.images_names[idx] })
def on_navigate(link): if link == 'fold': for t in p.templates: if t.region.contains(point): r.fold() return elif link == 'unfold': for t in p.templates: if t.region.contains(point): r.unfold() return else: sublime.active_window().run_command( utils.cmd('page'), { 'action': utils.cmd('show_page'), 'action_params': { 'title': link.replace(' ', '_') } })
def get_page(self, index): if index >= 0: # escape from quick panel return -1 page_name = self.category_strip_special_prefix( self.pages_names[index]) if self.pages[page_name] == utils.api.CATEGORY_NAMESPACE: self.update_category_path(page_name) self.show_list(page_name) else: try: sublime.active_window().run_command( utils.cmd('page'), { 'action': utils.cmd('show_page'), 'action_params': { 'title': page_name } }) except ValueError as e: sublime.message_dialog(e)
def on_done(self, idx): if idx >= 0: template = mw.api.get_page('Template:%s' % self.templates_names[idx]) if mw.api.page_can_read(template): text = mw.api.page_get_text(page=template) params_text = self.get_template_params(text) index_of_cursor = self.view.sel()[0].begin() template_text = '{{%s%s}}' % (self.templates_names[idx], params_text) self.view.run_command(mw.cmd('insert_text'), {'position': index_of_cursor, 'text': template_text}) else: mw.status_message('')
def on_done(self, idx): if idx >= 0: template = utils.api.get_page('Template:%s' % self.templates_names[idx]) if utils.api.page_can_read(template): text = utils.api.page_get_text(page=template) params_text = self.get_template_params(text) index_of_cursor = self.view.sel()[0].begin() template_text = '{{%s%s}}' % (self.templates_names[idx], params_text) self.view.run_command(utils.cmd('insert_text'), { 'position': index_of_cursor, 'text': template_text }) else: utils.status_message('')
def on_modified(self): if mw.props.get_view_setting(self.view, 'is_here'): self.view.hide_popup() try: ch_cnt = mw.props.get_view_setting(self.view, 'autoreload') if ch_cnt: if not self.cnt: self.cnt = self.view.change_count() cnt_delta = self.view.change_count() - self.cnt if cnt_delta > ch_cnt: sublime.status_message('Autoreload: Generating preview..') sublime.active_window().run_command(mw.cmd('preview')) self.cnt = None else: sublime.status_message('\nAutoreload: change %s of %s..' % (cnt_delta, ch_cnt)) except Exception as e: mw.status_message('Preview exception: %s' % e)
def on_modified(self): if utils.props.get_view_setting(self.view, 'is_here'): self.view.hide_popup() try: ch_cnt = utils.props.get_view_setting( self.view, 'autoreload') if ch_cnt: if not self.cnt: self.cnt = self.view.change_count() cnt_delta = self.view.change_count() - self.cnt if cnt_delta > ch_cnt: utils.status_message( 'Autoreload: Generating preview..') sublime.active_window().run_command( utils.cmd('preview')) self.cnt = None else: utils.status_message( '\nAutoreload: change %s of %s..' % (cnt_delta, ch_cnt)) except Exception as e: utils.status_message('Preview exception: %s' % e)
def run(self): self.window.run_command(utils.cmd('page'), {"action": utils.cmd('add_template')})
def debug_html(self, html): view = sublime.active_window().new_file() view.set_name('debug.html') view.set_syntax_file(mw.from_package('HTML.sublime-syntax', name='HTML')) view.run_command(mw.cmd('insert_text'), {'position': 0, 'text': html, 'with_erase': True}) view.set_scratch(True)
def run(self): self.window.run_command(utils.cmd('page'), {"action": utils.cmd('upload')})
def run(self): if mw.get_setting('offline_mode'): return self.window.run_command(mw.cmd('page'), {"action": mw.cmd('add_template')})
def run(self): if mw.get_setting('offline_mode'): return self.window.run_command(mw.cmd('page'), {"action": mw.cmd('search_string_list')})
def run(self): self.window.run_command(mw.cmd('page_list'), {'storage_name': 'favorites'})
def run(self): self.window.run_command(utils.cmd('page'), {"action": utils.cmd('page_backlinks')})
def set_category(self, category): index_of_textend = self.view.size() self.view.run_command(mw.cmd('insert_text'), {'position': index_of_textend, 'text': '[[%s]]' % category}) self.view.show(self.view.size())
def debug_html(self, html): view = sublime.active_window().new_file() view.set_name('debug.html') view.set_syntax_file(utils.p.from_package('HTML.sublime-syntax', name='HTML')) view.run_command(utils.cmd('insert_text'), {'position': 0, 'text': html, 'with_erase': True}) view.set_scratch(True)
def run(self): self.window.run_command(utils.cmd('page'), {"action": utils.cmd('page_diff_vs_server')})
def run(self): self.window.run_command(utils.cmd('page'), {"action": utils.cmd('preview_page')})
def edit_item(self): if self.item is not None: sublime.set_timeout(lambda: self.view.window().run_command(mw.cmd('page'), { 'action': mw.cmd('show_page'), 'action_params': {'title': self.item['open']} }), 1)
def on_activated_async(self, view): ''' unsupported on ST2, gutters too - skipping.. ''' # folding gutters if mw.props.get_view_setting(view, 'is_here'): sublime.active_window().run_command(mw.cmd('colapse'))
def on_site_selected(self, index): if index < 0: return self.src_site_name = self.site_keys[index] # get remote page src_api = utils.PreAPI(conman=utils.conman, site_name=self.src_site_name) src_page = src_api.call('get_page', title=self.title) if not src_api.page_can_read(src_page): sublime.message_dialog(utils.api.PAGE_CANNOT_READ_MESSAGE) return text = src_api.page_get_text(src_page) cnt = len([i for i in src_page.images()]) if sublime.ok_cancel_dialog('Copy %s images from source page?' % cnt): images = src_page.images() for image in images: file_name = src_api.page_attr(image, 'page_title') is_success = utils.api.call( 'process_upload', url=image.imageinfo['url'], filename=file_name, description='Image for page "%s", copied from "%s"' % (self.title, self.src_site_name)) if is_success: utils.status_message( 'File %s successfully copied to wiki' % (file_name)) else: utils.status_message( 'Error while trying to copy file %s to wiki' % (file_name)) cnt = len([i for i in src_page.templates()]) if sublime.ok_cancel_dialog( 'Copy %s templates (only first level) from source page?' % cnt): templates = src_page.templates() for template in templates: template_name = src_api.page_attr(template, 'page_title') template_text = src_api.page_get_text(template) is_success = utils.api.save_page( page=template, text=template_text, summary='Template copy from %s for page %s' % (self.src_site_name, self.title), mark_as_minor=False) if not is_success: utils.status_message( 'There was an error while trying to copy template [[%s]] to wiki "%s".' % (template_name, utils.get_view_site()), replace=['[', ']']) else: utils.status_message( 'Template [[%s]] was successfully copied to wiki "%s".' % (self.title, utils.get_view_site()), replace=['[', ']']) # get local page page = utils.api.call('get_page', title=self.title) is_success = utils.api.save_page(page=page, text=text, summary='Page copy from %s' % self.src_site_name, mark_as_minor=False) if not is_success: utils.status_message( 'There was an error while trying to copy page [[%s]] to wiki "%s".' % (self.title, utils.get_view_site()), replace=['[', ']']) return else: utils.status_message( 'Page [[%s]] was successfully copied to wiki "%s".' % (self.title, utils.get_view_site()), replace=['[', ']']) self.view.window().run_command( utils.cmd('page'), { 'action': utils.cmd('show_page'), 'action_params': { 'title': self.title, 'new_tab': True } })
def run(self): self.window.run_command(utils.cmd('page'), {"action": utils.cmd('search_string_list')})
def run(self): if utils.props.get_setting('offline_mode'): return self.window.run_command(utils.cmd('page'), {"action": utils.cmd('category_list')})
def on_activated_async(self, view): ''' unsupported on ST2, gutters too - skipping.. ''' # folding gutters if utils.props.get_view_setting(view, 'is_here'): sublime.active_window().run_command(utils.cmd('colapse'))
def run(self): if mw.get_setting('offline_mode'): return self.window.run_command(mw.cmd('page'), {"action": mw.cmd('page_diff_vs_server')})
def run(self): self.window.run_command(utils.cmd('page_list'), {'storage_name': 'favorites'})
def on_done(self, idx): if idx >= 0: index_of_cursor = self.view.sel()[0].begin() self.view.run_command(mw.cmd('insert_text'), {'position': index_of_cursor, 'text': '[[Image:%s]]' % self.images_names[idx]})
def on_done(self, index): if index >= 0: self.page_name = self.links[index] sublime.active_window().run_command(mw.cmd('page'), {'action': mw.cmd('show_page'), 'action_params': {'title': self.page_name}})