Folder Browser Dialog


Node Information
Displays a folder browser dialog, lets user select a folder. You also have the option to let the user to be able to create a new folder in the dialog by setting 'NewFolderButton' to true in the properties window, also you can set the Description that will show in the FolderBrowserDialog above the directory tree. If folder is selectd 'OK' will fire, if folder selection cancelled, 'Cancel' will fire.
General Information
• This node doesn't have other available options.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Show IN RUN MULTIPLE FALSE FALSE
NewFolderButton IN Boolean ONE FALSE FALSE
Description IN String ONE FALSE FALSE
AppendBackSlash IN Boolean ONE FALSE FALSE
OK OUT RUN MULTIPLE FALSE FALSE
Cancel OUT RUN MULTIPLE FALSE FALSE
Path OUT String MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Application.Dialogs
{
    [IsNode("Folder Browser Dialog")]
    public class FolderBrowserDialog : Node
    {
        Port run = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Show");
        Port newfolder = new Port(PortType.IN, typeof(bool), AcceptsLinks.ONE, "NewFolderButton");
        Port desc = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, "Description");
        Port appendslash = new Port(PortType.IN, typeof(bool), AcceptsLinks.ONE, "AppendBackSlash");
        Port path = new Port(PortType.OUT, typeof(string), AcceptsLinks.MULTIPLE, "Path");
        Port onok = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "OK");
        Port oncancel = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "Cancel");
        private bool AppendBackSlash
        {
            get { return GetRuntimeValue(appendslash); }
        }
        public FolderBrowserDialog()
        {
            this.NodeType = KGraph.NodeType.Method;
            this.Name = "Folder Browser Dialog";
            AddPort(run);
            AddPort(newfolder);
            AddPort(desc);
            AddPort(appendslash);
            AddPort(onok);
            AddPort(oncancel);
            AddPort(path);
            path.IsVariable = true;
            path.VariableType = typeof(string);
            Information = "Displays a folder browser dialog, lets user select a folder. You also have " +
                "the option to let the user to be able to create a new folder in the dialog by setting " +
                "'NewFolderButton' to true in the properties window, also you can set the Description that will " +
                "show in the FolderBrowserDialog above the directory tree. If folder is selectd 'OK' will fire, " +
                "if folder selection cancelled, 'Cancel' will fire.";
        }
        public override string Code()
        {
            path.Instructions = path.ID;
            string fileInit = path.ID + " = ofd.SelectedPath;";
            if (AppendBackSlash)
            {
                fileInit = path.ID + " = ofd.SelectedPath + @" + q + @"\" + q + ";";
            }
            return "System.Windows.Forms.FolderBrowserDialog ofd = new System.Windows.Forms.FolderBrowserDialog();\r\n" +
            "ofd.ShowNewFolderButton = " + GetValue(newfolder) + ";\r\n" +
            "ofd.Description = " + GetValue(desc) + ";\r\n" +
            "System.Windows.Forms.DialogResult result = ofd.ShowDialog();\r\n" +
            "if (result == System.Windows.Forms.DialogResult.OK)\r\n{\r\n" + fileInit + "\r\n" + GetValue(onok) + "\r\n" +
            "}\r\n" +
            "if(result == System.Windows.Forms.DialogResult.Cancel)\r\n{\r\n" + GetValue(oncancel) + "\r\n}";
        }
    }
}