예제 #1
0
    def openGUIThreadSuccess(self):
        # Only increment count on successful buffer loads
        Buffer.count += 1
        self.order_loaded = Buffer.count

        self.closeBufferedReader()

        self.stc.openSuccess(self)

        self.setName()

        # If it doesn't exist, that means we are creating the file, so it
        # should be writable.
        self.readonly = not (vfs.can_write(self.url)
                             or not vfs.exists(self.url))
        #dprint("readonly = %s" % self.readonly)

        self.stc.EmptyUndoBuffer()

        # Add to the currently-opened buffer list
        BufferList.addBuffer(self)

        # Send a message to any interested plugins that a new buffer
        # has been successfully opened.
        pub.sendMessage('buffer.opened', buffer=self)
        wx.CallAfter(self.showModifiedAll)
예제 #2
0
 def save(self, url=None):
     assert self.dprint(u"Buffer: saving buffer %s as %s" % (self.url, url))
     try:
         if url is None:
             saveas = self.url
         else:
             saveas = vfs.normalize(url)
         self.stc.prepareEncoding()
         fh = self.stc.openFileForWriting(saveas)
         self.stc.writeTo(fh, saveas)
         self.stc.closeFileAfterWriting(fh)
         self.stc.SetSavePoint()
         self.removeAutosaveIfExists()
         if saveas != self.url:
             try:
                 permissions = vfs.get_permissions(self.url)
                 vfs.set_permissions(saveas, permissions)
             except OSError:
                 # The original file may have been deleted, in which case
                 # the permissions setting will fail.
                 pass
             self.setURL(saveas)
             self.setName()
             self.readonly = not vfs.can_write(saveas)
             pub.sendMessage('buffer.opened', buffer=self)
         self.setInitialStateIsUnmodified()
         self.showModifiedAll()
         self.saveTimestamp()
     except IOError, e:
         eprint(u"Failed writing to %s: %s" % (self.url, e))
         raise
예제 #3
0
    def projectInfo(cls, msg):
        """Publish/subscribe callback called by major mode creation process.
        
        This is used to add the L{ProjectInfo} to a major mode when it's
        contained in a project.  If the file is found to belong to a project,
        another message is sent indicating that the mode does belong to a
        project.  This is currently used, for instance, in the openrecent
        plugin to add the project file to a recent projects menu.
        
        Additionally, this is where template processing is handled for project
        files.  If the major mode determines that it would like to use a
        template, it is applied here.
        """
        mode = msg.data

        # Add 'project' keyword to Buffer object if the file belongs to a
        # project
        cls.registerProject(mode)

        # If the file belongs to a project, send message to anyone interested
        # that we've found the project
        if mode.project_info:
            pub.sendMessage("project.file.opened", mode=mode)

        # handle templates for empty files
        if hasattr(mode, "isTemplateNeeded"):
            if mode.isTemplateNeeded():
                template = cls.findProjectTemplate(mode)
                if template:
                    mode.setTextFromTemplate(template)
예제 #4
0
    def projectInfo(cls, msg):
        """Publish/subscribe callback called by major mode creation process.
        
        This is used to add the L{ProjectInfo} to a major mode when it's
        contained in a project.  If the file is found to belong to a project,
        another message is sent indicating that the mode does belong to a
        project.  This is currently used, for instance, in the openrecent
        plugin to add the project file to a recent projects menu.
        
        Additionally, this is where template processing is handled for project
        files.  If the major mode determines that it would like to use a
        template, it is applied here.
        """
        mode = msg.data

        # Add 'project' keyword to Buffer object if the file belongs to a
        # project
        cls.registerProject(mode)

        # If the file belongs to a project, send message to anyone interested
        # that we've found the project
        if mode.project_info:
            pub.sendMessage('project.file.opened', mode=mode)

        # handle templates for empty files
        if hasattr(mode, "isTemplateNeeded"):
            if mode.isTemplateNeeded():
                template = cls.findProjectTemplate(mode)
                if template:
                    mode.setTextFromTemplate(template)
