Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
{
"caption": "Colorsublime: Browse Themes Online",
"command": "browse"
},
{
"caption": "Colorsublime: Install Random Theme",
"command": "install_random"
}
]
30 changes: 27 additions & 3 deletions colorsublime-plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import imp
import sys
import random

import sublime_plugin

Expand All @@ -8,6 +9,7 @@
from .colorsublime import logger

NO_SELECTION = -1
CONN_ERR_MSG = 'Theme list not found. Please check internet connection or enable debug in settings and report the stack traces.'

# Make sure all dependencies are reloaded on upgrade
reloader_path = 'Colorsublime.colorsublime.reloader'
Expand All @@ -29,9 +31,7 @@ def run(self):
def display_list(self, themes):
self.status.stop()
if not themes:
status.error('Theme list not found. Please check internet ' +
'connection or enable debug in settings and ' +
'report the stack traces.')
status.error(CONN_ERR_MSG)
return

self.themes = themes
Expand Down Expand Up @@ -83,3 +83,27 @@ def uninstall(self, index):
class BrowseCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command('open_url', {'url': 'https://colorsublime.github.io/'})

class InstallRandomCommand(sublime_plugin.WindowCommand):
def run(self):
log.info('Running install random command')
self.theme_status = {}
self.status = status.loading('Getting Theme list')
commands.fetch_repo(self.pick_theme)
self.status.stop()

def pick_theme(self, themes):
if not themes:
status.error(CONN_ERR_MSG)
return

current_theme = commands.get_current_theme()
while True:
random_theme = random.choice( tuple(themes.values()) )
if current_theme != random_theme.cache_path.rel:
break

commands.install_theme(random_theme)
status.message('Theme %s installed!' % random_theme.name)
self.themes = themes