Changeset 1503

Show
Ignore:
Timestamp:
07/22/08 21:11:32 (7 weeks ago)
Author:
rob
Message:

Added canonicalize parameter to Buffer
* controls whether or not the canonicalized url is used as the buffer keyword
* if the canonical url is not used, the normalized url is used which allows query string and fragments to be significant

Location:
trunk/peppy
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/buffers.py

    r1501 r1503  
    164164     
    165165    """ 
    166     def __init__(self, url, created_from_url=None): 
     166    def __init__(self, url, created_from_url=None, canonicalize=True): 
    167167        """Initialize the mixin. 
    168168         
     
    173173        for a local filesystem working directory if a working directory can't 
    174174        be determined from the real url. 
     175         
     176        @param canonicalize: whether or not the url should be canonicalized 
     177        before storing in the buffer list. 
    175178        """ 
    176179        self.bfh = None 
    177180        self.last_mtime = None 
     181        self.canonicalize = canonicalize 
    178182        self.setURL(url) 
    179183        self.created_from_url = created_from_url 
     
    184188        if not url: 
    185189            url = vfs.normalize("untitled") 
    186         else: 
     190        elif self.canonicalize: 
    187191            url = vfs.canonical_reference(url) 
     192        else: 
     193            url = vfs.normalize(url) 
    188194        self.url = url 
    189195        self.saveTimestamp() 
    190196 
    191197    def isURL(self, url): 
    192         url = vfs.canonical_reference(url) 
     198        if self.canonicalize: 
     199            url = vfs.canonical_reference(url) 
     200        else: 
     201            url = vfs.normalize(url) 
    193202        if url == self.url: 
    194203            return True 
     
    393402 
    394403        if not self.permanent: 
    395             basename=self.stc.getShortDisplayName(self.url) 
     404            basename=self.stc.getShortDisplayName(self.raw_url) 
    396405 
    397406            BufferList.removeBuffer(self) 
     
    408417 
    409418    def isBasename(self, basename): 
    410         return basename == self.stc.getShortDisplayName(self.url) 
     419        return basename == self.stc.getShortDisplayName(self.raw_url) 
    411420 
    412421    def setName(self): 
    413         basename=self.stc.getShortDisplayName(self.url) 
     422        basename=self.stc.getShortDisplayName(self.raw_url) 
    414423        if basename in self.filenames: 
    415424            count=self.filenames[basename]+1 
     
    582591    def createPostHook(self): 
    583592        self.showBusy(True) 
    584         wx.CallAfter(self.frame.openThreaded, self.buffer.user_url, 
     593        wx.CallAfter(self.frame.openThreaded, self.buffer.raw_url, 
    585594                     self.buffer, mode_to_replace=self) 
    586595 
    587596class LoadingBuffer(BufferVFSMixin, debugmixin): 
    588     def __init__(self, url, modecls=None, created_from_url=None): 
    589         self.user_url = url 
    590         BufferVFSMixin.__init__(self, url, created_from_url) 
     597    def __init__(self, url, modecls=None, created_from_url=None, canonicalize=True): 
     598        BufferVFSMixin.__init__(self, url, created_from_url, canonicalize) 
    591599        self.busy = True 
    592600        self.readonly = False 
     
    598606            self.modecls = modecls 
    599607        else: 
    600             self.modecls = MajorModeMatcherDriver.match(self) 
     608            self.modecls = MajorModeMatcherDriver.match(self, url=self.raw_url) 
    601609            self.dprint("found major mode = %s" % self.modecls) 
    602610        self.stc = LoadingSTC(unicode(url)) 
     
    608616     
    609617    def allowThreadedLoading(self): 
    610         return self.modecls.preferThreadedLoading(self.user_url) 
     618        return self.modecls.preferThreadedLoading(self.raw_url) 
    611619     
    612620    def clone(self): 
    613621        """Get a real Buffer instance from this temporary buffer""" 
    614         dprint(self.user_url) 
    615         return Buffer(self.user_url, self.modecls, self.created_from_url) 
     622        return Buffer(self.raw_url, self.modecls, self.created_from_url) 
    616623 
    617624    def addViewer(self, mode): 
  • trunk/peppy/frame.py

    r1488 r1503  
    704704            self.open(url) 
    705705 
    706     def open(self, url, modecls=None, mode_to_replace=None, force_new_tab=False, created_from_url=None): 
     706    def open(self, url, modecls=None, mode_to_replace=None, force_new_tab=False, created_from_url=None, canonicalize=True): 
    707707        """Open a new tab to edit the given URL. 
    708708         
     
    726726        creating a new file in the mem: filesystem and want a working directory 
    727727        on the local filesystem to be available if needed to save a copy. 
     728         
     729        @param canonicalize: (optional) whether or not the URL should be 
     730        canonicalized before searching the existing buffer list.  This is used 
     731        in the rare case where a fragment or query string is significant to 
     732        locating the data on the file system. 
    728733        """ 
    729734        # The canonical url stored in the buffer will be without query string 
     
    731736        # query string and fragment) it separately. 
    732737        user_url = vfs.normalize(url) 
    733         try: 
    734             buffer = BufferList.findBufferByURL(user_url) 
    735         except NotImplementedError: 
    736             # This means that the vfs implementation doesn't recognize the 
    737             # filesystem type.  This is the first place in the loading chain 
    738             # that the error can be encountered, so check for it here and load 
    739             # a new plugin if necessary. 
    740             found = False 
    741             plugins = wx.GetApp().plugin_manager.getActivePluginObjects() 
    742             for plugin in plugins: 
    743                 assert self.dprint("Checking %s" % plugin) 
    744                 plugin.loadVirtualFileSystem(user_url) 
    745                 try: 
    746                     buffer = BufferList.findBufferByURL(user_url) 
    747                     found = True 
    748                     break 
    749                 except NotImplementedError: 
    750                     pass 
    751             if not found: 
    752                 self.openFailure(user_url, "Unknown URI scheme") 
    753                 return 
     738        buffer = None 
     739        if canonicalize: 
     740            try: 
     741                buffer = BufferList.findBufferByURL(user_url) 
     742            except NotImplementedError: 
     743                # This means that the vfs implementation doesn't recognize the 
     744                # filesystem type.  This is the first place in the loading chain 
     745                # that the error can be encountered, so check for it here and load 
     746                # a new plugin if necessary. 
     747                found = False 
     748                plugins = wx.GetApp().plugin_manager.getActivePluginObjects() 
     749                for plugin in plugins: 
     750                    assert self.dprint("Checking %s" % plugin) 
     751                    plugin.loadVirtualFileSystem(user_url) 
     752                    try: 
     753                        buffer = BufferList.findBufferByURL(user_url) 
     754                        found = True 
     755                        break 
     756                    except NotImplementedError: 
     757                        pass 
     758                if not found: 
     759                    self.openFailure(user_url, "Unknown URI scheme") 
     760                    return 
    754761 
    755762        if buffer is not None: 
     
    758765        else: 
    759766            try: 
    760                 buffer = LoadingBuffer(user_url, modecls, created_from_url) 
     767                buffer = LoadingBuffer(user_url, modecls, created_from_url, canonicalize) 
    761768            except Exception, e: 
    762769                import traceback 
  • trunk/peppy/hsi/loader.py

    r1501 r1503  
    2626        return False 
    2727     
     28    def getShortDisplayName(self, url): 
     29        """Return a short name for display in tabs or other context without 
     30        needing a pathname. 
     31        """ 
     32        if url.fragment: 
     33            return "%s#%s" % (url.path.get_name(), url.fragment) 
     34        return url.path.get_name() 
     35 
    2836    def getHandler(self): 
    2937        return self.dataset.__class__