Save File Dialog


Node Information
Displays file browser dialog, lets user select a location to save a file. 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 also set the dialog Title in the properties window. 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
FilePath OUT String MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Application.Dialogs
{
    [IsNode("Save File Dialog")]
    public class SaveFileDialog : Node
    {
        Port run = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Show");
        Port filename = new Port(PortType.OUT, typeof(string), AcceptsLinks.MULTIPLE, "FilePath");
        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 SaveFileDialog()
        {
            this.NodeType = KGraph.NodeType.Method;
            this.Name = "Save File Dialog";
            AddPort(run);
            AddPort(onok);
            AddPort(oncancel);
            AddPort(filename);
            filename.IsVariable = true;
            filename.VariableType = typeof(string);
            filename.Instructions = "init";
            Information = "Displays file browser dialog, lets user select a location to save a file. 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 also set the dialog Title in the properties window. " +
                "If file is selectd 'OK' will fire, " +
                "if file selection cancelled, 'Cancel' will fire.";
        }
        public override string Code()
        {
            filename.Instructions = filename.ID;
            string code = "System.Windows.Forms.SaveFileDialog ofd = new System.Windows.Forms.SaveFileDialog();\r\n" +
            "ofd.Filter = " + q + Filter + q + ";\r\n" +
            "ofd.Title = " + q + Title + q + ";\r\n" +
            "System.Windows.Forms.DialogResult result = ofd.ShowDialog();\r\n" +
            "if (result == System.Windows.Forms.DialogResult.OK)\r\n{\r\n" +
            filename.ID + "= ofd.FileName;\r\n" +
            GetValue(onok) + "\r\n}\r\n" +
            "if(result == System.Windows.Forms.DialogResult.Cancel)\r\n{\r\n" + GetValue(oncancel) + "}";
            return code;
        }
    }
}