Skip to content

Commit

Permalink
Add more window kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Jan 5, 2023
1 parent 4d2de48 commit 6484222
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@ The easiest way to install is using [Package Control](https://packagecontrol.io)
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.
to show the `Switch Window` Quick Panel directly.

## Kind Info

The kind of a window is displayed via icon.

| icon | description
|:----:|:---
| P | A project/workspace is opened in the window
| F | One or more folders are opened in the window. The best matching one according to the active file is displayed in description line.
| f | A file is displayed in active view of a window, which has no project or folder open.
| S | An unsaved view is displayed in active view of a window, which has no project or folder open.
Binary file modified preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions switch_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def list_items(self):
items = []

kind_project = [sublime.KIND_ID_NAMESPACE, "P", "Project"]
kind_file = [sublime.KIND_ID_NAVIGATION, "F", "File"]
kind_folder = [sublime.KIND_ID_NAMESPACE, "F", "Folder"]
kind_file = [sublime.KIND_ID_NAVIGATION, "f", "File"]
kind_scratch = [sublime.KIND_ID_AMBIGUOUS, "S", "Scratch"]

active_window = sublime.active_window()
for window in sublime.windows():
Expand All @@ -41,20 +43,22 @@ def list_items(self):

else:
title = active_file_name
kind = kind_file

folders = window.folders()
if folders:
kind = kind_folder
for folder in window.folders():
if active_file_name.startswith(folder):
second_line = f"Folder: {folder}"
break
else:
second_line = f"Folder: {folders[0]}"
elif active_file_location:
kind = kind_file
second_line = f"Location: {active_file_location}"
else:
second_line = "Scratch"
kind = kind_scratch
second_line = "Scratch Window"

items.append(
sublime.ListInputItem(
Expand Down

0 comments on commit 6484222

Please sign in to comment.