Home Download Buy Blog Forum Support

Order ctrl+p results with root first?

Order ctrl+p results with root first?

Postby AbsoluteDestiny on Mon Nov 16, 2009 5:14 pm

I often use ctrl+p and wonder why the subdirectory links appear before the links in the root project folder. The other way around seems a bit more logical to me.

Actually, in an ideal world the results of ctrl+p would promote the priority of items that are directory neighbours to the file you are currently editing, with the rest of the results being ordered in the usual, predictable, alphanumeric way. That's imho. There's a million ways you could order them and the current is, at least, very predictable :)
AbsoluteDestiny
 
Posts: 12
Joined: Fri Oct 23, 2009 2:27 pm

Re: Order ctrl+p results with root first?

Postby barty on Wed Nov 18, 2009 5:00 pm

it's not exactly what you want but here are a couple of commands that list the current directory tree using depth first and breadth first search.

Code: Select all
import sublime, sublimeplugin
import os.path
import functools


badExtensions = ['.jpg', '.gif', '.png', '.pyc', '.pyo', '.bin', '.o',
   '.so', '.obj', '.lib', '.pdb', '.suo', '.ncb', '.dll', '.exe', '.zip',
   '.tar', '.gz', '.bz2', '.tgz', '.rar', '.pdf', '.doc', '.tmp', '.bak']

def wantFile(cwd, f):
   root, ext = os.path.splitext(f)
   return os.path.isfile(os.path.join(cwd,f)) and not ext in badExtensions

class PromptOpenFileInCurrentDirectoryTreeDFSCommand(sublimeplugin.WindowCommand):
   """Open a file in the current directory tree using dfs"""

   def run(self, window, args):
      cwd = os.getcwdu()
      files = []
      cnt = 0
      max = 1000
      for root, subFolders, filesInFolder in os.walk(cwd):
         for file in filesInFolder:
            if wantFile(root,file):
               files.append(os.path.join(root,file))
               cnt += 1
               if cnt>=max: break
            if cnt>=max: break
         if cnt>=max: break

      # construct list of files minus the top directory for display
      l = 1+len(cwd)
      displayFiles = [f[l:] for f in files]

      window.showQuickPanel("", "open", files, displayFiles,
         sublime.QUICK_PANEL_FILES | sublime.QUICK_PANEL_MULTI_SELECT)

class PromptOpenFileInCurrentDirectoryTreeCommand(sublimeplugin.WindowCommand):
   """Open a file in the current directory tree using breadth first search"""

   # code taken from http://code.activestate.com/recipes/511456/
   def breadthFirstFileScan( self, root, max ) :
      cnt  = 0
      dirs = [root]
      # while we have dirs to scan
      while len(dirs) :
         nextDirs = []
         for parent in dirs :
            # scan each dir
            for f in os.listdir( parent ) :
               # if there is a dir, then save for next ittr
               # if it  is a file then yield it (we'll return later)
               ff = os.path.join( parent, f )
               if os.path.isdir( ff ) :
                  nextDirs.append( ff )
               else :
                  if wantFile(parent, f):
                     yield ff
                     cnt += 1
                     if cnt >= max: return
         # once we've done all the current dirs then
         # we set up the next itter as the child dirs
         # from the current itter.
         dirs = nextDirs

   def run(self, window, args):
      cwd = os.getcwdu()
      files = []
      for f in self.breadthFirstFileScan( cwd, 1000 ) :
         files.append( f)

      # construct list of files minus the top directory for display
      l = 1+len(cwd)
      displayFiles = [f[l:] for f in files]

      window.showQuickPanel("", "open", files, displayFiles,
         sublime.QUICK_PANEL_FILES | sublime.QUICK_PANEL_MULTI_SELECT)

barty
 
Posts: 47
Joined: Thu Sep 10, 2009 5:39 am


Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 15 guests