public void OpenDocument(Document document) { var ext = Path.GetExtension(document.FilePath); if (OpenDocuments.FirstOrDefault(x => x.FilePath.Equals(document.FilePath, StringComparison.OrdinalIgnoreCase)) is KDocument doc) { doc.IsSelected = false; doc.IsSelected = true; return; } if (ext.Equals(".cs", StringComparison.OrdinalIgnoreCase)) { OpenDocuments.Add(new CSDocument(document) { IsSelected = true, IsSaved = true, Name = document.Name }); } else if (ext.Equals(".xaml", StringComparison.OrdinalIgnoreCase)) { OpenDocuments.Add(new XamlDocument(document) { IsSelected = true, IsSaved = true, Name = document.Name }); } }
public void ProjectDoubleClick() { if (SelectedSolutionItem == null || !SelectedSolutionItem.HasPreview) { return; } var alreadyOpenDocument = OpenDocuments.FirstOrDefault(d => d.AssociatedModel == SelectedSolutionItem); if (alreadyOpenDocument?.IsTemporary == true) { OpenDocuments.Remove(alreadyOpenDocument); alreadyOpenDocument = null; } if (alreadyOpenDocument != null) { ActiveDocument = alreadyOpenDocument; } else { var document = OpenDocument(SelectedSolutionItem); OpenDocuments.Add(document); ActiveDocument = document; } }
public void OpenDocument(DocumentViewModel document) { var openDocument = OpenDocuments.FirstOrDefault(x => x.Document == document); if (openDocument == null) { openDocument = new OpenDocumentViewModel(this, document); OpenDocuments.Add(openDocument); } CurrentOpenDocument = openDocument; }
//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 void OpenDocument(DocumentViewModel document) { if (document.IsFolder) { return; } var openDocument = OpenDocuments.FirstOrDefault(x => x.Document == document); if (openDocument == null) { openDocument = GetOpenDocumentViewModel(document); OpenDocuments.Add(openDocument); } CurrentOpenDocument = openDocument; }
public void OnSelectedSolutionItemChanged() { if (!(SelectedSolutionItem?.HasPreview ?? false)) { return; } var alreadyOpenDocument = OpenDocuments.FirstOrDefault(d => d.AssociatedModel == SelectedSolutionItem); if (alreadyOpenDocument != null) { ActiveDocument = alreadyOpenDocument; return; } var currentTemporary = OpenDocuments.FirstOrDefault(d => d.IsTemporary); var document = OpenDocument(SelectedSolutionItem); if (currentTemporary == null) { currentTemporary = new DocumentViewModel { IsTemporary = true }; OpenDocuments.Add(currentTemporary); } currentTemporary.AssociatedModel = document.AssociatedModel; currentTemporary.Content = document.Content; currentTemporary.Syntax = document.Syntax; currentTemporary.Title = $"*{document.Title}"; ActiveDocument = currentTemporary; }