Ejemplo n.º 1
0
def show(window, path, view_id=None, ignore_existing=False, goto=None):
    """
    Determines the correct view to use, creating one if necessary, and prepares it.
    """
    if not(path.endswith(os.sep) or path == os.sep):
        path += os.sep

    view = None
    if view_id:
        # The Goto command was used so the view is already known and its contents should be
        # replaced with the new path.
        view = first(window.views(), lambda v: v.id() == view_id)

    if not view and not ignore_existing:
        # See if a view for this path already exists.
        view = first(window.views(), lambda v: v.settings().get('dired_path') == path)

    if not view:
        view = window.new_file()
        view.set_scratch(True)

    if path == os.sep:
        view_name = os.sep
    else:
        view_name = basename(path.rstrip(os.sep))

    name = u"𝌆 {0}".format(view_name)

    view.set_name(name)
    view.settings().set('dired_path', path)
    view.settings().set('dired_rename_mode', False)
    window.focus_view(view)
    view.run_command('dired_refresh', { 'goto': goto })
Ejemplo n.º 2
0
def set_view(view_id, window, ignore_existing, path, single_pane):
    view = None
    if view_id:
        # The Goto command was used so the view is already known and its contents should be
        # replaced with the new path.
        view = first(window.views(), lambda v: v.id() == view_id)

    if not view and not ignore_existing:
        # See if a view for this path already exists.
        same_path = lambda v: v.settings().get('dired_path') == path
        # See if any reusable view exists in case of single_pane argument
        any_path = lambda v: v.score_selector(0, "text.dired") > 0
        view = first(window.views(), any_path if single_pane else same_path)

    if not view:
        view = window.new_file()
        view.settings().add_on_change('color_scheme',
                                      lambda: set_proper_scheme(view))
        view.set_syntax_file('Packages/FileBrowser/dired.hidden-tmLanguage')
        view.set_scratch(True)
        reset_sels = True
    else:
        reset_sels = path != view.settings().get('dired_path', '')

    return (view, reset_sels)
def set_view(view_id, window, ignore_existing, single_pane):
    view = None
    if view_id:
        # The Goto command was used so the view is already known and its contents should be
        # replaced with the new path.
        view = first(window.views(), lambda v: v.id() == view_id)

    if not view and not ignore_existing:
        # See if any reusable view exists in case of single_pane argument
        any_path = lambda v: v.score_selector(0, "text.outline") > 0
        view = first(window.views(), any_path if single_pane else same_path)

    if not view:
        view = window.new_file()
        view.settings().add_on_change('color_scheme',
                                      lambda: set_proper_scheme(view))
        view.set_syntax_file('Packages/Outline+/outline.hidden-tmLanguage')
        view.set_scratch(True)
        reset_sels = True
    # Adam: This is not a valid statement ('path is not defined')
    #       I assume 'path' was meant to point to the .path property of a'outlineBaseCommand' class
    #       in 'common.py' but this no longer looks used.
    #else:
    #    reset_sels = path != view.settings().get('outline_path', '')
    else:
        reset_sels = False

    return (view, reset_sels)
Ejemplo n.º 4
0
def show(window,
         path,
         view_id=None,
         ignore_existing=False,
         single_pane=False,
         goto=None):
    """
    Determines the correct view to use, creating one if necessary, and prepares it.
    """
    if not (path.endswith(os.sep) or path == os.sep):
        path += os.sep

    view = None
    if view_id:
        # The Goto command was used so the view is already known and its contents should be
        # replaced with the new path.
        view = first(window.views(), lambda v: v.id() == view_id)

    if not view and not ignore_existing:
        # See if a view for this path already exists.
        same_path = lambda v: v.settings().get('dired_path') == path
        # See if any reusable view exists in case of single_pane argument
        any_path = lambda v: v.score_selector(0, "text.dired") > 0
        view = first(window.views(), any_path if single_pane else same_path)

    if not view:
        view = window.new_file()
        view.set_scratch(True)

    if path == os.sep:
        view_name = os.sep
    else:
        view_name = basename(path.rstrip(os.sep))

    name = u"𝌆 {0}".format(view_name)

    view.set_name(name)
    view.settings().set('dired_path', path)
    view.settings().set('dired_rename_mode', False)
    window.focus_view(view)
    view.run_command('dired_refresh', {'goto': goto})
