Skip to content

Commit 22aae6d

Browse files
committed
Add command to open a project with a package
1 parent 4d32f8b commit 22aae6d

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

Package/Main.sublime-menu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
{ "caption": "Create Package…",
1313
"command": "packagedev_create_package" },
1414

15+
{ "caption": "Open Package…",
16+
"command": "packagedev_open_package" },
17+
1518
{ "caption": "-" },
1619

1720
{ "caption": "New Syntax Definition…",

Package/PackageDev.sublime-commands

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
"command": "packagedev_create_package",
1717
},
1818

19+
{ "caption": "PackageDev: Open Package",
20+
"command": "packagedev_open_package",
21+
},
22+
1923
// Snippets
2024
{ "caption": "PackageDev: New Raw Snippet",
2125
"command": "packagedev_new_resource",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Detailed documentation is available [at the repository's wiki][wiki].
8787
snippets are available with the trigger `e` and `ee`
8888
for a short and a long entry, respectively.
8989

90-
- Commands to create a package
90+
- Commands to create (or open) a package
9191
and various resource files with standard templates.
9292

9393
- Checking for unknown settings keys.

plugins_/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .create_package import * # noqa
66
from .file_conversion import * # noqa
77
from .new_resource_file import * # noqa
8+
from .open_package import * # noqa
89
from .settings import * # noqa
910
from .snippet_dev import * # noqa
1011
from .syntax_dev import * # noqa

plugins_/open_package.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import glob
2+
import os
3+
4+
import sublime
5+
import sublime_plugin
6+
7+
from .create_package import _open_folder_in_st, _is_override_package
8+
9+
__all__ = ('PackagedevOpenPackageCommand',)
10+
11+
OVERRIDE_SUFFIX = " [*Override*]"
12+
13+
14+
def _list_normal_packages():
15+
pkgspath = sublime.packages_path()
16+
folders = glob.glob(os.path.join(pkgspath, "*/", ""))
17+
names = (os.path.basename(fold.strip("\\/")) for fold in folders)
18+
for name in names:
19+
yield (name, _is_override_package(name))
20+
21+
22+
class NameInputHandler(sublime_plugin.ListInputHandler):
23+
24+
def placeholder(self):
25+
return "Package"
26+
27+
def list_items(self):
28+
packages = list(sorted(_list_normal_packages()))
29+
print(packages)
30+
items = [name + (OVERRIDE_SUFFIX if override else "")
31+
for name, override in packages]
32+
return items
33+
34+
35+
class PackagedevOpenPackageCommand(sublime_plugin.WindowCommand):
36+
37+
def input(self, args):
38+
return NameInputHandler()
39+
40+
def run(self, name):
41+
if not name:
42+
return
43+
name = name.split(OVERRIDE_SUFFIX)[0]
44+
path = os.path.join(sublime.packages_path(), name)
45+
# TODO find a .sublime-project file and open that instead?
46+
_open_folder_in_st(path)

0 commit comments

Comments
 (0)