Exemplo n.º 1
0
    def OnSave(self, evt):
        """Save Current or All Buffers
        @param evt: Event fired that called this handler
        @type evt: wxMenuEvent

        """
        e_id = evt.GetId()
        ctrls = list()
        if e_id == ID_SAVE:
            page = self.nb.GetSelection()
            ctrls = [(self.nb.GetPageText(page), self.nb.GetCurrentCtrl(),
                      page)]
        elif e_id == ID_SAVEALL:
            # Collect all open editor buffers
            for page in xrange(self.nb.GetPageCount()):
                if issubclass(
                        self.nb.GetPage(page).__class__,
                        wx.stc.StyledTextCtrl):
                    ctrls.append((self.nb.GetPageText(page),
                                  self.nb.GetPage(page), page))
        else:
            evt.Skip()
            return

        for ctrl in ctrls:
            fname = util.GetFileName(ctrl[1].GetFileName())
            if fname != '':
                fpath = ctrl[1].GetFileName()
                result = ctrl[1].SaveFile(fpath)
                if result:
                    self.PushStatusText(_("Saved File: %s") % fname, SB_INFO)
                    if e_id == ID_SAVEALL:
                        if ctrl[2] != self.nb.GetSelection():
                            self.nb.SetPageText(ctrl[2], fname)
                        else:
                            self.nb.OnUpdatePageText(None)
                else:
                    err = ctrl[1].GetDocument().GetLastError()
                    self.PushStatusText(_("ERROR: %s") % err, SB_INFO)
                    ed_mdlg.SaveErrorDlg(self, fname, err)
                    ctrl[1].GetDocument().ResetAll()
            else:
                ret_val = self.OnSaveAs(ID_SAVEAS, ctrl[0], ctrl[1])
                if ret_val:
                    self.AddFileToHistory(ctrl[1].GetFileName())
Exemplo n.º 2
0
    def OnSaveAs(self, evt, title=u'', page=None):
        """Save File Using a new/different name
        @param evt: Event fired that called this handler
        @type evt: wxMenuEvent

        """
        if page:
            ctrl = page
        else:
            ctrl = self.nb.GetCurrentCtrl()

        if title == u'':
            title = os.path.split(ctrl.GetFileName())[1]

        dlg = wx.FileDialog(self, _("Choose a Save Location"),
                            os.path.dirname(ctrl.GetFileName()),
                            title.lstrip("*"),
                            ''.join(syntax.GenFileFilters()),
                            wx.SAVE | wx.OVERWRITE_PROMPT)

        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            dlg.Destroy()

            result = ctrl.SaveFile(path)
            fname = util.GetFileName(ctrl.GetFileName())
            if not result:
                err = ctrl.GetDocument().GetLastError()
                ed_mdlg.SaveErrorDlg(self, fname, err)
                ctrl.GetDocument().ResetAll()
                self.PushStatusText(
                    _("ERROR: Failed to save %s") % fname, SB_INFO)
            else:
                self.PushStatusText(_("Saved File As: %s") % fname, SB_INFO)
                self.SetTitle("%s - file://%s" % (fname, ctrl.GetFileName()))
                self.nb.SetPageText(self.nb.GetSelection(), fname)
                self.nb.GetCurrentCtrl().FindLexer()
                self.nb.UpdatePageImage()
            return result
        else:
            dlg.Destroy()