Changeset 1682:cfc7a1a73805

Show
Ignore:
Timestamp:
11/22/08 00:05:18 (7 weeks ago)
Author:
Ali Afshar <aafshar@…>
Parents:
1679:b24dbcc340fd, 1681:b6979d84d3f8
Message:

merged 270

Files:
2 removed
1 modified

Legend:

Unmodified
Added
Removed
  • pida/core/document.py

    r1680 r1682  
    8282 
    8383    def __init__(self, boss, filename=None, project=None): 
     84        """ 
     85        Create a new Document instance. 
     86         
     87        @boss: boss this document belongs to 
     88        @filename: path to the file or None (unamed buffer) 
     89        @project: project this document belongs to 
     90        """ 
    8491        self.boss = boss 
    8592        if filename is not None: 
    86             filename = os.path.realpath(filename) 
    87         self.filename = filename 
     93            self.filename = os.path.realpath(filename) 
     94        else: 
     95            self.filename = None 
    8896        self.project = project 
    8997        self.editor = None 
     
    108116 
    109117    def clear(self): 
     118        """ 
     119        Clear document caches 
     120        """ 
    110121        self._str = None 
    111122        self._lines = None 
     
    171182    @property 
    172183    def stat(self): 
     184        """ 
     185        Returns the stat of the current file 
     186        """ 
    173187        try: 
    174188            return os.stat(self.filename) 
     
    178192    @cached_property 
    179193    def mimetype(self): 
     194        """ 
     195        Returns the mimetype guessed from the file 
     196        """ 
    180197        #FIXME: use doctypes 
    181198        typ, encoding = mimetypes.guess_type(self.filename) 
     
    188205    @property 
    189206    def filesize(self): 
     207        """ 
     208        Filesize of Document 
     209        """ 
    190210        return self.stat[stat.ST_SIZE] 
    191211 
     
    210230    @property 
    211231    def markup_title(self): 
    212         """Returns a markup version of unicode""" 
     232        """ 
     233        Returns a markup version of unicode 
     234        """ 
    213235        if self.filename is None: 
    214236            if self.newfile_index > 1: 
     
    229251    @property 
    230252    def encoding(self): 
     253        """ 
     254        Encoding of file 
     255        """ 
    231256        self._load() 
    232257        # FIXME: if self.is_new we should run the _encode detection from 
     
    243268    @property 
    244269    def live(self): 
     270        """ 
     271        Returns a boolean if the document is loaded in the editor 
     272        """ 
    245273        # live indicates that this object has a editor instance which get_content 
    246274        #self.live = False 
     
    250278        return False 
    251279 
    252     def get_content(self): 
    253         if hasattr(self.editor, 'get_content') and self.editor: 
     280    def get_content(self, live=True): 
     281        """ 
     282        Returns the content of the document. 
     283        If live is true and the document is loaded into an editor the 
     284        content of the editor is returned 
     285        """ 
     286        if live and hasattr(self.editor, 'get_content') and self.editor: 
    254287            return self.boss.editor.get_content(self.editor) 
    255288        self._load() 
    256289        return self._str 
    257290 
    258     def set_content(self, value, flush=True): 
     291    def set_content(self, value, flush=True, live=True): 
     292        """ 
     293        Sets the content of the document. 
     294        If live is True and the document is loaded, it's content is returned 
     295        """ 
    259296        if hasattr(self.boss.editor, 'set_content') and self.editor: 
    260297            return self.boss.editor.set_content(self.editor, value) 
     
    269306 
    270307    def flush(self): 
     308        """ 
     309        Flush the buffer. 
     310        If editor has loaded this document, it's value 
     311        is fetched befor writing to disc 
     312        """ 
    271313        if hasattr(self.editor, 'get_content') and self.editor: 
    272314            value = self.boss.editor.get_content(self.editor) 
     
    294336    @property 
    295337    def directory(self): 
     338        """ 
     339        Directory name the Document is located in 
     340        """ 
    296341        if self.is_new: 
    297342            return None 
     
    300345    @property 
    301346    def directory_basename(self): 
     347        """ 
     348        Directory's name the Document is located in 
     349        """ 
    302350        if self.is_new: 
    303351            return None 
     
    306354    @property 
    307355    def basename(self): 
     356        """ 
     357        Basename of the file. It's actuall filename 
     358        """ 
    308359        if self.is_new: 
    309360            return None 
     
    319370 
    320371    def get_markup(self, markup_string=None, style=None): 
     372        """ 
     373        Returns a markup version the Document designed for 
     374        beeing embedded in gtk views 
     375        """ 
    321376        if markup_string is None: 
    322377            if self.project: 
     
    335390 
    336391    def get_markup_tworow(self, style=None): 
     392        """ 
     393        Two rowed version of above 
     394        """ 
    337395        if self.project: 
    338396            mark = self.get_markup(self.markup_string_tworow_project) 
     
    359417    @property 
    360418    def project_name(self): 
     419        """ 
     420        Name of Project or None 
     421        """ 
    361422        if self.project is not None: 
    362423            return self.project.display_name 
     
    365426 
    366427    def get_project_relative_path(self): 
     428        """ 
     429        Returns the relative path to Project's root 
     430        """ 
    367431        if self.filename is None: 
    368432            return None, None 
     
    379443    @property 
    380444    def is_new(self): 
     445        """ 
     446        True if the Document is not associated to a filename 
     447        """ 
    381448        return self.filename is None 
    382449 
     
    401468 
    402469    def append(self, line): 
     470        """ 
     471        Add a line to the Document 
     472        """ 
    403473        self._list.append(line) 
    404474        self._update_content_from_lines()