-
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.
feat: New theme configurator popup and menu
Add a new theme configurator pop that allow the activation and the customization through the context menu and the Tools > Material Theme menu. More info here: https://github.com/equinusocio/material-theme#activate-the-theme
- Loading branch information
1 parent
4782eef
commit 2a9599e
Showing
7 changed files
with
346 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
{ | ||
"caption": "Material Theme", | ||
"children": | ||
[ | ||
{ | ||
"caption": "Material Theme Config", | ||
"command": "mt_config" | ||
}, | ||
{ "caption": "-" }, | ||
{ | ||
"caption": "GitHub Repository", | ||
"command": "mt_repo" | ||
}, | ||
{ | ||
"caption": "GitHub Issues", | ||
"command": "mt_issues" | ||
}, | ||
{ "caption": "-" }, | ||
{ | ||
"caption": "Changelog", | ||
"command": "mt_changes" | ||
} | ||
] | ||
} | ||
] |
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,6 @@ | ||
[ | ||
{ | ||
"caption": "Material Theme: Configuration", | ||
"command": "mt_config" | ||
} | ||
] |
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,34 @@ | ||
[ | ||
{ | ||
"id": "tools", | ||
"children": | ||
[ | ||
{ | ||
|
||
"caption": "Material Theme", | ||
"children": | ||
[ | ||
{ | ||
"caption": "Material Theme Config", | ||
"command": "mt_config" | ||
}, | ||
{ "caption": "-" }, | ||
{ | ||
"caption": "GitHub Repository", | ||
"command": "mt_repo" | ||
}, | ||
{ | ||
"caption": "GitHub Issues", | ||
"command": "mt_issues" | ||
}, | ||
{ "caption": "-" }, | ||
{ | ||
"caption": "Changelog", | ||
"command": "mt_changes" | ||
}, | ||
] | ||
|
||
} | ||
] | ||
} | ||
] |
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,24 @@ | ||
"""Changelog.""" | ||
import sublime | ||
import sublime_plugin | ||
import mdpopups | ||
|
||
|
||
class MtChangesCommand(sublime_plugin.WindowCommand): | ||
"""Changelog command.""" | ||
|
||
def run(self): | ||
"""Show the changelog in a new view.""" | ||
text = sublime.load_resource('Packages/Material Theme/CHANGELOG.md') | ||
view = self.window.new_file() | ||
view.set_name('Material Theme - Changlog') | ||
view.settings().set('gutter', False) | ||
mdpopups.add_phantom(view, 'chagelog', sublime.Region(0), text, sublime.LAYOUT_INLINE) | ||
view.set_read_only(True) | ||
view.set_scratch(True) | ||
|
||
def is_enabled(self): | ||
"""Check if is enabled.""" | ||
return (mdpopups.version() >= (1, 7, 3)) and (int(sublime.version()) >= 3118) | ||
|
||
is_visible = is_enabled |
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,25 @@ | ||
{ | ||
// BE SURE TO REMOVE THESE COMMENTS BEFORE USING THIS TEMPLATE SINCE | ||
// COMMENTS ARE NOT ALLOWED IN JSON | ||
|
||
// This file is a filesystem-level solution for specifying dependencies | ||
// for packages. This is most useful for package developers since they are | ||
// not installing their own packages from a repository or channel, and | ||
// need to make sure Package Control installs the dependencies they need. | ||
|
||
// The file contains two levels of selectors, platform and Sublime Text | ||
// version, to pick what set of dependencies should be installed. | ||
// The most-specific selectors will be used, and all other ignored. This | ||
// means that some dependencies will be duplicated under a specific | ||
// platform and under *. | ||
|
||
|
||
// Matching of platform and version selectors is exclusive. Thus, these | ||
// dependencies will only be installed if no other keys matched first. | ||
"*": { | ||
">=3080": [ | ||
"mdpopups", | ||
"webbrowser" | ||
] | ||
} | ||
} |
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,211 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Material Theme Config.""" | ||
import sublime | ||
import sublime_plugin | ||
import mdpopups | ||
import os | ||
from collections import OrderedDict | ||
|
||
OPTIONS = OrderedDict( | ||
( | ||
( | ||
"Accent", | ||
[ | ||
"material_theme_accent_lime", | ||
"material_theme_accent_purple", | ||
"material_theme_accent_red", | ||
"material_theme_accent_orange", | ||
"material_theme_accent_yellow", | ||
"material_theme_accent_indigo", | ||
"material_theme_accent_pink", | ||
"material_theme_accent_blue", | ||
"material_theme_accent_cyan" | ||
], | ||
), | ||
( | ||
"Tabs", | ||
[ | ||
"material_theme_tabs_autowidth", | ||
"material_theme_tabs_separator", | ||
"material_theme_bold_tab", | ||
"material_theme_small_tab" | ||
], | ||
), | ||
( | ||
"Sidebar", | ||
[ | ||
"material_theme_disable_fileicons", | ||
"material_theme_disable_folder_animation", | ||
"material_theme_compact_sidebar", | ||
"material_theme_disable_tree_indicator", | ||
"material_theme_tree_headings" | ||
], | ||
), | ||
( | ||
"Panels", | ||
[ | ||
"material_theme_compact_panel", | ||
"material_theme_small_statusbar", | ||
"material_theme_panel_separator", | ||
"material_theme_contrast_mode" | ||
], | ||
) | ||
) | ||
) | ||
|
||
|
||
|
||
BACK = '[❮ BACK](back){: .mt-config .ui-backlink }' | ||
SECTIONS = '[• %(section)s](::%(section)s){: .mt-config .ui-control }\n' | ||
SECTION_LABEL = '\n\n## Material Theme - %s\n\n' | ||
SECTIONS_LABEL = '\n\n## Config - Material Theme\n\n' | ||
GENERAL_SETTING = '''[**%(status)s**{: .mt-config %(class)s} %(name)s](%(name)s:%(set)s:%(section)s)\ | ||
{: .mt-config .ui-control }\n''' | ||
SCHEME = '''[**%(status)s**{: .mt-config %(class)s} %(name)s](color_scheme:%(set)s:%(section)s)\ | ||
{: .mt-config .ui-control }\n''' | ||
THEME_LABEL = '\n\n## Themes - Material Theme\n\n' | ||
SCHEME_LABEL = '\n\n## Schemes - Material Theme\n\n' | ||
OTHER_SCHEME = '''[**%(status)s**{: .mt-config .ui-control %(class)s} Other: %(name)s]\ | ||
(color_scheme:%(set)s:%(section)s){: .mt-config .ui-control }\n''' | ||
THEME = '''[**%(status)s**{: .mt-config .ui-control %(class)s} %(name)s](theme:%(set)s:%(section)s)\ | ||
{: .mt-config .ui-control }\n''' | ||
OTHER_THEME = '''[**%(status)s**{: .mt-config .ui-control %(class)s} Other: %(name)s](theme:%(set)s:%(section)s)\ | ||
{: .mt-config .ui-control }\n''' | ||
MARKED = "☑︎" | ||
UNMARKED = "☐" | ||
RADIO_MARKED = "•" | ||
RADIO_UNMARKED = "•" | ||
css = """\ | ||
p { padding: 4px 16px; } | ||
h1, h2, h3, h4, h5, h6 { padding: 0 16px; margin: 8px 16px 8px 0; } | ||
.mt-config.small { font-size: {{'*.8px'|relativesize}}; } | ||
.mt-config.ui-control { text-decoration: none; } | ||
.mt-config.ui-backlink { text-decoration: none; padding: 4px 0; } | ||
""" | ||
|
||
|
||
def is_mt_res(item): | ||
"""Check if a boxy resource.""" | ||
|
||
return item.startswith('Packages/Material Theme/') | ||
|
||
|
||
class MtConfigCommand(sublime_plugin.TextCommand): | ||
"""Material Theme Configuration.""" | ||
|
||
def on_navigate(self, href): | ||
"""Handle option selection.""" | ||
|
||
if href == 'back': | ||
self.show_popup('Main') | ||
else: | ||
settings = sublime.load_settings('Preferences.sublime-settings') | ||
name, value, section = href.split(':') | ||
if name: | ||
if name not in ('theme', 'color_scheme'): | ||
boolean = True if value == 'True' else False | ||
if boolean: | ||
settings.set(name, boolean) | ||
else: | ||
settings.erase(name) | ||
else: | ||
settings.set(name, value) | ||
sublime.save_settings('Preferences.sublime-settings') | ||
|
||
self.show_popup(section) | ||
|
||
def show_popup(self, menu): | ||
"""Show config popup.""" | ||
|
||
settings = sublime.load_settings('Preferences.sublime-settings') | ||
popup = [] | ||
if menu != 'Main': | ||
popup = [BACK] | ||
|
||
if menu == 'Main': | ||
popup.append(SECTIONS_LABEL) | ||
for k in ['Theme', 'Color Scheme'] + list(OPTIONS.keys()): | ||
popup.append(SECTIONS % {"section": k}) | ||
elif menu == 'Theme': | ||
theme = settings.get('theme', '') | ||
mt_themes = [ | ||
os.path.basename(bt) for bt in sorted(sublime.find_resources('Material-Theme*.sublime-theme')) if is_mt_res(bt) | ||
] | ||
popup.append(THEME_LABEL) | ||
for option in mt_themes: | ||
option_value = theme == option | ||
popup.append( | ||
THEME % { | ||
"name": option, | ||
"status": RADIO_MARKED if option_value else RADIO_UNMARKED, | ||
"set": option, | ||
"class": '.success' if option_value else '.error', | ||
'section': "Theme" | ||
} | ||
) | ||
if theme is not None and theme not in mt_themes: | ||
popup.append( | ||
OTHER_THEME % { | ||
"name": theme, | ||
"status": RADIO_MARKED, | ||
"set": option, | ||
"class": '.success' if option_value else '.error', | ||
'section': "Theme" | ||
} | ||
) | ||
elif menu == 'Color Scheme': | ||
scheme = settings.get('color_scheme', '') | ||
mt_schemes = [ | ||
bs for bs in sorted(sublime.find_resources('Material-Theme*.tmTheme')) if is_mt_res(bs) | ||
] | ||
popup.append(SCHEME_LABEL) | ||
for option in mt_schemes: | ||
option_value = scheme == option | ||
scheme_name = option[32:].replace('/', ' ⚠️ ') | ||
popup.append( | ||
SCHEME % { | ||
"name": scheme_name, | ||
"status": RADIO_MARKED if option_value else RADIO_UNMARKED, | ||
"set": option, | ||
"class": '.success' if option_value else '.error', | ||
"section": 'Color Scheme' | ||
} | ||
) | ||
if scheme is not None and scheme not in mt_schemes: | ||
popup.append( | ||
OTHER_SCHEME % { | ||
"name": scheme, | ||
"status": RADIO_MARKED, | ||
"set": option, | ||
"class": '.success', | ||
"section": 'Color Scheme' | ||
} | ||
) | ||
else: | ||
popup.append(SECTION_LABEL % menu) | ||
for option in OPTIONS[menu]: | ||
option_value = bool(settings.get(option, False)) | ||
popup.append( | ||
GENERAL_SETTING % { | ||
"name": option, | ||
"status": MARKED if option_value else UNMARKED, | ||
"set": str(not option_value), | ||
"class": '.success' if option_value else '.error', | ||
"section": menu | ||
} | ||
) | ||
|
||
mdpopups.hide_popup(self.view) | ||
mdpopups.show_popup( | ||
self.view, | ||
''.join(popup), | ||
css=css, | ||
on_navigate=self.on_navigate, | ||
max_width=1024, | ||
max_height=1024 | ||
) | ||
|
||
def run(self, edit): | ||
"""Run Command.""" | ||
|
||
self.show_popup('Main') |
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,20 @@ | ||
"""Changelog.""" | ||
import sublime | ||
import sublime_plugin | ||
import webbrowser | ||
|
||
|
||
class MtRepoCommand(sublime_plugin.WindowCommand): | ||
"""Changelog command.""" | ||
|
||
def run(self): | ||
"""Show the changelog in a new view.""" | ||
webbrowser.open_new_tab('https://github.com/equinusocio/material-theme') | ||
|
||
|
||
class MtIssuesCommand(sublime_plugin.WindowCommand): | ||
"""Changelog command.""" | ||
|
||
def run(self): | ||
"""Show the changelog in a new view.""" | ||
webbrowser.open_new_tab('https://github.com/equinusocio/material-theme/issues') |