forked from thatsIch/sublime-rainmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open_skin_as_project.py
52 lines (38 loc) · 1.63 KB
/
open_skin_as_project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
This module is for the feature "Open Skin as Project".
This feature provides a command which lists all Rainmeter Skins
installed in the Rainmeter Skin folder and allows a quick panel
to open the skin in a new window.
This is done by creating a new sublime text instance using subprocesses.
"""
import os
import subprocess
import sublime
import sublime_plugin
from .path.skin_path_provider import get_cached_skin_path
def on_skin_selected(selected_skin_id):
"""
This is a callback upon user selecting a skin.
This can handle user canceling the input.
Upon selection a respective path is evaluated
and send to a new sublime text instance.
"""
if selected_skin_id == -1:
return
skins_path = get_cached_skin_path()
skins = os.listdir(skins_path)
selected_skin = skins[selected_skin_id]
selected_skin_path = os.path.join(skins_path, selected_skin)
# to open a folder in new window, just create a new process with the folder as argument
st_path = sublime.executable_path()
subprocess.Popen([
st_path,
selected_skin_path
])
class RainmeterOpenSkinAsProjectCommand(sublime_plugin.ApplicationCommand): # pylint: disable=R0903; only provide one method
"""You can execute this command via the sublime API like sublime.run_command("rainmeter_open_skin_as_project")."""
def run(self): # pylint: disable=R0201; we do not need the self instance
"""Automatically called upon calling the command."""
skins_path = get_cached_skin_path()
skins = os.listdir(skins_path)
sublime.active_window().show_quick_panel(skins, on_skin_selected, 0, 0, None)