Select to view content in your preferred language

ProWindow and Modal Dialog not working with Progressor

599
1
Jump to solution
12-12-2023 03:32 AM
Vidar
by
Frequent Contributor

Hi,

I have a pro window that is modal - it lists the maps in the project. You select a map and press ok. 

 

Vidar_0-1702379750178.png

 

Meanwhile there is QueuedTask that opens up the map, this can take some time so I use a progress dialog just so the user knows Pro is doing things.

Vidar_1-1702380552252.png

However if I don't put a message box after it has opened the map, code execution continues and won't allow the user to select a file to save the json and just says "JSON file not saved".

I want to get rid of this!I want to get rid of this!

This is really strange because the save file dialog is modal but its almost like the computer has automatically cancelled the dialog and continued execution on it's own accord. I though execution had to halt on a modal dialog.

If anyone can help me get rid of the unnecessary message box that would be great. Also an explanation to what stupid thing I'm doing wrong would be great. I have tried many things but I can't seem to solve it.

The code below should be able to be copy pasted behind a ribbon button in pro. However you may need some rudimentary XAML for the pro window. Just an ok button would do I guess.

 

 

 protected async override void OnClick()
 {
    var proWindowModal = new MapPaneChooserWindow
    {
        DataContext = new MapPaneChooserWindowVM(),
        Owner = FrameworkApplication.Current.MainWindow
    };

    var dialogResult = proWindowModal.ShowDialog();
    if (dialogResult == true)
    {
        ProgressorSource ps = new ProgressorSource("Opening map...");
		
		//This can take some time - so we use a progress dialog.
		chosenMap = await QueuedTask.Run(() =>
		{
			return Module1.MapPaneChooserWindowVM.SelectedMap.GetMap();
		}, ps.Progressor);
        
		//!!!! Forced to put a message box here or it will run automatically to "Layer collection not saved" section below !!!!
		//If you take this message box out of hte code - you will see the effect
        MessageBox.Show("Finished opening map.", "Map", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);

        SaveFileDialog saveFileDialog = new SaveFileDialog();
        saveFileDialog.Filter = "JSON files (*.json)|*.json";
        saveFileDialog.Title = "Save JSON File";

        var result = saveFileDialog.ShowDialog();

        if (result == true)
        {
            //do stuff about saving a json file here...
        }
        else
        {
            MessageBox.Show("JSON file not saved", "Save JSON file", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
        }
	}
 }

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

I would suggest you do not use Windows Forms SaveFileDialog in ArcGIS Pro. Use ArcGIS Pro SaveItemDialog:

                var dlg = new SaveItemDialog();
                dlg.Title = "Save JSON File";
                dlg.OverwritePrompt = true;
                dlg.DefaultExt = "json";
                dlg.InitialLocation = @"C:\Temp";

                var fileFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_browseFiles");
                fileFilter.FileExtension = "json";//restrict to specific extensions as needed
                fileFilter.BrowsingFilesMode = false;

                //Specify a name to show in the filter dropdown combo box - otherwise the name
                //will show as "Default"
                fileFilter.Name = "(*.json)";
                dlg.BrowseFilter = fileFilter;

                bool? result = dlg.ShowDialog();

With SaveItemDialog it works as you expected.

View solution in original post

1 Reply
GKmieliauskas
Esri Regular Contributor

Hi,

I would suggest you do not use Windows Forms SaveFileDialog in ArcGIS Pro. Use ArcGIS Pro SaveItemDialog:

                var dlg = new SaveItemDialog();
                dlg.Title = "Save JSON File";
                dlg.OverwritePrompt = true;
                dlg.DefaultExt = "json";
                dlg.InitialLocation = @"C:\Temp";

                var fileFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_browseFiles");
                fileFilter.FileExtension = "json";//restrict to specific extensions as needed
                fileFilter.BrowsingFilesMode = false;

                //Specify a name to show in the filter dropdown combo box - otherwise the name
                //will show as "Default"
                fileFilter.Name = "(*.json)";
                dlg.BrowseFilter = fileFilter;

                bool? result = dlg.ShowDialog();

With SaveItemDialog it works as you expected.