예제 #5
0
파일: buffers.py 프로젝트: betsegaw/peppy
 def save(self, url=None):
     assert self.dprint(u"Buffer: saving buffer %s as %s" % (self.url, url))
     try:
         if url is None:
             saveas = self.url
         else:
             saveas = vfs.normalize(url)
         self.stc.prepareEncoding()
         fh = self.stc.openFileForWriting(saveas)
         self.stc.writeTo(fh, saveas)
         self.stc.closeFileAfterWriting(fh)
         self.stc.SetSavePoint()
         self.removeAutosaveIfExists()
         if saveas != self.url:
             try:
                 permissions = vfs.get_permissions(self.url)
                 vfs.set_permissions(saveas, permissions)
             except OSError:
                 # The original file may have been deleted, in which case
                 # the permissions setting will fail.
                 pass
             self.setURL(saveas)
             self.setName()
             self.readonly = not vfs.can_write(saveas)
             pub.sendMessage('buffer.opened', buffer=self)
         self.setInitialStateIsUnmodified()
         self.showModifiedAll()
         self.saveTimestamp()
     except IOError, e:
         eprint(u"Failed writing to %s: %s" % (self.url, e))
         raise
예제 #6
0
파일: buffers.py 프로젝트: betsegaw/peppy
    def openGUIThreadSuccess(self):
        # Only increment count on successful buffer loads
        Buffer.count+=1
        self.order_loaded = Buffer.count
        
        self.closeBufferedReader()
        
        self.stc.openSuccess(self)
        
        self.setName()

        # If it doesn't exist, that means we are creating the file, so it
        # should be writable.
        self.readonly = not (vfs.can_write(self.url) or not vfs.exists(self.url))
        #dprint("readonly = %s" % self.readonly)
        
        self.stc.EmptyUndoBuffer()

        # Add to the currently-opened buffer list
        BufferList.addBuffer(self)

        # Send a message to any interested plugins that a new buffer
        # has been successfully opened.
        pub.sendMessage('buffer.opened', buffer=self)
        wx.CallAfter(self.showModifiedAll)
예제 #7
0
파일: notebook.py 프로젝트: betsegaw/peppy
 def OnTabBackgroundContextMenu(self, evt):
     """Handle context menu on the tab area background.
     
     If a right click occurs on a tab, L{OnTabContextMenu} is called instead.
     """
     action_classes = []
     pub.sendMessage('tab_background.context_menu', action_classes=action_classes)
     #dprint(action_classes)
     if action_classes:
         PopupMenu(self.frame, self, None, action_classes)
예제 #8
0
파일: notebook.py 프로젝트: zendbit/peppy
 def OnTabBackgroundContextMenu(self, evt):
     """Handle context menu on the tab area background.
     
     If a right click occurs on a tab, L{OnTabContextMenu} is called instead.
     """
     action_classes = []
     pub.sendMessage('tab_background.context_menu',
                     action_classes=action_classes)
     #dprint(action_classes)
     if action_classes:
         PopupMenu(self.frame, self, None, action_classes)
예제 #9
0
    def removeAllViewsAndDelete(self):
        # Have to make a copy of self.viewers, because when the viewer
        # closes itself, it removes itself from this list of viewers,
        # so unless you make a copy the for statement is operating on
        # a changing list.
        viewers = self.viewers[:]

        # keep track of notebook tabs that get modified
        pending_updates = {}

        for viewer in viewers:
            assert self.dprint("count=%d" % len(self.viewers))
            assert self.dprint("removing view %s of %s" % (viewer, self))
            tab = viewer.frame.tabs
            pending_updates[tab] = True
            tab.holdChanges()
            viewer.frame.tabs.closeWrapper(viewer)
        assert self.dprint("final count=%d" % len(self.viewers))

        # Now, process the changes in the notebook tabs so we don't needlessly
        # create menubars for each tab that is removed.
        for tab in pending_updates.keys():
            tab.processChanges()

        if not self.permanent:
            basename = self.stc.getShortDisplayName(self.raw_url)

            BufferList.removeBuffer(self)
            # Need to destroy the base STC or self will never get garbage
            # collected
            self.stc.Destroy()
            pub.sendMessage('buffer.closed', url=self.url)
            dprint(u"removed buffer %s" % self.url)

            # If we don't have any more buffers with this basename, reset the
            # counter
            if not BufferList.findBuffersByBasename(basename):
                del self.filenames[basename]
