示例#1
0
 // Returns 'null' if no file is chosen.
 // "currentPath" can be a file path or a directory path containing placeholders (or null).
 public static string BrowseFile(IWin32Window owner, LevelSettings levelSettings, string currentPath, string title, IEnumerable <FileFormat> fileFormats, VariableType?baseDirType, bool save)
 {
     using (FileDialog dialog = save ? (FileDialog) new SaveFileDialog() : new OpenFileDialog())
     {
         dialog.Filter = fileFormats.GetFilter();
         dialog.Title  = title;
         if (!string.IsNullOrWhiteSpace(currentPath))
         {
             try
             {
                 string path = levelSettings?.MakeAbsolute(currentPath) ?? currentPath;
                 if (Directory.Exists(path))
                 {
                     dialog.InitialDirectory = path;
                 }
                 else
                 {
                     dialog.FileName         = Path.GetFileName(path);
                     dialog.InitialDirectory = Path.GetDirectoryName(path);
                 }
             }
             catch (Exception)
             { }
         }
         if (dialog.ShowDialog(owner) != DialogResult.OK)
         {
             return(null);
         }
         return(baseDirType != null && levelSettings != null?levelSettings.MakeRelative(dialog.FileName, baseDirType.Value) : dialog.FileName);
     }
 }
示例#2
0
        public ImportedGeometryManager()
        {
            InitializeComponent();

            _correctColor = dataGridView.BackColor.MixWith(Color.LimeGreen, 0.55);
            _wrongColor   = dataGridView.BackColor.MixWith(Color.DarkRed, 0.55);

            dataGridView.CellMouseDoubleClick += dataGridView_CellMouseDoubleClick;

            // Initialize sound path data grid view
            dataGridViewControls.DataGridView = dataGridView;
            dataGridViewControls.Enabled      = true;
            dataGridViewControls.CreateNewRow = delegate
            {
                List <string> paths = LevelFileDialog.BrowseFiles(this, null, PathC.GetDirectoryNameTry(LevelSettings.LevelFilePath),
                                                                  "Select 3D files that you want to see imported.", ImportedGeometry.FileExtensions).ToList();

                // Load imported geometries
                var importInfos = new List <KeyValuePair <ImportedGeometry, ImportedGeometryInfo> >();
                foreach (string path in paths)
                {
                    using (var settingsDialog = new GeometryIOSettingsDialog(new IOGeometrySettings()))
                    {
                        settingsDialog.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets);
                        settingsDialog.SelectPreset("Normal scale to TR scale");

                        if (settingsDialog.ShowDialog(this) == DialogResult.Cancel)
                        {
                            continue;
                        }

                        var info = new ImportedGeometryInfo(LevelSettings.MakeRelative(path, VariableType.LevelDirectory), settingsDialog.Settings);
                        importInfos.Add(new KeyValuePair <ImportedGeometry, ImportedGeometryInfo>(new ImportedGeometry(), info));
                    }
                }

                LevelSettings.ImportedGeometryUpdate(importInfos);
                LevelSettings.ImportedGeometries.AddRange(importInfos.Select(entry => entry.Key));
                return(importInfos.Select(entry => new ImportedGeometryWrapper(this, entry.Key)));
            };
            dataGridView.DataSource = _dataGridViewDataSource;
            dataGridViewControls.DeleteRowCheckIfCancel = MessageUserAboutHimDeletingRows;
            _dataGridViewDataSource.ListChanged        += delegate(object sender, ListChangedEventArgs e)
            {
                switch (e.ListChangedType)
                {
                case ListChangedType.ItemDeleted:
                    var remainingElements = new HashSet <ImportedGeometry>(_dataGridViewDataSource.Select(wrapper => wrapper.Object));
                    LevelSettings.ImportedGeometries.RemoveAll(obj => !remainingElements.Contains(obj));         // Don't use indices here, the wrapper indices might not match with the real object if sorting was enabled.
                    break;
                }
            };
            Enabled = true;
        }
示例#3
0
 // Returns 'null' if no folder is chosen.
 // "currentPath" should be a directory path containing placeholders (or null).
 public static string BrowseFolder(IWin32Window owner, LevelSettings levelSettings, string currentPath, string title, VariableType?baseDirType)
 {
     using (var dialog = new BrowseFolderDialog())
     {
         dialog.Title = title;
         if (!string.IsNullOrWhiteSpace(currentPath))
         {
             try
             {
                 dialog.InitialFolder = levelSettings?.MakeAbsolute(currentPath) ?? currentPath;
             }
             catch (Exception)
             { }
         }
         if (dialog.ShowDialog(owner) != DialogResult.OK)
         {
             return(null);
         }
         return(baseDirType != null && levelSettings != null?levelSettings.MakeRelative(dialog.Folder, baseDirType.Value) : dialog.Folder);
     }
 }
示例#4
0
 // Returns an empty collection if no folder is chosen.
 // "currentPath" should be a directory path containing placeholders (or null).
 public static IEnumerable <string> BrowseFiles(IWin32Window owner, LevelSettings levelSettings, string currentPath, string title, IEnumerable <FileFormat> fileFormats, VariableType?baseDirType = null)
 {
     using (OpenFileDialog dialog = new OpenFileDialog())
     {
         dialog.Multiselect = true;
         dialog.Filter      = fileFormats.GetFilter();
         dialog.Title       = title;
         if (!string.IsNullOrWhiteSpace(currentPath))
         {
             dialog.InitialDirectory = levelSettings?.MakeAbsolute(currentPath) ?? currentPath;
         }
         if (dialog.ShowDialog(owner) != DialogResult.OK)
         {
             return(new string[0]);
         }
         return(baseDirType != null && levelSettings != null?dialog.FileNames.Select(fileName => levelSettings.MakeRelative(fileName, baseDirType.Value)) : dialog.FileNames);
     }
 }