Skip to content

Commit 6ecc383

Browse files
committed
Enhancement: Configurable tab cycle through dashboard.
Relates to timbrel#261.
1 parent bf788bd commit 6ecc383

8 files changed

+89
-34
lines changed

Default.sublime-keymap

+16-8
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@
309309
},
310310
{
311311
"keys": ["tab"],
312-
"command": "gs_show_branch",
313-
"args": { "commandeer_active_view": true },
312+
"command": "gs_tab_cycle",
313+
"args": { "source": "status" },
314314
"context": [
315315
{ "key": "setting.git_savvy.status_view", "operator": "equal", "operand": true }
316316
]
@@ -450,8 +450,8 @@
450450
},
451451
{
452452
"keys": ["tab"],
453-
"command": "gs_show_status",
454-
"args": { "commandeer_active_view": true },
453+
"command": "gs_tab_cycle",
454+
"args": { "source": "tags" },
455455
"context": [
456456
{ "key": "setting.git_savvy.tags_view", "operator": "equal", "operand": true }
457457
]
@@ -576,8 +576,8 @@
576576
},
577577
{
578578
"keys": ["tab"],
579-
"command": "gs_show_rebase",
580-
"args": { "commandeer_active_view": true },
579+
"command": "gs_tab_cycle",
580+
"args": { "source": "branch" },
581581
"context": [
582582
{ "key": "setting.git_savvy.branch_view", "operator": "equal", "operand": true }
583583
]
@@ -625,6 +625,14 @@
625625
{ "key": "setting.git_savvy.log_graph_view", "operator": "equal", "operand": true }
626626
]
627627
},
628+
{
629+
"keys": ["tab"],
630+
"command": "gs_tab_cycle",
631+
"args": { "source": "graph" },
632+
"context": [
633+
{ "key": "setting.git_savvy.log_graph_view", "operator": "equal", "operand": true }
634+
]
635+
},
628636

629637
//////////////////////
630638
// REBASE DASHBOARD //
@@ -761,8 +769,8 @@
761769
},
762770
{
763771
"keys": ["tab"],
764-
"command": "gs_show_tags",
765-
"args": { "commandeer_active_view": true },
772+
"command": "gs_tab_cycle",
773+
"args": { "source": "rebase" },
766774
"context": [
767775
{ "key": "setting.git_savvy.rebase_view", "operator": "equal", "operand": true }
768776
]

GitSavvy.sublime-settings

+21-1
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,25 @@
213213
Set this value to true if you'd like GitSavvy to automatically attempt
214214
to decode using the `fallback_encoding` value, without prompting.
215215
*/
216-
"silent_fallback": false
216+
"silent_fallback": false,
217+
218+
/*
219+
GitSavvy allows you to press `Tab` to cycle from one dashboard interface
220+
to the next. This setting defines the order of that cycle. The following
221+
are valid entries, and can be included in your preferred order:
222+
223+
status
224+
branch
225+
rebase
226+
tags
227+
graph
228+
229+
*/
230+
"tab_order": [
231+
"status",
232+
"branch",
233+
"rebase",
234+
"tags",
235+
"graph"
236+
]
217237
}

common/ui.py

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def create_view(self, repo_path):
7676
self.view.settings().set("git_savvy.repo_path", repo_path)
7777
self.view.set_name(self.title())
7878
self.view.settings().set("git_savvy.{}_view".format(self.interface_type), True)
79-
self.view.settings().set("git_savvy.is_interface", True)
8079
self.view.settings().set("git_savvy.interface", self.interface_type)
8180
self.view.settings().set("word_wrap", self.word_wrap)
8281
self.view.set_syntax_file(self.syntax_file)

core/interfaces/__init__.py

+40
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
1+
import sublime
2+
from sublime_plugin import TextCommand
3+
14
from .status import *
25
from .branch import *
36
from .rebase import *
47
from .tags import *
8+
9+
10+
class GsTabCycleCommand(TextCommand, GitCommand):
11+
commands = {
12+
"status": "gs_show_status",
13+
"branch": "gs_show_branch",
14+
"rebase": "gs_show_rebase",
15+
"tags": "gs_show_tags",
16+
"graph": "gs_log_graph"
17+
}
18+
19+
view_signatures = {
20+
"status": "git_savvy.status_view",
21+
"branch": "git_savvy.branch_view",
22+
"rebase": "git_savvy.rebase_view",
23+
"tags": "git_savvy.tags_view",
24+
"graph": "git_savvy.log_graph_view"
25+
}
26+
27+
def run(self, edit, source=None, target=None):
28+
to_load = target or self.get_next(source)
29+
view_signature = self.view_signatures[to_load]
30+
31+
self.view.window().run_command("hide_panel", {"cancel": True})
32+
33+
self.view.window().run_command(self.commands[to_load])
34+
if not self.view.settings().get(view_signature):
35+
self.view.close()
36+
37+
def get_next(self, source):
38+
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
39+
tab_order = savvy_settings.get("tab_order")
40+
41+
source_idx = tab_order.index(source)
42+
next_idx = 0 if source_idx == len(tab_order) - 1 else source_idx + 1
43+
44+
return tab_order[next_idx]

