//private async Task RequestOpenFile(string fullPath) //{ // if (!File.Exists(fullPath)) // { // _ = await Task.FromException<FileNotFoundException>(new FileNotFoundException(nameof(RequestOpenFile), fullPath)); // } // // check if in // await RequestFileOpen(fullPath); //} /// <summary> /// Open a file and return its content in a viewmodel. /// </summary> /// <returns></returns> private IDocumentViewModel Open(string fullPath, EWolvenKitFile type) { // Check if we have already loaded this file and return it if so var fileViewModel = OpenDocuments.FirstOrDefault(fm => fm.ContentId == fullPath); if (fileViewModel != null) { return(fileViewModel); } // open file switch (type) { case EWolvenKitFile.Cr2w: fileViewModel = new RedDocumentViewModel(fullPath); break; case EWolvenKitFile.Redscript: fileViewModel = new ScriptDocumentViewModel(fullPath); break; case EWolvenKitFile.Tweak: fileViewModel = new TweakDocumentViewModel(fullPath); break; default: break; } //var result = await fileViewModel.OpenFileAsync(fullPath); var result = fileViewModel.OpenFile(fullPath); if (result) { _loggerService.Success($"Opening File: {fullPath}"); // TODO: this is not threadsafe //handler.Report(fileViewModel); //Dispatcher.CurrentDispatcher.Invoke(new Action(() => //{ // addfiledel(fileViewModel); //}), DispatcherPriority.ContextIdle); return(fileViewModel); } _loggerService.Warning($"Unable to open file: {fullPath}"); return(null); }
public frmScriptEditor(ScriptDocumentViewModel documentViewModel) { vm = documentViewModel; vm.ClosingRequest += (sender, e) => this.Close(); vm.ActivateRequest += (sender, e) => this.Activate(); vm.PropertyChanged += ViewModel_PropertyChanged; InitializeComponent(); ApplyCustomTheme(); scintillaFindReplace = new FindReplace(scintillaControl); scintillaFindReplace.KeyPressed += ScintillaFindReplaceOnKeyPressed; this.ShowIcon = false; ConfigureScintilla(); scintillaControl.ScrollWidth = 0; scintillaControl.ScrollWidthTracking = true; scintillaControl.KeyDown += ScintillaControlOnKeyDown; }