Exemple #1
0
        AppResult GenerateChildrenForNSView(NSView view, List <AppResult> resultSet)
        {
            AppResult firstChild = null, lastChild = null;

            foreach (var child in view.Subviews)
            {
                AppResult node = new NSObjectResult(child)
                {
                    SourceQuery = ToString()
                };
                resultSet.Add(node);

                if (firstChild == null)
                {
                    firstChild = node;
                    lastChild  = node;
                }
                else
                {
                    lastChild.NextSibling = node;
                    node.PreviousSibling  = lastChild;
                    lastChild             = node;
                }

                if (child.Subviews != null)
                {
                    AppResult children = GenerateChildrenForNSView(child, resultSet);
                    node.FirstChild = children;
                }
            }

            return(firstChild);
        }
Exemple #2
0
        AppResult GenerateChildrenForNSView(NSView view, List <AppResult> resultSet)
        {
            AppResult firstChild = null, lastChild = null;

            foreach (var child in view.Subviews)
            {
                AppResult node = new NSObjectResult(child)
                {
                    SourceQuery = ToString()
                };
                resultSet.Add(node);

                if (firstChild == null)
                {
                    firstChild = node;
                    lastChild  = node;
                }
                else
                {
                    lastChild.NextSibling = node;
                    node.PreviousSibling  = lastChild;
                    lastChild             = node;
                }

                if (child.Subviews != null)
                {
                    AppResult children = GenerateChildrenForNSView(child, resultSet);
                    node.FirstChild = children;
                }
            }

            if (view is NSSegmentedControl || view.GetType().IsSubclassOf(typeof(NSSegmentedControl)))
            {
                var segmentedControl = (NSSegmentedControl)view;
                LoggingService.LogInfo($"Found 'NSSegmentedControl' with {segmentedControl.SegmentCount} children");
                for (int i = 0; i < segmentedControl.SegmentCount; i++)
                {
                    var node = new NSObjectResult(view, i);
                    resultSet.Add(node);
                    if (firstChild == null)
                    {
                        firstChild = node;
                        lastChild  = node;
                    }
                    else
                    {
                        lastChild.NextSibling = node;
                        node.PreviousSibling  = lastChild;
                        lastChild             = node;
                    }
                }
            }

            return(firstChild);
        }
