Created
March 7, 2012 17:04
-
-
Save agibsonsw/1994404 to your computer and use it in GitHub Desktop.
ST navigate sorted files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin, os, datetime | |
from operator import itemgetter | |
file_views = [] | |
class OrderedFilesCommand(sublime_plugin.TextCommand): | |
def run(self, edit, index): | |
global file_views | |
file_views = [] | |
for vw in self.view.window().views(): | |
head, tail = os.path.split(vw.file_name()) | |
modified = os.path.getmtime(vw.file_name()) | |
file_views.append((tail, vw, modified)) | |
file_views.sort(key = itemgetter(index)) | |
print file_views | |
if index == 2: | |
self.view.window().show_quick_panel([ | |
(datetime.datetime.fromtimestamp(z)).strftime("%d-%m-%y %H:%M") + ' ' + x \ | |
for (x, y, z) in file_views], self.on_chosen) | |
else: | |
self.view.window().show_quick_panel([x for (x, y, z) in file_views], \ | |
self.on_chosen) | |
def on_chosen(self, index): | |
if index != -1: | |
win = self.view.window() | |
win.focus_view(file_views[index][1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assign key bindings such as
{ "keys": ["ctrl+alt+x"], "command": "ordered_files", "args": { "index": 0 } },
{ "keys": ["ctrl+alt+c"], "command": "ordered_files", "args": { "index": 2 } },
to show a quick panel listing open files sorted alphabetically (index == 0) or by modified date (index == 2).
Choosing a file activates it.