示例#1
0
def _start_diff(buf_id):
	view = eutils.view_for_buffer_id(buf_id)
	if view is None:
		return

	state = _diff_state[buf_id]
	prev_content = state['content']
	content = eutils.content(view)
	syntax = get_syntax(view)

	state['required'] = False

	client = ws.find_client({'supports': 'css'})

	if client:
		logger.debug('Use connected "%s" client for diff' % client.name())
		lock_state(state)
		ws.send({
			'action': 'diff',
			'data': {
				'file': buf_id,
				'syntax': syntax,
				'source1': prev_content,
				'source2': content
			}
		}, client)
	else:
		logger.error('No suitable client for diff')
示例#2
0
def _start_diff(buf_id, callback):
    view = eutils.view_for_buffer_id(buf_id)
    if view is None:
        return

    state = _diff_state[buf_id]
    prev_content = state['content']
    content = eutils.content(view)
    syntax = get_syntax(view)

    @eutils.main_thread
    def _c(result):
        callback(buf_id, result)

        if buf_id in _diff_state:
            state = _diff_state[buf_id]
            state['running'] = False
            if result is not None:
                state['content'] = content

            if state['required']:
                diff(buf_id, callback)

    state['required'] = False
    state['running'] = True

    with PyV8.JSLocker():
        threading.Thread(target=_run_diff,
                         args=(prev_content, content, syntax, _c)).start()
示例#3
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.')
示例#4
0
def _start_patch(buf_id, patch):
	view = eutils.view_for_buffer_id(buf_id)
	if view is None:
		logger.debug('No view to patch')
		return

	content = eutils.content(view)
	syntax = get_syntax(view)
	state = _patch_state[buf_id]


	client = ws.find_client({'supports': 'css'})
	logger.debug('Client: %s' % client)

	if client:
		logger.debug('Use connected "%s" client for patching' % client.name())
		lock_state(state)
		ws.send({
			'action': 'patch',
			'data': {
				'file': buf_id,
				'syntax': syntax,
				'patches': patch,
				'source': content
			}
		}, client)
	else:
		logger.error('No suitable client for patching')
示例#5
0
def _start_diff(buf_id, callback):
	view = eutils.view_for_buffer_id(buf_id)
	if view is None:
		return

	state = _diff_state[buf_id]
	prev_content = state['content']
	content = eutils.content(view)

	@eutils.main_thread
	def _c(result):
		callback(buf_id, result)

		if buf_id in _diff_state:
			state = _diff_state[buf_id]
			state['running'] = False
			if result is not None:
				state['content'] = content

			if state['required']:
				diff(buf_id, callback)
	
	state['required'] = False
	state['running'] = True
	with PyV8.JSLocker():
		threading.Thread(target=_run_diff, args=(prev_content, content, _c)).start()
示例#6
0
def _start_patch(buf_id, patch):
    view = eutils.view_for_buffer_id(buf_id)
    if view is None:
        logger.debug('No view to patch')
        return

    content = eutils.content(view)
    syntax = get_syntax(view)
    state = _patch_state[buf_id]

    client = ws.find_client({'supports': 'css'})
    logger.debug('Client: %s' % client)

    if client:
        logger.debug('Use connected "%s" client for patching' % client.name())
        lock_state(state)
        ws.send(
            {
                'action': 'patch',
                'data': {
                    'file': buf_id,
                    'syntax': syntax,
                    'patches': patch,
                    'source': content
                }
            }, client)
    else:
        logger.error('No suitable client for patching')
示例#7
0
def _start_diff(buf_id):
    view = eutils.view_for_buffer_id(buf_id)
    if view is None:
        return

    state = _diff_state[buf_id]
    prev_content = state['content']
    content = eutils.content(view)
    syntax = get_syntax(view)

    state['required'] = False

    client = ws.find_client({'supports': 'css'})

    if client:
        logger.debug('Use connected "%s" client for diff' % client.name())
        lock_state(state)
        ws.send(
            {
                'action': 'diff',
                'data': {
                    'file': buf_id,
                    'syntax': syntax,
                    'source1': prev_content,
                    'source2': content
                }
            }, client)
    else:
        logger.error('No suitable client for diff')
