Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating windows get closed after calling SetFocusedDockable #351

Open
BradBergstrom opened this issue Aug 12, 2024 · 2 comments
Open

Floating windows get closed after calling SetFocusedDockable #351

BradBergstrom opened this issue Aug 12, 2024 · 2 comments

Comments

@BradBergstrom
Copy link

BradBergstrom commented Aug 12, 2024

I am trying to write a function for showing/opening tools. I have this function inside my DockFactory class implementation. Im not sure if this is a bug, or if I have something implemented wrong, but whenever I call either of the functions:

SetActiveDockable(dockable);
SetFocusedDockable(toolDock, dockable);

All of my floating windows get closed. Does anyone know why this is happening?

Here is my full function:

public void ShowTool(string toolId)
{
	try
	{
		if (DockableLocator.TryGetValue(toolId, out Func<IDockable?>? getDockable))
		{
			IDockable? dockable = getDockable();
			if (dockable != null)
			{
				Console.WriteLine("Dockable object retrieved successfully.");
				if (dockable.Owner is ToolDock toolDock)
				{
					if (toolDock.VisibleDockables != null && toolDock.VisibleDockables.Contains(dockable))
					{
						//then the tool has not been closed
						SetActiveDockable(dockable);
						SetFocusedDockable(toolDock, dockable);
					}
					else
					{
						//tool has been closed 
						FloatDockable(dockable);
					}
				}
				else
				{
					//tool has never been opened
				}
			}
		}
	}  
        catch(Exception ex)
	{
		
	}
}
@BradBergstrom BradBergstrom changed the title Floated windows get closed after calling SetFocusedDockable Floating windows get closed after calling SetFocusedDockable Aug 12, 2024
@BradBergstrom
Copy link
Author

BradBergstrom commented Aug 12, 2024

Found another clue while debugging.

If I go through the following steps:

  1. Float Tool with float option in GUI provided by the library.
  2. Hit the X on the floating tool to close it.
  3. Call my ShowTool function, which then calls FloatDockable as shown above.

Then the floating window will work perfectly. It wont be closed by subsequent calls to the ShowTool function, and calling that function with the ToolId for it, it will properly set as active.

Edit: Literally changing my code to this fixes the bug. I don't want to be doing this, so whats the solution to get this to work right the first time?

toolDock.Factory?.FloatDockable(dockable);
dockable.OnClose();
toolDock.Factory?.FloatDockable(dockable);

@BradBergstrom
Copy link
Author

Another interesting thing I've noticed while doing more debugging, is that when a floating tool is in a good state (See previous post as to how to get Tool into a good state), there are two RootDocks that are returned when querying the function FactoryBase.Find like so:

var results = Find(x => x is IRootDock);

This line is pulled directly from the function FactoryBase.SetFocusedDockable.

When a tool is floating in a bad state, there is only 1 RootDock that is returned from that function (which checks FactoryBase.DockControls).

I believe this may be why the bad state floating Tools are getting destroyed. The DockControl for the floating Tool doesn't get created until after going through the 3 steps to enter the tool into the good state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant