Exemple #1
0
    def select_entry(window, locations, idx, event):

        nonlocal clear_to_right, side_by_side, replace

        if idx >= 0:
            for view_id in open_file_states:
                restore_view = sublime.View(view_id)
                if file_name(restore_view) != locations[idx].path:
                    restore_selections(restore_view)

            if side_by_side and clear_to_right:
                new_tab = True
                reopen_location = True
                if event:
                    if 'primary' in event['modifier_keys']:
                        reopen_location = False
                        new_tab = False
                    elif 'shift' in event['modifier_keys']:
                        new_tab = True
                    elif 'alt' in event['modifier_keys']:
                        replace = True
                        new_tab = False
                if reopen_location:
                    window.select_sheets(prev_selected)
                    window.focus_view(view)
                    if replace:
                        highlighted_view.close()
                    open_location(window, locations[idx], new_tab, replace,
                                  False)

            # When in side-by-side mode, the file will already be open
            if not side_by_side:
                new_tab = False
                if event:
                    if 'primary' in event['modifier_keys']:
                        new_tab = True
                        clear_to_right = True
                    elif 'shift' in event['modifier_keys']:
                        new_tab = True
                    elif 'alt' in event['modifier_keys']:
                        replace = True
                open_location(window, locations[idx], new_tab, replace,
                              clear_to_right)
        else:
            for view_id in open_file_states:
                restore_selections(sublime.View(view_id))

            if window.active_view() != highlighted_view:
                window.select_sheets(prev_selected)

                if highlighted_view.sheet().is_semi_transient():
                    highlighted_view.close()
                elif view.is_valid():
                    window.focus_view(view)

            elif highlighted_view.sheet().is_transient():
                window.select_sheets(prev_selected)
def on_selection_modified_async(view_id):
    v = sublime.View(view_id)
    for callback in all_callbacks['on_selection_modified_async']:
        try:
            callback.on_selection_modified_async(v)
        except:
            traceback.print_exc()
def on_deactivated(view_id):
    v = sublime.View(view_id)
    for callback in all_callbacks['on_deactivated']:
        try:
            callback.on_deactivated(v)
        except:
            traceback.print_exc()
    def run(self, edit, **args):
        """
        Runs the command to write to a serial output view
        :param args: The args for writing to the view.  Needs to contain:
                    "text": string of text to write to the view
                    or
                    "view_id": The id of the input view
                    "region_begin": Starting index for the input view
                    "region_end": Ending index for the input view
        :type args: dict
        :return:
        """
        # Check if the end of the output file is visible.  If so, enable the auto-scroll
        should_autoscroll = self.view.visible_region().contains(
            self.view.size())

        self.view.set_read_only(False)
        if "text" in args:
            self.view.insert(edit, self.view.size(), args["text"])
        else:
            view = sublime.View(args["view_id"])
            begin = args["region_begin"]
            end = args["region_end"]
            self.view.insert(edit, self.view.size(),
                             view.substr(sublime.Region(begin, end)))
        self.view.set_read_only(True)

        if should_autoscroll and not self.view.visible_region().contains(
                self.view.size()):
            self.view.window().run_command("serial_monitor_scroll",
                                           {"view_id": self.view.id()})
Exemple #5
0
def on_clone_async(view_id):
    v = sublime.View(view_id)
    for callback in all_callbacks['on_clone_async']:
        try:
            callback.on_clone_async(v)
        except:
            traceback.print_exc()
def on_post_text_command(view_id, name, args):
    v = sublime.View(view_id)
    for callback in all_callbacks['on_post_text_command']:
        try:
            callback.on_post_text_command(v, name, args)
        except:
            traceback.print_exc()
Exemple #7
0
 def run(self,
         view_id: int,
         command: str,
         args: Optional[Dict[str, Any]] = None) -> None:
     view = sublime.View(view_id)
     if view.is_valid():
         view.run_command(command, args)
Exemple #8
0
def on_query_completions(view_id, prefix, locations):
    v = sublime.View(view_id)

    completions = []
    flags = 0
    for callback in all_callbacks['on_query_completions']:
        try:
            res = callback.on_query_completions(v, prefix, locations)

            if isinstance(res, tuple):
                completions += [normalise_completion(c) for c in res[0]]
                flags |= res[1]
            elif isinstance(res, list):
                completions += [normalise_completion(c) for c in res]
        except:
            traceback.print_exc()

    for vel in event_listeners_for_view(v):
        if 'on_query_completions' in vel.__class__.__dict__:
            try:
                res = vel.on_query_completions(prefix, locations)

                if isinstance(res, tuple):
                    completions += [normalise_completion(c) for c in res[0]]
                    flags |= res[1]
                elif isinstance(res, list):
                    completions += [normalise_completion(c) for c in res]
            except:
                traceback.print_exc()

    return (completions, flags)
