Ejemplo n.º 1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="component">组件</param>
        public override void Initialize(IComponent component)
        {
            base.Initialize(component);

            m_designerControl = (IDesignerControl)component;
            _ = EnableDesignMode(m_designerControl.DesignerControl, "DesignerControl");
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Default ctor
 /// </summary>
 internal XmlEditorView(OpenedFile file, XmlViewModel viewModel, IDesignerControl control)
 {
     this.viewModel = viewModel;
     this.control = control;
     Files.Add(file);
     file.ForceInitializeView(this);
     ComponentDispatcher.ThreadIdle += OnIdle;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Default ctor
 /// </summary>
 internal XmlEditorView(OpenedFile file, XmlViewModel viewModel, IDesignerControl control)
 {
     this.viewModel = viewModel;
     this.control   = control;
     Files.Add(file);
     file.ForceInitializeView(this);
     ComponentDispatcher.ThreadIdle += OnIdle;
 }
Ejemplo n.º 4
0
        private UserControl GetControlSet(string category)
        {
            Type             designerType    = designAbleResources[category];
            Type             genericType     = typeof(DesignerControl <>);
            Type             customListType  = genericType.MakeGenericType(designerType);
            IDesignerControl designerControl = (IDesignerControl)Activator.CreateInstance(customListType);

            IDesignable designable = designerControl.ControlSet;

            designable.JsonData = fastColoredTextBox1.Text;

            return((UserControl)designable);
        }
Ejemplo n.º 5
0
        private void CreateUI()
        {
            Label label = AddControl <Label>();
            {
                label.Content.Text = "Settings";
                label.Style        = new VisualStyle(EditorStyle.BoldLabel);
            }

            Tab tab = AddControl <Tab>();
            {
                tab.Content.Text = string.Empty;

                IDesignerControl general  = tab.AddItem("General");
                IDesignerControl security = tab.AddItem("Security");

                // Create the controls on the tabs
                CreateGeneralTab(general);
                CreateSecurityTab(security);
            }
        }
Ejemplo n.º 6
0
        private void CreateGeneralTab(IDesignerControl parent)
        {
            int labelWidth = 200;

            // Space
            parent.AddControl <Spacer>();

            // Case Sensitive Names setting
            HorizontalLayout a = parent.AddControl <HorizontalLayout>();
            {
                // Create the label
                Label label = a.AddControl <Label>();
                {
                    label.Content.Text    = "Case Sensitive Names";
                    label.Content.Tooltip = "Should type and member name searches be case sensitive";
                    label.Layout.Size     = new Vector2(labelWidth, 0);
                }

                // Create the toggle box
                ToggleBox box = a.AddControl <ToggleBox>();
                {
                    box.Checked    = DynamicCSharp.Settings.caseSensitiveNames;
                    box.OnToggled += (object sender, bool value) =>
                    {
                        DynamicCSharp.Settings.caseSensitiveNames = value;
                    };
                }
            }

            // Discover Non-Public Types setting
            HorizontalLayout b = parent.AddControl <HorizontalLayout>();
            {
                // Create the label
                Label label = b.AddControl <Label>();
                {
                    label.Content.Text    = "Discover non-public types";
                    label.Content.Tooltip = "Should types that are not marked 'public' be discovered";
                    label.Layout.Size     = new Vector2(labelWidth, 0);
                }

                // Create the toggle box
                ToggleBox box = b.AddControl <ToggleBox>();
                {
                    box.Checked    = DynamicCSharp.Settings.discoverNonPublicTypes;
                    box.OnToggled += (object sender, bool value) =>
                    {
                        DynamicCSharp.Settings.discoverNonPublicTypes = value;
                    };
                }
            }

            // Discover Non-Public Members
            HorizontalLayout c = parent.AddControl <HorizontalLayout>();
            {
                // Create the label
                Label label = c.AddControl <Label>();
                {
                    label.Content.Text    = "Discover non-public members";
                    label.Content.Tooltip = "Should class members that are not parked 'public' be discovered";
                    label.Layout.Size     = new Vector2(labelWidth, 0);
                }

                // Create the toggle box
                ToggleBox box = c.AddControl <ToggleBox>();
                {
                    box.Checked    = DynamicCSharp.Settings.discoverNonPublicMembers;
                    box.OnToggled += (object sender, bool value) =>
                    {
                        DynamicCSharp.Settings.discoverNonPublicMembers = value;
                    };
                }
            }

            // Debug mode
            HorizontalLayout d = parent.AddControl <HorizontalLayout>();

            {
                // Create the label
                Label label = d.AddControl <Label>();
                {
                    label.Content.Text    = "Debug Mode";
                    label.Content.Tooltip = "When enabled the compile will generate and load debug symbols";
                    label.Layout.Size     = new Vector2(labelWidth, 0);
                }

                // Create the toggle box
                ToggleBox box = d.AddControl <ToggleBox>();
                {
                    box.Checked    = DynamicCSharp.Settings.debugMode;
                    box.OnToggled += (object sender, bool value) =>
                    {
                        DynamicCSharp.Settings.debugMode = value;
                    };
                }
            }

            // Spacer
            parent.AddControl <Spacer>();

            EditListBox listbox = parent.AddControl <EditListBox>();
            {
                listbox.Content.Text = "Assembly References";
                listbox.ItemStyle    = new VisualStyle(EditorStyle.ToolbarButton);

                foreach (string value in DynamicCSharp.Settings.assemblyReferences)
                {
                    listbox.AddItem(value);
                }

                // On add clicked
                listbox.OnAddClicked += (object sender) =>
                {
                    // Show an input dialog
                    InputDialog dialog = InputDialog.ShowDialog <InputDialog>(new Vector2(0, 0));

                    dialog.WindowTitle = "Add Assembly Reference";
                    dialog.Content     = "Enter the name of the assembly you want to add including the '.dll' file extension";
                    dialog.CenterAt(UiEvent.mouseScreenPosition);

                    dialog.OnClosed += (object s, DialogResult result) =>
                    {
                        // Check for dialog accepted
                        if (result == DialogResult.OK)
                        {
                            InputDialog window = s as InputDialog;

                            // Make sure the input is not empty
                            if (string.IsNullOrEmpty(window.Text) == false)
                            {
                                // Add to listbox
                                listbox.AddItem(window.Text);

                                // Add to settings
                                DynamicCSharp.Settings.AddAssemblyReference(window.Text);
                            }
                        }
                    };
                };

                // On remove clicked
                listbox.OnRemoveClicked += (object sender) =>
                {
                    // Catch exceptions when the list is empty
                    try
                    {
                        // Remove selection
                        listbox.RemoveItem(listbox.SelectedItemName);

                        // Remove from settings
                        DynamicCSharp.Settings.RemoveAssemblyReference(listbox.SelectedIndex);
                    }
                    catch { }
                };
            }
        }
Ejemplo n.º 7
0
        private void CreateSecurityTab(IDesignerControl parent)
        {
            // Security check code
            HorizontalLayout a = parent.AddControl <HorizontalLayout>();

            {
                // Create the label
                Label label = a.AddControl <Label>();
                {
                    label.Content.Text    = "Security Check Code";
                    label.Content.Tooltip = "When enabled, all code will be security checked before it can be loaded";
                }

                // Create the toggle box
                ToggleBox box = a.AddControl <ToggleBox>();
                {
                    box.Checked    = DynamicCSharp.Settings.securityCheckCode;
                    box.OnToggled += (object sender, bool value) =>
                    {
                        DynamicCSharp.Settings.securityCheckCode = value;
                    };
                }
            }

            parent.AddControl <Spacer>();

            EditListBox referenceListbox = parent.AddControl <EditListBox>();

            {
                referenceListbox.Content.Text = "Assembly Reference Restrictions";
                referenceListbox.ItemStyle    = new VisualStyle(EditorStyle.ToolbarButton);

                foreach (ReferenceRestriction value in DynamicCSharp.Settings.referenceRestrictions)
                {
                    referenceListbox.AddItem(value.RestrictedName);
                }

                // On add clicked
                referenceListbox.OnAddClicked += (object sender) =>
                {
                    // Show an input dialog
                    InputDialog dialog = InputDialog.ShowDialog <InputDialog>(new Vector2(0, 0));

                    dialog.WindowTitle = "Add Assembly Reference Restriction";
                    dialog.Content     = "Enter the name of the assembly you want to restrict including the '.dll' file extension";
                    dialog.CenterAt(UiEvent.mouseScreenPosition);

                    dialog.OnClosed += (object s, DialogResult result) =>
                    {
                        if (result == DialogResult.OK)
                        {
                            InputDialog window = s as InputDialog;

                            if (string.IsNullOrEmpty(window.Text) == false)
                            {
                                // Add to listbox
                                referenceListbox.AddItem(window.Text);

                                // Add to settings
                                DynamicCSharp.Settings.AddReferenceRestriction(window.Text);
                            }
                        }
                    };
                };

                // On remove clicked
                referenceListbox.OnRemoveClicked += (object sender) =>
                {
                    // Catch exceptions cause by empty list
                    try
                    {
                        // Remove selection
                        referenceListbox.RemoveItem(referenceListbox.SelectedItemName);

                        // Remove from settings
                        DynamicCSharp.Settings.RemoveReferenceRestriction(referenceListbox.SelectedIndex);
                    }
                    catch { }
                };
            }

            parent.AddControl <Spacer>();

            EditListBox namespaceListbox = parent.AddControl <EditListBox>();
            {
                namespaceListbox.Content.Text = "Namespace Restrictions";
                namespaceListbox.ItemStyle    = new VisualStyle(EditorStyle.ToolbarButton);

                foreach (NamespaceRestriction value in DynamicCSharp.Settings.namespaceRestrictions)
                {
                    namespaceListbox.AddItem(value.RestrictedNamespace);
                }

                // On add clicked
                namespaceListbox.OnAddClicked += (object sender) =>
                {
                    // Show an input dialog
                    InputDialog dialog = InputDialog.ShowDialog <InputDialog>(new Vector2(0, 0));

                    dialog.WindowTitle = "Add Namespace Restriction";
                    dialog.Content     = "Enter the namespace you want to restrict. For example, 'System.IO'";
                    dialog.CenterAt(UiEvent.mouseScreenPosition);

                    dialog.OnClosed += (object s, DialogResult result) =>
                    {
                        if (result == DialogResult.OK)
                        {
                            InputDialog window = s as InputDialog;

                            if (string.IsNullOrEmpty(window.Text) == false)
                            {
                                // Add to listbox
                                namespaceListbox.AddItem(window.Text);

                                // Add to settings
                                DynamicCSharp.Settings.AddNamespaceRestriction(window.Text);
                            }
                        }
                    };
                };

                // On remove clicked
                namespaceListbox.OnRemoveClicked += (object sender) =>
                {
                    // Catch exceptions cause by empty list
                    try
                    {
                        // Remove selection
                        namespaceListbox.RemoveItem(namespaceListbox.SelectedItemName);

                        // Remove from settings
                        DynamicCSharp.Settings.RemoveNamespaceRestriction(namespaceListbox.SelectedIndex);
                    }
                    catch { }
                };
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Called after the WindowPane has been sited with an IServiceProvider from the environment
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Create and initialize the editor
            #region Register with IOleComponentManager
            var componentManager = (IOleComponentManager)GetService(typeof(SOleComponentManager));
            if (this.componentId == 0 && componentManager != null)
            {
                var crinfo = new OLECRINFO[1];
                crinfo[0].cbSize            = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crinfo[0].grfcrf            = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
                crinfo[0].grfcadvf          = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 100;
                int hr = componentManager.FRegisterComponent(this, crinfo, out this.componentId);
                ErrorHandler.Succeeded(hr);
            }
            #endregion

            var resources = new ComponentResourceManager(typeof(XmlEditorPane));

            #region Hook Undo Manager
            // Attach an IOleUndoManager to our WindowFrame. Merely calling QueryService
            // for the IOleUndoManager on the site of our IVsWindowPane causes an IOleUndoManager
            // to be created and attached to the IVsWindowFrame. The WindowFrame automaticall
            // manages to route the undo related commands to the IOleUndoManager object.
            // Thus, our only responsibilty after this point is to add IOleUndoUnits to the
            // IOleUndoManager (aka undo stack).
            undoManager = (IOleUndoManager)GetService(typeof(SOleUndoManager));

            // In order to use the IVsLinkedUndoTransactionManager, it is required that you
            // advise for IVsLinkedUndoClient notifications. This gives you a callback at
            // a point when there are intervening undos that are blocking a linked undo.
            // You are expected to activate your document window that has the intervening undos.
            if (undoManager != null)
            {
                IVsLinkCapableUndoManager linkCapableUndoMgr = (IVsLinkCapableUndoManager)undoManager;
                if (linkCapableUndoMgr != null)
                {
                    linkCapableUndoMgr.AdviseLinkedUndoClient(this);
                }
            }
            #endregion

            // hook up our
            var dteVersion       = Dot42Package.DteVersion;
            var xmlEditorService = XmlEditorServiceProvider.GetEditorService(this, dteVersion);
            if (xmlEditorService == null)
            {
                throw new InvalidOperationException("XmlEditorService required");
            }
            store             = xmlEditorService.CreateXmlStore();
            store.UndoManager = undoManager;

            model = store.OpenXmlModel(new Uri(_fileName));

            // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
            // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
            // the object returned by the Content property.
            //designerControl = new VsDesignerControl(new ViewModel(store, model, this, textBuffer));
            designerControl = context.CreateDesigner(thisPackage.Ide, store, model, this, textBuffer);
            base.Content    = designerControl;

            RegisterIndependentView(true);

            var mcs = GetService(typeof(IMenuCommandService)) as IMenuCommandService;
            if (null != mcs)
            {
                // Now create one object derived from MenuCommnad for each command defined in
                // the CTC file and add it to the command service.

                // For each command we have to define its id that is a unique Guid/integer pair, then
                // create the OleMenuCommand object for this command. The EventHandler object is the
                // function that will be called when the user will select the command. Then we add the
                // OleMenuCommand to the menu service.  The addCommand helper function does all this for us.
                AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.NewWindow, OnNewWindow, OnQueryNewWindow);
                AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.ViewCode, OnViewCode, OnQueryViewCode);
            }
        }
        private void createUI()
        {
            Toolbar toolbar = AddControl <Toolbar>();

            {
                Label label = toolbar.AddControl <Label>();
                {
                    label.Content.Text = "Update Rate: ";
                    label.Layout.Size  = new Vector2(0, 0);
                }
                ToggleButton slow = toolbar.AddControl <ToggleButton>("0");
                {
                    slow.Style           = new VisualStyle(EditorStyle.ToolbarButton);
                    slow.Content.Text    = "Slow Update";
                    slow.Content.Tooltip = "Set the refresh mode to slow. Less updates per frame";

                    slow.OnClicked += (object sender) =>
                    {
                        setUpdateRate(0);
                    };
                }
                ToggleButton medium = toolbar.AddControl <ToggleButton>("1");
                {
                    medium.Style           = new VisualStyle(EditorStyle.ToolbarButton);
                    medium.Content.Text    = "Medium Update";
                    medium.Content.Tooltip = "Set the refresh mode to medium. The default settings";

                    medium.OnClicked += (object sender) =>
                    {
                        setUpdateRate(1);
                    };
                }
                ToggleButton fast = toolbar.AddControl <ToggleButton>("2");
                {
                    fast.Style           = new VisualStyle(EditorStyle.ToolbarButton);
                    fast.Content.Text    = "Fast Update";
                    fast.Content.Tooltip = "Set the refresh mode to fast. More updates per frames for more accurate data";

                    fast.OnClicked += (object sender) =>
                    {
                        setUpdateRate(2);
                    };
                }
                toolbar.AddControl <FlexibleSpacer>();

                // Set the mode
                setUpdateRate(-1);
            }

            parent = AddControl <VerticalLayout>();
            {
                HelpBox timingHelp = parent.AddControl <HelpBox>();
                {
                    timingHelp.Content.Text = "Shows the average and peek time taken to complete the algorithm";
                }

                Chart timingChart = parent.AddControl <Chart>();
                {
                    timingChart.Layout.MinSize = new Vector2(0, 0);
                    timingChart.SetChartAxis(ChartAxis.Horizontal, 0, 1, "Update (Frame Step)");
                    timingChart.SetChartAxis(ChartAxis.Vertical, 0, 1, "Time (ms)");

                    timingChart.SetDatasetCount(2);
                    timingChart.SetDataset(0, timingData);
                    timingChart.SetDataset(1, timingPeekData);

                    timingData.Name     = "Average Time (Per sample)";
                    timingPeekData.Name = "Highest Time (Per sample)";
                }

                HelpBox usageHelp = parent.AddControl <HelpBox>();
                {
                    usageHelp.Content.Text = "Shows the current usages value for all worker threads (When active)";
                }

                HorizontalLayout usageLayout = parent.AddControl <HorizontalLayout>();
                {
                    Chart usageChart = usageLayout.AddControl <Chart>();
                    {
                        usageChart.Layout.MinSize = new Vector2(0, 0);
                        usageChart.SetChartAxis(ChartAxis.Horizontal, 0, 1, "Update (Frame Step)");
                        usageChart.SetChartAxis(ChartAxis.Vertical, 0, 1, "Usage (%)");

                        // Set data
                        usageChart.SetDatasetCount(3);

                        for (int i = 0; i < ThreadManager.maxAllowedWorkerThreads; i++)
                        {
                            usageData[i]      = new ChartDynamicDataset();
                            usageData[i].Name = string.Format("Thread {0}", i + 1);
                            usageChart.SetDataset(i, usageData[i]);
                        }
                    }

                    usageView = usageLayout.AddControl <ThreadViewCollectionControl>();
                    {
                        usageView.Layout.Size = new Vector2(230, 0);
                    }
                }
            }

            hint = AddControl <HelpBox>();
            {
                hint.HelpType     = HelpBoxType.Info;
                hint.Content.Text = "Waiting for game to launch. Timing and usage statistics can only be gathered in play mode";
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Called after the WindowPane has been sited with an IServiceProvider from the environment
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Create and initialize the editor
            #region Register with IOleComponentManager
            var componentManager = (IOleComponentManager)GetService(typeof(SOleComponentManager));
            if (this.componentId == 0 && componentManager != null)
            {
                var crinfo = new OLECRINFO[1];
                crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
                crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 100;
                int hr = componentManager.FRegisterComponent(this, crinfo, out this.componentId);
                ErrorHandler.Succeeded(hr);
            }
            #endregion

            var resources = new ComponentResourceManager(typeof(XmlEditorPane));

            #region Hook Undo Manager
            // Attach an IOleUndoManager to our WindowFrame. Merely calling QueryService
            // for the IOleUndoManager on the site of our IVsWindowPane causes an IOleUndoManager
            // to be created and attached to the IVsWindowFrame. The WindowFrame automaticall
            // manages to route the undo related commands to the IOleUndoManager object.
            // Thus, our only responsibilty after this point is to add IOleUndoUnits to the
            // IOleUndoManager (aka undo stack).
            undoManager = (IOleUndoManager)GetService(typeof(SOleUndoManager));

            // In order to use the IVsLinkedUndoTransactionManager, it is required that you
            // advise for IVsLinkedUndoClient notifications. This gives you a callback at
            // a point when there are intervening undos that are blocking a linked undo.
            // You are expected to activate your document window that has the intervening undos.
            if (undoManager != null)
            {
                IVsLinkCapableUndoManager linkCapableUndoMgr = (IVsLinkCapableUndoManager)undoManager;
                if (linkCapableUndoMgr != null)
                {
                    linkCapableUndoMgr.AdviseLinkedUndoClient(this);
                }
            }
            #endregion

            // hook up our
            var dteVersion = Dot42Package.DteVersion;
            var xmlEditorService = XmlEditorServiceProvider.GetEditorService(this, dteVersion);
            if (xmlEditorService == null)
                throw new InvalidOperationException("XmlEditorService required");
            store = xmlEditorService.CreateXmlStore();
            store.UndoManager = undoManager;

            model = store.OpenXmlModel(new Uri(_fileName));

            // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
            // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
            // the object returned by the Content property.
            //designerControl = new VsDesignerControl(new ViewModel(store, model, this, textBuffer));
            designerControl = context.CreateDesigner(thisPackage.Ide, store, model, this, textBuffer);
            base.Content = designerControl;

            RegisterIndependentView(true);

            var mcs = GetService(typeof(IMenuCommandService)) as IMenuCommandService;
            if (null != mcs)
            {
                // Now create one object derived from MenuCommnad for each command defined in
                // the CTC file and add it to the command service.

                // For each command we have to define its id that is a unique Guid/integer pair, then
                // create the OleMenuCommand object for this command. The EventHandler object is the
                // function that will be called when the user will select the command. Then we add the
                // OleMenuCommand to the menu service.  The addCommand helper function does all this for us.
                AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.NewWindow, OnNewWindow, OnQueryNewWindow);
                AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.ViewCode, OnViewCode, OnQueryViewCode);
            }
        }