Select to view content in your preferred language

Map tool opened from two different places back to back

383
7
05-28-2024 12:32 AM
JamesAkaes
New Contributor II

 

Hi,

I have a map tool that can be opened from Ribbon as well as from Modify Features. From the ribbon, it is a button. On the button click using tool id I am making my map tool as active.

FrameworkApplication.SetCurrentToolAsync(ToolID);

Now the use case is that if the user has opened the tool from the Ribbon, it is opened as a separate dock pane as well as making that tool as active. And now if the user will try to open the same tool again from Modify Features, nothing is happening. Can we make the user move to already opened dock pane of the same tool (which was earlier opened from the button click)?

@Wolf @NarelleChedzey @UmaHarano @GKmieliauskas @CharlesMacleod 

Tags (1)
0 Kudos
7 Replies
RichardDaniels
Regular Contributor

In your implementation config.daml you set a className in the <button> tag. This is the class that is initiated when the button is clicked in the ArcGIS Pro tab. This class will have a OnClick() event that is fired each time you click the button on the interface. Assuming you are opening a Form you can catch the event something like this.

 

//declare an instance of the Form you want to open
public static GISWB_Main mainForm = new GISWB_Main();

protected override void OnClick()
{

var mapView = MapView.Active;

//Only open the form if we have an map open

if (mapView != null)

{
if (mainForm.getFormHandle() == null)
{

//do other things such as set the from name, version numbers, etc. that you want to dynamically update before opening the form for the 1st time.

mainForm.setFormHandle(mainForm);

mainForm.Show()

}

else
      {
      mainForm.Show();
      }

   }

}

 

The below items would be in the class definition (not in the Form)

public void setFormHandle(Form theForm)
{
theMainForm = theForm;
}

public Form getFormHandle()
{
return theMainForm;
}

 

0 Kudos
RichardDaniels
Regular Contributor

The code shown above is designed to allow only one instance of the Form to be open at any given time. If you have a Close button on the form you could use form.hide to vs. form.close as well to ensure only one instance of the form is ever created.

0 Kudos
JamesAkaes
New Contributor II

But I am talking about opening the same tool from Modify Features dock pane(from where also we can open map tools or construction tools. When opened from modify features nothing is happening since that tool is already opened as a separate dock pane when opened from ribbon. My requirement is in this case that already open dock pane should open.

@RichardDaniels 

0 Kudos
CharlesMacleod
Esri Regular Contributor

if I understand u correctly >>My requirement is in this case that already open dock pane should open.<< then call Activate() on your dockpane.

DockPane pane = FrameworkApplication.DockPaneManager.Find("Acme_Dockpane1");
pane?.Activate();
JamesAkaes
New Contributor II

But when I am in modify features dock pane clicking a tool how will i know which tool user is clicking. Any event that gets fired when tool is opened from modify features dock pane? Based on that i will get a tool id to open its dock pane.

@CharlesMacleod @RichardDaniels @Wolf 

0 Kudos
CharlesMacleod
Esri Regular Contributor

On the modify dockpane those are commands ("buttons") firing, not tools - which, as i think u have found out, activate a dockpane. The only event I see that is associated with this is the ActiveWindowChangedEvent. I think it may fire multiple times depending on the context (map becoming active, dockpane inactive and vice versa).

From this event, u can determine if a dockpane is being activated (in which case "Window" will be a Dockpane) but Im not sure if that gets u further along...

ArcGIS.Desktop.Framework.Events.ActiveWindowChangedEvent.Subscribe(
 (args) => {
  if (args.Window is DockPane dockPane){
    //a dockpane is being activated
    var id = dockPane.ID;
    var caption = dockPane.Caption;
    //etc, etc
  }
});

 

0 Kudos
JamesAkaes
New Contributor II

Yes, when I am trying to open the tool from the Modify Features pane, it calls the same OnClick() method as the button when it is opened from the Ribbon. But now the problem is how to shift the user to the already opened pane because it is of type Embeddable Control, not a dock pane.

Summarizing my use case again:

1. Open the tool from the button in the ribbon. It opens the tool in a separate pane. Also the tool is now active.

2. Now open Modify Features pane and go to the same tool in the list of tools there. Since tool is already active user will see border around it telling the user this tool is already active. 

3. Now expectation is if user will open the tool from there, it should open or shift the user to the already opened tool which was opened as a separate pane in first step. 

But the tool or its view model is created as a Embeddable control.

Also I have noticed once tool is opened from Ribbon, then opened through Modify features for the first time it doesn't call OnClick method. Then if I will close the tool which was opened through Ribbon and then try again it will call OnClick method when again opened through Modify Features.

@CharlesMacleod @Wolf 

0 Kudos