diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..153c8d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +*.cmd diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..98fccd6 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.8 \ No newline at end of file diff --git a/Default.sublime-commands b/Default.sublime-commands new file mode 100644 index 0000000..46e1832 --- /dev/null +++ b/Default.sublime-commands @@ -0,0 +1,3 @@ +[ + { "caption": "Switch: Window", "command": "switch_window"}, +] \ No newline at end of file diff --git a/Default.sublime-keymap b/Default.sublime-keymap new file mode 100644 index 0000000..0c27100 --- /dev/null +++ b/Default.sublime-keymap @@ -0,0 +1,7 @@ +[ + { + "keys": ["ctrl+k", "ctrl+tab"], + "command": "show_overlay", + "args": {"overlay": "command_palette", "command": "switch_window"} + } +] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8d63fa9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,8 @@ +The MIT License (MIT) +Copyright (c) 2023 Sublime Text Packages + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Main.sublime-menu b/Main.sublime-menu new file mode 100644 index 0000000..fc16b9f --- /dev/null +++ b/Main.sublime-menu @@ -0,0 +1,10 @@ +[ + { + "id": "file", + "children": + [ + { "caption": "-", "id": "window" }, + { "caption": "Switch Windowโ€ฆ", "command": "switch_window" } + ] + } +] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b9090c5 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# Switch Window + +A Sublime Text plugin which lets you +quickly switch between windows +via Command Palette or key bindings. + +![](preview.png) +## Installation + +### Package Control + +The easiest way to install is using [Package Control](https://packagecontrol.io). It's listed as `Switch Window`. + +1. Open `Command Palette` using ctrl+shift+P or menu item `Tools โ†’ Command Palette...` +2. Choose `Package Control: Install Package` +3. Find `Switch Window` and hit Enter + +### Manual Install + +1. Download [Switch Window.sublime-package](https://github.com/SublimeText/Liquid/releases). +2. Copy it into _Installed Packages_ directory + +> To find _Installed Packages_... +> +> 1. call _Menu > Preferences > Browse Packages.._ +> 2. Navigate to parent folder + +## Usage + +1. Open `Command Palette` using ctrl+shift+P or menu item `Tools โ†’ Command Palette...` +2. Type `Switch: Window` and hit enter + +or hit ctrl+k, ctrl+tab in sequence +to show the `Switch Window` Quick Panel directly. \ No newline at end of file diff --git a/preview.png b/preview.png new file mode 100644 index 0000000..26799ff Binary files /dev/null and b/preview.png differ diff --git a/switch_window.py b/switch_window.py new file mode 100644 index 0000000..5008ccf --- /dev/null +++ b/switch_window.py @@ -0,0 +1,75 @@ +import os + +import sublime +import sublime_plugin + + +class WindowInputHandler(sublime_plugin.ListInputHandler): + + def name(self): + return "window_id" + + def placeholder(self): + return "Chosse a window" + + def list_items(self): + items = [] + + kind_project = [sublime.KIND_ID_NAMESPACE, "๐Ÿ—”", "Project"] + kind_file = [sublime.KIND_ID_NAVIGATION, "๐Ÿ—”", "File"] + + for window in sublime.windows(): + active_file_name = "untitled" + view = window.active_view() + if view: + file_name = view.file_name() + if file_name: + active_file_name = os.path.basename(file_name) + elif view.name(): + active_file_name = view.name() + + project_file_name = window.project_file_name() + if project_file_name: + title = f"Project: {os.path.splitext(os.path.basename(project_file_name))[0]}" + kind = kind_project + details = [ + f"Active File: {active_file_name}" + ] + else: + title = f"File: {active_file_name}" + kind = kind_file + details = [ + f"Project: none" + ] + + items.append( + sublime.ListInputItem( + text=title, + value=window.id(), + annotation=f"Window {window.id()}", + kind=kind, + details=details + ) + ) + + return items + + +class SwitchWindowCommand(sublime_plugin.ApplicationCommand): + + def input_description(self): + return "Switch Window" + + def input(self, args): + if args.get("window_id") is None: + return WindowInputHandler() + return None + + def run(self, window_id=None): + for window in sublime.windows(): + if window.id() == window_id: + window.bring_to_front() + break + + def is_enabled(self): + return len(sublime.windows()) > 1