示例#8
0
def send_unsaved_files(payload, sender):
	files = payload.get('files', [])
	out = []
	for f in files:
		view = eutils.view_for_file(f)
		if not view:
			continue

		content = eutils.content(view)
		if view and view.is_dirty():
			fname = view.file_name()
			pristine = None
			if not fname:
				# untitled file
				pristine = ''
			elif os.path.exists(fname):
				pristine = read_file(fname)

			if pristine is not None:
				out.append({
					'file': f,
					'pristine': pristine,
					'content': content
				})

	if out:
		ws.send({
			'action': 'unsavedFiles',
			'data': {
				'files': out
			}
		}, sender)
	else:
		logger.info('No unsaved changes')
def send_unsaved_files(payload, sender):
    files = payload.get('files', [])
    out = []
    for f in files:
        view = eutils.view_for_file(f)
        if not view:
            continue

        content = eutils.content(view)
        if view and view.is_dirty():
            fname = view.file_name()
            pristine = None
            if not fname:
                # untitled file
                pristine = ''
            elif os.path.exists(fname):
                pristine = read_file(fname)

        if pristine is not None and pristine != content:
            out.append({'file': f, 'pristine': pristine, 'content': content})

    if out:
        ws.send({'action': 'unsavedFiles', 'data': {'files': out}}, sender)
    else:
        logger.info('No unsaved changes')
示例#10
0
def send_unsaved_files(payload, sender):
    files = payload.get("files", [])
    out = []
    for f in files:
        view = eutils.view_for_file(f)
        if not view:
            continue

        content = eutils.content(view)
        if view and view.is_dirty():
            fname = view.file_name()
            pristine = None
            if not fname:
                # untitled file
                pristine = ""
            elif os.path.exists(fname):
                pristine = read_file(fname)

        if pristine is not None:
            out.append({"file": f, "pristine": pristine, "content": content})

    if out:
        ws.send({"action": "unsavedFiles", "data": {"files": out}}, sender)
    else:
        logger.info("No unsaved changes")
示例#11
0
def prepare_diff(buf_id):
	"Prepare buffer for diff'ing"
	if not has_pyv8(): return

	view = eutils.view_for_buffer_id(buf_id)
	if view is None:
		return

	if buf_id not in _diff_state:
		_diff_state[buf_id] = {'running': False, 'required': False, 'content': ''}

	_diff_state[buf_id]['content'] = eutils.content(view)
示例#12
0
def prepare_diff(buf_id):
    "Prepare buffer for diff'ing"
    view = eutils.view_for_buffer_id(buf_id)
    if view is None:
        return

    if buf_id not in _diff_state:
        _diff_state[buf_id] = {
            'running': False,
            'required': False,
            'content': '',
            'start_time': 0
        }

    _diff_state[buf_id]['content'] = eutils.content(view)
示例#13
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.'
            )
示例#14
0
def _start_patch(buf_id, patch, callback):
	view = eutils.view_for_buffer_id(buf_id)
	if view is None:
		return

	content = eutils.content(view)

	@eutils.main_thread
	def _c(result):
		callback(buf_id, result)

		if buf_id in _patch_state:
			state = _patch_state[buf_id]
			state['running'] = False
			if state['patches']:
				patch(buf_id, None, callback)

	_patch_state[buf_id]['running'] = True
	with PyV8.JSLocker():
		threading.Thread(target=_run_patch, args=(content, patch, _c)).start()
示例#15
0
def _start_patch(buf_id, patch, callback):
    view = eutils.view_for_buffer_id(buf_id)
    if view is None:
        return

    content = eutils.content(view)

    @eutils.main_thread
    def _c(result):
        callback(buf_id, result)

        if buf_id in _patch_state:
            state = _patch_state[buf_id]
            state['running'] = False
            if state['patches']:
                patch(buf_id, None, callback)

    _patch_state[buf_id]['running'] = True
    with PyV8.JSLocker():
        threading.Thread(target=_run_patch, args=(content, patch, _c)).start()