Ejemplo n.º 5
0
def set_view(view_id, window, ignore_existing, path, single_pane):
    view = None
    if view_id:
        # The Goto command was used so the view is already known and its contents should be
        # replaced with the new path.
        view = first(window.views(), lambda v: v.id() == view_id)

    if not view and not ignore_existing:
        # See if a view for this path already exists.
        same_path = lambda v: v.settings().get('dired_path') == path
        # See if any reusable view exists in case of single_pane argument
        any_path = lambda v: v.score_selector(0, "text.dired") > 0
        view = first(window.views(), any_path if single_pane else same_path)

    if not view:
        view = window.new_file()
        view.settings().add_on_change('color_scheme', lambda: set_proper_scheme(view))
        view.set_syntax_file('Packages/FileBrowser/dired' + SYNTAX_EXTENSION)
        view.set_scratch(True)
        reset_sels = True
    else:
        reset_sels = path != view.settings().get('dired_path', '')

    return (view, reset_sels)
Ejemplo n.º 6
0
	def on_selection_modified(self, view):
		if 'outline.hidden-tmLanguage' not in view.settings().get('syntax'):
			return

		sym_view, sym_group, fb_view, fb_group = get_sidebar_views_groups(view)

		sym_view = view
		window = view.window()
		sym_group, i = window.get_view_index(sym_view)
			
		if len(sym_view.sel()) == 0:
			return

		(row, col) = sym_view.rowcol(sym_view.sel()[0].begin())

		active_view =None
		active_view_id = sym_view.settings().get('active_view')
		if active_view_id:
			active_view = first(window.views(), lambda v: v.id() == active_view_id)

		#if there is no active view set yet
		if active_view == None:
			for group in range(window.num_groups()):
				if group != sym_group and group != fb_group:
					active_view = window.active_view_in_group(group)

		if active_view != None:
			symkeys = sym_view.settings().get('symkeys')
			if not symkeys:
				return
			region_position = symkeys[row]
			r = Region(region_position[0], region_position[1])
			active_view.show_at_center(r)
			active_view.sel().clear()
			active_view.sel().add(r)
			window.focus_view(active_view)
