Better path changing support
* Create a get_collection method similar to get_* methods for objects. * Fix title initialization of a collection * Remove the hack were both id and title were allowed when CDing. That hack only worked with the canalplus module, and failed with others like redmine (but they still showed in suggestions). Moreover, the canalplus module now has friendlier IDs so this is not really needed anymore. * Allow backends to tell if a path is valid or not. For instance, it now allows to cd in a Redmine project with no issues in it. It also won't display "404" for invalid project IDs. By default, we still use the unreliable method of checking there is at least one result in iter_resources(). * Fix cd completion to work with unicode strings (all strings after an unicode string were ignored!) * Do not suggest '..' when completing cd in the root refs #774
This commit is contained in:
parent
1a5ece25df
commit
b6021d4732
5 changed files with 57 additions and 24 deletions
|
|
@ -894,16 +894,16 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
else:
|
||||
self.working_path.cd1(line)
|
||||
|
||||
objects, collections = self._fetch_objects(objs=self.COLLECTION_OBJECTS)
|
||||
if len(objects) + len(collections) == 0:
|
||||
collections = [res for backend, res in self.do('get_collection',
|
||||
objs=self.COLLECTION_OBJECTS, split_path=self.working_path.get(),
|
||||
caps=ICapCollection) if res is not None]
|
||||
if len(collections):
|
||||
self._change_prompt()
|
||||
else:
|
||||
print >>sys.stderr, u"Path: %s not found" % unicode(self.working_path)
|
||||
self.working_path.restore()
|
||||
return 1
|
||||
|
||||
self._change_prompt()
|
||||
self.objects = objects
|
||||
self.collections = collections
|
||||
|
||||
def _fetch_objects(self, objs):
|
||||
objects = []
|
||||
collections = []
|
||||
|
|
@ -927,7 +927,9 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
return (objects, collections)
|
||||
|
||||
def complete_cd(self, text, line, begidx, endidx):
|
||||
directories = set(['..'])
|
||||
directories = set()
|
||||
if len(self.working_path.get()):
|
||||
directories.add('..')
|
||||
mline = line.partition(' ')[2]
|
||||
offs = len(mline) - len(text)
|
||||
|
||||
|
|
@ -935,9 +937,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
self.objects, self.collections = self._fetch_objects(objs=self.COLLECTION_OBJECTS)
|
||||
|
||||
for collection in self.collections:
|
||||
directories.add(collection.id)
|
||||
if collection.title:
|
||||
directories.add(collection.title)
|
||||
directories.add(collection.id.encode(sys.stdout.encoding or locale.getpreferredencoding()))
|
||||
|
||||
return [s[offs:] for s in directories if s.startswith(mline)]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue