Exemplo n.º 1
0
 def run(self, edit):
     """Run the command."""
     if util.get_scope(self.view, skip_sel_check=True):
         if ch_file_thread is None or not ch_file_thread.is_alive():
             start_file_index(self.view)
         else:
             sublime.error_message("File indexer is already running!")
     else:
         sublime.error_message('Cannot index colors in this file!')
Exemplo n.º 2
0
def start_file_index(view):
    """Kick off current file color index."""
    global ch_file_thread
    if view is not None and (ch_file_thread is None or not ch_file_thread.is_alive()):
        scope = util.get_scope(view, skip_sel_check=True)
        if scope:
            source = []
            for r in view.find_by_selector(scope):
                source.append(view.substr(r))
            util.debug('Regions to search:\n', source)
            if len(source):
                ch_file_thread = ChFileIndexThread(view, ' '.join(source))
                ch_file_thread.start()
                sublime.status_message('File color indexer started...')
Exemplo n.º 3
0
    def payload(self):
        """Code to run."""

        self.modified = False
        self.ignore_all = True
        window = sublime.active_window()
        view = window.active_view()
        if view is not None:
            info = False
            execute = False
            sels = view.sel()
            scope = util.get_scope(view)
            if (
                scope and
                len(sels) == 1 and sels[0].size() == 0
                and view.score_selector(sels[0].begin(), scope)
            ):
                point = sels[0].begin()
                visible = view.visible_region()
                start = point - 50
                end = point + 50
                if start < visible.begin():
                    start = visible.begin()
                if end > visible.end():
                    end = visible.end()
                bfr = view.substr(sublime.Region(start, end))
                ref = point - start
                for m in util.COLOR_ALL_RE.finditer(bfr):
                    if ref >= m.start(0) and ref < m.end(0):
                        if (
                            m.group('hex') or m.group('rgb') or m.group('rgba') or
                            m.group('hsl') or m.group('hsla') or m.group('webcolors')
                        ):
                            info = True
                            execute = True
                        break
                    elif ref == m.end(0):
                        if (
                            m.group('hash') or m.group('rgb_open') or m.group('rgba_open') or
                            m.group('hsl_open') or m.group('hsla_open')
                        ):
                            execute = True
                        break
                if execute:
                    view.run_command('color_helper', {"mode": "palette" if not info else "info"})
        self.ignore_all = False
        self.time = time()