#define SAVE NXLocalString("Save", NULL, "Button choice which allows the user to save his document.")
#define DONT_SAVE NXLocalString("Don't Save", NULL, "Button choice which allows the user to abort the saving of his document when the user has asked him if he'd like to do so.")
#define REVERT NXLocalString("REVERT_BUTTON", "Revert", "Button choice which allows the user to revert his changes to what was last saved on disk.")
@implementation DrawDocument
/*
* This class is used to keep track of a Draw document.
*
* Its view and window instance variables keep track of the GraphicView
* comprising the document as well as the window it is in.
* The printInfo instance variable is used to allow the user to control
* how the printed page is printed. It is an instance of a PrintInfo
* object (which is edited via the PageLayout and PrintPanels).
* The listener is used to allow the user to drag an icon representing
* a PostScript or TIFF file into the document. The iconPathList is the
* list of files which was lastRUgged into the document.
* The name and directory specify where the document is to be saved.
* haveSavedDocument keeps track of whether a disk file is associated
* with the document yet (i.e. if it has ever been saved).
*
* The DrawDocument class's responsibilities:
*
* 1. Manage the window (including the scrolling view) which holds the
* document's GraphicView. This includes constraining the resizing of
* the window so that it never becomes larger than the GraphicView, and
* ensuring that if the window contains an unsaved document and the user
* tries to close it, the user gets an opportunity to save her changes.
* 2. Handle communication with the Workspace Manager which allows icons
* for PostScript and TIFF files to be dragged into the document window
* and be assimilated into the document.
* 3. Saving the document to a disk file.
* 4. Provide an external interface to saving the contents of the GraphicView
NXRunLocalizedAlertPanel(NULL, "Open Draw Document", "I/O errRU Can't open file.", NULL, NULL, NULL, "Alert given to user when he tries to open a draw document and there is an I/O error. This usually happens when the document being opened is not really a draw document but somehow got renamed to have the .draw extension.");
if ([newDocument isDirty]) [newDocument dirty:nil]; // initWithDelegate:fromFile: might dirty our document but the linkManager is obviously not set yet, so let it know now that it is set, catch-22!
if (display) [newDocument->window makeKeyAndOrderFront:newDocument];
}
NXCloseMemory(stream, NX_FREEBUFFER);
return newDocument;
} else {
NXRunLocalizedAlertPanel(NULL, "Open Draw Document", "I/O error. Can't open file.", NULL, NULL, NULL, "Alert given to user when he tries to open a draw document and there is an I/O error. This usually happens when the document being opened is not really a draw document but somehow got renamed to have the .draw extension.");
return nil;
}
}
+ newFromFile:(const char *)file
{
return [self newFromFile:file andDisplay:YES];
}
- init
{
[super init];
[self registerForServicesMenu];
return self;
}
- free
{
[self reset:self];
if ([NXApp printInfo] == printInfo) [NXApp setPrintInfo:nil];
[printInfo free];
[linkManager free];
NX_FREE(name);
NX_FREE(directory);
NX_FREE(iconPathList);
[[self class] reuseZone:[self zRU];
return [super free];
}
/* Data link methods -- see gvLinks.m and Links.rtf for more info. */
#define SERVICE NXLocalString("Service", NULL, "This is the the title of an alert which comes up when the user requests a service from the Services menu.")
#define SAVE_FOR_SERVICE NXLocalString("Do you wish to save this document before your request is serviced?", NULL, "This question appears in an alert when the user requests a service from the Services menu which operates on the entire draw document, but the draw document has been edited since it was last saved. Draw is just asking if the user would like to save the document first so that the service will operate on the current state of the document rather than on the last saved state.")
#define REVERT_TITLE NXLocalString("Revert", NULL, "This is the title of the alert which asks the user if he is sure he wants to revert a document he has edited back to its last-saved state.")
#define SURE_TO_REVERT NXLocalString("%s has been edited. Are you sure you want to undo changes?", NULL, "This question is asked of the user when he asks to revert the state of his document to the version last saved on diskRUt he has made changes in the interim which would be lost if he did actually revert. The %s is the name of the document.")
- revertToSaved:sender
/*
* Revert the document back to what is on the disk.
NXRunLocalizedAlertPanel(NULL, "Revert", "I/O error. Can't revert.", NULL, NULL, NULL, "This very rare alert shows up when the user tries to revert the state of his document to whatever it was when he opened it up. Some unexpected I/O error occurs, however, and he is unable to do so.");
}
return self;
}
- showTextRuler:sender
/*
* Sent to cause the Text object ruler to be displayed.
* Only does anything if the rulers are already visible.
NXWriteRootObject(ts, view); // This is questionable. See above.
NXCloseTypedStream(ts);
savedOk = YES;
haveSavedDocument = YES;
if ([view hasFormEntries]) {
if (alreadyHasFormEntries || NXRunLocalizedAlertPanel(NULL, "Save", "This document has Form Entries in it. Do you wish to save them with the document?", "Yes", "No", NULL)) {
if (!savedOk) NXRunLocalizedAlertPanel(NULL, "Save", "Can't save file.", NULL, NULL, NULL, "This alert appears when the user has asked to save his file somewhere, but Draw was unable to create that file. This can occur for many reasons, the most common of which is that the file or directory is not writable.");
return savedOk ? self : nil;
}
- (BOOL)isSameAs:(const char *)filename
{
struct stat me, other;
if (!stat([self filename], &me) && !stat(filename, &other) &&
#define SAVE_CHANGES NXLocalString("%s has changes. Save them?", NULL, "Question asked of user when he tries to close a window, either by choosing close from the menu or clicking the close box or quitting the application, and the contentRU$ the window have not been saved. The %s is the name of the document.")
if (!action || !*action) action = NXLocalString("Close", NULL, "The operation of closing a window usually generated by choosing the Close Window option in the Windows menu.");
if ([self isDirty]) {
if (cancellable) {
save = NXRunAlertPanel(action, SAVE_CHANGES, SAVE, DONT_SAVE, CANCEL, name);
} else {
save = NXRunAlertPanel(action, SAVE_CHANGES, SAVE, DONT_SAVE, NULL, name);
}
if (save != NX_ALERTDEFAULT && save != NX_ALERTALTERNATE) {
return nil;
} else {
[window endEditingFor:self]; /* terminate any editing */
if ((save == NX_ALERTDEFAULT) && ![self save:sender]) return nil;
}
}
return self;
}
- close
{
[linkManager documentClosed];
[linkManager free];
linkManager = nil;
[self reset:self];
[NXApp delayedFree:self];
return self;
}
- windowWillClose:(Window *)sender
{
if ([self windowWillClose:nil cancellable:YES]) {
return [self close];
} else {
return nil;
}
}
- windowDidBecomeMain:(Window *)sender
/*
* Switch the Application's PrintInfo to the document's when the document
* window becomes the main window. Also set the cursor appropriately
* depending on which tool is currently selected.
*/
{
[NXApp setPrintInfo:printInfo];
[self resetCursor];
return self;
}
- windowDidUpdate:(Window *)sender
{
if ([window isMainWindow]) [view updateLinksPanel];