-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrefreshcommands.py
101 lines (79 loc) · 3.45 KB
/
refreshcommands.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import getpass
import os.path
import sublime
import sublime_plugin
import rainmeter
class RainmeterRefreshConfigCommand(sublime_plugin.ApplicationCommand):
"""Refresh a given skin file, or Rainmeter if no path is specified"""
def run(self, cmd):
# Get Rainmeter exe path
rainmeter_exe = rainmeter.program_path()
if not rainmeter_exe:
sublime.error_message(
"Error while trying to refresh Rainmeter" +
" skin: The Rainmeter executable could not be found." +
" Please check the value of your \"rainmeter_path\"" +
" setting.")
return
rainmeter_exe = os.path.join(rainmeter_exe, "Rainmeter.exe")
# Refresh skin (or whole rainmeter if no skin specified)
if not cmd:
sublime.status_message("Refreshing Rainmeter")
sublime.active_window().run_command("exec",
{"cmd": [rainmeter_exe, "!RefreshApp"]})
else:
config = rainmeter.get_current_config(cmd[0])
fil = rainmeter.get_current_file(cmd[0])
if not fil:
fil = ""
if not config:
sublime.error_message(
"Error while trying to refresh Rainmeter skin:" +
" The config could not be found. Please check the" +
" path of the config and your" +
" \"rainmeter_skins_path\" setting.")
sublime.status_message("Refreshing config: " + config)
# Load activate setting
settings = sublime.load_settings("Rainmeter.sublime-settings")
activate = settings.get("rainmeter_refresh_and_activate", True)
if activate:
sublime.active_window().run_command(
"exec",
{
"cmd": [
rainmeter_exe,
"!ActivateConfig",
config,
fil,
"&&",
rainmeter_exe,
"!Refresh",
config
],
"shell": True
})
else:
sublime.active_window().run_command(
"exec",
{"cmd": [rainmeter_exe, "!Refresh", config]})
def description(self):
return "Refresh Rainmeter Config"
class RainmeterRefreshCommand(sublime_plugin.ApplicationCommand):
"""Refresh Rainmeter"""
def run(self):
sublime.run_command("rainmeter_refresh_config", {"cmd": []})
class RainmeterRefreshCurrentSkinCommand(sublime_plugin.TextCommand):
"""Refresh the current skin file opened in a view"""
def run(self, edit):
# Get current file's path
filepath = self.view.file_name()
if not filepath: return
# Refresh config
sublime.run_command("rainmeter_refresh_config", {"cmd": [filepath]})
def is_enabled(self):
# Check if current syntax is rainmeter
israinmeter = self.view.score_selector(self.view.sel()[0].a,
"source.rainmeter")
return israinmeter > 0
def description(self):
return "Refresh Current Rainmeter Skin"