-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tips.py
86 lines (60 loc) · 2.33 KB
/
Tips.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
from os import path
import sublime
import sublime_plugin
import random
import re
from typing import List
def plugin_loaded():
platform = sublime.platform()
if platform == "windows":
tips = "tips (Windows).txt"
if platform == "linux":
tips = "tips (Linux).txt"
if platform == "osx":
tips = "tips (OSX).txt"
tips = sublime.load_resource(path.join("Packages", "Tips", tips))
Tips.tips = tips.splitlines()
sublime.set_timeout_async(autostart)
def autostart():
settings = sublime.load_settings('Tips.sublime-settings')
if settings["show_random_tips_on_start"] is False:
return
cache: List[str] = [random.choice(Tips.tips).strip()]
index: int = 0
while True:
msg = cache[index]
msg = msg.replace(': ', ':\n')
result: sublime.DialogResult = sublime.yes_no_cancel_dialog(
msg=msg, yes_title='Next Tip', no_title='Previous Tip', title='Random Tip 💡'
)
if result == sublime.DialogResult.CANCEL:
break
if result == sublime.DialogResult.YES:
cache.append(random.choice(Tips.tips).strip())
index += 1
elif index > 0:
index -= 1
def clear_status_tip(view: sublime.View):
view.erase_status("tips_status_bar_msg")
class Tips(sublime_plugin.EventListener):
tips = []
def on_activated_async(self, view):
if len(self.tips) <= 0:
return
random.shuffle(self.tips)
tip = self.tips[0].strip()
settings = sublime.load_settings('Tips.sublime-settings')
msgFormat = str(settings.get("message_format", "💡 {tip}"))
hideDelay = settings.get("display_seconds", 60)
hideDelay = int(str(hideDelay)) * 1000
view.set_status("tips_status_bar_msg", msgFormat.format(tip=tip))
if hideDelay > 0:
sublime.set_timeout_async(lambda v=view: clear_status_tip(v), hideDelay)
class TipsToggleAutostartCommand(sublime_plugin.WindowCommand):
def run(self):
settings = sublime.load_settings('Tips.sublime-settings')
settings.set("show_random_tips_on_start", not settings["show_random_tips_on_start"]);
sublime.save_settings('Tips.sublime-settings')
class TipsShowRandomCommand(sublime_plugin.WindowCommand):
def run(self):
sublime.set_timeout_async(autostart)