Example #1
0
        public static void DisposeAllChildWebBrowserControls(IWindowForm ownerForm)
        {
            //dispose all web browser (child) windows inside this window form
            List <MyCefBrowser> foundList;

            if (registerTopWindowForms.TryGetValue(ownerForm, out foundList))
            {
                //remove webbrowser controls
                for (int i = foundList.Count - 1; i >= 0; --i)
                {
                    MyCefBrowser   mycefBw = foundList[i];
                    IWindowControl wb      = mycefBw.ParentControl;
                    mycefBw.NotifyCloseBw();
                    //---------------------------------------
                    var parent = wb.GetParent();
                    parent.RemoveChild(wb);

                    //this Dispose() will terminate cef_life_time_handle ***
                    //after native side dispose the wb control
                    //it will raise event BrowserDisposed
                    wb.Dispose();

                    //---------------------------------------
                }
                registerTopWindowForms.Remove(ownerForm);
            }
        }
Example #2
0
    public async Task ShowWindowAsync(IWindowControl windowContent, ShowWindowFlags flags = ShowWindowFlags.None, params string[] groupNames)
    {
        var openWindowInstance = new OpenWindowInstance(new WeakReference <IWindowControl>(windowContent), groupNames);

        try
        {
            // Remove instances which have been collected by the GC
            OpenWindows.RemoveWhere(x => !x.Window.TryGetTarget(out _));

            Type contentType = windowContent.UIContent.GetType();

            IWindowControl blockingWindow = OpenWindows.
                                            Select(x => x.Window.TryGetTarget(out IWindowControl w) ? new { Window = w, x.GroupNames } : null).
                                            FirstOrDefault(x =>
            {
                // Check for duplicate types
                if (!flags.HasFlag(ShowWindowFlags.DuplicateTypesAllowed) && x?.Window.UIContent.GetType() == contentType)
                {
                    return(true);
                }

                // Check for duplicate group names
                if (groupNames.Any() && x?.GroupNames.Any(groupNames.Contains) == true)
                {
                    return(true);
                }

                return(false);
            })?.Window;

            // If there is a window blocking this one from showing we return
            if (blockingWindow != null)
            {
                Logger.Info("The window is not being shown due to a window of the same type or ID being available", contentType);

                // Focus the blocking window
                if (!flags.HasFlag(ShowWindowFlags.DoNotFocusBlockingWindow))
                {
                    blockingWindow.WindowInstance?.Focus();
                }

                return;
            }

            OpenWindows.Add(openWindowInstance);

            // Show the window
            await ShowWindowAsync(windowContent, false, null);
        }
        finally
        {
            OpenWindows.Remove(openWindowInstance);

            windowContent.Dispose();
        }
    }