예제 #10
0
파일: buffers.py 프로젝트: betsegaw/peppy
    def removeAllViewsAndDelete(self):
        # Have to make a copy of self.viewers, because when the viewer
        # closes itself, it removes itself from this list of viewers,
        # so unless you make a copy the for statement is operating on
        # a changing list.
        viewers=self.viewers[:]
        
        # keep track of notebook tabs that get modified
        pending_updates = {}
        
        for viewer in viewers:
            assert self.dprint("count=%d" % len(self.viewers))
            assert self.dprint("removing view %s of %s" % (viewer,self))
            tab = viewer.frame.tabs
            pending_updates[tab] = True
            tab.holdChanges()
            viewer.frame.tabs.closeWrapper(viewer)
        assert self.dprint("final count=%d" % len(self.viewers))
        
        # Now, process the changes in the notebook tabs so we don't needlessly
        # create menubars for each tab that is removed.
        for tab in pending_updates.keys():
            tab.processChanges()

        if not self.permanent:
            basename=self.stc.getShortDisplayName(self.raw_url)

            BufferList.removeBuffer(self)
            # Need to destroy the base STC or self will never get garbage
            # collected
            self.stc.Destroy()
            pub.sendMessage('buffer.closed', url=self.url)
            dprint(u"removed buffer %s" % self.url)
            
            # If we don't have any more buffers with this basename, reset the
            # counter
            if not BufferList.findBuffersByBasename(basename):
                del self.filenames[basename]
예제 #11
0
파일: notebook.py 프로젝트: zendbit/peppy
    def OnTabContextMenu(self, evt):
        """Handle context menu on a tab button.
        
        Unlike a traditional notebook control that has a single row of tabs at
        the top of the control, an AUI notebook may have multiple rows of tab
        buttons if the control is split.  The index number of any particular
        tab is dependent on which row of tab buttons the event happens.
        
        However, there is another index that is invariant and based on the
        order in which the page was added to the notebook itself.  This is the
        index used by the AuiNotebook.GetPage method.
        
        Only this context menu driver is concerned about multiple rows of tab
        buttons; the index produced by this method and passed to the popup
        menu as the C{context_tab} key is the invariant index.
        """
        # The event will be reported on one of the potentially multiple
        # AuiTabCtrl controls
        tabctrl = evt.GetEventObject()
        tab = evt.GetSelection()
        aui_notebook_page = tabctrl.GetPage(tab)
        wrapper = aui_notebook_page.window

        # This index is the invariant index
        index = self._tabs.GetIdxFromWindow(wrapper)
        #dprint("Context menu over tab %d: %s" % (tab, aui_notebook_page.caption))
        action_classes = []
        pub.sendMessage('tabs.context_menu', action_classes=action_classes)
        #dprint(action_classes)
        options = {
            'context_tab': index,
            'wrapper': wrapper,
            'mode': wrapper.editwin,
        }
        if action_classes:
            PopupMenu(self.frame, self, None, action_classes, options)
예제 #12
0
파일: notebook.py 프로젝트: betsegaw/peppy
 def OnTabContextMenu(self, evt):
     """Handle context menu on a tab button.
     
     Unlike a traditional notebook control that has a single row of tabs at
     the top of the control, an AUI notebook may have multiple rows of tab
     buttons if the control is split.  The index number of any particular
     tab is dependent on which row of tab buttons the event happens.
     
     However, there is another index that is invariant and based on the
     order in which the page was added to the notebook itself.  This is the
     index used by the AuiNotebook.GetPage method.
     
     Only this context menu driver is concerned about multiple rows of tab
     buttons; the index produced by this method and passed to the popup
     menu as the C{context_tab} key is the invariant index.
     """
     # The event will be reported on one of the potentially multiple
     # AuiTabCtrl controls
     tabctrl = evt.GetEventObject()
     tab = evt.GetSelection()
     aui_notebook_page = tabctrl.GetPage(tab)
     wrapper = aui_notebook_page.window
     
     # This index is the invariant index
     index = self._tabs.GetIdxFromWindow(wrapper)
     #dprint("Context menu over tab %d: %s" % (tab, aui_notebook_page.caption))
     action_classes = []
     pub.sendMessage('tabs.context_menu', action_classes=action_classes)
     #dprint(action_classes)
     options = {
         'context_tab': index,
         'wrapper': wrapper,
         'mode': wrapper.editwin,
         }
     if action_classes:
         PopupMenu(self.frame, self, None, action_classes, options)
예제 #13
0
 def showModifiedAll(self):
     for view in self.viewers:
         assert self.dprint("notifing: %s modified = %s" %
                            (view, self.modified))
         view.showModified(self.modified)
     pub.sendMessage('buffer.modified', buffer=self)
예제 #14
0
파일: buffers.py 프로젝트: betsegaw/peppy
 def showModifiedAll(self):
     for view in self.viewers:
         assert self.dprint("notifing: %s modified = %s" % (view, self.modified))
         view.showModified(self.modified)
     pub.sendMessage('buffer.modified', buffer=self)