Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Jan 1, 2023
0 parents commit ac0b5b9
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
*.cmd
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
3 changes: 3 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{ "caption": "Switch: Window", "command": "switch_window"},
]
7 changes: 7 additions & 0 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"keys": ["ctrl+k", "ctrl+tab"],
"command": "show_overlay",
"args": {"overlay": "command_palette", "command": "switch_window"}
}
]
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 10 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"id": "file",
"children":
[
{ "caption": "-", "id": "window" },
{ "caption": "Switch Window…", "command": "switch_window" }
]
}
]
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <kbd>ctrl+shift+P</kbd> or menu item `Tools → Command Palette...`
2. Choose `Package Control: Install Package`
3. Find `Switch Window` and hit <kbd>Enter</kbd>

### 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 <kbd>ctrl+shift+P</kbd> or menu item `Tools → Command Palette...`
2. Type `Switch: Window` and hit <kbd>enter</kbd>

or hit <kbd>ctrl+k</kbd>, <kbd>ctrl+tab</kbd> in sequence
to show the `Switch Window` Quick Panel directly.
Binary file added preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions switch_window.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ac0b5b9

Please sign in to comment.