forked from jisaacks/GitGutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_collection.py
More file actions
129 lines (107 loc) · 3.7 KB
/
view_collection.py
File metadata and controls
129 lines (107 loc) · 3.7 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import os
import sublime
import tempfile
import time
class ViewCollection:
views = {} # Todo: these aren't really views but handlers. Refactor/Rename.
git_times = {}
git_files = {}
buf_files = {}
compare_against = "HEAD"
@staticmethod
def add(view):
key = ViewCollection.get_key(view)
try:
from .git_gutter_handler import GitGutterHandler
except (ImportError, ValueError):
from git_gutter_handler import GitGutterHandler
handler = ViewCollection.views[key] = GitGutterHandler(view)
handler.reset()
return handler
@staticmethod
def git_path(view):
key = ViewCollection.get_key(view)
if key in ViewCollection.views:
return ViewCollection.views[key].get_git_path()
else:
return False
@staticmethod
def get_key(view):
return view.file_name()
@staticmethod
def has_view(view):
key = ViewCollection.get_key(view)
return key in ViewCollection.views
@staticmethod
def get_handler(view):
if ViewCollection.has_view(view):
key = ViewCollection.get_key(view)
return ViewCollection.views[key]
else:
return ViewCollection.add(view)
@staticmethod
def diff(view):
return ViewCollection.get_handler(view).diff()
@staticmethod
def untracked(view):
return ViewCollection.get_handler(view).untracked()
@staticmethod
def ignored(view):
return ViewCollection.get_handler(view).ignored()
@staticmethod
def total_lines(view):
return ViewCollection.get_handler(view).total_lines()
@staticmethod
def git_time(view):
key = ViewCollection.get_key(view)
if not key in ViewCollection.git_times:
ViewCollection.git_times[key] = 0
return time.time() - ViewCollection.git_times[key]
@staticmethod
def clear_git_time(view):
key = ViewCollection.get_key(view)
ViewCollection.git_times[key] = 0
@staticmethod
def update_git_time(view):
key = ViewCollection.get_key(view)
ViewCollection.git_times[key] = time.time()
@staticmethod
def tmp_file():
'''
Create a temp file and return the filepath to it.
Caller is responsible for clean up
'''
fd, filepath = tempfile.mkstemp(prefix='git_gutter_')
os.close(fd)
return filepath
@staticmethod
def git_tmp_file(view):
key = ViewCollection.get_key(view)
if not key in ViewCollection.git_files:
ViewCollection.git_files[key] = ViewCollection.tmp_file()
return ViewCollection.git_files[key]
@staticmethod
def buf_tmp_file(view):
key = ViewCollection.get_key(view)
if not key in ViewCollection.buf_files:
ViewCollection.buf_files[key] = ViewCollection.tmp_file()
return ViewCollection.buf_files[key]
@staticmethod
def set_compare(commit):
print("GitGutter now comparing against:",commit)
ViewCollection.compare_against = commit
@staticmethod
def get_compare(view):
compare = ViewCollection.compare_against or "HEAD"
return view.settings().get('git_gutter_compare_against', compare)
@staticmethod
def current_branch(view):
key = ViewCollection.get_key(view)
return ViewCollection.views[key].git_current_branch()
@staticmethod
def show_status(view):
key = ViewCollection.get_key(view)
return ViewCollection.views[key].show_status
def plugin_loaded():
settings = sublime.load_settings('GitGutter.sublime-settings')
ViewCollection.compare_against = settings.get('compare_against', 'HEAD')