I'm creating a richtextbox editor and need to put a save function as well as a save as. I can easily do a save as function by using the savefiledialog but im not sure how to save without this. Can anyone help?
+5
A:
The way this usually works is to keep track of the file name the user either opened or saved as.
Then, when they use the Save function, simply save to the file name that was previously specified. If no file has been specified, then show the Save As.
Jon Seigel
2010-02-22 15:07:32
+5
A:
Create a field somewhere, say string filename
. Set it to null
initially.
When a document is opened, store the file name in a filename
.
When a document is saved through Save As, also store this file name in filename
.
When Save is invoked, check the value of filename
. If it is null
, invoke Save As instead. If it is not null
, save to the file name specified in filename
.
Thomas
2010-02-22 15:08:05
And if you have a Load() to fill the editor from a file, then also set that 'filename'.
Hans Kesting
2010-02-22 15:53:33
thank you exactly what I needed. Just another question though. How would I make a message box show if you went to click "New document" button and the text had been changed since it was last saved. I know how to do the message box etc. but not for only when the document has been edited and not saved..if you understand..:-S
Pops
2010-02-22 16:09:24
@Pops: When the file is changed then set an `UnsavedChanges` bool to true. When it is saved set it to false.
Jim McKeeth
2010-02-22 16:48:03
+2
A:
Isn't "Save" simply the following (in pseudocode)?
Save() =
WriteTo(oldfilename)
SaveAs() =
stream = OpenDialog()
oldfilename = stream.filename
Save()
Eamon Nerbonne
2010-02-22 15:09:25