Select to view content in your preferred language

Get result of "Save Project"-Question when ArcGIS is closed

932
3
Jump to solution
01-11-2021 04:55 AM
RehmSoftware
Regular Contributor

Hi,

when ArcGIS Pro is closed by the user and there are pending changes like camera pan or whatever, the user is presented with the question whether the changes shall be saved:CloseProject.png

 

 

 

 

I need to know whether the user clicked Yes or No because depending on what was clicked, I need to commit/rollback a transaction in an external SQL database. I looked around and found some events like ProjectSavingEvent etc. but that doesn't quite do it for me. Is there something I missed in the SDK or is the functionality I need simply not present?

Any help is greatly appreciated.

Best regards

Christian

 

0 Kudos
1 Solution

Accepted Solutions
RehmSoftware
Regular Contributor

Okay, I figured it out.. one needs to subscribe to ProjectClosingEvent, ProjectSavingEvent, ProjectCloseCanceledEvent and ProjectClosedEvent

If project closing starts and afterwards the ProjectSavingEvent fires, the user chose to save the changes. If the ProjectCloseCanceledEvent fires, he chose to cancel the changes and if no event fires between ProjectClosingEvent and ProjectCloseEvent then the user didn't save the changes. This works but come on, I wonder why there is no specialized event just for that...

View solution in original post

3 Replies
GKmieliauskas
Esri Regular Contributor

Hi Christian,

I would suggest you to use ProjectClosingEvent.

On initializing call :

ProjectClosingEvent.Subscribe(OnProjectClosing);

Body of OnProjectClosing:

private Task OnProjectClosing(ProjectClosingEventArgs args)
{
// if already cancelled, ignore
if (args.Cancel)
return Task.CompletedTask;

// Do your tasks
//var vm = FrameworkApplication.DockPaneManager.Find(_dockPaneID);
//if (vm != null) vm.Hide();

return Task.CompletedTask;
}

 

 

 

RehmSoftware
Regular Contributor

Hi,

thanks for your reply but the ProjectClosingEvent fires BEFORE ArcGIS Pro displays the MessageBox I mentioned above so obviously I can't know what the user clicked eventually from that event handler..

As I said, I looked through the events but couldn't find one that suits my needs.. I'm starting to believe that ArcGIS simply doesn't provide any means to get the info I need, but maybe you or somebody else has another idea..

Best regards

Christian

0 Kudos
RehmSoftware
Regular Contributor

Okay, I figured it out.. one needs to subscribe to ProjectClosingEvent, ProjectSavingEvent, ProjectCloseCanceledEvent and ProjectClosedEvent

If project closing starts and afterwards the ProjectSavingEvent fires, the user chose to save the changes. If the ProjectCloseCanceledEvent fires, he chose to cancel the changes and if no event fires between ProjectClosingEvent and ProjectCloseEvent then the user didn't save the changes. This works but come on, I wonder why there is no specialized event just for that...