コード例 #1
0
 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)
コード例 #2
0
 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})
コード例 #3
0
ファイル: mw_cli.py プロジェクト: rabin-io/Mediawiker
    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)
コード例 #4
0
 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)
コード例 #5
0
ファイル: mw_page_list.py プロジェクト: rabin-io/Mediawiker
 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)
コード例 #6
0
 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)
コード例 #7
0
    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
                    }
                })
コード例 #8
0
ファイル: mw_hovers.py プロジェクト: rabin-io/Mediawiker
 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)
コード例 #9
0
 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
                 })
コード例 #10
0
 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)
コード例 #11
0
    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)
コード例 #12
0
ファイル: mw_hovers.py プロジェクト: rabin-io/Mediawiker
 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(' ', '_')}
         })
コード例 #13
0
 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
                     })
コード例 #14
0
    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)
コード例 #15
0
 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())
コード例 #16
0
 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)
コード例 #17
0
 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]
             })
コード例 #18
0
 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(' ', '_')
                 }
             })
コード例 #19
0
 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)
コード例 #20
0
 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('')
コード例 #21
0
 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('')
コード例 #22
0
ファイル: mw_events.py プロジェクト: rabin-io/Mediawiker
        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)
コード例 #23
0
        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)
コード例 #24
0
 def run(self):
     self.window.run_command(utils.cmd('page'),
                             {"action": utils.cmd('add_template')})
コード例 #25
0
ファイル: mw_html.py プロジェクト: rabin-io/Mediawiker
 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)
コード例 #26
0
 def run(self):
     self.window.run_command(utils.cmd('page'),
                             {"action": utils.cmd('upload')})
コード例 #27
0
    def run(self):
        if mw.get_setting('offline_mode'):
            return

        self.window.run_command(mw.cmd('page'), {"action": mw.cmd('add_template')})
コード例 #28
0
    def run(self):
        if mw.get_setting('offline_mode'):
            return

        self.window.run_command(mw.cmd('page'), {"action": mw.cmd('search_string_list')})
コード例 #29
0
ファイル: mw_favorites.py プロジェクト: rabin-io/Mediawiker
 def run(self):
     self.window.run_command(mw.cmd('page_list'), {'storage_name': 'favorites'})
コード例 #30
0
 def run(self):
     self.window.run_command(utils.cmd('page'),
                             {"action": utils.cmd('page_backlinks')})
コード例 #31
0
 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())
コード例 #32
0
 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)
コード例 #33
0
 def run(self):
     self.window.run_command(utils.cmd('page'),
                             {"action": utils.cmd('page_diff_vs_server')})
コード例 #34
0
 def run(self):
     self.window.run_command(utils.cmd('page'), {"action": utils.cmd('preview_page')})
コード例 #35
0
 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)
コード例 #36
0
ファイル: mw_events.py プロジェクト: rabin-io/Mediawiker
 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'))
コード例 #37
0
    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
                }
            })
コード例 #38
0
 def run(self):
     self.window.run_command(utils.cmd('page'),
                             {"action": utils.cmd('search_string_list')})
コード例 #39
0
    def run(self):
        if utils.props.get_setting('offline_mode'):
            return

        self.window.run_command(utils.cmd('page'),
                                {"action": utils.cmd('category_list')})
コード例 #40
0
 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'))
コード例 #41
0
ファイル: mw_diff.py プロジェクト: rabin-io/Mediawiker
    def run(self):
        if mw.get_setting('offline_mode'):
            return

        self.window.run_command(mw.cmd('page'), {"action": mw.cmd('page_diff_vs_server')})
コード例 #42
0
 def run(self):
     self.window.run_command(utils.cmd('page_list'),
                             {'storage_name': 'favorites'})
コード例 #43
0
ファイル: mw_add_image.py プロジェクト: rabin-io/Mediawiker
 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]})
コード例 #44
0
    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}})