Skip to content

Commit

Permalink
fix: Theme dependencies and add a new Info command
Browse files Browse the repository at this point in the history
  • Loading branch information
equinusocio committed Aug 2, 2016
1 parent e428177 commit dadd824
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
{
"caption": "Changelog",
"command": "mt_changes"
},
{
"caption": "Theme Info",
"command": "mt_info"
}
]
}
Expand Down
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
{
"caption": "Material Theme: Configuration",
"command": "mt_config"
},
{
"caption": "Material Theme: Info",
"command": "mt_info"
}
]
4 changes: 4 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
"caption": "Changelog",
"command": "mt_changes"
},
{
"caption": "Theme Info",
"command": "mt_info"
}
]

}
Expand Down
7 changes: 6 additions & 1 deletion changes.py → mt_changes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Changelog."""
import sublime
import sublime_plugin
import mdpopups

CSS = '''
.mt-config-changes { {{'.background'|css}} margin: 0; padding: 0; }
Expand All @@ -22,6 +21,7 @@ class MtChangesCommand(sublime_plugin.WindowCommand):

def run(self):
"""Show the changelog in a new view."""
import mdpopups
text = sublime.load_resource('Packages/Material Theme/CHANGELOG.md')
view = self.window.new_file()
view.set_name('Material Theme - Changelog')
Expand All @@ -33,6 +33,11 @@ def run(self):

def is_enabled(self):
"""Check if is enabled."""
try:
import mdpopups
except Exception:
return False

return (mdpopups.version() >= (1, 7, 3)) and (int(sublime.version()) >= 3118)

is_visible = is_enabled
6 changes: 5 additions & 1 deletion material_theme.py → mt_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"""Material Theme Config."""
import sublime
import sublime_plugin
import mdpopups
import os
import mdpopups
from collections import OrderedDict

OPTIONS = OrderedDict(
Expand Down Expand Up @@ -102,6 +102,10 @@ class MtConfigCommand(sublime_plugin.TextCommand):

def on_navigate(self, href):
"""Handle option selection."""
try:
import mdpopups
except Exception:
return False

if href == 'back':
self.show_popup('Main')
Expand Down
92 changes: 92 additions & 0 deletions mt_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""Support command."""
import sublime
import sublime_plugin
import textwrap

__version__ = "3.1.2"
__pc_name__ = 'Material Theme'


def list2string(obj):
"""Convert list to string."""

return '.'.join([str(x) for x in obj])


def format_version(module, attr, call=False):
"""Format the version."""

try:
if call:
version = getattr(module, attr)()
else:
version = getattr(module, attr)
except Exception as e:
print(e)
version = 'Version could not be acquired!'

if not isinstance(version, str):
version = list2string(version)
return version


def is_installed_by_package_control():
"""Check if installed by package control."""

settings = sublime.load_settings('Package Control.sublime-settings')
return str(__pc_name__ in set(settings.get('installed_packages', [])))


class MtInfoCommand(sublime_plugin.ApplicationCommand):
"""Support info."""

def run(self):
"""Run command."""

info = {}

info["platform"] = sublime.platform()
info["version"] = sublime.version()
info["arch"] = sublime.arch()
info["bh_version"] = __version__
info["pc_install"] = is_installed_by_package_control()
try:
import mdpopups
info["mdpopups_version"] = format_version(mdpopups, 'version', call=True)
except Exception:
info["mdpopups_version"] = 'Version could not be acquired!'

try:
import markdown
info["markdown_version"] = format_version(markdown, 'version')
except Exception:
info["markdown_version"] = 'Version could not be acquired!'

try:
import jinja2
info["jinja_version"] = format_version(jinja2, '__version__')
except Exception:
info["jinja_version"] = 'Version could not be acquired!'

try:
import pygments
info["pygments_version"] = format_version(pygments, '__version__')
except Exception:
info["pygments_version"] = 'Version could not be acquired!'

msg = textwrap.dedent(
"""\
• ST ver.: %(version)s
• Platform: %(platform)s
• Arch: %(arch)s
• Theme: %(bh_version)s
• Install via PC: %(pc_install)s
• mdpopups: %(mdpopups_version)s
• markdown: %(markdown_version)s
• pygments: %(pygments_version)s
• jinja2: %(jinja_version)s
""" % info
)

sublime.message_dialog(msg + '\nInfo has been copied to the clipboard.')
sublime.set_clipboard(msg)
File renamed without changes.

0 comments on commit dadd824

Please sign in to comment.