コード例 #1
0
        public void Loaded(ViewLoadedParams p)
        {
            // Specify the text displayed on the menu item
            viewportMenuItem = new MenuItem {
                Header = "Launch Viewport"
            };

            // Define the behavior when menu item is clicked
            viewportMenuItem.Click += (sender, args) =>
            {
                // Instantiate a viewModel and window
                var viewModel = new ViewportWindowViewModel(p);
                var window    = new ViewportWindow(viewModel)
                {
                    // Set the data context for the main grid in the window
                    // This refers to the main grid also seen in our xaml file
                    MainGrid = { DataContext = viewModel },

                    // Set the owner of the window to the Dynamo window.
                    Owner = p.DynamoWindow
                };

                // Show a modeless window.
                window.Show();
            };

            // add the menu item to our loaded parameters
            p.AddMenuItem(MenuBarType.View, viewportMenuItem);
        }
コード例 #2
0
        public ViewportWindow(ViewportWindowViewModel vm)
        {
            if (!Cef.IsInitialized)
            {
                var settings = new CefSettings {
                    RemoteDebuggingPort = 8088
                };

                settings.RegisterScheme(new CefCustomScheme
                {
                    SchemeName           = CefSharpSchemeHandlerFactory.SchemeName,
                    SchemeHandlerFactory = new CefSharpSchemeHandlerFactory()
                });

                Cef.Initialize(settings);
            }

            InitializeComponent();

            // When view model is updated call javascript update function
            if (vm == null)
            {
                return;
            }
            vm.PropertyChanged += ExecuteJavascript;

            // Center initial viewport window upon launch
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;

            ScriptTextBox.KeyDown += new KeyEventHandler(textBoxKeyDown);
        }
コード例 #3
0
        // Update geometry when view model new changes
        private async void ExecuteJavascript(object sender, EventArgs e)
        {
            //check what property is How often is this being triggered?
            PropertyChangedEventArgs eventArgs = e as PropertyChangedEventArgs;
            string changedProperty             = eventArgs.PropertyName;

            if (changedProperty == "RenderData")
            {
                ViewportWindowViewModel vm = sender as ViewportWindowViewModel;
                string jsonString          = vm.RenderData;

                if (!string.IsNullOrWhiteSpace(jsonString))
                {
                    JavascriptResponse response = await Browser.EvaluateScriptAsync(jsonString);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates and add the library view to the WPF visual tree
        /// </summary>
        /// <returns>LibraryView control</returns>
        internal ViewportView AddViewportToExtensionsPanel(IViewExtension ext, ViewLoadedParams p)
        {
            var model = new ViewportWindowViewModel(this.viewLoadedParams, this.address);
            var view  = new ViewportView(model);

            var browser = view.Browser;

            this.browser = browser;

            p.AddToExtensionsSideBar(ext, view);

            browser.RegisterAsyncJsObject("controller", this);

            view.Loaded         += OnViewportViewLoaded;
            browser.SizeChanged += Browser_SizeChanged;
            browser.LoadError   += Browser_LoadError;

            return(view);
        }
コード例 #5
0
        /// <summary>
        /// Call this method to create a new node in Dynamo canvas.
        /// </summary>
        /// <param name="nodeName">Node creation name</param>

/*
 *      public void CreateNode(string nodeName)
 *      {
 *          dynamoWindow.Dispatcher.BeginInvoke(new Action(() =>
 *          {
 *              //if the node we're trying to create is a customNode, lets disable the eventObserver.
 *              // this will stop the libraryController from refreshing the libraryView on custom node creation.
 *              var resultGuid = Guid.Empty;
 *              if (Guid.TryParse(nodeName, out resultGuid))
 *              {
 *                  this.disableObserver = true;
 *              }
 *              //Create the node of given item name
 *              var cmd = new DynamoModel.CreateNodeCommand(Guid.NewGuid().ToString(), nodeName, -1, -1, true, false);
 *              commandExecutive.ExecuteCommand(cmd, Guid.NewGuid().ToString(), ViewExtension.ExtensionName);
 *              LogEventsToInstrumentation(CreateNodeInstrumentationString, nodeName);
 *
 *              this.disableObserver = false;
 *          }));
 *      }
 */

        /// <summary>
        /// Creates and add the library view to the WPF visual tree
        /// </summary>
        /// <returns>LibraryView control</returns>
        internal ViewportView AddViewportView()
        {
            var libraryViewColumn = dynamoWindow.FindName("LeftExtensionsViewColumn") as ColumnDefinition;

            libraryViewColumn.MaxWidth = dynamoWindow.ActualWidth - 50; // TODO - cleanup

            var model = new ViewportWindowViewModel(this.viewLoadedParams, this.address);
            var view  = new ViewportView(model); // This crashes

            var browser = view.Browser;

            this.browser = browser;

            var sidebarGrid = dynamoWindow.FindName("sidebarGrid") as Grid;

            sidebarGrid.Children.Clear(); // Clear library contents
            sidebarGrid.Children.Add(view);
            browser.RegisterAsyncJsObject("controller", this);

            view.Loaded         += OnViewportViewLoaded;
            browser.SizeChanged += Browser_SizeChanged;
            browser.LoadError   += Browser_LoadError;

            // TODO - this was added Fall 2017 due to issues with
            // library failing to load due to timing issues.

            /*
             *          //wait for the browser to load before setting the resources
             *          browser.LoadingStateChanged += (sender, args) =>
             *          {
             *              //Wait for the Page to finish loading
             *              if (args.IsLoading == false)
             *              {
             *                  RegisterResources(browser);
             *              }
             *          };
             */
            return(view);
        }