From 77300bbf3af1f6a11799dbf9301a189d0a8b099b Mon Sep 17 00:00:00 2001 From: Simon Christmann Date: Sat, 12 Dec 2020 23:12:21 +0100 Subject: [PATCH 1/8] Add to Side Bar --- Side Bar.sublime-menu | 3 +++ sublime_tower.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 Side Bar.sublime-menu diff --git a/Side Bar.sublime-menu b/Side Bar.sublime-menu new file mode 100644 index 0000000..19e6170 --- /dev/null +++ b/Side Bar.sublime-menu @@ -0,0 +1,3 @@ +[ + {"caption": "Open in Tower", "command": "tower_open_from_sidebar", "args": {"paths": []}} +] diff --git a/sublime_tower.py b/sublime_tower.py index c38f41e..72be156 100644 --- a/sublime_tower.py +++ b/sublime_tower.py @@ -84,3 +84,22 @@ def run(self, edit): if is_in_repo(current_dir): path = get_repo_root(current_dir) open_in_tower(path) + +class TowerOpenFromSidebarCommand(sublime_plugin.WindowCommand): + """ + Open the repo of the given paths[] in Tower. + paths[] may contain multiple files/directories if the user selected them + from the Side Bar. Process only the first. + """ + + def run(self, paths): + given_path = paths[0] + + if os.path.isfile(given_path): + current_dir = os.path.dirname(given_path) + else: + current_dir = given_path + + if is_in_repo(current_dir): + path = get_repo_root(current_dir) + open_in_tower(path) From f159f08734bba986efc422844d06a48dc3fb7a21 Mon Sep 17 00:00:00 2001 From: Simon Christmann Date: Sat, 12 Dec 2020 23:42:55 +0100 Subject: [PATCH 2/8] =?UTF-8?q?Make=20Side=20Bar=20Item=20appear=20under?= =?UTF-8?q?=20Sublime=E2=80=99s=20Git=20Cmds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Side Bar.sublime-menu | 1 + 1 file changed, 1 insertion(+) diff --git a/Side Bar.sublime-menu b/Side Bar.sublime-menu index 19e6170..f22641a 100644 --- a/Side Bar.sublime-menu +++ b/Side Bar.sublime-menu @@ -1,3 +1,4 @@ [ + { "caption": "-", "id": "repo_commands" }, {"caption": "Open in Tower", "command": "tower_open_from_sidebar", "args": {"paths": []}} ] From ea38fc994f4a73a9a6812d996af0283ea3515b9c Mon Sep 17 00:00:00 2001 From: Simon Christmann Date: Sun, 13 Dec 2020 00:16:04 +0100 Subject: [PATCH 3/8] Fix is_in_repo(); Allow Git Init with Tower --- sublime_tower.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sublime_tower.py b/sublime_tower.py index 72be156..6beac06 100644 --- a/sublime_tower.py +++ b/sublime_tower.py @@ -32,9 +32,9 @@ def is_in_repo(path): output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True, universal_newlines=True, timeout=2) + return output.strip() == 'true' except subprocess.CalledProcessError as e: - pass - return output.strip() == 'true' + return False def get_repo_root(path): @@ -103,3 +103,5 @@ def run(self, paths): if is_in_repo(current_dir): path = get_repo_root(current_dir) open_in_tower(path) + else: + open_in_tower(current_dir) From b5030b3c2ee1c94763a6aafdc23e31c7f0ec642d Mon Sep 17 00:00:00 2001 From: Simon Christmann Date: Sun, 13 Dec 2020 00:38:30 +0100 Subject: [PATCH 4/8] Visibility: Show only if 1 item selected --- sublime_tower.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sublime_tower.py b/sublime_tower.py index 6beac06..6391155 100644 --- a/sublime_tower.py +++ b/sublime_tower.py @@ -85,11 +85,12 @@ def run(self, edit): path = get_repo_root(current_dir) open_in_tower(path) + class TowerOpenFromSidebarCommand(sublime_plugin.WindowCommand): """ Open the repo of the given paths[] in Tower. - paths[] may contain multiple files/directories if the user selected them - from the Side Bar. Process only the first. + paths[] may contain multiple files/directories if the user selected multiple + elements from the Side Bar, hide the menu entry. """ def run(self, paths): @@ -103,5 +104,16 @@ def run(self, paths): if is_in_repo(current_dir): path = get_repo_root(current_dir) open_in_tower(path) + + def is_visible(self, paths): + if len(paths) != 1: + return False + + given_path = paths[0] + + if os.path.isfile(given_path): + current_dir = os.path.dirname(given_path) else: - open_in_tower(current_dir) + current_dir = given_path + + return is_in_repo(current_dir) From 85ce7e34d2e23538d86922020767dda6d74f0e5b Mon Sep 17 00:00:00 2001 From: Simon Christmann Date: Sun, 13 Dec 2020 00:39:21 +0100 Subject: [PATCH 5/8] Add separate Element for Initializing --- Side Bar.sublime-menu | 3 ++- sublime_tower.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Side Bar.sublime-menu b/Side Bar.sublime-menu index f22641a..9f4312d 100644 --- a/Side Bar.sublime-menu +++ b/Side Bar.sublime-menu @@ -1,4 +1,5 @@ [ { "caption": "-", "id": "repo_commands" }, - {"caption": "Open in Tower", "command": "tower_open_from_sidebar", "args": {"paths": []}} + {"caption": "Open in Tower", "command": "tower_open_from_sidebar", "args": {"paths": []}}, + {"caption": "Create new Repository in Tower", "command": "tower_create_new_repo_from_sidebar", "args": {"dirs": []}} ] diff --git a/sublime_tower.py b/sublime_tower.py index 6391155..439d65c 100644 --- a/sublime_tower.py +++ b/sublime_tower.py @@ -117,3 +117,27 @@ def is_visible(self, paths): current_dir = given_path return is_in_repo(current_dir) + + +class TowerCreateNewRepoFromSidebarCommand(sublime_plugin.WindowCommand): + """ + If a single directory is given as argument, initialize Git repository + with Tower. + """ + + def run(self, dirs): + given_path = dirs[0] + open_in_tower(given_path) + + def is_visible(self, dirs): + if len(dirs) != 1: + return False + + given_path = dirs[0] + + if os.path.isfile(given_path): + current_dir = os.path.dirname(given_path) + else: + current_dir = given_path + + return not is_in_repo(current_dir) From 55ae789b1d87f6fdca309839bf65f12b57f9dc21 Mon Sep 17 00:00:00 2001 From: Simon Christmann Date: Sun, 13 Dec 2020 00:48:41 +0100 Subject: [PATCH 6/8] Rename --- Side Bar.sublime-menu | 2 +- sublime_tower.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Side Bar.sublime-menu b/Side Bar.sublime-menu index 9f4312d..6a4807c 100644 --- a/Side Bar.sublime-menu +++ b/Side Bar.sublime-menu @@ -1,5 +1,5 @@ [ { "caption": "-", "id": "repo_commands" }, {"caption": "Open in Tower", "command": "tower_open_from_sidebar", "args": {"paths": []}}, - {"caption": "Create new Repository in Tower", "command": "tower_create_new_repo_from_sidebar", "args": {"dirs": []}} + {"caption": "Create new Repository in Tower", "command": "tower_create_new_repository_from_sidebar", "args": {"dirs": []}} ] diff --git a/sublime_tower.py b/sublime_tower.py index 439d65c..e453cd2 100644 --- a/sublime_tower.py +++ b/sublime_tower.py @@ -119,7 +119,7 @@ def is_visible(self, paths): return is_in_repo(current_dir) -class TowerCreateNewRepoFromSidebarCommand(sublime_plugin.WindowCommand): +class TowerCreateNewRepositoryFromSidebarCommand(sublime_plugin.WindowCommand): """ If a single directory is given as argument, initialize Git repository with Tower. From bc538aad61530e2697004a8197514f35933b9550 Mon Sep 17 00:00:00 2001 From: Simon Christmann Date: Sun, 13 Dec 2020 01:01:13 +0100 Subject: [PATCH 7/8] Add Command to Context Menu --- Context.sublime-menu | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Context.sublime-menu diff --git a/Context.sublime-menu b/Context.sublime-menu new file mode 100644 index 0000000..01930d9 --- /dev/null +++ b/Context.sublime-menu @@ -0,0 +1,4 @@ +[ + {"caption": "-", "id": "repo_commands"}, + {"caption": "Open in Tower", "command": "tower_open"} +] \ No newline at end of file From 7cf895426d94ff0fc5dcfa0aa1f89dce8d72367f Mon Sep 17 00:00:00 2001 From: Simon Christmann Date: Sun, 13 Dec 2020 01:01:23 +0100 Subject: [PATCH 8/8] Add Visibility --- sublime_tower.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sublime_tower.py b/sublime_tower.py index e453cd2..4a0aad8 100644 --- a/sublime_tower.py +++ b/sublime_tower.py @@ -85,6 +85,16 @@ def run(self, edit): path = get_repo_root(current_dir) open_in_tower(path) + def is_visible(self): + current_file_path = self.view.file_name() + + if not current_file_path: + return False + + current_dir = os.path.dirname(current_file_path) + + return is_in_repo(current_dir) + class TowerOpenFromSidebarCommand(sublime_plugin.WindowCommand): """