-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_gutter.py
119 lines (94 loc) · 4.46 KB
/
git_gutter.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import sublime_plugin
try:
from .git_gutter_handler import GitGutterHandler
from .git_gutter_compare import (
GitGutterCompareCommit, GitGutterCompareBranch, GitGutterCompareTag,
GitGutterCompareHead, GitGutterCompareOrigin, GitGutterShowCompare)
from .git_gutter_jump_to_changes import GitGutterJumpToChanges
from .git_gutter_popup import show_diff_popup
from .git_gutter_show_diff import GitGutterShowDiff
except (ImportError, ValueError):
from git_gutter_handler import GitGutterHandler
from git_gutter_compare import (
GitGutterCompareCommit, GitGutterCompareBranch, GitGutterCompareTag,
GitGutterCompareHead, GitGutterCompareOrigin, GitGutterShowCompare)
from git_gutter_jump_to_changes import GitGutterJumpToChanges
from git_gutter_popup import show_diff_popup
from git_gutter_show_diff import GitGutterShowDiff
class GitGutterCommand(sublime_plugin.TextCommand):
def __init__(self, *args, **kwargs):
sublime_plugin.TextCommand.__init__(self, *args, **kwargs)
self.is_valid_view = self.view.settings().get('is_widget') is not True
self.git_handler = None
self.show_diff_handler = None
def is_enabled(self, **kwargs):
return self.is_valid_view
def run(self, edit, **kwargs):
if not self.git_handler:
self.git_handler = GitGutterHandler(self.view)
if not self.show_diff_handler:
self.show_diff_handler = GitGutterShowDiff(
self.view, self.git_handler)
if not self.git_handler.on_disk() or not self.git_handler.git_dir:
return
if kwargs:
self._handle_subcommand(**kwargs)
return
self.show_diff_handler.run()
def _handle_subcommand(self, **kwargs):
view = self.view
git_handler = self.git_handler
action = kwargs['action']
if action == 'jump_to_next_change':
GitGutterJumpToChanges(view, git_handler).jump_to_next_change()
elif action == 'jump_to_prev_change':
GitGutterJumpToChanges(view, git_handler).jump_to_prev_change()
elif action == 'compare_against_commit':
GitGutterCompareCommit(view, git_handler).run()
elif action == 'compare_against_branch':
GitGutterCompareBranch(view, git_handler).run()
elif action == 'compare_against_tag':
GitGutterCompareTag(view, git_handler).run()
elif action == 'compare_against_head':
GitGutterCompareHead(view, git_handler).run()
elif action == 'compare_against_origin':
GitGutterCompareOrigin(view, git_handler).run()
elif action == 'show_compare':
GitGutterShowCompare(view, git_handler).run()
elif action == 'show_diff_popup':
point = kwargs['point']
highlight_diff = kwargs['highlight_diff']
flags = kwargs['flags']
show_diff_popup(
view, point, git_handler, highlight_diff=highlight_diff,
flags=flags)
else:
assert False, 'Unhandled sub command "%s"' % action
class GitGutterShowCompareCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command('git_gutter', {'action': 'show_compare'})
class GitGutterCompareHeadCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command('git_gutter', {'action': 'compare_against_head'})
class GitGutterCompareOriginCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command(
'git_gutter', {'action': 'compare_against_origin'})
class GitGutterCompareCommitCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command(
'git_gutter', {'action': 'compare_against_commit'})
class GitGutterCompareBranchCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command(
'git_gutter', {'action': 'compare_against_branch'})
class GitGutterCompareTagCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command(
'git_gutter', {'action': 'compare_against_tag'})
class GitGutterNextChangeCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command('git_gutter', {'action': 'jump_to_next_change'})
class GitGutterPrevChangeCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command('git_gutter', {'action': 'jump_to_prev_change'})