Exemple #3
0
        protected ObjectProperties GetProperties(object resultObject)
        {
            var propertiesObject = new ObjectProperties();

            if (resultObject != null)
            {
                propertiesObject.Add("ToString", new ObjectResult(resultObject.ToString()), null);
                var properties = resultObject.GetType().GetProperties(
                    BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
                foreach (var property in properties)
                {
                    try {
                        var       value  = GetPropertyValue(property.Name, resultObject);
                        AppResult result = null;

                        var gtkNotebookValue = value as Gtk.Notebook;
                        if (gtkNotebookValue != null)
                        {
                            result = new GtkNotebookResult(gtkNotebookValue);
                        }
                        var gtkTreeviewValue = value as Gtk.TreeView;
                        if (gtkTreeviewValue != null && result == null)
                        {
                            result = new GtkTreeModelResult(gtkTreeviewValue, gtkTreeviewValue.Model, 0);
                        }
                        var gtkWidgetValue = value as Gtk.Widget;
                        if (gtkWidgetValue != null && result == null)
                        {
                            result = new GtkWidgetResult(gtkWidgetValue);
                        }
                                                #if MAC
                        var nsObjectValue = value as Foundation.NSObject;
                        if (nsObjectValue != null && result == null)
                        {
                            result = new NSObjectResult(nsObjectValue);
                        }
                                                #endif
                        if (result == null)
                        {
                            result = new ObjectResult(value);
                        }
                        propertiesObject.Add(property.Name, result, property);
                    } catch (Exception e) {
                        MonoDevelop.Core.LoggingService.LogInfo("Failed to fetch property '{0}' on '{1}' with Exception: {2}", property, resultObject, e);
                    }
                }
            }

            return(propertiesObject);
        }
Exemple #4
0
        AppResult AddNSObjectResult(NSView view, int index = -1)
        {
            // If the view is hidden and we don't include hidden, don't add it.
            if (view == null || (!includeHidden && view.Hidden))
            {
                return(null);
            }

            AppResult node = new NSObjectResult(view, index)
            {
                SourceQuery = sourceQuery
            };

            return(AddToResultSet(node));
        }
Exemple #5
0
        protected ObjectProperties GetProperties(object resultObject)
        {
            var propertiesObject = new ObjectProperties();

            if (resultObject != null)
            {
                var properties = resultObject.GetType().GetProperties(
                    BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
                foreach (var property in properties)
                {
                    var       value  = GetPropertyValue(property.Name, resultObject);
                    AppResult result = null;

                    var gtkNotebookValue = value as Gtk.Notebook;
                    if (gtkNotebookValue != null)
                    {
                        result = new GtkNotebookResult(gtkNotebookValue);
                    }
                    var gtkTreeviewValue = value as Gtk.TreeView;
                    if (gtkTreeviewValue != null && result == null)
                    {
                        result = new GtkTreeModelResult(gtkTreeviewValue, gtkTreeviewValue.Model, 0);
                    }
                    var gtkWidgetValue = value as Gtk.Widget;
                    if (gtkWidgetValue != null && result == null)
                    {
                        result = new GtkWidgetResult(gtkWidgetValue);
                    }
                                        #if MAC
                    var nsObjectValue = value as Foundation.NSObject;
                    if (nsObjectValue != null && result == null)
                    {
                        result = new NSObjectResult(nsObjectValue);
                    }
                                        #endif
                    if (result == null)
                    {
                        result = new ObjectResult(value);
                    }

                    propertiesObject.Add(property.Name, result, property);
                }
            }

            return(propertiesObject);
        }
Exemple #6
0
        void ProcessNSWindow(NSWindow window, AppResult rootNode, ref AppResult lastChild)
        {
            // Don't process hidden windows.
            if (!includeHidden && !window.IsVisible)
            {
                return;
            }

            AppResult node = new NSObjectResult(window)
            {
                SourceQuery = sourceQuery
            };

            AddToResultSet(node);
            AddChild(rootNode, node, ref lastChild);

            AppResult nsWindowLastNode = null;

            foreach (var child in window.ContentView.Subviews)
            {
                AppResult childNode = AddNSObjectResult(child);
                if (childNode == null)
                {
                    continue;
                }

                AddChild(node, childNode, ref nsWindowLastNode);
                GenerateChildrenForNSView(childNode, child);
            }

            NSToolbar toolbar = window.Toolbar;

            if (toolbar == null)
            {
                return;
            }

            AppResult toolbarNode = new NSObjectResult(toolbar)
            {
                SourceQuery = sourceQuery
            };

            // Was missing before too, maybe should be added to fullResultSet?

            AddChild(node, toolbarNode, ref nsWindowLastNode);

            if (toolbar == null)
            {
                return;
            }

            AppResult lastItemNode = null;

            foreach (var item in toolbar.Items)
            {
                AppResult itemNode = AddNSObjectResult(item.View);
                if (itemNode == null)
                {
                    continue;
                }

                AddChild(toolbarNode, itemNode, ref lastItemNode);
                GenerateChildrenForNSView(itemNode, item.View);
            }
        }
Exemple #7
0
        List <AppResult> ResultSetFromWindows()
        {
            Gtk.Window[] windows = Gtk.Window.ListToplevels();

            // null for AppResult signifies root node
            rootNode = new GtkWidgetResult(null)
            {
                SourceQuery = ToString()
            };
            List <AppResult> fullResultSet = new List <AppResult> ();

            // Build the tree and full result set recursively
            AppResult lastChild = null;

            foreach (var window in windows)
            {
                AppResult node = new GtkWidgetResult(window)
                {
                    SourceQuery = ToString()
                };
                fullResultSet.Add(node);

                if (rootNode.FirstChild == null)
                {
                    rootNode.FirstChild = node;
                    lastChild           = node;
                }
                else
                {
                    // Add the new node into the chain
                    lastChild.NextSibling = node;
                    node.PreviousSibling  = lastChild;
                    lastChild             = node;
                }

                // Create the children list and link them onto the node
                AppResult children = GenerateChildrenForContainer((Gtk.Container)window, fullResultSet);
                node.FirstChild = children;
            }

#if MAC
            NSWindow[] nswindows = NSApplication.SharedApplication.Windows;
            if (nswindows != null)
            {
                foreach (var window in nswindows)
                {
                    AppResult node = new NSObjectResult(window)
                    {
                        SourceQuery = ToString()
                    };
                    AppResult nsWindowLastNode = null;
                    fullResultSet.Add(node);

                    if (rootNode.FirstChild == null)
                    {
                        rootNode.FirstChild = node;
                        lastChild           = node;
                    }
                    else
                    {
                        lastChild.NextSibling = node;
                        node.PreviousSibling  = lastChild;
                        lastChild             = node;
                    }

                    foreach (var child in window.ContentView.Subviews)
                    {
                        AppResult childNode = new NSObjectResult(child)
                        {
                            SourceQuery = ToString()
                        };
                        fullResultSet.Add(childNode);

                        if (node.FirstChild == null)
                        {
                            node.FirstChild  = childNode;
                            nsWindowLastNode = childNode;
                        }
                        else
                        {
                            nsWindowLastNode.NextSibling = childNode;
                            childNode.PreviousSibling    = nsWindowLastNode;
                            nsWindowLastNode             = childNode;
                        }

                        if (child.Subviews != null)
                        {
                            AppResult children = GenerateChildrenForNSView(child, fullResultSet);
                            childNode.FirstChild = children;
                        }
                    }

                    NSToolbar toolbar     = window.Toolbar;
                    AppResult toolbarNode = new NSObjectResult(toolbar)
                    {
                        SourceQuery = ToString()
                    };

                    if (node.FirstChild == null)
                    {
                        node.FirstChild  = toolbarNode;
                        nsWindowLastNode = toolbarNode;
                    }
                    else
                    {
                        nsWindowLastNode.NextSibling = toolbarNode;
                        toolbarNode.PreviousSibling  = nsWindowLastNode;
                        nsWindowLastNode             = toolbarNode;
                    }

                    if (toolbar != null)
                    {
                        AppResult lastItemNode = null;
                        foreach (var item in toolbar.Items)
                        {
                            if (item.View != null)
                            {
                                AppResult itemNode = new NSObjectResult(item.View)
                                {
                                    SourceQuery = ToString()
                                };
                                fullResultSet.Add(itemNode);

                                if (toolbarNode.FirstChild == null)
                                {
                                    toolbarNode.FirstChild = itemNode;
                                    lastItemNode           = itemNode;
                                }
                                else
                                {
                                    lastItemNode.NextSibling = itemNode;
                                    itemNode.PreviousSibling = lastItemNode;
                                    lastItemNode             = itemNode;
                                }

                                if (item.View.Subviews != null)
                                {
                                    AppResult children = GenerateChildrenForNSView(item.View, fullResultSet);
                                    itemNode.FirstChild = children;
                                }
                            }
                        }
                    }
                }
            }
#endif
            return(fullResultSet);
        }