Esempio n. 1
0
 public FileDialog(string[] filters, FileOpenerStyle style, Action <string> callback)
 {
     InitializeComponent();
     Filters     = filters;
     OpenerStyle = style;
     Callback    = callback;
 }
Esempio n. 2
0
 /// <summary>
 /// Allows you to prompt the user to select a file, either to open or save, and filter the types of files they can select.
 /// </summary>
 /// <param name="types">An array of file extensions that the user may select.</param>
 /// <param name="style">The UI style of the new file select frontend.</param>
 /// <param name="callback">The Action that is called when the user selects a file. The string argument provided by this call is the path of the file they selected.</param>
 public static void GetFile(string[] types, FileOpenerStyle style, Action <string> callback)
 {
     _fs.GetPath(types, style, callback);
 }
Esempio n. 3
0
        public FileDialog(string[] filetypes, FileOpenerStyle style, Action <string> _callback)
        {
            callback = _callback;
            InitializeComponent();
            foreach (var itm in filetypes)
            {
                cbfiletypes.Items.Add(itm);
            }
            cbfiletypes.SelectedIndex          = 0;
            cbfiletypes.SelectedIndexChanged  += (o, a) => { ResetList(); };
            this.lvitems.SelectedIndexChanged += (o, a) =>
            {
                try
                {
                    var itm = lvitems.SelectedItems[0];
                    if (cbfiletypes.Text != "Directory")
                    {
                        if (FileExists(currentdir + "/" + itm.Text))
                        {
                            txtfilename.Text = itm.Text;
                        }
                    }
                    else
                    {
                        if (DirectoryExists(currentdir + "/" + itm.Text))
                        {
                            txtfilename.Text = itm.Text;
                        }
                    }
                }
                catch { }
            };
            btnok.Click += (o, a) =>
            {
                string fname = "";
                fname = (!string.IsNullOrWhiteSpace(txtfilename.Text)) ? txtfilename.Text : "";
                if (cbfiletypes.Text != "Directory")
                {
                    fname = (!fname.EndsWith(cbfiletypes.SelectedItem.ToString())) ? fname + cbfiletypes.SelectedItem.ToString() : fname;
                    fname = (fname == cbfiletypes.SelectedItem.ToString()) ? "" : fname;
                }

                switch (style)
                {
                case FileOpenerStyle.Open:

                    if (cbfiletypes.Text == "Directory")
                    {
                        if (DirectoryExists(currentdir + "/" + fname))
                        {
                            callback?.Invoke(currentdir + "/" + fname);
                            this.Close();
                        }
                        else
                        {
                            Infobox.Show("{TITLE_FILENOTFOUND}", "{PROMPT_FILENOTFOUND}");
                        }
                    }
                    else
                    {
                        if (FileExists(currentdir + "/" + fname))
                        {
                            callback?.Invoke(currentdir + "/" + fname);
                            this.Close();
                        }
                        else
                        {
                            Infobox.Show("{FILE_NOT_FOUND}", "{FILE_NOT_FOUND_EXP}");
                        }
                    }
                    break;

                case FileOpenerStyle.Save:
                    if (!string.IsNullOrWhiteSpace(fname))
                    {
                        callback?.Invoke(currentdir + "/" + fname);
                        this.Close();
                    }
                    else
                    {
                        Infobox.Show("{ENTER_FILENAME}", "{ENTER_FILENAME_EXP}");
                    }
                    break;
                }
            };
            btnok.Text = style.ToString();
            this.Text  = style.ToString() + " File";
            this.lvitems.DoubleClick += new EventHandler(this.lvitems_DoubleClick);
            this.Load += (o, a) =>
            {
                ChangeDirectory(Paths.GetPath("root"));
            };
        }
Esempio n. 4
0
 public void GetPath(string[] filetypes, FileOpenerStyle style, Action <string> callback)
 {
     AppearanceManager.SetupDialog(new Applications.FileDialog(filetypes, style, callback));
 }