.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Close event 'Save Changes'

4 REPLIES 4
Reply
Message 1 of 5
Meridius2000
687 Views, 4 Replies

Close event 'Save Changes'

Hi all;

I am currently writing an ACAD app that writes data to a database when the user saves a drawing. I can do this on a save command by subscribing to the CommandEnded event as follows:

{code}
MdiActiveDocument.CommandEnded += new CommandEventHandler(MdiActiveDocument_CommandEnded);

void MdiActiveDocument_CommandEnded(object sender, CommandEventArgs e)
{
if (e.GlobalCommandName.ToUpper().Contains("SAVE"))
{
//Do work...
}
}
{code}

The problem I am having is when the user closes a drawing. I know I can intercept a close in the same manner as above through the BeginDocumentClose event. However, its the "Save Changes" prompt that occurs when the use closes after making changes that is causing my trouble. I can't figure how to determine whether the user has selected "Yes" or "No". Basically, I don't want to execute my save if the user has opted not to save the drawing; I only want to to execute my save if the user has selected "Yes".

Any help or thoughts on this would be greatly appreciated!
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Meridius2000

You shouldn't use the CommandEnded event for this.

The BeginSave event should fire regardless of how a save is done, but you
may also need to weed out AutoSave if you don't want to handle those.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6285443@discussion.autodesk.com...
Hi all;

I am currently writing an ACAD app that writes data to a database when the
user saves a drawing. I can do this on a save command by subscribing to the
CommandEnded event as follows:

{code}
MdiActiveDocument.CommandEnded += new
CommandEventHandler(MdiActiveDocument_CommandEnded);

void MdiActiveDocument_CommandEnded(object sender, CommandEventArgs e)
{
if (e.GlobalCommandName.ToUpper().Contains("SAVE"))
{
//Do work...
}
}
{code}

The problem I am having is when the user closes a drawing. I know I can
intercept a close in the same manner as above through the BeginDocumentClose
event. However, its the "Save Changes" prompt that occurs when the use
closes after making changes that is causing my trouble. I can't figure how
to determine whether the user has selected "Yes" or "No". Basically, I don't
want to execute my save if the user has opted not to save the drawing; I
only want to to execute my save if the user has selected "Yes".

Any help or thoughts on this would be greatly appreciated!
Message 3 of 5
Meridius2000
in reply to: Meridius2000

Thanks Tony - that helps a lot!

The trouble I am having now relates to canceling the save. If my custom routine fails, I don't want to save the drawing. I have tried sending an escape character using SendCommand and also subscribing to the DocumentLockModeChanged and using the 'Veto' method - neither strategy seems to work. Here's my code so far (simplified of course):

{code}

bool _cancelSave = false;
void Database_BeginSave(object sender, DatabaseIOEventArgs e)
{
string[] input = { "SAVE", "SAVEAS", "QSAVE", "CLOSE" };
List validCommands = new List(input);

if (validCommands.Contains(MdiActiveDocument.CommandInProgress))
{
if (!doWork())
_cancelSave = true;
/* Or we could send escape:
* String esc = Convert.ToChar(Keys.Escape).ToString();
* SendCommand(esc, false);
*/
}

}

void DocumentManager_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e)
{
if (cancelSave)
e.Veto();

_cancelSave = false;
}

{code}

Again - any thoughts would be greatly appreciated!
Message 4 of 5
Anonymous
in reply to: Meridius2000

Are you saying that if something goes wrong in your extension (e.g., a
software bug), the user should not be able to save the file at all ?????????

You're kidding right?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6286027@discussion.autodesk.com...
Thanks Tony - that helps a lot! The trouble I am having now relates to
canceling the save. If my custom routine fails, I don't want to save the
drawing. I have tried sending an escape character using SendCommand and also
subscribing to the DocumentLockModeChanged and using the 'Veto' method -
neither strategy seems to work. Here's my code so far (simplified of
course): {code} bool _cancelSave = false; void Database_BeginSave(object
sender, DatabaseIOEventArgs e) { string[] input = { "SAVE", "SAVEAS",
"QSAVE", "CLOSE" }; List validCommands = new List(input); if
(validCommands.Contains(MdiActiveDocument.CommandInProgress)) { if
(!doWork()) _cancelSave = true; /* Or we could send escape: * String esc =
Convert.ToChar(Keys.Escape).ToString(); * SendCommand(esc, false); */ } }
void DocumentManager_DocumentLockModeChanged(object sender,
DocumentLockModeChangedEventArgs e) { if (cancelSave) e.Veto(); _cancelSave
= false; } {code} Again - any thoughts would be greatly appreciated!
Message 5 of 5
Meridius2000
in reply to: Meridius2000

I hear ya - but yes that's the spec I'm working with at the moment. There will be a way the user can turn off that behavior if they have to, but by default that's the way it would work. Seems like it may not be possible, but I could be wrong.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost