def run(self, edit, **kw): if not eutils.is_css_view(self.view, True): return sublime.error_message('You should run this action on CSS file') # build sources list sources = [view for view in eutils.all_views() if re.search(r'[\/\\]lspatch-[\w\-]+\.json$', view.file_name() or '')] # gather all available items display_items = [] patches = [] def add_item(patch, name): for p in patch: display_items.append([p['file'], 'Updated selectors: %s' % ', '.join(p['selectors']), name]) patches.append(json.dumps(p['data'])) for view in sources: add_item(lsutils.diff.parse_patch(eutils.content(view)), view.file_name()) # check if buffer contains valid patch pb = sublime.get_clipboard() if lsutils.diff.is_valid_patch(pb): add_item(lsutils.diff.parse_patch(pb), 'Clipboard') def on_done(ix): if ix == -1: return apply_patch_on_view(self.view, patches[ix]) if len(display_items) == 1: on_done(0) elif display_items: self.view.window().show_quick_panel(display_items, on_done) else: sublime.error_message('No patches found. You have to open patch files in Sublime Text or copy patch file contents into clipboard and run this action again.')
def should_handle(view): "Checks whether incoming view modification should be handled" if view.id() in _suppressed: _suppressed.remove(view.id()) return False # don't do anything if there are no connected clients # or change performed outside of CSS file return WSHandler.clients and eutils.is_css_view(view, True)
def apply_patch_on_view(view, patch): "Waita until view is loaded and applies patch on it" if view.is_loading(): return sublime.set_timeout(lambda: apply_patch_on_view(view, patch), 100) # make sure it's a CSS file if not eutils.is_css_view(view, True): logger.debug('File %s is not CSS, aborting' % eutils.file_name(view)) return focus_view(view) lsutils.diff.patch(view.buffer_id(), patch, apply_patched_source)
def run(self, edit, **kw): if not eutils.is_css_view(self.view, True): return sublime.error_message( 'You should run this action on CSS file') # build sources list sources = [ view for view in eutils.all_views() if re.search(r'[\/\\]lspatch-[\w\-]+\.json$', view.file_name() or '') ] # gather all available items display_items = [] patches = [] def add_item(patch, name): for p in patch: display_items.append([ p['file'], 'Updated selectors: %s' % ', '.join(p['selectors']), name ]) patches.append(json.dumps(p['data'])) for view in sources: add_item(lsutils.diff.parse_patch(eutils.content(view)), view.file_name()) # check if buffer contains valid patch pb = sublime.get_clipboard() if lsutils.diff.is_valid_patch(pb): add_item(lsutils.diff.parse_patch(pb), 'Clipboard') def on_done(ix): if ix == -1: return apply_patch_on_view(self.view, patches[ix]) if len(display_items) == 1: on_done(0) elif display_items: self.view.window().show_quick_panel(display_items, on_done) else: sublime.error_message( 'No patches found. You have to open patch files in Sublime Text or copy patch file contents into clipboard and run this action again.' )
def on_activated(self, view): if eutils.is_css_view(view, True): logger.debug('Prepare diff') lsutils.diff.prepare_diff(view.buffer_id())
def on_load(self, view): _view_file_names[view.id()] = eutils.file_name(view) if eutils.is_css_view(view): update_files()