コード例 #1
0
    def test_file_extension(self):
        other = NamedSettingsDict(self.name + '.sublime-settings')

        self.fancy.pop("example_setting", None)
        self.assertNotIn("example_setting", self.fancy)
        self.fancy["example_setting"] = "Hello, World!"
        self.assertEquals(other['example_setting'], 'Hello, World!')
コード例 #2
0
    def run(self):
        settings = NamedSettingsDict('Syntax Selector')

        view = self.window.active_view()
        current_syntax_path = view.settings().get('syntax')

        syntaxes = [
            s for s in list_syntaxes()
            if settings['show_hidden_syntaxes'] or not s.hidden
        ]

        selected = next((s for s in syntaxes if s.path == current_syntax_path),
                        NO_SELECTION)

        def change_syntax(s):
            view.assign_syntax(s.path)

        if settings['preview_on_highlight']:
            on_cancel = partial(view.assign_syntax, current_syntax_path)
            on_highlight = change_syntax
        else:
            on_cancel = None
            on_highlight = None

        show_selection_panel(
            self.window,
            syntaxes,
            selected=selected,
            labels=lambda s: (s.name or '', s.path),
            on_select=change_syntax,
            on_cancel=on_cancel,
            on_highlight=on_highlight,
        )
コード例 #3
0
ファイル: linter.py プロジェクト: DigDug101/sublime-lsl
def plugin_loaded():

    try:
        from package_control import events
    except ImportError:
        pass
    else:
        pc_settings = NamedSettingsDict(PKGCTRL)
        sublinter_installed = bool(SUBLINTER in set(
            # FIXME: fix NoneType Error on startup
            pc_settings.get('installed_packages', [])))
        if events.install(PKG_NAME) and not sublinter_installed:
            if sublime.ok_cancel_dialog(
                    '"{}" requires "{}", would you like to install it now?'.
                    format(PKG_NAME, SUBLINTER)):
                # TODO: if sublime.ok_cancel_dialog(f'"{PKG_NAME}" requires "{SUBLINTER}", would you like to install it now?'):
                sublime.run_command('advanced_install_package',
                                    {'packages': SUBLINTER})
コード例 #4
0
    def test_named(self):
        other = NamedSettingsDict(self.name)

        self.fancy.pop("example_setting", None)
        self.assertNotIn("example_setting", self.fancy)
        self.fancy["example_setting"] = "Hello, World!"

        self.assertIn("example_setting", self.fancy)
        self.assertIn("example_setting", other)

        self.fancy.save()

        yield

        self.assertTrue(path.exists(self.settings_path))
コード例 #5
0
ファイル: storage.py プロジェクト: sublime-china/sublime-666
class StorageSetting(Storage):
    def __init__(self, name):
        super(StorageSetting, self).__init__(name)
        self._dict = NamedSettingsDict(name)

    def save(self):
        self._dict.save()

    def clear(self):
        self._dict.update({})
        self._dict.save()
コード例 #6
0
def plugin_loaded():
    global settings, current_highlight_color, INITIAL_HIGHLIGHT_COLOR

    # A settings layer that handled settings that included `trailing_spaces_` prefix (now deprecated).
    class DeprecatedSettingsDict(NamedSettingsDict):
        def __getitem__(self, key):
            return super().__getitem__('trailing_spaces_%s' % key)

    deprecated_settings = DeprecatedSettingsDict(SETTINGS_FILENAME)
    settings = ChainMap(deprecated_settings,
                        NamedSettingsDict(SETTINGS_FILENAME), DEFAULT_SETTINGS)

    current_highlight_color = settings['highlight_color']
    INITIAL_HIGHLIGHT_COLOR = current_highlight_color

    if not settings['enabled']:
        current_highlight_color = ""
        if settings['highlight_color'] != current_highlight_color:
            settings[0].save()
コード例 #7
0
class TestNamedSettingsDict(DeferrableTestCase):
    def setUp(self):
        self.name = "_sublime_lib_NamedSettingsDictTest"
        self.fancy = NamedSettingsDict(self.name)
        self.settings_path = path.join(sublime.packages_path(), 'User', self.fancy.file_name)

    def tearDown(self):
        try:
            os.remove(self.settings_path)
        except FileNotFoundError:
            pass

    def test_named(self):
        other = NamedSettingsDict(self.name)

        self.fancy.pop("example_setting", None)
        self.assertNotIn("example_setting", self.fancy)
        self.fancy["example_setting"] = "Hello, World!"

        self.assertIn("example_setting", self.fancy)
        self.assertIn("example_setting", other)

        self.fancy.save()

        yield

        self.assertTrue(path.exists(self.settings_path))

    def test_file_extension(self):
        other = NamedSettingsDict(self.name + '.sublime-settings')

        self.fancy.pop("example_setting", None)
        self.assertNotIn("example_setting", self.fancy)
        self.fancy["example_setting"] = "Hello, World!"
        self.assertEquals(other['example_setting'], 'Hello, World!')

    def test_equal(self):
        other = NamedSettingsDict(self.name + '.sublime-settings')
        self.assertEqual(self.fancy, other)

    def test_not_equal(self):
        other = NamedSettingsDict('Preferences.sublime-settings')
        self.assertNotEqual(self.fancy, other)

    def test_not_equal_unnamed(self):
        other = SettingsDict(self.fancy.settings)
        self.assertNotEqual(self.fancy, other)
        self.assertNotEqual(other, self.fancy)
コード例 #8
0
def get_settings():
    global SETTINGS
    if SETTINGS is None:
        SETTINGS = NamedSettingsDict('JS Custom')
    return SETTINGS
コード例 #9
0
ファイル: storage.py プロジェクト: sublime-china/sublime-666
 def __init__(self, name):
     super(StorageSetting, self).__init__(name)
     self._dict = NamedSettingsDict(name)
コード例 #10
0
def plugin_loaded():
    global SETTINGS
    SETTINGS = NamedSettingsDict("SublimeTemplate")
コード例 #11
0
 def test_not_equal(self):
     other = NamedSettingsDict('Preferences.sublime-settings')
     self.assertNotEqual(self.fancy, other)
コード例 #12
0
 def test_equal(self):
     other = NamedSettingsDict(self.name + '.sublime-settings')
     self.assertEqual(self.fancy, other)
コード例 #13
0
 def setUp(self):
     self.name = "_sublime_lib_NamedSettingsDictTest"
     self.fancy = NamedSettingsDict(self.name)
     self.settings_path = path.join(sublime.packages_path(), 'User', self.fancy.file_name)