Skip to content

Commit

Permalink
Fix #37: add uninstall command
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Lopker committed Aug 7, 2017
1 parent aabbead commit a9672ca
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Default.sublime-commands
Expand Up @@ -4,7 +4,11 @@
"command": "install_theme"
},
{
"caption": "Colorsublime: Browse Themes",
"caption": "Colorsublime: Uninstall Theme",
"command": "uninstall_theme"
},
{
"caption": "Colorsublime: Browse Themes Online",
"command": "browse"
}
]
4 changes: 4 additions & 0 deletions Makefile
@@ -1 +1,5 @@
all: touch colorsublime-plugin.py

# for development
sync:
cp -r ./* "/Users/blopker/Library/Application Support/Sublime Text 3/Packages/Colorsublime/"
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -43,6 +43,7 @@ Functions
---------
* Install: Installs/Previews themes ("color schemes") from the Colorsublime repository.
* Browse: Takes you to https://colorsublime.github.io/
* Uninstall: Removes themes from the installed theme directory. Does not change your current theme.

Windows Proxy Support
---------------------
Expand Down
21 changes: 20 additions & 1 deletion colorsublime-plugin.py
Expand Up @@ -5,6 +5,7 @@

from .colorsublime import commands
from .colorsublime import status
from .colorsublime import logger

NO_SELECTION = -1

Expand All @@ -15,10 +16,12 @@
from .colorsublime import reloader
reloader.reload()

log = logger.get(__name__)


class InstallThemeCommand(sublime_plugin.WindowCommand):
def run(self):
print('Running install command.')
log.info('Running install command.')
self.theme_status = {}
self.status = status.loading('Getting Theme list')
commands.fetch_repo(self.display_list)
Expand Down Expand Up @@ -61,6 +64,22 @@ def _quick_list_to_theme(self, index):
return self.themes[self.quick_list[index][0]]


class UninstallThemeCommand(sublime_plugin.WindowCommand):
def run(self):
log.info('Running uninstall command.')
self.installed_themes = commands.get_installed_themes()
if not self.installed_themes:
status.message('No themes installed.')
return
quick_list = [[theme.name] for theme in self.installed_themes]
self.window.show_quick_panel(quick_list, self.uninstall)

def uninstall(self, index):
theme = self.installed_themes[index]
commands.uninstall_theme(theme)
log.info('Uninstalled theme %s' % theme.name)


class BrowseCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command('open_url', {'url': 'https://colorsublime.github.io/'})
2 changes: 1 addition & 1 deletion colorsublime/async.py
Expand Up @@ -4,8 +4,8 @@
import traceback
from .lib.concurrent import futures
from . import logger
log = logger.get(__name__)
from . import settings
log = logger.get(__name__)
asyncPool = futures.ThreadPoolExecutor(max_workers=10)


Expand Down
20 changes: 19 additions & 1 deletion colorsublime/commands.py
Expand Up @@ -11,18 +11,32 @@
import os

from . import logger
log = logger.get(__name__)
from . import settings
from . import http
from . import io
from .async import async
from .theme import Theme

log = logger.get(__name__)


def get_current_theme():
return settings.get_current_theme()


def get_installed_themes():
theme_filenames = os.listdir(settings.install_path())
themes = []

for t in theme_filenames:
if t.endswith('.tmTheme'):
name = t.replace('.tmTheme', '')
themes.append(Theme(name=name, file_name=t))

themes.sort()
return themes


@async
def fetch_repo():
""" Get current theme archive in a new thread """
Expand Down Expand Up @@ -64,3 +78,7 @@ def install_theme(theme):
def revert_theme(path):
log.debug('Reverting theme at path %s', path)
settings.set_theme(path)


def uninstall_theme(theme):
os.remove(theme.install_path.abs)
2 changes: 1 addition & 1 deletion colorsublime/logger.py
Expand Up @@ -37,6 +37,6 @@ def _out(self, level, *messages):


def get(name):
''' Get a new named logger. Usually called like: logger.get(__name__).Short
''' Get a new named logger. Usually called like: logger.get(__name__). Short
and sweet '''
return Logger(name)

0 comments on commit a9672ca

Please sign in to comment.