Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added command to activate theme using command palette (#36)
* Added gruvbox_select command * Added GruvboxSelect class * Added .gruvbox entry
- Loading branch information
1 parent
314a4af
commit ff77d88
Showing
3 changed files
with
69 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
|
||
from .documentation import * | ||
from .support import * | ||
from .gruvbox import * | ||
|
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,62 @@ | ||
import math | ||
import sublime | ||
import sublime_plugin | ||
|
||
class GruvboxSelect(sublime_plugin.TextCommand): | ||
def run(self, action): | ||
color_schemes = sublime.find_resources("gruvbox*.tmTheme") | ||
color_themes = sublime.find_resources("gruvbox*.sublime-theme") | ||
|
||
temp_schemes = [] | ||
self.themes = [] | ||
self.schemes = [] | ||
|
||
for scheme in color_schemes: | ||
if 'Packages/gruvbox/' in scheme: | ||
temp_schemes.append(scheme[17:-8]) | ||
|
||
for i in range(len(temp_schemes)): | ||
if (i % 2) == 0: | ||
self.schemes.insert(i + 1, temp_schemes[i]) | ||
else: | ||
self.schemes.insert(i - 1, temp_schemes[i]) | ||
|
||
for theme in color_themes: | ||
if 'Packages/gruvbox/' in theme: | ||
self.themes.append(theme[17:]) | ||
|
||
self.show_panel() | ||
|
||
def show_panel(self): | ||
self.view.window().show_quick_panel(self.schemes, self.on_done, on_highlight=self.on_highlighted) | ||
|
||
def on_done(self, index): | ||
self.set_scheme('Packages/gruvbox/' + self.schemes[index] + '.tmTheme') | ||
self.set_theme(self.themes[self.find_index(index)]) | ||
self.save_settings(self.schemes[index]) | ||
|
||
def on_highlighted(self, index): | ||
self.set_scheme('Packages/gruvbox/' + self.schemes[index] + '.tmTheme') | ||
self.set_theme(self.themes[self.find_index(index)]) | ||
|
||
def find_index(self, index): | ||
if index == 0 or index == 1: | ||
return 0 | ||
else: | ||
return int(math.floor((index / 2))) | ||
|
||
def set_scheme(self, scheme): | ||
self.get_settings().set('color_scheme', scheme) | ||
|
||
def set_theme(self, theme): | ||
self.get_settings().set('theme', theme) | ||
|
||
def get_settings(self): | ||
return sublime.load_settings('Preferences.sublime-settings') | ||
|
||
def save_settings(self, theme): | ||
sublime.save_settings('Preferences.sublime-settings') | ||
sublime.status_message('gruvbox: ' + theme) | ||
print('') | ||
print('[gruvbox] ' + theme) | ||
print('') |