Changeset 1424

Show
Ignore:
Timestamp:
06/28/08 08:09:58 (5 months ago)
Author:
rob
Message:

Refs #318 and #158: added template support
* rudimentary template support needs to be related to projects, so added a stub project plugin that also deals with global templates

Location:
trunk/peppy
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/fundamental.py

    r1399 r1424  
    198198         
    199199        self.spell = None 
     200         
     201        self.applyTemplate() 
    200202 
    201203        self.applySettings() 
     
    290292        if self.spell and self.spell.hasDictionary(): 
    291293            self.status_info.addIcon("icons/book_open.png", "Dictionary available for %s" % self.spell.getLanguage()) 
     294     
     295    def applyTemplate(self): 
     296        """Attempt to load a template when encountering a zero length file 
     297         
     298        """ 
     299        if self.GetLength() == 0: 
     300            info = dict(url=self.buffer.url, mode=self, templates=list()) 
     301            Publisher().sendMessage('template.find', info) 
     302            dprint(info) 
     303             
     304            # templates is a list, where each element is a tuple consisting of 
     305            # the sort order and the template 
     306            sorted = info['templates'] 
     307            sorted.sort(key=lambda x:x[0]) 
     308            dprint(sorted) 
     309            if len(sorted) > 0: 
     310                template = sorted[0][1] 
     311                self.resetText(template) 
    292312 
    293313    def applySettings(self): 
  • trunk/peppy/stcbase.py

    r1415 r1424  
    206206    def openSuccess(self, buffer, headersize=1024, encoding=None): 
    207207        bytes = self.tempstore.getvalue() 
     208         
     209        self.resetText(bytes, headersize, encoding) 
     210         
     211        del self.tempstore 
     212     
     213    def resetText(self, bytes, headersize=1024, encoding=None): 
    208214        numbytes = len(bytes) 
    209215        if headersize > numbytes: 
     
    218224        self.decodeText(bytes) 
    219225        assert self.dprint("found encoding = %s" % self.refstc.encoding) 
    220          
    221         del self.tempstore 
    222226     
    223227    def readFrom(self, fh, amount=None, chunk=65536, length=0, message=None):