def on_post_save(view_id):
    v = sublime.View(view_id)
    for callback in all_callbacks['on_post_save']:
        try:
            callback.on_post_save(v)
        except:
            traceback.print_exc()
def on_close(view_id):
    v = sublime.View(view_id)

    detach_view(v)

    for callback in all_callbacks['on_close']:
        run_callback('on_close', callback, lambda: callback.on_close(v))
def on_load(view_id):
    v = sublime.View(view_id)

    attach_view(v)

    for callback in all_callbacks['on_load']:
        run_callback('on_load', callback, lambda: callback.on_load(v))
Exemple #12
0
def on_text_command(view_id, name, args):
    v = sublime.View(view_id)

    for vel in event_listeners_for_view(v):
        if 'on_text_command' in vel.__class__.__dict__:
            try:
                res = vel.on_text_command(name, args)
                if isinstance(res, tuple):
                    return res
                elif res:
                    return (res, None)
            except:
                traceback.print_exc()

    for callback in all_callbacks['on_text_command']:
        try:
            res = callback.on_text_command(v, name, args)
            if isinstance(res, tuple):
                return res
            elif res:
                return (res, None)
        except:
            traceback.print_exc()

    return ("", None)
Exemple #13
0
    def run(self, edit, output=False):
        """Display the tree and its diff preview.

        Args:
            output (bool): Indicates if we're re-drawing the tree.
        """
        vis = None
        if util.check_view(self.view):
            # Find our visualization view:
            if not output:
                # We don't have an output view, so it's an initial draw.
                window = sublime.active_window()
                old = window.active_view()
                vis = window.new_file()

                # Set the layout.
                side = util.get_setting('layout', 'left')
                nag, group = util.set_active_group(window, vis, side)

                util.VIS_TO_VIEW[vis.id()] = self.view
                vis.set_name('Sublundo: History View')
                vis.settings().set('gutter', False)
                vis.settings().set('word_wrap', False)

                buf = util.render(util.VIEW_TO_TREE[self.view.id()]['tree'])
                vis.replace(edit, sublime.Region(0, vis.size()), buf)

                vis.set_syntax_file(
                    'Packages/Sublundo/Sublundo.sublime-syntax')
                vis.set_read_only(True)
                vis.set_scratch(True)
                vis.sel().clear()

                window.run_command('hide_overlay')
                window.focus_view(old)

                if not window.find_output_panel('sublundo'):
                    p = window.create_output_panel('sublundo', False)
                    p.assign_syntax('Packages/Diff/Diff.sublime-syntax')

                if util.get_setting('diff', True):
                    window.run_command('show_panel',
                                       {'panel': 'output.sublundo'})
            else:
                # We were given an output view, so it's a re-draw.
                vis = sublime.View(output)
                buf = util.render(util.VIEW_TO_TREE[self.view.id()]['tree'])

                vis.set_read_only(False)
                vis.replace(edit, sublime.Region(0, vis.size()), buf)
                vis.set_read_only(True)

            # Move to the active node.
            sublime.active_window().focus_view(vis)
            pos = vis.find_by_selector('keyword.other.sublundo.tree.position')
            if pos:
                vis.show(pos[0], True)
            else:
                t = util.VIEW_TO_TREE[self.view.id()]['tree']
                util.debug('No active node? Total size = {0}.'.format(len(t)))
Exemple #14
0
    def test_WeCanShowInputPanel(self):
        view = sublime.View()
        window = mock.Mock()
        view.window = window
        cmd = uberselection.UberSelectionCommand()
        cmd.showInputPanel(view)

        self.assertTrue(view.window().showInputPanel.called)
Exemple #15
0
 def create_output(self, window, name, read_only=False):
     for view_id, window_id in self.views.items():
         if window.id() == window_id != None:
             return sublime.View(view_id)
     view = window.create_output_panel(name)
     view.set_read_only(read_only)
     self.views[view.id()] = window.id()
     return view
Exemple #16
0
def on_deactivated_async(view_id):
    v = sublime.View(view_id)
    for callback in all_callbacks['on_deactivated_async']:
        try:
            callback.on_deactivated_async(v)
        except:
            traceback.print_exc()
    run_async_view_listener_callback(v, 'on_deactivated_async')
Exemple #17
0
 def clear_on_hover(self):
     """Clear Vale's regions and hover data.
     """
     for alert in self.on_hover:
         for level in ["error", "warning", "suggestion"]:
             sublime.View(alert["view_id"]).erase_regions(
                 "vale-server-" + level
             )
     del self.on_hover[:]
Exemple #18
0
 def update_views(self, update_command, string, output_name=None):
     if output_name is not None:
         self.create_output(sublime.active_window(), output_name, True)
         sublime.active_window().run_command(
             'show_panel', {'panel': 'output.' + output_name})
     for view_id in self.views.keys():
         sublime.View(view_id).run_command(update_command,
                                           {'string': string})
     return
