Skip to content

Commit ac0b5b9

Browse files
committed
Initial Commit
0 parents  commit ac0b5b9

File tree

9 files changed

+140
-0
lines changed

9 files changed

+140
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
*.cmd

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.8

Default.sublime-commands

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
{ "caption": "Switch: Window", "command": "switch_window"},
3+
]

Default.sublime-keymap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"keys": ["ctrl+k", "ctrl+tab"],
4+
"command": "show_overlay",
5+
"args": {"overlay": "command_palette", "command": "switch_window"}
6+
}
7+
]

LICENSE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2023 Sublime Text Packages
3+
4+
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:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
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.

Main.sublime-menu

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"id": "file",
4+
"children":
5+
[
6+
{ "caption": "-", "id": "window" },
7+
{ "caption": "Switch Window…", "command": "switch_window" }
8+
]
9+
}
10+
]

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Switch Window
2+
3+
A Sublime Text plugin which lets you
4+
quickly switch between windows
5+
via Command Palette or key bindings.
6+
7+
![](preview.png)
8+
## Installation
9+
10+
### Package Control
11+
12+
The easiest way to install is using [Package Control](https://packagecontrol.io). It's listed as `Switch Window`.
13+
14+
1. Open `Command Palette` using <kbd>ctrl+shift+P</kbd> or menu item `Tools → Command Palette...`
15+
2. Choose `Package Control: Install Package`
16+
3. Find `Switch Window` and hit <kbd>Enter</kbd>
17+
18+
### Manual Install
19+
20+
1. Download [Switch Window.sublime-package](https://github.com/SublimeText/Liquid/releases).
21+
2. Copy it into _Installed Packages_ directory
22+
23+
> To find _Installed Packages_...
24+
>
25+
> 1. call _Menu > Preferences > Browse Packages.._
26+
> 2. Navigate to parent folder
27+
28+
## Usage
29+
30+
1. Open `Command Palette` using <kbd>ctrl+shift+P</kbd> or menu item `Tools → Command Palette...`
31+
2. Type `Switch: Window` and hit <kbd>enter</kbd>
32+
33+
or hit <kbd>ctrl+k</kbd>, <kbd>ctrl+tab</kbd> in sequence
34+
to show the `Switch Window` Quick Panel directly.

preview.png

81.2 KB
Loading

switch_window.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import os
2+
3+
import sublime
4+
import sublime_plugin
5+
6+
7+
class WindowInputHandler(sublime_plugin.ListInputHandler):
8+
9+
def name(self):
10+
return "window_id"
11+
12+
def placeholder(self):
13+
return "Chosse a window"
14+
15+
def list_items(self):
16+
items = []
17+
18+
kind_project = [sublime.KIND_ID_NAMESPACE, "🗔", "Project"]
19+
kind_file = [sublime.KIND_ID_NAVIGATION, "🗔", "File"]
20+
21+
for window in sublime.windows():
22+
active_file_name = "untitled"
23+
view = window.active_view()
24+
if view:
25+
file_name = view.file_name()
26+
if file_name:
27+
active_file_name = os.path.basename(file_name)
28+
elif view.name():
29+
active_file_name = view.name()
30+
31+
project_file_name = window.project_file_name()
32+
if project_file_name:
33+
title = f"Project: {os.path.splitext(os.path.basename(project_file_name))[0]}"
34+
kind = kind_project
35+
details = [
36+
f"Active File: {active_file_name}"
37+
]
38+
else:
39+
title = f"File: {active_file_name}"
40+
kind = kind_file
41+
details = [
42+
f"Project: none"
43+
]
44+
45+
items.append(
46+
sublime.ListInputItem(
47+
text=title,
48+
value=window.id(),
49+
annotation=f"Window {window.id()}",
50+
kind=kind,
51+
details=details
52+
)
53+
)
54+
55+
return items
56+
57+
58+
class SwitchWindowCommand(sublime_plugin.ApplicationCommand):
59+
60+
def input_description(self):
61+
return "Switch Window"
62+
63+
def input(self, args):
64+
if args.get("window_id") is None:
65+
return WindowInputHandler()
66+
return None
67+
68+
def run(self, window_id=None):
69+
for window in sublime.windows():
70+
if window.id() == window_id:
71+
window.bring_to_front()
72+
break
73+
74+
def is_enabled(self):
75+
return len(sublime.windows()) > 1

0 commit comments

Comments
 (0)