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

The window cannot be automatically filled after being unpined #276

Closed
bouyeijiang opened this issue Apr 19, 2023 · 3 comments
Closed

The window cannot be automatically filled after being unpined #276

bouyeijiang opened this issue Apr 19, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@bouyeijiang
Copy link

image

@ZSYMAX
Copy link

ZSYMAX commented Apr 19, 2023

@wieslawsoltes
I'm trying to solve this problem,maybe a bad solution.

In ProportionalStackPanel.cs,i have changed the AssignProportions method,this is my code

    Dictionary<Control, double> lastProportion = new Dictionary<Control, double>();
    private void AssignProportions(IList<Control?> children)
    {
        var assignedProportion = 0.0;
        var unassignedProportions = 0;

        #region My change

        double unassign = 0.0;
        foreach (var control in children)
        {
            if (control.DataContext is IProportionalDock pdock && pdock.VisibleDockables != null)
            {
                // if all tooldocks has no ActiveDockable,then set the proportion of the parent ProportionalStackPanel to 0;
                var toolDocks = pdock.VisibleDockables.OfType<IToolDock>();
                if (toolDocks.All(x => x.ActiveDockable == null))
                {
                    var proportion = ProportionalStackPanelSplitter.GetProportion(control);
                    ProportionalStackPanelSplitter.SetProportion(control, 0);
                    unassign += proportion;

                    //record the last proportion
                    lastProportion[control] = proportion;
                }
                else
                {
                    if (lastProportion.TryGetValue(control, out var value))
                    {
                        ProportionalStackPanelSplitter.SetProportion(control, value);
                    }
                }
            }
        }
        if (unassign > 0)
        {
            //if has the document dock,add the remaining proportion to the document dock
            var documentDock = children.OfType<DocumentDockControl>().FirstOrDefault();
            if (documentDock != null)
            {
                var p = ProportionalStackPanelSplitter.GetProportion(documentDock);
                p += unassign;
                ProportionalStackPanelSplitter.SetProportion(documentDock, p);
            }
        }
        #endregion


        foreach (var control in children)
        {
            if (control is { } and not ProportionalStackPanelSplitter)
            {
                var proportion = ProportionalStackPanelSplitter.GetProportion(control);

                if (double.IsNaN(proportion))
                {
                    unassignedProportions++;
                }
                else
                {
                    assignedProportion += proportion;
                }
            }
        }

        if (unassignedProportions > 0)
        {
            var toAssign = assignedProportion;
            foreach (var control in children.Where(c => c is { } && double.IsNaN(ProportionalStackPanelSplitter.GetProportion(c))))
            {
                if (control is { } and not ProportionalStackPanelSplitter)
                {
                    var proportion = (1.0 - toAssign) / unassignedProportions;
                    ProportionalStackPanelSplitter.SetProportion(control, proportion);
                    assignedProportion += (1.0 - toAssign) / unassignedProportions;
                }
            }
        }

        if (assignedProportion < 1)
        {
            var numChildren = (double)children.Count(c => c is not ProportionalStackPanelSplitter);

            var toAdd = (1.0 - assignedProportion) / numChildren;

            foreach (var child in children.Where(c => c is not ProportionalStackPanelSplitter))
            {
                if (child is { })
                {
                    var proportion = ProportionalStackPanelSplitter.GetProportion(child) + toAdd;
                    ProportionalStackPanelSplitter.SetProportion(child, proportion);
                }
            }
        }
        else if (assignedProportion > 1)
        {
            var numChildren = (double)children.Count(c => c is not ProportionalStackPanelSplitter);

            var toRemove = (assignedProportion - 1.0) / numChildren;

            foreach (var child in children.Where(c => c is not ProportionalStackPanelSplitter))
            {
                if (child is { })
                {
                    var proportion = ProportionalStackPanelSplitter.GetProportion(child) - toRemove;
                    ProportionalStackPanelSplitter.SetProportion(child, proportion);
                }
            }
        }
    }

i only add some code in region

@wieslawsoltes
Copy link
Owner

It's known issue, didn't yet found a working solution.

@wieslawsoltes wieslawsoltes added the bug Something isn't working label Sep 5, 2023
@wieslawsoltes wieslawsoltes closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2024
@BAndysc
Copy link
Contributor

BAndysc commented Mar 10, 2024

#324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants