-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
You can now activate the theme through the command palette and menu
- Loading branch information
1 parent
c1fd2e8
commit 9d0c61a
Showing
4 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Material Theme Activation | ||
""" | ||
|
||
import sublime | ||
import sublime_plugin | ||
import functools | ||
|
||
NO_SELECTION = -1 | ||
PREFERENCES = 'Preferences.sublime-settings' | ||
THEMES = [ | ||
'Material-Theme', | ||
'Material-Theme-Darker', | ||
'Material-Theme-Lighter' | ||
] | ||
|
||
def get_color_scheme(): | ||
return sublime.load_settings(PREFERENCES).get('color_scheme', '') | ||
|
||
def set_color_scheme(path): | ||
return sublime.load_settings(PREFERENCES).set('color_scheme', path) | ||
|
||
def preview_color_scheme(path): | ||
set_color_scheme(path) | ||
|
||
def activate_color_scheme(path): | ||
set_color_scheme(path) | ||
commit() | ||
|
||
def revert_color_scheme(path): | ||
set_color_scheme(path) | ||
|
||
def get_ui_theme(): | ||
return sublime.load_settings(PREFERENCES).get('theme', '') | ||
|
||
def set_ui_theme(path): | ||
return sublime.load_settings(PREFERENCES).set('theme', path) | ||
|
||
def preview_ui_theme(path): | ||
set_ui_theme(path) | ||
|
||
def activate_ui_theme(path): | ||
set_ui_theme(path) | ||
commit() | ||
|
||
def revert_ui_theme(path): | ||
set_ui_theme(path) | ||
|
||
def commit(): | ||
return sublime.save_settings(PREFERENCES) | ||
|
||
class MtActivateCommand(sublime_plugin.WindowCommand): | ||
|
||
def display_list(self, themes): | ||
self.themes = themes | ||
self.initial_color_scheme = get_color_scheme() | ||
self.initial_ui_theme = get_ui_theme() | ||
|
||
quick_list = [theme for theme in self.themes] | ||
self.quick_list = quick_list | ||
|
||
self.window.show_quick_panel(quick_list, self.on_done, on_highlight=self.on_highlighted) | ||
|
||
if self.initial_ui_theme.startswith('Material Theme') is False: | ||
sublime.set_timeout_async(functools.partial(self.window.run_command, 'insert', args = {'characters': 'Material Theme'}), 100) | ||
|
||
def on_highlighted(self, index): | ||
preview_color_scheme(self._quick_list_to_scheme(index)) | ||
preview_ui_theme(self._quick_list_to_theme(index)) | ||
|
||
def on_done(self, index): | ||
if index is NO_SELECTION: | ||
revert_color_scheme(self.initial_color_scheme) | ||
revert_ui_theme(self.initial_ui_theme) | ||
return | ||
|
||
color_scheme = self._quick_list_to_scheme(index) | ||
activate_color_scheme(color_scheme) | ||
|
||
ui_theme = self._quick_list_to_theme(index) | ||
activate_ui_theme(ui_theme) | ||
|
||
def _quick_list_to_scheme(self, index): | ||
return 'Packages/Material Theme/schemes/%s.tmTheme' % self.quick_list[index] | ||
|
||
def _quick_list_to_theme(self, index): | ||
return '%s.sublime-theme' % self.quick_list[index] | ||
|
||
def run(self): | ||
self.display_list(THEMES) |