Author Topic: Cancel Document Switching  (Read 1770 times)

0 Members and 1 Guest are viewing this topic.

Odoshi

  • Guest
Cancel Document Switching
« on: November 03, 2012, 03:26:43 AM »
I am picking up the DocumentToBeDeactivated event when the user switches to another open drawing. I would like to be able to cancel AutoCAD from changing documents, if the user so wishes.

Is there a way to stop AutoCAD from changing drawings?

Thanks,

BlackBox

  • King Gator
  • Posts: 3770
Re: Cancel Document Switching
« Reply #1 on: November 03, 2012, 12:12:35 PM »
I'm not sure that I understand... Why would you want to prevent the user from switching to another Document, yet allow them to add the Document to the DocumentManager (read Open) in the first place?

Wouldn't simply forcing the session into SDI mode (SDI = 1) rather than MDI mode (SDI = 0) be sufficient?
"How we think determines what we do, and what we do determines what we get."

Odoshi

  • Guest
Re: Cancel Document Switching
« Reply #2 on: November 04, 2012, 07:39:26 AM »
I am storing some data on a palette and if the drawing is switched, the palette will discard the previous data and load the next drawing's data.

So I wanted to offer them a Yes/No/Cancel option to save the palette data. Yes, to save the data and procede to the next drawing, No, to discard the data and procede to the next drawing, or Cancel, to stay in the current drawing.

Maybe there is a better/more standardized way to approach this? But ideally, I wanted to stop them from going to another drawing while unsaved data was on the palette.

I suppose leaving it at a Yes/No would just prompt them to save or not, and go to the other drawing no matter what.

Thanks,
Mike

TheMaster

  • Guest
Re: Cancel Document Switching
« Reply #3 on: November 04, 2012, 02:37:01 PM »
I am storing some data on a palette and if the drawing is switched, the palette will discard the previous data and load the next drawing's data.

So I wanted to offer them a Yes/No/Cancel option to save the palette data. Yes, to save the data and procede to the next drawing, No, to discard the data and procede to the next drawing, or Cancel, to stay in the current drawing.

Maybe there is a better/more standardized way to approach this? But ideally, I wanted to stop them from going to another drawing while unsaved data was on the palette.

I suppose leaving it at a Yes/No would just prompt them to save or not, and go to the other drawing no matter what.

Thanks,
Mike


You can save the data shown in the palette in an object that's associated with the document. You can have multiple instances of the object, each associated with a different open document (sometimes referred to as a 'per-document' data class). If you do that, you can just save any data in the palette in the object and restore it when the associated document is active again. If you take that kind of approach, nothing would be lost when switching documents.

You can also use data binding to bind controls on a form or usercontrol to properties of a class, and that would eliminate a lot of the manual code needed to synchronize the view of the data (the control) with the source of the data (the non-visual class or datasource).

Odoshi

  • Guest
Re: Cancel Document Switching
« Reply #4 on: November 05, 2012, 12:48:57 AM »
Yes, that sounds good. The app will only require 1-2 drawings open at a time so I'll look into simplifying the prompt to just Yes/No and forcing the save if needed.

But if anyone for curiousity's sake knows how to stop the document from being loaded and which event to listen for, I'd be greatful.

Thanks!

n.yuan

  • Bull Frog
  • Posts: 348
Re: Cancel Document Switching
« Reply #5 on: November 05, 2012, 09:48:45 AM »
AutoCAD is a multiple document hosting application (Although it can still be set to single document mode, but it is due to the history). If I am your user, I'd be very annoyed, whenever I switch active drawing I'd be forced answer Yes/No, even I do not intent to close a drawing. Not to mention how user would be frustrated when your program prevent new drawing being opened.

Your problem is that you use a UI component (palette) for both user interaction and data holding, which is not a good practice. You should separate your app into layers/components, each plays diferent roles ("separating concerns" in software develoment term). As Tony suggested, if you create a data model for each document, which syncs with the UI (palette), then the UI is free to switch. And you only ask user YES?NO for saving changes when it is needed (i.e. if user is to close the drawing). The data component stays in the memory and being upated with user palette. You can choose to persist the change into drawing database, if the data is about the drawing, just as the Properties palette does, or you can let it stay in memory and only choose persist it or discard it when user is to save/close the drawing.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Cancel Document Switching
« Reply #6 on: November 05, 2012, 01:17:31 PM »
Like mentioned in previous post keep your data saved(or stored) per document and maybe let them have toggle per document if they want save data, or at most to keep from annoying user maybe just prompt them when document is going to be destroyed if they want to save data.

Odoshi

  • Guest
Re: Cancel Document Switching
« Reply #7 on: November 05, 2012, 10:31:05 PM »
Keeping the data in memory for each drawing is nice, but I have about 12 tabs on the palette and each tab can have up to 50 controls on it. I suppose I could make a struct or class to keep it all safe. I appreciate the comments on keeping the user happy and not being nagged to save all the time. I'm a bit of a HCI buff and am also very picky on how things look and behave.