I’ve just moved the following commands from my sublimefiles to my polyfill package which is available from Package Control.
- Enable Theme
- Enable Color Scheme
The color scheme includes a preview, I opted against a preview for themes because Sublime doesn’t handle that very well. The color scheme preview is fast, and the commands are as simple as possible, no bloat, no nonsense. They can be added as custom commands if you don’t want to install a package.
Also, with polyfill, you can navigate the overlay with ctr+j
and ctrl+k
. Try it when previewing color schemes.
Enable Theme
User/Default.sublime-commands
:
{
{
"caption": "Application: Enable Theme",
"command": "enable_theme"
}
}
User/enable_theme.py
import sublime
import sublime_plugin
import os
class EnableThemeCommand(sublime_plugin.ApplicationCommand):
def run(self):
self.themes = []
for theme in sublime.find_resources('*.sublime-theme'):
if "Addon" not in theme:
self.themes.append(os.path.basename(theme))
if len(self.themes) > 0:
sublime.active_window().show_quick_panel(self.themes, self.on_done)
def on_done(self, index):
if index == -1:
return
theme = self.themes[index]
settings = sublime.load_settings('Preferences.sublime-settings')
settings.set('theme', theme)
sublime.save_settings('Preferences.sublime-settings')
Enable color Scheme
Includes preview!
User/Default.sublime-commands
:
{
{
"caption": "Application: Enabe Color Scheme",
"command": "enable_color_scheme"
}
}
User/enable_color_scheme.py
import sublime
import sublime_plugin
import os
class EnableColorSchemeCommand(sublime_plugin.ApplicationCommand):
def run(self):
self.color_schemes = []
for color_scheme in sublime.find_resources('*.tmTheme'):
if "(SL)" not in color_scheme:
self.color_schemes.append(color_scheme)
if len(self.color_schemes) > 1:
color_scheme = sublime.load_settings('Preferences.sublime-settings').get('color_scheme')
if color_scheme not in self.color_schemes:
self.color_schemes.insert(0, color_scheme)
self.window = sublime.active_window()
self.window.show_quick_panel(
self.color_schemes,
self.on_done,
0,
self.color_schemes.index(color_scheme),
self.on_select
)
def on_select(self, index):
if index == -1:
return
color_scheme = self.color_schemes[index]
for group in range(0, self.window.num_groups()):
active_view_in_group = self.window.active_view_in_group(group)
if active_view_in_group:
active_view_in_group.settings().set('color_scheme', color_scheme)
def on_done(self, index):
for view in self.window.views():
view.settings().erase('color_scheme')
if index == -1:
return
color_scheme = self.color_schemes[index]
settings = sublime.load_settings('Preferences.sublime-settings')
settings.set('color_scheme', color_scheme)
sublime.save_settings('Preferences.sublime-settings')