예제 #1
0
	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.')
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
    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.'
            )
예제 #7
0
	def on_activated(self, view):
		if eutils.is_css_view(view, True):
			logger.debug('Prepare diff')
			lsutils.diff.prepare_diff(view.buffer_id())
예제 #8
0
	def on_load(self, view):
		_view_file_names[view.id()] = eutils.file_name(view)

		if eutils.is_css_view(view):
			update_files()
예제 #9
0
 def on_activated(self, view):
     if eutils.is_css_view(view, True):
         logger.debug('Prepare diff')
         lsutils.diff.prepare_diff(view.buffer_id())
예제 #10
0
    def on_load(self, view):
        _view_file_names[view.id()] = eutils.file_name(view)

        if eutils.is_css_view(view):
            update_files()