Exemple #19
0
def on_clone(view_id):
    v = sublime.View(view_id)

    attach_view(v)

    for callback in all_callbacks['on_clone']:
        try:
            callback.on_clone(v)
        except:
            traceback.print_exc()
Exemple #20
0
def create_text_commands(view_id):
    view = sublime.View(view_id)
    cmds = []
    for class_ in text_command_classes:
        try:
            cmds.append(class_(view))
        except TypeError:
            print(class_)
            raise
    return cmds
def on_hover(view_id, point, hover_zone):
    v = sublime.View(view_id)
    for callback in all_callbacks['on_hover']:
        run_callback('on_hover', callback, lambda: callback.on_hover(v, point, hover_zone))

    for vel in event_listeners_for_view(v):
        if 'on_hover' in vel.__class__.__dict__:
            try:
                vel.on_hover(point, hover_zone)
            except:
                traceback.print_exc()
Exemple #22
0
def on_query_context(view_id, key, operator, operand, match_all):
    v = sublime.View(view_id)
    for callback in all_callbacks['on_query_context']:
        try:
            val = callback.on_query_context(v, key, operator, operand, match_all)
            if val:
                return True
        except:
            traceback.print_exc()

    return False
Exemple #23
0
    def attach(self, view, edit=None):
        window_id = sublime_api.view_window(view.view_id)
        if self.window_id != window_id:
            self.attach_window(sublime_api.view_window(view.view_id))

        if view == self.output:
            view = sublime.View(sublime_api.window_active_view(window_id))

        self.window = self.get_window()
        self.view = view
        self.edit = edit
Exemple #24
0
    def test_sbot(self):
        '''Also has tests for the simple sbot.py.'''
        # self.assertEqual('foo'.upper(), 'FOO')

        view = sublime.View(600)

        sel = sublime.Selection(view.id())
        sel.add(sublime.Region(10, 20, 101))
        view.sel = MagicMock(return_value = sel)

        evt = sbot.SbotEvent()
        evt.on_selection_modified(view)
def on_text_command(view_id, name, args):
    v = sublime.View(view_id)
    for callback in all_callbacks['on_text_command']:
        try:
            res = callback.on_text_command(v, name, args)
            if isinstance(res, tuple):
                return res
            elif res:
                return (res, None)
        except:
            traceback.print_exc()

    return ("", None)
Exemple #26
0
def on_post_text_command(view_id, name, args):
    v = sublime.View(view_id)
    for callback in all_callbacks['on_post_text_command']:
        try:
            callback.on_post_text_command(v, name, args)
        except:
            traceback.print_exc()

    for vel in event_listeners_for_view(v):
        if 'on_post_text_command' in vel.__class__.__dict__:
            try:
                vel.on_post_text_command(name, args)
            except:
                traceback.print_exc()
def _unset_expanded_ok(vid):
    # type: (sublime.ViewId) -> None
    view = sublime.View(vid)
    if not view.is_valid():
        return

    filename = util.get_filename(view)
    # Keep expanded if linters are running to minimize redraws
    if State['running'].get(filename, 0) > 0:
        enqueue_unset_expanded_ok(view)
        return

    State['expanded_ok'].discard(filename)
    draw(view, State['problems_per_file'][filename], expanded_ok=False)
Exemple #28
0
    def cleanup(self, session):
        settings = sublime.load_settings("remote_subl.sublime-settings")
        vid_to_pop = []
        for vid, file in FILES.items():
            if file.session == session:
                # only show message once
                if not vid_to_pop:
                    if settings.get("pop_up_when_connection_lost", True):
                        sublime.message_dialog(
                            CONNECTION_LOST.format(file.host or "remote"))
                vid_to_pop.append(vid)

        for vid in vid_to_pop:
            LOST_FILES[vid] = FILES.pop(vid)
            sublime.View(vid).run_command("remote_subl_update_status_bar")
Exemple #29
0
    def test_format_json(self):
        v = sublime.View(601)

        with open(r'.\files\test.json', 'r') as fp:
            # The happy path.
            s = fp.read()
            cmd = sbot_format.SbotFormatJsonCommand(v)
            res = cmd._do_one(s)
            self.assertEqual(
                res[:50],
                '{\n    "MarkPitch": {\n        "Original": 0,\n      ')

            # Make it a bad file.
            s = s.replace('\"Original\"', '')
            res = cmd._do_one(s)
            self.assertEqual(
                res[:50], "Json Error: Expecting property name enclosed in do")
def on_query_completions(view_id, prefix, locations):
    v = sublime.View(view_id)

    completions = []
    flags = 0
    for callback in all_callbacks['on_query_completions']:
        try:
            res = callback.on_query_completions(v, prefix, locations)

            if isinstance(res, tuple):
                completions += [normalise_completion(c) for c in res[0]]
                flags |= res[1]
            elif isinstance(res, list):
                completions += [normalise_completion(c) for c in res]
        except:
            traceback.print_exc()

    return (completions, flags)