Ejemplo n.º 7
0
def show(window, path, view_id=None, ignore_existing=False, single_pane=False, goto=None, other_group=''):
    """
    Determines the correct view to use, creating one if necessary, and prepares it.
    """
    if not(path.endswith(os.sep) or path == os.sep):
        path += os.sep

    view = None
    if view_id:
        # The Goto command was used so the view is already known and its contents should be
        # replaced with the new path.
        view = first(window.views(), lambda v: v.id() == view_id)

    if not view and not ignore_existing:
        # See if a view for this path already exists.
        same_path = lambda v: v.settings().get('dired_path') == path
        # See if any reusable view exists in case of single_pane argument
        any_path = lambda v: v.score_selector(0, "text.dired") > 0
        view = first(window.views(), any_path if single_pane else same_path)

    if other_group:
        prev_focus = window.active_view()
        # simulate 'toggle sidebar':
        if prev_focus and 'dired' in prev_focus.scope_name(0):
            window.run_command('close_file')
            return

    if not view:
        view = window.new_file()
        view.settings().add_on_change('color_scheme', lambda: set_proper_scheme(view))
        view.set_syntax_file('Packages/FileBrowser/dired.hidden-tmLanguage')
        view.set_scratch(True)

    nag = window.active_group()
    if other_group:
        group = 0 if other_group == 'left' else 1
        if window.num_groups() == 1:
            cols = [0.0, 0.16, 1.0] if other_group == 'left' else [0.0, 0.84, 1.0]
            window.set_layout({"cols": cols, "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]})
        elif view:
            groups = window.num_groups()
            if groups <= 4 and nag < 2:
                group = 1 if nag == 0 else 0
            elif groups == 4 and nag >= 2:
                group = 3 if nag == 2 else 2
            else:
                group = nag - 1
        window.set_view_index(view, group, 0)
    else:
        group = nag

    # when other_group is left, we need move all views to right except FB view
    if nag == 0 and other_group == 'left' and group == 0:
        for v in reversed(window.views_in_group(nag)[1:]):
            window.set_view_index(v, 1, 0)

    if other_group and prev_focus:
        window.focus_view(prev_focus)

    if path == os.sep:
        view_name = os.sep
    else:
        view_name = basename(path.rstrip(os.sep))

    if ST3:
        name = u"𝌆 {0}".format(view_name)
    else:
        name = u"■ {0}".format(view_name)

    view.set_name(name)
    view.settings().set('dired_path', path)
    view.settings().set('dired_rename_mode', False)
    window.focus_view(view)
    view.run_command('dired_refresh', { 'goto': goto })
Ejemplo n.º 8
0
def get(*args, **kwargs):
    """Return first element from search
    """
    return common.first(search(*args, **kwargs))
Ejemplo n.º 9
0
def show(window, path, view_id=None, ignore_existing=False, single_pane=False, goto=None, other_group=''):
    """
    Determines the correct view to use, creating one if necessary, and prepares it.
    """
    if not(path.endswith(os.sep) or path == os.sep):
        path += os.sep

    view = None
    if view_id:
        # The Goto command was used so the view is already known and its contents should be
        # replaced with the new path.
        view = first(window.views(), lambda v: v.id() == view_id)

    if not view and not ignore_existing:
        # See if a view for this path already exists.
        same_path = lambda v: v.settings().get('dired_path') == path
        # See if any reusable view exists in case of single_pane argument
        any_path = lambda v: v.score_selector(0, "text.dired") > 0
        view = first(window.views(), any_path if single_pane else same_path)

    if other_group:
        prev_focus = window.active_view()
        # simulate 'toggle sidebar':
        if prev_focus and 'dired' in prev_focus.scope_name(0):
            window.run_command('close_file')
            return

    if not view:
        view = window.new_file()
        view.settings().add_on_change('color_scheme', lambda: set_proper_scheme(view))
        view.set_syntax_file('Packages/FileBrowser/dired.hidden-tmLanguage')
        view.set_scratch(True)

    nag = window.active_group()
    if other_group:
        group = 0 if other_group == 'left' else 1
        if window.num_groups() == 1:
            cols = [0.0, 0.3, 1.0] if other_group == 'left' else [0.0, 0.66, 1.0]
            window.set_layout({"cols": cols, "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]})
        elif view:
            groups = window.num_groups()
            if groups <= 4 and nag < 2:
                group = 1 if nag == 0 else 0
            elif groups == 4 and nag >= 2:
                group = 3 if nag == 2 else 2
            else:
                group = nag - 1
        window.set_view_index(view, group, 0)
    else:
        group = nag

    # when other_group is left, we need move all views to right except FB view
    if nag == 0 and other_group == 'left' and group == 0:
        for v in reversed(window.views_in_group(nag)[1:]):
            window.set_view_index(v, 1, 0)

    if other_group and prev_focus:
        window.focus_view(prev_focus)

    if path == os.sep:
        view_name = os.sep
    else:
        view_name = basename(path.rstrip(os.sep))

    if ST3:
        name = u"𝌆 {0}".format(view_name)
    else:
        name = u"■ {0}".format(view_name)

    view.set_name(name)
    view.settings().set('dired_path', path)
    view.settings().set('dired_rename_mode', False)
    window.focus_view(view)
    view.run_command('dired_refresh', { 'goto': goto })
Ejemplo n.º 10
0
 def get(self, xpath):
     """Return the first result from this XPath selection
     """
     results = self._xpath(self.parse(xpath), self.html, limit=1)
     return common.first(results)
Ejemplo n.º 11
0
def get(*args, **kwargs):
    """Return first element from search
    """
    return common.first(search(*args, **kwargs))
Ejemplo n.º 12
0
 def get(self, xpath):
     """Return the first result from this XPath selection
     """
     results = self._xpath(self.parse(xpath), self.html, limit=1)
     return common.first(results)
Ejemplo n.º 13
0
from common import transpose, first, groupby, cat
import unittest

if __name__ == '__main__':

    assert tuple(transpose(((1, 2, 3), (4, 5, 6)))) == ((1, 4), (2, 5), (3, 6))
    assert first('abc') == first(['a', 'b', 'c']) == 'a'
    assert cat(['a', 'b', 'c']) == 'abc'
    assert (groupby(['test', 'one', 'two', 'three', 'four'], key=len) == {
        3: ['one', 'two'],
        4: ['test', 'four'],
        5: ['three']
    })
    unittest.main()