internal static void SetCaptionHeight(WindowX windowX, double height)
 {
     windowX.Dispatcher.BeginInvoke(new Action(() =>
     {
         var chrome = WindowChrome.GetWindowChrome(windowX);
         if (chrome == null || double.IsNaN(height) || double.IsInfinity(height))
         {
             return;
         }
         chrome.CaptionHeight = height;
     }), System.Windows.Threading.DispatcherPriority.Loaded);
 }
        public PendingBoxWindow(Window owner, bool interopOwnersMask, Rect?ownerRect, string message, string caption, bool canCancel, string windowStyle, string cancelButtonStyle, string spinnerStyle, string contentTemplate, object cancelButtonContent, PendingHandlerImpl handler)
        {
            _captionText = caption;
            _messageText = message;
            _canCancel   = canCancel;

            _cancelButtonContent = cancelButtonContent;

            _handler = handler;
            _handler.SetWindow(this);


            Style              = XamlUtil.FromXaml <Style>(windowStyle);
            ContentTemplate    = XamlUtil.FromXaml <DataTemplate>(contentTemplate);
            _cancelButtonStyle = XamlUtil.FromXaml <Style>(cancelButtonStyle);
            _spinnerStyle      = XamlUtil.FromXaml <Style>(spinnerStyle);

            if (ownerRect == null)
            {
                WindowStartupLocation = owner == null
                  ? WindowStartupLocation.CenterScreen
                  : WindowStartupLocation.CenterOwner;
            }

            if (ownerRect == null)
            {
                Owner = owner;
            }
            else
            {
                _ownerRect = ownerRect;
                Topmost    = true;
            }
            if (owner is WindowX ownerX && interopOwnersMask)
            {
                ownerX.Dispatcher.BeginInvoke(new Action(() =>
                {
                    ownerX.IsMaskVisible = true;
                }));
                _owner = ownerX;
            }
            Loaded += PendingBoxWindow_Loaded;
        }
        private UIElement CreatePreviewView(WindowX view, object content)
        {
            var contentControl = new ContentControl()
            {
                Foreground = view.Foreground,
                Content    = content,
            };
            var grid = new Grid();

            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(view.DisableDragMove ? 0 : WindowXCaption.GetHeight(view))
            });
            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Star)
            });
            grid.Children.Add(new Border()
            {
                Background = WindowXCaption.GetBackground(view),
                Child      = new ContentControl()
                {
                    Content         = view.DataContext is Window ? "" : view.DataContext,
                    ContentTemplate = WindowXCaption.GetHeaderTemplate(view),
                }
            });
            Grid.SetRow(contentControl, 1);
            grid.Children.Add(contentControl);
            var border = new Border()
            {
                Background      = view.Background,
                BorderBrush     = view.BorderBrush ?? Brushes.Gray,
                BorderThickness = view.BorderThickness.Left == 0 ? new Thickness(1) : view.BorderThickness,
                Width           = view.Width,
                Height          = view.Height,
                Child           = grid,
            };

            return(border);
        }
        internal static void SetCaptionHeight(WindowX windowX, double height)
        {
            var action = new Action(() =>
            {
                var chrome = WindowChrome.GetWindowChrome(windowX);
                if (chrome == null)
                {
                    return;
                }
                chrome.CaptionHeight = height;
            });

            if (windowX.IsLoaded)
            {
                action();
            }
            else
            {
                windowX.Loaded += delegate
                {
                    action();
                };
            }
        }
 public EditMapConfigViewModel(WindowX wnd, string mapConfigName)
 {
     this.windowX = wnd;
     this.MapName = mapConfigName;
     LoadMapConfig(mapConfigName);
 }
