-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.py
98 lines (77 loc) · 2.66 KB
/
plugin.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
import sublime
import sublime_plugin
import os
import sys
# Append module directory on PYTHONPATH
sys.path.append(os.path.join(os.path.dirname(__file__), "modules"))
try:
from .modules import is_work_tree, get_active_project_path, GitRepo, status_manipulate
except ImportError:
# Failed to import at least one module.
# This can happen after upgrade due to internal structure changes.
sublime.message_dialog(
"GitStatus failed to reload some of its modules.\n"
"Please restart Sublime Text!")
class GitStatusCommand():
def __init__(self):
self.view = sublime.active_window().active_view()
self.my_repo = get_repo()
self.is_clean = status_manipulate(self.my_repo.get_git_status())[1] if self.my_repo else None
def run(self):
if self.my_repo:
# Clears the named status.
self.view.erase_status("info")
#The value will be displayed in the status bar, in a comma separated list of all status values, ordered by key.
if self.is_clean:
self.view.set_status("info", self.my_repo.branch + ": Clean")
else:
self.view.set_status("info", self.my_repo.branch + ": Dirty")
class SeeStatusCommand(sublime_plugin.WindowCommand):
# shortcuts
def run(self):
my_repo = get_repo()
if my_repo:
git_status_info = my_repo.get_git_status()
msg = status_manipulate(git_status_info)[0]
sublime.message_dialog(msg)
else:
sublime.message_dialog(
"GitStatus failed to load because this is not a git project!")
class StatusBarHandler(sublime_plugin.EventListener):
def check(self):
GitStatusCommand().run()
def on_activated_async(self, view):
# Called when a view gains input focus.
self.check()
# def on_clone_async(self, view):
# # Called when a view is cloned from an existing one.
# self.check()
# def on_load_async(self, view):
# # Called when the file is finished loading.
# self.check()
# def on_new_async(self, view):
# # Called when a new buffer is created.
# self.check()
def on_post_save_async(self, view):
# Called after a view has been saved.
self.check()
def get_repo():
# Init repo object
repo = None
path = os.path.normpath(get_active_project_path())
if is_work_tree(path):
repo = GitRepo(path)
return repo
def plugin_loaded():
# Show initital status
view = sublime.active_window().active_view()
my_repo = get_repo()
if my_repo:
is_clean = status_manipulate(my_repo.get_git_status())[1]
# Clears the named status.
view.erase_status("info")
#The value will be displayed in the status bar, in a comma separated list of all status values, ordered by key.
if is_clean:
view.set_status("info", my_repo.branch + ": Clean")
else:
view.set_status("info", my_repo.branch + ": Dirty")