├── VERSION ├── .python-version ├── messages ├── 0.0.2.md ├── 0.1.4.md ├── 0.0.4.md ├── 0.0.5.md ├── 0.1.2.md ├── 0.1.5.md ├── 0.0.1.md ├── 0.0.3.md ├── 0.1.0.md ├── 0.1.1.md ├── 0.1.3.md └── install.md ├── messages.json ├── NEWS.md ├── LICENSE.txt ├── ProjectAndWorkspaceManagement.sublime-settings ├── ProjectAndWorkspaceManagement.sublime-commands ├── README.md └── ProjectAndWorkspaceManagement.py /VERSION: -------------------------------------------------------------------------------- 1 | 0.1.4 -------------------------------------------------------------------------------- /.python-version: -------------------------------------------------------------------------------- 1 | 3.8 -------------------------------------------------------------------------------- /messages/0.0.2.md: -------------------------------------------------------------------------------- 1 | # 0.0.2 2 | - commands: `open workspace` 3 | 4 | (please refer to the [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#commands) 5 | for more information) -------------------------------------------------------------------------------- /messages/0.1.4.md: -------------------------------------------------------------------------------- 1 | # 0.1.4 2 | - fixed bug in default settings 3 | 4 | (please refer to the [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#commands) 5 | for more information) -------------------------------------------------------------------------------- /messages/0.0.4.md: -------------------------------------------------------------------------------- 1 | # 0.0.4 2 | - commands: `create project files at existing folder` 3 | 4 | (please refer to the [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#commands) 5 | for more information) -------------------------------------------------------------------------------- /messages/0.0.5.md: -------------------------------------------------------------------------------- 1 | # 0.0.5 2 | - commands: `import project files at current folder` 3 | 4 | (please refer to the [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#commands) 5 | for more information) -------------------------------------------------------------------------------- /messages/0.1.2.md: -------------------------------------------------------------------------------- 1 | # 0.1.2 2 | - commands: `rename workspace` and `delete workspace` 3 | 4 | (please refer to the [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#commands) 5 | for more information) -------------------------------------------------------------------------------- /messages/0.1.5.md: -------------------------------------------------------------------------------- 1 | # 0.1.4 2 | - fixed fatal bug 3 | - support for `~` in new project path 4 | 5 | (please refer to the [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#commands) 6 | for more information) -------------------------------------------------------------------------------- /messages/0.0.1.md: -------------------------------------------------------------------------------- 1 | # 0.0.1 2 | - initial release 3 | - commands: `new project` and `new workspace` 4 | 5 | (please refer to the [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#commands) 6 | for more information) -------------------------------------------------------------------------------- /messages/0.0.3.md: -------------------------------------------------------------------------------- 1 | # 0.0.3 2 | - renamed plugin from `Project Management` to `Project And Workspace Management` 3 | 4 | (please refer to the [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#commands) 5 | for more information) -------------------------------------------------------------------------------- /messages/0.1.0.md: -------------------------------------------------------------------------------- 1 | # 0.1.0 2 | - first release 3 | - bug fix for command `import project files at current folder` 4 | 5 | (please refer to the [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#commands) 6 | for more information) -------------------------------------------------------------------------------- /messages/0.1.1.md: -------------------------------------------------------------------------------- 1 | # 0.1.1 2 | - bug fix for not opening new workspaces automatically in command `new workspace` 3 | 4 | (please refer to the [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#commands) 5 | for more information) -------------------------------------------------------------------------------- /messages/0.1.3.md: -------------------------------------------------------------------------------- 1 | # 0.1.3 2 | - commands: `edit settings` 3 | - added a default `sublime-settings` file and user overrides 4 | 5 | (please refer to the [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#commands) 6 | for more information) -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "0.1.5": "messages/0.1.5.md", 3 | "0.1.4": "messages/0.1.4.md", 4 | "0.1.3": "messages/0.1.3.md", 5 | "0.1.2": "messages/0.1.2.md", 6 | "0.1.1": "messages/0.1.1.md", 7 | "0.1.0": "messages/0.1.0.md", 8 | "0.0.5": "messages/0.0.5.md", 9 | "0.0.4": "messages/0.0.4.md", 10 | "0.0.3": "messages/0.0.3.md", 11 | "0.0.2": "messages/0.0.2.md", 12 | "0.0.1": "messages/0.0.1.md", 13 | "install": "messages/install.md" 14 | } -------------------------------------------------------------------------------- /messages/install.md: -------------------------------------------------------------------------------- 1 | # Project And Workspace Management Plugin 2 | 3 | Thanks for trying out this plugin, please refer to the 4 | [README.md](https://github.com/tshrpl/ProjectAndWorkspaceManagement#readme) 5 | file for intructions on how to use this plugin 6 | 7 | if you dont have time though: 8 | - you can just run the `Project And Workspace Management: Edit Settings` command from the pallete, save the file on the right and close the window 9 | - explore the command prefixed with `Project And Workspace Management: ` and you'll get the hang of it -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # 0.1.5 2 | - fixed fatal bug 3 | - support for `~` in new project path 4 | 5 | # 0.1.4 6 | - fixed bug in default settings 7 | 8 | # 0.1.3 9 | - commands: `edit settings` 10 | - added a default `sublime-settings` file and user overrides 11 | 12 | # 0.1.2 13 | - commands: `rename workspace` and `delete workspace` 14 | 15 | # 0.1.1 16 | - bug fix for not opening new workspaces automatically in command `new workspace` 17 | 18 | # 0.1.0 19 | - first release 20 | - bug fix for command `import project files at current folder` 21 | solves #3 22 | 23 | # 0.0.5 24 | - commands: `import project files at current folder` 25 | 26 | # 0.0.4 27 | - commands: `create project files at existing folder` 28 | 29 | # 0.0.3 30 | - renamed plugin from `Project Management` to `Project And Workspace Management` 31 | 32 | # 0.0.2 33 | - commands: `open workspace` 34 | 35 | # 0.0.1 36 | - initial release 37 | - commands: `new project` and `new workspace` 38 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022 Tushar Paul 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /ProjectAndWorkspaceManagement.sublime-settings: -------------------------------------------------------------------------------- 1 | 2 | // dont change this file 3 | // override in Packages/User/ProjectAndWorkspaceManagement.sublime-settings instead\ 4 | // there should be a `Project And Workspace Management: Edit Settings` command in the pallate 5 | // just drop an issue at https://github.com/tshrpl/ProjectAndWorkspaceManagement/issues if 6 | // you are having some trouble, but check the other issues before that, might save you some time 7 | 8 | { 9 | 10 | // replace `\` with `\\` 11 | "default_project_path": "/projects/", 12 | 13 | // a relative (to project root) path where .sublime-workspace files are stored 14 | "workspaces_subpath": ".sublime_workspaces", 15 | 16 | // the default .sublime-project file, everything should be properly escaped 17 | // just drop an issue at https://github.com/tshrpl/ProjectAndWorkspaceManagement/issues if you need some help 18 | "default_project_file_text": "{\n\t\"folders\": [\n\t\t{\n\t\t\t\"path\": \".\",\n\t\t\t\"folder_exclude_patterns\": [\".sublime_workspaces\"]\n\t\t}\n\t]\n}", 19 | 20 | // the default .gitignore file, everything should be properly escaped 21 | "default_gitignore_file_text": "\n#sublime text files\n.sublime_workspaces/\n" 22 | 23 | } 24 | -------------------------------------------------------------------------------- /ProjectAndWorkspaceManagement.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Project And Worspsace Management: New Project", 4 | "command": "project_and_workspace_management_new_project" 5 | }, 6 | { 7 | "caption": "Project And Worspsace Management: New Workspace", 8 | "command": "project_and_workspace_management_new_workspace" 9 | }, 10 | { 11 | "caption": "Project And Worspsace Management: Open Workspace", 12 | "command": "project_and_workspace_management_open_workspace" 13 | }, 14 | { 15 | "caption": "Project And Worspsace Management: Rename Workspace", 16 | "command": "project_and_workspace_management_rename_workspace" 17 | }, 18 | { 19 | "caption": "Project And Worspsace Management: Delete Workspace", 20 | "command": "project_and_workspace_management_delete_workspace" 21 | }, 22 | { 23 | "caption": "Project And Workspace Management: Create Project Files At Existing Folder", 24 | "command": "project_and_workspace_management_create_project_files_at_existing_folder" 25 | }, 26 | { 27 | "caption": "Project And Workspace Management: Import Project Files At Current Folder", 28 | "command": "project_and_workspace_management_import_project_files_at_current_folder" 29 | }, 30 | { 31 | "caption": "Project And Workspace Management: Edit Settings", 32 | "command": "edit_settings", 33 | "args": { 34 | "base_file": "${packages}/Project And Workspace Management/ProjectAndWorkspaceManagement.sublime-settings", 35 | "user_file": "${packages}/User/ProjectAndWorkspaceManagement.sublime-settings", 36 | "default": "// overrides settings in ProjectAndWorkspaceManagement/ProjectAndWorkspaceManagement.sublime-settings\n{\n\t$0\n}\n" 37 | } 38 | } 39 | ] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Project And Workspace Management 2 | A Project and Workspace Management plugin for [Sublime Text 4](https://www.sublimetext.com). 3 | > This project was inspired by https://github.com/randy3k/ProjectManager 4 | 5 | # Functionality 6 | This plugin helps you manage your sublime workspace files. You can create and quickly switch between multiple workspaces for a single sublime text project. Extra functionality to be added (see [Todo Section](https://github.com/tshrpl/ProjectManagement#Todo)). 7 | > Please open the one of the `.sublime-workspace` files to open a project because opening the `.sublime-project` file will create a new workspace at the root instead of the hidden folder! 8 | 9 | # Commands 10 | | Commands | Function | 11 | |----------------|----------| 12 | | Edit Settings | Opens a window with the default, non-editable settings on the left and user overrides file on the right, closes when the user file is closed | 13 | | New Project | Creates new project files (`.sublime-project`, `.sublime-workspaces` folder and `.gitignore`) at the specified path | 14 | | New Workspace | Creates new workspace file inside `.sublime-workspaces` folder | 15 | | Open Workspace | Opens existing workspace in a new window | 16 | | Rename Workspace | Renames existing workspace and opens it in a new window | 17 | | Delete Workspace | Deletes existing workspace | 18 | | Create Project at existing folder | Create Project files at currently open folder (if any) | 19 | | Import Project Files At Current Folder | Edits `workspace` files inside `.sublime_workspaces/` to work with the new project path and rename Project/Workspace files (__use with caution__ and __only use once on a copied/moved project__) 20 | 21 | # Settings 22 | | Commands | Function | 23 | |--------------------------------|----------| 24 | | `default_project_path` | default value for `New Project` input | 25 | | `workspaces_subpath` | properly formatted path to store workspaces to (e.g. `.sublime-workspaces`, `.sublime/workspaces`) | 26 | | `default_project_file_text` | properly formatted json text for `.sublime-project` file | 27 | | `default_gitignore_file_text` | properly formatted json text for `.gitignore` file | 28 | 29 | # Todo 30 | - [ ] search for existing project files on disk 31 | - [ ] support for centralization (absolute paths in `workspaces_subpath` and/or `default_project_path`) 32 | 33 | # License 34 | Project And Workspace Management is [MIT licensed](https://github.com/tshrpl/ProjectManagement/blob/master/LICENSE.txt). 35 | -------------------------------------------------------------------------------- /ProjectAndWorkspaceManagement.py: -------------------------------------------------------------------------------- 1 | import sublime 2 | import sublime_plugin 3 | from pathlib import Path 4 | import os 5 | import json 6 | import subprocess 7 | 8 | 9 | SETTINGS_FILE_NAME = "ProjectAndWorkspaceManagement.sublime-settings" 10 | 11 | 12 | 13 | ##################### 14 | # helper functions 15 | 16 | def set_platform_specific_path(platform, path): 17 | if type(path)!=str: path = str(path) 18 | if platform == 'windows': 19 | path = path.replace("\\",'/') 20 | path = '/'+path.replace(':','') 21 | return path 22 | 23 | def get_platform_specific_path(platform, path): 24 | if type(path)!=str: path = str(path) 25 | if platform == 'windows': 26 | path = path[1]+':\\'+path[2:].replace('/', '\\') 27 | return path 28 | 29 | def workspaces_path(): 30 | return sublime.load_settings(SETTINGS_FILE_NAME)['workspaces_subpath'].strip('/').strip('\\') 31 | 32 | 33 | 34 | variables = None 35 | 36 | ##################### 37 | # function taken from 38 | # https://github.com/randy3k/ProjectManager/blob/fdfd0372cf8ef705ac8a6c352e9c6ce21df1b0de/project_manager.py#L52 39 | def subl(*args): 40 | executable_path = sublime.executable_path() 41 | if sublime.platform() == 'osx': 42 | app_path = executable_path[:executable_path.rfind('.app/') + 5] 43 | executable_path = app_path + 'Contents/SharedSupport/bin/subl' 44 | 45 | subprocess.Popen([executable_path] + list(args)) 46 | 47 | def on_activated(): 48 | window = sublime.active_window() 49 | view = window.active_view() 50 | 51 | if sublime.platform() == 'windows': 52 | # fix focus on windows 53 | window.run_command('focus_neighboring_group') 54 | window.focus_view(view) 55 | 56 | sublime_plugin.on_activated(view.id()) 57 | sublime.set_timeout_async(lambda: sublime_plugin.on_activated_async(view.id())) 58 | 59 | sublime.set_timeout(on_activated, 300) 60 | 61 | 62 | 63 | class NewProjectPathInputHandler(sublime_plugin.TextInputHandler): 64 | 65 | def initial_text(self): 66 | return sublime.load_settings(SETTINGS_FILE_NAME)['default_project_path'] 67 | 68 | def placeholder(Self): 69 | return "Enter full project path" 70 | 71 | def description(self, text): 72 | return 'path' 73 | 74 | def preview(self, text): 75 | if Path(os.path.expanduser(text)).exists(): 76 | return sublime.Html(f"Path already exists") 77 | return sublime.Html(f"Creating Project at {text}") 78 | 79 | def validate(self, text): 80 | if Path(os.path.expanduser(text)).exists(): 81 | return False 82 | return True 83 | 84 | 85 | 86 | class ProjectAndWorkspaceManagementNewProjectCommand(sublime_plugin.ApplicationCommand): 87 | 88 | def run(self, new_project_path): 89 | path = Path(os.path.expanduser(new_project_path)) 90 | project_name = path.name 91 | 92 | path.mkdir(parents=True) 93 | 94 | project_file_path = path / (project_name+'.sublime-project') 95 | # make project file 96 | with open(project_file_path, 'w') as f: 97 | f.write(sublime.load_settings(SETTINGS_FILE_NAME)['default_project_file_text']) 98 | 99 | gitignore_file_path = path / '.gitignore' 100 | # make .gitignore file 101 | with open(gitignore_file_path, 'w') as f: 102 | f.write(sublime.load_settings(SETTINGS_FILE_NAME)['default_gitignore_file_text']) 103 | 104 | path = path / workspaces_path() 105 | path.mkdir(parents=True) 106 | 107 | # make workspace file inside workspace folder 108 | workspace_path = path / ('w1 '+project_name+'.sublime-workspace') 109 | with open(workspace_path, 'w') as f: 110 | if sublime.platform() == "windows": 111 | project_file_path = str(project_file_path).replace("\\",'/') 112 | project_file_path = '/'+project_file_path.replace(':','') 113 | f.write('{"project":"'+ str(project_file_path) +'"}') 114 | 115 | subl('-n', '--project', workspace_path) 116 | 117 | def input(self, args): 118 | return NewProjectPathInputHandler() 119 | 120 | def input_description(self): 121 | return "Path" 122 | 123 | 124 | 125 | class NewWorkspaceNameInputHandler(sublime_plugin.TextInputHandler): 126 | 127 | def initial_text(self): 128 | global variables 129 | if 'project_name' in variables.keys(): 130 | try: 131 | if (Path(variables['project_path']) / (f'{workspaces_path()}/w1 '+variables['project_base_name']+'.sublime-workspace')).exists(): 132 | n = sorted([int(x.name.split(' ')[0][1:]) for x in (Path(variables['project_path']) / workspaces_path()).glob('**/*')])[-1] 133 | return f'w{str(n+1)} {variables["project_base_name"]}' 134 | except Exception: 135 | pass 136 | return 'workspace name' 137 | 138 | def placeholder(Self): 139 | return "Enter new workspace name" 140 | 141 | def description(self, text): 142 | return 'name' 143 | 144 | def preview(self, text): 145 | if (Path(variables['project_path']) / (f'{workspaces_path()}/{text}.sublime-workspace')).exists(): 146 | return sublime.Html(f"Workspace already exists") 147 | return sublime.Html(f"Creating New workspace {text}") 148 | 149 | def validate(self, text): 150 | if (Path(variables['project_path']) / (f'{workspaces_path()}/{text}.sublime-workspace')).exists(): 151 | return False 152 | return True 153 | 154 | 155 | 156 | class ProjectAndWorkspaceManagementNewWorkspaceCommand(sublime_plugin.WindowCommand): 157 | 158 | def run(self, new_workspace_name): 159 | path = Path(variables['project_path']) / workspaces_path() 160 | if not path.exists(): 161 | path.mkdir(parents=True) 162 | 163 | # make workspace file inside workspace folder 164 | workspace_path = path / (new_workspace_name+'.sublime-workspace') 165 | with open(workspace_path, 'w') as f: 166 | project_file_path = set_platform_specific_path(sublime.platform(), variables['project']) 167 | f.write('{"project":"'+ project_file_path +'"}') 168 | 169 | subl('--project', workspace_path) 170 | 171 | def input(self, args): 172 | global variables 173 | variables = self.window.extract_variables() 174 | 175 | return NewWorkspaceNameInputHandler() 176 | 177 | def input_description(self): 178 | return "Name" 179 | 180 | 181 | 182 | class OpenWorkspaceIndexInputHandler(sublime_plugin.ListInputHandler): 183 | 184 | def list_items(self): 185 | try: 186 | path = Path(variables['project_path']) / f'{workspaces_path()}/' 187 | self.file_name_paths = [x for x in (path).glob('**/*') if x.is_file()] 188 | self.file_names = [x.name.replace('.sublime-workspace','') for x in self.file_name_paths] 189 | return [(x, i) for i,x in enumerate(self.file_names)] 190 | except Exception: 191 | return [(' ', -1)] 192 | 193 | def preview(self, value): 194 | try: 195 | if not (Path(variables['project_path']) / f'{workspaces_path()}/').exists(): 196 | return sublime.Html(f"No workspaces found") 197 | except Exception: 198 | return sublime.Html("No open projects") 199 | return sublime.Html(f"Opening workspace {self.file_names[value]}") 200 | 201 | def validate(self, value): 202 | try: 203 | if (Path(variables['project_path']) / f'{workspaces_path()}/').exists(): 204 | return True 205 | except Exception: 206 | pass 207 | return False 208 | 209 | 210 | 211 | class ProjectAndWorkspaceManagementOpenWorkspaceCommand(sublime_plugin.WindowCommand): 212 | 213 | def run(self, open_workspace_index): 214 | path = Path(variables['project_path']) / f'{workspaces_path()}/' 215 | file_names = [x for x in (path).glob('**/*') if x.is_file()] 216 | 217 | subl('--project', file_names[open_workspace_index]) 218 | 219 | def input(self, args): 220 | global variables 221 | variables = self.window.extract_variables() 222 | 223 | return OpenWorkspaceIndexInputHandler() 224 | 225 | def input_description(self): 226 | return "Workspace" 227 | 228 | 229 | 230 | class GetWorkspaceIndexToRenameInputHandler(sublime_plugin.ListInputHandler): 231 | 232 | def list_items(self): 233 | try: 234 | path = Path(variables['project_path']) / f'{workspaces_path()}/' 235 | self.file_name_paths = [x for x in (path).glob('**/*') if x.is_file()] 236 | self.file_names = [x.name.replace('.sublime-workspace','') for x in self.file_name_paths] 237 | return [(x, i) for i,x in enumerate(self.file_names)] 238 | except Exception: 239 | return [(' ', -1)] 240 | 241 | def preview(self, value): 242 | try: 243 | if not (Path(variables['project_path']) / workspaces_path()).exists(): 244 | return sublime.Html(f"No workspaces found") 245 | except Exception: 246 | return sublime.Html("No open projects") 247 | return sublime.Html(f"Renaming workspace {self.file_names[value]}") 248 | 249 | def validate(self, value): 250 | try: 251 | if (Path(variables['project_path']) / workspaces_path()).exists(): 252 | return True 253 | except Exception: 254 | pass 255 | return False 256 | 257 | def next_input(self, args): 258 | return RenameWorkspaceNameInputHandler() 259 | 260 | 261 | class RenameWorkspaceNameInputHandler(sublime_plugin.TextInputHandler): 262 | 263 | def initial_text(self): 264 | return 'New workspace name' 265 | 266 | def preview(self, value): 267 | return f"renaming to {value}.sublime-workspace" 268 | 269 | 270 | 271 | class ProjectAndWorkspaceManagementRenameWorkspaceCommand(sublime_plugin.WindowCommand): 272 | 273 | def run(self, get_workspace_index_to_rename, rename_workspace_name): 274 | path = Path(variables['project_path']) / workspaces_path() 275 | current_workspace_path = [x for x in (path).glob('**/*') if x.is_file()][get_workspace_index_to_rename] 276 | new_path = Path(current_workspace_path.parent, rename_workspace_name + current_workspace_path.suffix) 277 | 278 | current_workspace_path.rename(new_path) 279 | subl('--project', new_path) 280 | 281 | def input(self, args): 282 | global variables 283 | variables = self.window.extract_variables() 284 | 285 | if not args.get('open_workspace'): 286 | return GetWorkspaceIndexToRenameInputHandler() 287 | 288 | if not args.get('rename_workspace_name'): 289 | return RenameWorkspaceNameInputHandler() 290 | 291 | def input_description(self): 292 | return "Rename Workspace" 293 | 294 | 295 | 296 | class GetWorkspaceIndexToDeleteInputHandler(sublime_plugin.ListInputHandler): 297 | 298 | def list_items(self): 299 | r = [] 300 | try: 301 | path = Path(variables['project_path']) / workspaces_path() 302 | self.file_name_paths = [x for x in (path).glob('**/*') if x.is_file()] 303 | self.file_names = [x.name.replace('.sublime-workspace','') for x in self.file_name_paths] 304 | r += [(x, i) for i,x in enumerate(self.file_names)] 305 | except Exception: 306 | pass 307 | if len(r)<1: r += [(' ', -1)] 308 | return r 309 | 310 | def preview(self, value): 311 | try: 312 | if (Path(variables['project_path']) / workspaces_path()).exists(): 313 | if any((Path(variables['project_path']) / workspaces_path()).iterdir()): 314 | return sublime.Html(f"Deleting workspace {self.file_names[value]}") 315 | except Exception: 316 | return sublime.Html("No open projects") 317 | return sublime.Html(f"No workspaces found") 318 | 319 | def validate(self, value): 320 | try: 321 | if (Path(variables['project_path']) / workspaces_path()).exists(): 322 | if any((Path(variables['project_path']) / workspaces_path()).iterdir()): 323 | return True 324 | except Exception: 325 | pass 326 | return False 327 | 328 | 329 | 330 | class ProjectAndWorkspaceManagementDeleteWorkspaceCommand(sublime_plugin.WindowCommand): 331 | 332 | def run(self, get_workspace_index_to_delete): 333 | path = Path(variables['project_path']) / workspaces_path() 334 | current_workspace_path = [x for x in (path).glob('**/*') if x.is_file()][get_workspace_index_to_delete] 335 | 336 | current_workspace_path.unlink() 337 | 338 | def input(self, args): 339 | global variables 340 | variables = self.window.extract_variables() 341 | return GetWorkspaceIndexToDeleteInputHandler() 342 | 343 | def input_description(self): 344 | return "Delete Workspace" 345 | 346 | 347 | 348 | class ProjectAndWorkspaceManagementCreateProjectFilesAtExistingFolderCommand(sublime_plugin.WindowCommand): 349 | 350 | def run(self): 351 | global variables 352 | variables = self.window.extract_variables() 353 | path = Path(variables['folder']) 354 | project_name = path.name 355 | 356 | # path.mkdir(parents=True) 357 | 358 | project_file_path = path / (project_name+'.sublime-project') 359 | # make project file 360 | with open(project_file_path, 'w') as f: 361 | f.write(sublime.load_settings(SETTINGS_FILE_NAME)['default_project_file_text']) 362 | 363 | gitignore_file_path = path / '.gitignore' 364 | # make .gitignore file 365 | with open(gitignore_file_path, 'w') as f: 366 | f.write(sublime.load_settings(SETTINGS_FILE_NAME)['default_gitignore_file_text']) 367 | 368 | try: 369 | path = path / workspaces_path() 370 | path.mkdir(parents=True) 371 | 372 | # make workspace file inside workspace folder 373 | workspace_path = path / ('w1 '+project_name+'.sublime-workspace') 374 | with open(workspace_path, 'w') as f: 375 | if sublime.platform() == "windows": 376 | project_file_path = str(project_file_path).replace("\\",'/') 377 | project_file_path = '/'+project_file_path.replace(':','') 378 | f.write('{"project":"'+ str(project_file_path) +'"}') 379 | except Exception as e: 380 | pass 381 | 382 | subl('-n', '--project', workspace_path) 383 | 384 | 385 | class projectAndWorkspaceManagementImportProjectFilesAtCurrentFolder(sublime_plugin.WindowCommand): 386 | 387 | def run(self): 388 | global variables 389 | variables = self.window.extract_variables() 390 | path = Path(variables['folder']) 391 | project_name = path.name 392 | 393 | workspaces_data = [] 394 | for workspace_file_path in path.glob(f'{workspaces_path()}/*.sublime-workspace'): 395 | with open(workspace_file_path, 'r') as workspace_file: 396 | workspaces_data.append((json.loads(workspace_file.read()), workspace_file_path)) 397 | 398 | for (workspace_data, workspace_file_path) in workspaces_data: 399 | old_project_name = workspace_data['project'].split('/')[-2] 400 | old_project_path = '/'.join(workspace_data['project'].split('/')[:-1]) 401 | 402 | for buffer_data in workspace_data['buffers']: 403 | buffer_data['file'] = set_platform_specific_path(sublime.platform(), path) + buffer_data['file'].replace(old_project_path, '') 404 | 405 | workspace_data['expanded_folders'] = [ set_platform_specific_path(sublime.platform(), path) + expanded_folder_data.replace(old_project_path, '') for expanded_folder_data in workspace_data['expanded_folders'] ] 406 | 407 | for group_data in workspace_data['groups']: 408 | for sheet_data in group_data['sheets']: 409 | sheet_data['file'] = set_platform_specific_path(sublime.platform(), path) + sheet_data['file'].replace(old_project_path, '') 410 | 411 | workspace_data['project'] = set_platform_specific_path(sublime.platform(), path / (path.name+'.sublime-project')) 412 | 413 | new_workspace_file_path = str(workspace_file_path).replace(old_project_name, path.name) 414 | with open(new_workspace_file_path, 'w') as f: 415 | f.write(json.dumps(workspace_data)) 416 | 417 | subl('-n', '--project', new_workspace_file_path) 418 | 419 | for _, p in workspaces_data: 420 | os.remove(p) 421 | 422 | for project_file_path in path.glob('*.sublime-project'): 423 | os.rename(project_file_path, str(project_file_path).replace(project_file_path.name.replace('.sublime-project', ''), path.name)) 424 | 425 | 426 | --------------------------------------------------------------------------------