skube wrote:How does one use this? Do you copy and save to a file call OrderedFiles.py? Does it have to go in any particular folder in the packages directory?
The file doesn't have to be named 'OrderedFiles.py', although it seems sensible to do so.
skube wrote:How does one use this? Do you copy and save to a file call OrderedFiles.py? Does it have to go in any particular folder in the packages directory?
{ "keys": ["ctrl+alt+x"], "command": "ordered_files", "args": { "index": 0 } },
{ "keys": ["ctrl+alt+c"], "command": "ordered_files", "args": { "index": 2 } }{ "keys": ["ctrl+alt+x"], "command": "ordered_files", "args": { "index": 0 } },
{ "keys": ["ctrl+alt+c"], "command": "ordered_files", "args": { "index": 2 } } << bet you need to add a comma!desperado70 wrote:I managed to get this running. However, this opens a new list/dopdown with all the open files. Would it be possible to use this to re-order the "open files" list on the left?
import sublime_plugin
from os import path
from operator import itemgetter
# A simple command to sort current tabs alphabetically (returning focus to the
# original tab).
# Does not work with different groups or windows. Not catered for unsaved views
# (although it seems to work okay if there are any). It could be modified to
# work in these circumstances.
# { "keys": ["ctrl+alt+b"], "command": "sort_tabs" },
class SortTabsCommand(sublime_plugin.WindowCommand):
def run(self):
file_views = []
win = self.window
curr_view = win.active_view()
for vw in win.views():
_, tail = path.split(vw.file_name() or path.sep)
group, _ = win.get_view_index(vw)
file_views.append((tail.lower(), vw, group))
file_views.sort(key = itemgetter(2, 0))
moving_index = 0
for index, (_, vw, group) in enumerate(file_views):
if index == 0 or group > prev_group:
moving_index = 0
prev_group = group
else:
moving_index += 1
win.set_view_index(vw, group, moving_index)
win.focus_view(curr_view)# suggested key binding
{ "keys": ["ctrl+alt+b"], "command": "sort_tabs" }
import sublime_plugin
from os import path
from operator import itemgetter
from datetime import datetime
# Lists open files in a quick panel for jumping to,
# ordered alphabetically or by modified date: index, 0, for alphabetical.
# { "keys": ["ctrl+alt+x"], "command": "ordered_files", "args": { "index": 0 } },
# { "keys": ["ctrl+alt+c"], "command": "ordered_files", "args": { "index": 2 } },
# Does not work with different groups, windows, or unsaved views (although it could
# be modified so that it does).
class OrderedFilesCommand(sublime_plugin.WindowCommand):
def run(self, index):
OF = OrderedFilesCommand
OF.file_views = []
win = self.window
for vw in win.views():
if vw.file_name() is not None:
_, tail = path.split(vw.file_name())
modified = path.getmtime(vw.file_name())
OF.file_views.append((tail, vw, modified))
else:
pass # leave new/untitled files (for the moment)
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])Return to Ideas and Feature Requests
Users browsing this forum: No registered users and 6 guests