.13 patch: Save as Copy

Developers
2005-10-04
2013-04-26
  • The one feature I've missed in DrPython that I found very useful in the SciTE editor is aSave as Copy. This allows me to, in effect, make code branches at specified intervals, so that I can always go back to where I was before. Yeah, I know that's what Subversion or CVS is for, but if you're trying out ideas in your code, you don't necessarily want to saving them in the tree.

    Anyway, please accept for consideration the patch outlined below.  I am currently developing in Tkinter, but this is the very first time I've hacked on wxPython code. If you find somethign amiss, please feel free to improve it.

    Isn't Open Source great!

    cheers
    Stewart

    In the patch code below, the .13 code is file 1, and my proposal is file 2.   I can send the full drPython.py, if you prefer. contact me by mail at stewart 'at' midwinter 'dot' ca.

    ---
    341a342,344
    >         #add midtoad 2005-10-03
    >         self.filemenu.Append(self.ID_SAVE_COPY, 'Save a Copy', True, 7)
    >         #end midtoad
    554a558,560
    >         #add midtoad 2005-10-03
    >         self.Bind(wx.EVT_MENU,  self.OnSaveCopy, id=self.ID_SAVE_COPY)
    >         #end midtoad
    1055a1062,1064
    >         #add midtoad 2005-10-03
    >         self.ID_SAVE_COPY = 110
    >         #end midtoad
    2310a2320,2339
    >
    >
    >     def OnSaveCopy(self, event):
    >         #add feature to save a copy, midtoad 2005-10-03
    >         dlg = drFileDialog.FileDialog(self, 'Save Copy To', 'Python File (*.py)|*.py|All files (*)|*', IsASaveDialog=True)
    >         if (len(self.ddirectory) > 0):
    >             try:
    >                 dlg.SetDirectory(self.ddirectory)
    >             except:
    >                 #franz: ddirectory
    >                 self.ShowMessage(("Error Setting Default Directory To: " + self.ddirectory), "DrPython Error")
    >         if (dlg.ShowModal() == wx.ID_OK):
    >             cfilename = dlg.GetPath().replace("\\", "/")
    >             self.ddirectory = os.path.dirname(cfilename)
    >             try:
    >                 shutil.copyfile(self.txtDocumentArray[docPos].filename, cfilename)
    >             except:
    >                 self.ShowMessage(("Error copying file to: " + self.copyName), "DrPython Error")
    >         dlg.Destroy()
    >

     
    • Sorry, I sent in the wrong patch. The previously posted one doesn't work. But the one below does, and provides a pop-up confirmation that a copy of the file was indeed saved.  Here it is:

      ---
      341a342,344
      >         #add midtoad 2005-10-03
      >         self.filemenu.Append(self.ID_SAVE_COPY, 'Save a Copy', True, 7)
      >         #end midtoad
      554a558,560
      >         #add midtoad 2005-10-03
      >         self.Bind(wx.EVT_MENU,  self.OnSaveCopy, id=self.ID_SAVE_COPY)
      >         #end midtoad
      1055a1062,1064
      >         #add midtoad 2005-10-03
      >         self.ID_SAVE_COPY = 110
      >         #end midtoad
      2310a2320,2338
      >
      >     def OnSaveCopy(self, event):
      >         #add feature to save a copy, midtoad 2005-10-03
      >         dlg = drFileDialog.FileDialog(self, "Save Copy To", self.prefs.wildcard, IsASaveDialog=True)
      >         if (len(self.ddirectory) > 0):
      >             try:
      >                 dlg.SetDirectory(self.ddirectory)
      >             except:
      >                 #franz: ddirectory
      >                 self.ShowMessage(("Error Setting Default Directory To: " + self.ddirectory), "DrPython Error")
      >         if (dlg.ShowModal() == wx.ID_OK):
      >             cfilename = dlg.GetPath().replace("\\", "/")
      >             self.ddirectory = os.path.dirname(cfilename)
      >             try:
      >                 shutil.copyfile(self.txtDocument.filename, cfilename)
      >                 self.ShowMessage("Saved %s to %s" % (self.txtDocument.filename, cfilename), "Save as Copy")
      >             except IOError:
      >                 self.ShowMessage(("Error copying file to: " + self.copyName), "DrPython Error")
      >             dlg.Destroy()

       
    • Many thanks!
      Added to release 161