Beispiel #6
0
    internal static void SetSearchFilter(this EditorWindow window, int[] instanceIDs, string title)
    {
        if (window == null)
        {
            WindowX.xClearDefinitionCache();
            window = WindowX.Hierarchy;
        }

        if (instanceIDs.Length == 0)
        {
            window.xInvoke(
                "SetSearchFilter", null, null,
                new object[] { "Hierarchy2tempfixemptysearch", SearchableEditorWindow.SearchMode.All, false });
            window.xSetSearchFilterTerm("iso:" + title);
            return;
        }

/*#if UNITY_4_6
 *      Debug.Log("Before");
 *
 *      //var sf = typeof(SearchableEditorWindow).xInvoke("CreateFilter", null, null, "iso:" +title, SearchableEditorWindow.SearchMode.All);
 *      window.xInvoke("SetSearchFilter", null, null, "iso:" + title, SearchableEditorWindow.SearchMode.All, false);
 *      window.xSetField("m_HasSearchFilterFocus", true);
 *
 *      var treeView        = window.xGetField("m_TreeView");
 *      var ds              = treeView.xGetProperty("data");
 *
 *
 *
 *
 *
 *
 *      window.Repaint();
 *
 *      Debug.Log("After");*/

#if UNITY_4_5 || UNITY_4_6 || UNITY_5
        //var treeViewSrcT    = "UnityEditor.TreeViewDataSource".xGetTypeByName("UnityEditor");
        var treeViewItemT = "UnityEditor.TreeViewItem".xGetTypeByName("UnityEditor");
        var treeView      = WindowX.Hierarchy.xGetField("m_TreeView");
        var treeViewData  = treeView.xGetProperty("data");
        var rootItem      = treeViewData.xGetField("m_RootItem");
        var children      = rootItem.GetChildrenTreeItem(treeViewItemT, true);
        var expandIds     = treeViewData.xInvoke("GetExpandedIDs"); //save the expand state to restore

        foreach (var t in children)                                 // expand all children
        {
            if (t != null)
            {
                treeViewData.xInvoke("SetExpandedWithChildren", null, null, t, true);
            }
        }

        //Debug.Log("ids :: " + instanceIDs.Length);

        var children1    = (IList)treeViewData.xInvoke("GetVisibleRows");
        var childrenList = treeViewItemT.xNewListT();
        for (var i = 0; i < children1.Count; i++)
        {
            var child = children1[i];

            if (instanceIDs.Contains((int)child.xGetField("m_ID", treeViewItemT)))
            {
                child.xSetField("m_Depth", 0, treeViewItemT);
                childrenList.Add(child);
            }
        }

        // restore the expand state for children
        treeViewData.xInvoke("SetExpandedIDs", null, null, expandIds);

        window.xInvoke(
            "SetSearchFilter", null, null, new object[] { "iso:" + title, SearchableEditorWindow.SearchMode.All, false });
        treeViewData.xSetField("m_VisibleRows", childrenList.xToListT(treeViewItemT));
        treeView.xSetField("m_AllowRenameOnMouseUp", false);
        treeView.xInvoke("Repaint");
#else
        var TBaseProjectWindow = "UnityEditor.BaseProjectWindow".xGetTypeByName("UnityEditor");
        var TFilteredHierarchy = "UnityEditor.FilteredHierarchy".xGetTypeByName("UnityEditor");

        //window.SetSearchFilter("iso:" + title);

        var instIDsParams = new object[] { instanceIDs };
        var fh            = window.xGetField("m_FilteredHierarchy", TBaseProjectWindow);
        var sf            = (SearchFilter)fh.xGetField("m_SearchFilter", TFilteredHierarchy);

        sf.ClearSearch();
        sf.referencingInstanceIDs = instanceIDs;
        fh.xInvoke("SetResults", TFilteredHierarchy, null, instIDsParams);

        var arr  = (object[])fh.xGetProperty("results", TFilteredHierarchy, null);   //(FilteredHierarchyType.GetProperty("results").GetValue(fh, null));
        var list = new List <int>();

        //patch
        var nMissing = 0;
        foreach (var t in arr)
        {
            if (t == null)
            {
                nMissing++;
                continue;
            }
            var id = (int)t.xGetField("instanceID");
            if (!list.Contains(id))
            {
                list.Add(id);
            }
        }

        if (nMissing > 0)
        {
            Debug.LogWarning("Filtered result may not be correct, missing " + nMissing + " results, please help report it to [email protected]");
        }
        instanceIDs = list.ToArray();

        //reapply
        sf.ClearSearch();
        sf.referencingInstanceIDs = instanceIDs;
        fh.xInvoke("SetResults", TFilteredHierarchy, null, new object[] { instanceIDs });
        window.Repaint();
#endif
    }
Beispiel #7
0
    internal static void SetSearchFilter(EditorWindow window, int[] instanceIDs, string title)
    {
        if (window == null)
        {
            WindowX.xClearDefinitionCache();
            window = WindowX.Hierarchy;
        }

        var goList = new List <GameObject>();

        for (var i = 0; i < instanceIDs.Length; i++)
        {
            var go = (GameObject)EditorUtility.InstanceIDToObject(instanceIDs[i]);
            if (go != null)
            {
                goList.Add(go);
            }
        }

        if (instanceIDs.Length == 0)
        {
            window.xInvoke("SetSearchFilter", null, null, new object[] { "Hierarchy2tempfixemptysearch", SearchableEditorWindow.SearchMode.All, false });
            window.xSetSearchFilterTerm("iso:" + title);
            return;
        }

        var TBaseProjectWindow = "UnityEditor.BaseProjectWindow".xGetTypeByName("UnityEditor");
        var TFilteredHierarchy = "UnityEditor.FilteredHierarchy".xGetTypeByName("UnityEditor");

        window.xSetSearchFilterTerm("iso:" + title);

        var instIDsParams = new object[] { instanceIDs };
        var fh            = window.xGetField("m_FilteredHierarchy", TBaseProjectWindow);
        var sf            = (SearchFilter)fh.xGetField("m_SearchFilter", TFilteredHierarchy);

        sf.ClearSearch();
        sf.referencingInstanceIDs = instanceIDs;
        fh.xInvoke("SetResults", TFilteredHierarchy, null, instIDsParams);

        var arr  = (object[])fh.xGetProperty("results", TFilteredHierarchy, null);   //(FilteredHierarchyType.GetProperty("results").GetValue(fh, null));
        var list = new List <int>();

        //patch
        var nMissing = 0;

        foreach (var t in arr)
        {
            if (t == null)
            {
                nMissing++;
                continue;
            }
            var id = (int)t.xGetField("instanceID");
            if (!list.Contains(id))
            {
                list.Add(id);
            }
        }

        if (nMissing > 0)
        {
            Debug.LogWarning("Filtered result may not be correct, missing " + nMissing + " results, please help report it to [email protected]");
        }
        instanceIDs = list.ToArray();

        //reapply
        sf.ClearSearch();
        sf.referencingInstanceIDs = instanceIDs;
        fh.xInvoke("SetResults", TFilteredHierarchy, null, instanceIDs);
        window.Repaint();
    }