コード例 #1
0
 /// <summary>
 /// Shows the save file dialog.
 /// </summary>
 /// <param name="categoryName">Name of the category.</param>
 /// <param name="saveTitle">The save dialog title.</param>
 /// <param name="savingParameters">The saving parameters.</param>
 /// <exception cref="BlackMateriaException"> Throws an exception if an error ocurred saving the file.</exception>
 public void ShowDialog(string categoryName, string saveTitle, params input[] savingParameters)
 {
     try
     {
         SaveFileDialog saveDialog = new SaveFileDialog();
         saveDialog.Filter = AerithUtils.CreateFilter(this.AllowedExtensions, categoryName);
         saveDialog.Title  = saveTitle;
         if (this.StartDirectory != String.Empty)
         {
             if (Directory.Exists(this.StartDirectory))
             {
                 DirectoryInfo dir = new DirectoryInfo(this.StartDirectory);
                 saveDialog.InitialDirectory = dir.FullName;
             }
             else
             {
                 throw new BlackMateriaException(String.Format(ERR_DIR_MISSING, this.StartDirectory));
             }
         }
         if (saveDialog.ShowDialog().Value&& saveDialog.FileName != String.Empty)
         {
             this.SaveAction(saveDialog.FileName, savingParameters);
             this.savedFilePath = saveDialog.FileName;
         }
     }
     catch (System.Exception exc)
     {
         throw exc.CreateNamelessException <BlackMateriaException>(ERR_SAVING_FILE, this.savedFilePath != null ? this.savedFilePath : String.Empty);
     }
 }
コード例 #2
0
        /// <summary>
        /// Gets the file path from the windows open file dialog
        /// </summary>
        /// <param name="catName">The file type category</param>
        /// <param name="fileDialogTitle">The file dialog title</param>
        /// <returns>The path of the selected file, empty if the selection is cancelled</returns>
        public Boolean PickPath(String catName, String fileDialogTitle, out String selPath)
        {
            Boolean        flag;
            OpenFileDialog oDialog = new OpenFileDialog();

            selPath             = String.Empty;
            oDialog.Filter      = AerithUtils.CreateFilter(ExtensionFilter, catName);
            oDialog.Title       = fileDialogTitle;
            oDialog.Multiselect = this.AllowMultipleSelection;
            if (InitialDirectory != null && Directory.Exists(InitialDirectory))
            {
                oDialog.InitialDirectory = InitialDirectory;
            }
            flag = oDialog.ShowDialog().Value;
            if (flag)
            {
                selPath = oDialog.FileName;
            }
            return(flag);
        }