Created
March 9, 2012 19:07
-
-
Save agibsonsw/2008129 to your computer and use it in GitHub Desktop.
ST navigate sorted files (Window)
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 | |
from os import path | |
from operator import itemgetter | |
from datetime import datetime | |
class OrderedFilesCommand(sublime_plugin.WindowCommand): | |
def run(self, index): | |
OF = OrderedFilesCommand | |
OF.file_views = [] | |
win = self.window | |
for vw in win.views(): | |
head, tail = path.split(vw.file_name()) | |
modified = path.getmtime(vw.file_name()) | |
OF.file_views.append((tail, vw, modified)) | |
if index == 0: # sort by file name (case-insensitive) | |
OF.file_views.sort(key = lambda (tail, _, Doh): tail.lower()) | |
win.show_quick_panel([x for (x, y, z) in OF.file_views], self.on_chosen) | |
else: # sort by modified date (index == 2) | |
OF.file_views.sort(key = itemgetter(2)) | |
win.show_quick_panel([ | |
(datetime.fromtimestamp(z)).strftime("%d-%m-%y %H:%M ") + x \ | |
for (x, y, z) in OF.file_views], self.on_chosen) | |
def on_chosen(self, index): | |
if index != -1: | |
self.window.focus_view(OrderedFilesCommand.file_views[index][1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is more suitable as a WindowCommand, as it applies to the window as a whole.