def run(self): # self.site_active = mw.get_setting('mediawiki_site_active') self.site_active = mw.get_view_site() sites = mw.get_setting('mediawiki_site') # self.site_keys = map(self.is_checked, list(sites.keys())) self.site_keys = [self.is_checked(x) for x in sites.keys()] sublime.set_timeout(lambda: self.window.show_quick_panel(self.site_keys, self.on_done), 1)
def on_activated(self, view): current_syntax = view.settings().get('syntax') current_site = mw.get_view_site() # TODO: move method to check mediawiker view to mwutils if current_syntax is not None and current_syntax.endswith('Mediawiker/Mediawiki.tmLanguage'): # Mediawiki mode view.settings().set('mediawiker_is_here', True) view.settings().set('mediawiker_wiki_instead_editor', mw.get_setting('mediawiker_wiki_instead_editor')) view.settings().set('mediawiker_site', current_site)
def run(self, storage_name='mediawiker_pagelist'): # site_name_active = mw.get_setting('mediawiki_site_active') site_name_active = mw.get_view_site() mediawiker_pagelist = mw.get_setting(storage_name, {}) self.my_pages = mediawiker_pagelist.get(site_name_active, []) if self.my_pages: self.my_pages.reverse() # error 'Quick panel unavailable' fix with timeout.. sublime.set_timeout(lambda: self.window.show_quick_panel(self.my_pages, self.on_done), 1) else: sublime.status_message('List of pages for wiki "%s" is empty.' % (site_name_active))
def command_run(self, password): # cases: # from view with page, opened from other site_active than in global settings - new page will be from the same site # from view with page, open page with another lang site - site param must be defined, will set it # from view with undefined site (new) open page by global site_active setting if not self.site_active: self.site_active = mw.get_view_site() if self.run_in_new_window: self.window.new_file() self.run_in_new_window = False self.window.active_view().settings().set('mediawiker_site', self.site_active) self.window.active_view().run_command(self.action, {"title": self.title, "password": password})
def run(self, edit, title, password): is_skip_summary = mw.get_setting('mediawiker_skip_summary', False) sitecon = mw.get_connect(password) self.title = mw.get_title() if self.title: self.page = sitecon.Pages[self.title] if self.page.can('edit'): self.current_text = self.view.substr(sublime.Region(0, self.view.size())) if not is_skip_summary: # summary_message = 'Changes summary (%s):' % mw.get_setting('mediawiki_site_active') summary_message = 'Changes summary (%s):' % mw.get_view_site() self.view.window().show_input_panel(summary_message, '', self.on_done, None, None) else: self.on_done('') else: sublime.status_message('You have not rights to edit this page') else: sublime.status_message('Can\'t publish page with empty title') return
def run(self, edit, title, password): is_writable = False sitecon = mw.get_connect(password) is_writable, text = mw.get_page_text(sitecon, title) self.view.set_syntax_file('Packages/Mediawiker/Mediawiki.tmLanguage') self.view.settings().set('mediawiker_is_here', True) self.view.settings().set('mediawiker_wiki_instead_editor', mw.get_setting('mediawiker_wiki_instead_editor')) self.view.set_name(title) if is_writable: if not text: sublime.status_message('Wiki page %s is not exists. You can create new..' % (title)) text = '<!-- New wiki page: Remove this with text of the new page -->' # insert text self.view.erase(edit, sublime.Region(0, self.view.size())) self.view.run_command('mediawiker_insert_text', {'position': 0, 'text': text}) sublime.status_message('Page %s was opened successfully from %s.' % (title, mw.get_view_site())) self.view.set_scratch(True) # own is_changed flag instead of is_dirty for possib. to reset.. self.view.settings().set('is_changed', False)
def process(self, index): if index == 0: site_active_new = None site_active = mw.get_view_site() sites = mw.get_setting('mediawiki_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("mediawiker_page", {"title": self.page_name, "action": "mediawiker_show_page", "site_active": site_active_new}) else: sublime.status_message('Settings not found for host %s.' % (host_new)) elif index == 1: self.view.run_command('mediawiker_replace_text', {'text': self.page_name})