Skip to content

Instantly share code, notes, and snippets.

@agibsonsw
Created March 8, 2012 18:56
Show Gist options
  • Save agibsonsw/2002704 to your computer and use it in GitHub Desktop.
Save agibsonsw/2002704 to your computer and use it in GitHub Desktop.
ST navigate sorted files (neater 2)
import sublime, sublime_plugin, os
from operator import itemgetter
from datetime import datetime
class OrderedFilesCommand(sublime_plugin.TextCommand):
def run(self, edit, index):
OF = OrderedFilesCommand
OF.file_views = []
win = self.view.window()
for vw in win.views():
head, tail = os.path.split(vw.file_name())
modified = os.path.getmtime(vw.file_name())
OF.file_views.append((tail, vw, modified))
if index == 0:
OF.file_views.sort(key = lambda (tail, Doh, Dur): tail.lower())
win.show_quick_panel([x for (x, y, z) in OF.file_views], self.on_chosen)
else:
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.view.window().focus_view(OrderedFilesCommand.file_views[index][1])
@agibsonsw
Copy link
Author

This neater, final, version has no additional functionality, but it removes the global variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment