private async void convertAllInCWD() { //pause the watcher; a lot of files are going to be modified cwdWatcher.EnableRaisingEvents = false; importableFileView.Refresh(); //these should all be importable files now. foreach (var file in importableFileView) { var castFS = (DetailedFSElement)file; uiDispatcher.Invoke(() => { selectFSElement(castFS); }); currMdlPath = castFS.Info.FullName; setExplorerActive(false); await Task.Run(async() => { var fileOpenResult = modelMgr.OpenFSElement(castFS.Info); setCurrentFileState(EditorFileState.Reading); ModelManager.OpenFSElemResult res = await fileOpenResult; updateLog(); }); writeModel(); //clear logs? } resetFileProgress(); setExplorerActive(true); setCurrentFileState(EditorFileState.Ready); //now re-enable the watcher cwdWatcher.EnableRaisingEvents = true; updateFSData(); }
//actual commands issued to the ModelManager private async void openFSElement() { var elem = selectedFSElem; if (elem == null) { return; } //this can do a LOT of different things; //the status message may thus vary depending //on what the selected element actually is. var fileOpenResult = modelMgr.OpenFSElement(elem.Info); //may need to swap the current file state var lastFileState = currentFileState; if (elem.IsDirectory) { setCurrentFileState(EditorFileState.ChangingDir); } else { setCurrentFileState(EditorFileState.Reading); } //progressUpdateTimer.Start(); //let view know you can't mess with the directory view setExplorerActive(false); ModelManager.OpenFSElemResult res = await fileOpenResult; updateLog(); resetFileProgress(); if (elem.IsDirectory) { setCurrentFileState(lastFileState); } else { setCurrentFileState(EditorFileState.ReadComplete); } //progressUpdateTimer.Stop(); //let view know the directory view is active setExplorerActive(true); //this all may be running on another thread; //ensure the UI knows what's happening uiDispatcher.Invoke(new Action(delegate { switch (res) { case ModelManager.OpenFSElemResult.FileOpened: //update the mesh selector updateMeshSelector(); currMdlPath = elem.Info.FullName; //and note that a lot of the info's changed onModelFileLoaded(); break; case ModelManager.OpenFSElemResult.DirectoryChanged: //CWD is different now, refresh it updateFSData(); break; case ModelManager.OpenFSElemResult.Failure: //notify failure break; case ModelManager.OpenFSElemResult.NoAction: default: //do nothing! break; } })); }