Open File Dialog


Node Information
Displays file browser dialog, lets user select files. You can set filters to allows users to only select specific type of files, in the properties window set Filter to the specified file type (ex: Text File|*.txt), you can have multiple file types separating them by '|' without quotes. You can also set the dialog Title in the properties window, also whether users are allowed to select multiple files.If file is selectd 'OK' will fire, if file 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
OK OUT RUN MULTIPLE FALSE FALSE
Cancel OUT RUN MULTIPLE FALSE FALSE
File OUT String ONE FALSE FALSE
Files OUT List<String> ONE TRUE FALSE

Source
namespace Korduene.KGraph.Nodes.Application.Dialogs
{
    [IsNode("Open File Dialog")]
    public class OpenFileDialog : Node
    {
        Port run = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Show");
        Port file = new Port(PortType.OUT, typeof(string), AcceptsLinks.ONE, "File");
        Port files = new Port(PortType.OUT, typeof(List<string>), AcceptsLinks.ONE, "Files");
        Port onok = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "OK");
        Port oncancel = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "Cancel");
        [IsNode("Define a filter, example: Text Files|*.txt")]
        public string Filter
        {
            set { Settings[0] = value; }
            get { return Settings[0]; }
        }
        public string Title
        {
            set { Settings[1] = value; }
            get { return Settings[1]; }
        }
        public bool MultSelect
        {
            set { Settings[2] = value.ToString(); }
            get
            {
                if (string.IsNullOrWhiteSpace(Settings[2])) { return false; }
                else { return bool.Parse(Settings[2]); }
            }
        }
        public OpenFileDialog()
        {
            this.NodeType = KGraph.NodeType.Method;
            this.Name = "Open File Dialog";
            AddPort(run);
            AddPort(onok);
            AddPort(oncancel);
            AddPort(file);
            AddPort(files);
            file.IsVariable = true;
            file.VariableType = typeof(string);
            files.IsVariable = true;
            files.VariableType = typeof(List<string>);
            Information = "Displays file browser dialog, lets user select files. You can set filters " +
                "to allows users to only select specific type of files, in the properties window set Filter " +
                "to the specified file type (ex: Text File|*.txt), you can have multiple file types separating them by '|' " +
                "without quotes. You can also set the dialog Title in the properties window, also whether users are allowed to " +
                "select multiple files." + "If file is selectd 'OK' will fire, " + "if file selection cancelled, 'Cancel' will fire.";
        }
        public override string Code()
        {
            file.Instructions = file.ID;
            files.Instructions = files.ID;
            string code =
            "System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();\r\n" +
            "ofd.Filter = " + q + Filter + q + ";\r\n" +
            "ofd.Title = " + q + Title + q + ";\r\n" +
            "ofd.Multiselect = " + MultSelect.ToString().ToLower() + ";\r\n" +
            "System.Windows.Forms.DialogResult result = ofd.ShowDialog();\r\n" +
            "if (result == System.Windows.Forms.DialogResult.OK)\r\n{\r\n" +
            file.ID + "= ofd.FileName;\r\n" +
            files.ID + "= ofd.FileNames.ToList();\r\n" +
            GetValue(onok) + "}\r\n" +
            "if(result == System.Windows.Forms.DialogResult.Cancel)\r\n{\r\n" + GetValue(oncancel) + "}";
            return code;
        }
    }
}