public void RegisterNodeType(Type type, string name, Image icon, ICustomNodeConverter converter, ICustomCodeGenerator generator)
        {
            CustomNodeConvert.RegisterCustomType(converter);
            CustomCodeGenerator.RegisterCustomType(generator);

            MainWindow.RegisterNodeType(type, name, icon ?? Properties.Resources.B16x16_Plugin);
        }
        public void DeregisterNodeType(Type type, ICustomNodeConverter converter, ICustomCodeGenerator generator)
        {
            CustomNodeConvert.DeregisterCustomType(converter);
            CustomCodeGenerator.DeregisterCustomType(generator);

            MainWindow.DeregisterNodeType(type);
        }
Exemplo n.º 3
0
        private void GenerateCodeForSelectedElement(bool showPopups)
        {
            var selectedElement = SelectedState.Self.SelectedElement;
            var settings        = control.CodeOutputElementSettings;

            string generatedFileName = settings.GeneratedFileName;

            if (string.IsNullOrEmpty(generatedFileName) && !string.IsNullOrEmpty(this.codeOutputProjectSettings.CodeProjectRoot))
            {
                string prefix = selectedElement is ScreenSave ? "Screens"
                    : selectedElement is ComponentSave ? "Components"
                    : "Standards";
                var splitName = (prefix + "/" + selectedElement.Name).Split('/');
                var nameWithNamespaceArray = splitName.Take(splitName.Length - 1).Append(CodeGenerator.GetClassNameForType(selectedElement.Name, CodeGenerator.GetVisualApiForElement(selectedElement)));
                generatedFileName = this.codeOutputProjectSettings.CodeProjectRoot + string.Join("\\", nameWithNamespaceArray) + ".Generated.cs";
            }

            if (!string.IsNullOrEmpty(generatedFileName) && FileManager.IsRelative(generatedFileName))
            {
                generatedFileName = ProjectState.Self.ProjectDirectory + generatedFileName;
            }


            if (string.IsNullOrEmpty(generatedFileName))
            {
                if (showPopups)
                {
                    GumCommands.Self.GuiCommands.ShowMessage("Generated file name must be set first");
                }
            }
            else
            {
                // We used to use the view model code, but the viewmodel may have
                // an instance within the element selected. Instead, we want to output
                // the code for the whole selected element.
                //var contents = ViewModel.Code;

                string contents = CodeGenerator.GetGeneratedCodeForElement(selectedElement, settings, codeOutputProjectSettings);
                contents = $"//Code for {selectedElement.ToString()}\n{contents}";

                string message = string.Empty;

                var codeDirectory = FileManager.GetDirectory(generatedFileName);
                if (!System.IO.Directory.Exists(codeDirectory))
                {
                    System.IO.Directory.CreateDirectory(codeDirectory);
                }

                System.IO.File.WriteAllText(generatedFileName, contents);

                // show a message somewhere?
                message += $"Generated code to {FileManager.RemovePath(generatedFileName)}";

                if (!string.IsNullOrEmpty(this.codeOutputProjectSettings.CodeProjectRoot))
                {
                    var splitFileWithoutGenerated = generatedFileName.Split('.').ToArray();
                    var customCodeFileName        = string.Join("\\", splitFileWithoutGenerated.Take(splitFileWithoutGenerated.Length - 2)) + ".cs";

                    // todo - only save this if it doesn't already exist
                    if (!System.IO.File.Exists(customCodeFileName))
                    {
                        var customCodeContents = CustomCodeGenerator.GetCustomCodeForElement(selectedElement, settings, codeOutputProjectSettings);
                        System.IO.File.WriteAllText(customCodeFileName, customCodeContents);
                    }
                }


                if (showPopups)
                {
                    GumCommands.Self.GuiCommands.ShowMessage(message);
                }
                else
                {
                    GumCommands.Self.GuiCommands.PrintOutput(message);
                }
            }
        }