core/interfaces/branch.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ class GsShowBranchCommand(WindowCommand, GitCommand):
1515
Open a branch dashboard for the active Git repository.
1616
"""
1717

18-
def run(self, commandeer_active_view=False):
19-
active_view = sublime.active_window().active_view()
20-
interface = BranchInterface(repo_path=self.repo_path)
21-
if commandeer_active_view and active_view != interface.view:
22-
active_view.close()
18+
def run(self):
19+
BranchInterface(repo_path=self.repo_path)
2320

2421

2522
class BranchInterface(ui.Interface, GitCommand):
@@ -58,7 +55,7 @@ class BranchInterface(ui.Interface, GitCommand):
5855
[H] diff history against active
5956
[e] toggle display of remote branches
6057
61-
[tab] transition to rebase dashboard
58+
[tab] transition to next dashboard
6259
[r] refresh
6360
6461
-

core/interfaces/rebase.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ class GsShowRebaseCommand(WindowCommand, GitCommand):
1414
Open a status view for the active git repository.
1515
"""
1616

17-
def run(self, commandeer_active_view=False):
18-
active_view = sublime.active_window().active_view()
19-
interface = RebaseInterface(repo_path=self.repo_path)
20-
if commandeer_active_view and active_view != interface.view:
21-
active_view.close()
17+
def run(self):
18+
RebaseInterface(repo_path=self.repo_path)
2219

2320

2421
class RebaseInterface(ui.Interface, GitCommand):
@@ -61,7 +58,7 @@ class RebaseInterface(ui.Interface, GitCommand):
6158
[u] move commit up (before previous) [A] abort rebase
6259
[w] show commit
6360
64-
[tab] transition to tags dashboard
61+
[tab] transition to next dashboard
6562
6663
[{super_key}-Z] undo previous action
6764
[{super_key}-Y] redo action

core/interfaces/status.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ class GsShowStatusCommand(WindowCommand, GitCommand):
1515
Open a status view for the active git repository.
1616
"""
1717

18-
def run(self, commandeer_active_view=False):
19-
active_view = sublime.active_window().active_view()
20-
interface = StatusInterface(repo_path=self.repo_path)
21-
if commandeer_active_view and active_view != interface.view:
22-
active_view.close()
18+
def run(self):
19+
StatusInterface(repo_path=self.repo_path)
2320

2421

2522
class StatusInterface(ui.Interface, GitCommand):
@@ -76,7 +73,7 @@ class StatusInterface(ui.Interface, GitCommand):
7673
###########
7774
7875
[r] refresh status
79-
[tab] transition to branch dashboard
76+
[tab] transition to next dashboard
8077
[.] move cursor to next file
8178
[,] move cursor to previous file
8279

core/interfaces/tags.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ class GsShowTagsCommand(WindowCommand, GitCommand):
2929
Open a branch dashboard for the active Git repository.
3030
"""
3131

32-
def run(self, commandeer_active_view=False):
33-
active_view = sublime.active_window().active_view()
34-
interface = TagsInterface(repo_path=self.repo_path)
35-
if commandeer_active_view and active_view != interface.view:
36-
active_view.close()
32+
def run(self):
33+
TagsInterface(repo_path=self.repo_path)
3734

3835

3936
class TagsInterface(ui.Interface, GitCommand):
@@ -63,7 +60,7 @@ class TagsInterface(ui.Interface, GitCommand):
6360
6461
[c] create [r] refresh dashboard
6562
[d] delete [e] toggle display of remote branches
66-
[p] push to remote [tab] transition to status dashboard
63+
[p] push to remote [tab] transition to next dashboard
6764
[P] push all tags to remote
6865
[l] view commit
6966

0 commit comments

Comments
 (0)