Home Download Buy Blog Forum Support

Sort Open Files

Sort Open Files

Postby pyparadigm on Sat Nov 26, 2011 4:38 am

It would be cool if there was a down arrow next to Open Files where you can sort by Manual, Alphabetical, File Type/Ext, maybe Last Modified, like:

Image

This would help you maintain a consistent interface for finding files easily if you have 20+ open at once.
pyparadigm
 
Posts: 23
Joined: Thu Aug 04, 2011 8:15 am

Re: Sort Open Files

Postby C0D312 on Sat Nov 26, 2011 8:15 pm

I don't see why you'd need this when there's the GoToAnything...
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Sort Open Files

Postby dfrechette on Thu Jan 05, 2012 8:18 pm

... because it would be easier on the eyes and some people, like myself, prefer to have things well ordered.
dfrechette
 
Posts: 6
Joined: Tue Oct 18, 2011 4:02 pm

Re: Sort Open Files

Postby allclone on Fri Feb 17, 2012 1:44 am

I think this would be a quick helpful thing to have available with many open files.

+1 for my interest.
allclone
 
Posts: 1
Joined: Fri Feb 17, 2012 1:40 am
Location: Kalamazoo, MI

Re: Sort Open Files

Postby tpneumat on Wed Mar 07, 2012 1:52 pm

+1 .. I want this too. I always end up working on 20+ files no matter how hard I try to keep closing them and at that point the tabs become unreadable and locating an open file would be simple if it was alpha sorted.
tpneumat
 
Posts: 6
Joined: Sat Mar 03, 2012 10:03 pm

Re: Sort Open Files

Postby agibsonsw on Wed Mar 07, 2012 2:13 pm

I suppose it wouldn't be impossible to create a TextCommand that closes all open files, re-opens them in a specific sorted order, and returns to the previous cursor position.

Easier, and perhaps more convenient, is to create a command that shows a quick panel listing the currently open files in a particular order, and allows you to switch to a selected file. This way, the SideBar will continue to list files in the order they were opened.

I quite like this idea.. might give it a bash. Added: However, Ctrl-P and other menu options seem to almost cover this anyway(?).
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Sort Open Files

Postby agibsonsw on Wed Mar 07, 2012 3:22 pm

Here's a rough and ready version (for Windows):

Code: Select all
import sublime, sublime_plugin, os

open_files = []
full_files = []

class OrderedFilesCommand(sublime_plugin.TextCommand):
   def run(self, edit):
      global open_files
      global full_files
      open_files = []
      full_files = []
      for vw in self.view.window().views():
         head, tail = os.path.split(vw.file_name())
         open_files.append(tail)
         full_files.append((tail, head))
      open_files.sort()
      full_files.sort()
      self.view.window().show_quick_panel(open_files, self.on_done_choosing)

   def on_done_choosing(self, index):
      if index != -1:
         win = self.view.window()
         win.open_file(full_files[index][1] + '\\' + full_files[index][0])

Assign it a shortcut key and it will open a quick panel listing files in alphabetical order. Select the file to activate it.

Amending '\\' to '\/' should get it to work with other os's, but I'm sure there's a property like 'file_separator' that will make it work in both.

It's not as neat as I would like, but not bad for a first attempt. It will be possible to amend it so that a different shortcut would show the list in, for example, last modified order. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Sort Open Files

Postby agibsonsw on Wed Mar 07, 2012 3:37 pm

This is much neater and doesn't require the file separator character:

Code: Select all
import sublime, sublime_plugin, os

open_files = []
their_view = []

class OrderedFilesCommand(sublime_plugin.TextCommand):
   def run(self, edit):
      global open_files
      global their_view
      open_files = []
      their_view = []
      for vw in self.view.window().views():
         head, tail = os.path.split(vw.file_name())
         open_files.append(tail)
         their_view.append((tail, vw))
      open_files.sort()
      their_view.sort()
      self.view.window().show_quick_panel(open_files, self.on_done_choosing)

   def on_done_choosing(self, index):
      if index != -1:
         win = self.view.window()
         win.focus_view(their_view[index][1])

I would prefer to only use one list. But if I have a list of tuples, how can I pass this as an array of strings - using only the first of the 2 tuple-elements?
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Sort Open Files

Postby agibsonsw on Wed Mar 07, 2012 3:49 pm

And finally :D 8-)

Code: Select all
import sublime, sublime_plugin, os

file_views = []

class OrderedFilesCommand(sublime_plugin.TextCommand):
   def run(self, edit):
      global file_views
      file_views = []
      for vw in self.view.window().views():
         head, tail = os.path.split(vw.file_name())
         file_views.append((tail, vw))
      file_views.sort()
      self.view.window().show_quick_panel([x for (x, y) 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])
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Sort Open Files

Postby tito on Wed Mar 07, 2012 4:10 pm

You can sort the tabs every time a new tab is opened or finish loading. That way the list will stay sorted always.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 708
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Next

Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 9 guests

cron