private static void ValidateWorkingDocument(WorkDocument workDocument) { if (workDocument == null) { throw new ArgumentNullException(nameof(workDocument)); } }
public static void SaveDocumentAsFile(WorkDocument workDocument) { using (var file = File.Create(workDocument.File.FullName)) { Serializer.Serialize(file, workDocument); } }
public static void AddDocument(WorkDocument workDocument) { ValidateWorkingDocument(workDocument); Instance._workingDocuments[workDocument.DocumentId] = workDocument; AddRecentDocument(workDocument); }
public static void RemoveRecentDocument(WorkDocument workDocument) { var index = FindRecentFileIndex(workDocument); if (index != -1) { Instance._recentFiles.RemoveAt(index); } }
public void Restore(WorkDocument workDocument) { var foldingEnumerator = FoldingManager.AllFoldings.GetEnumerator(); foreach (var isFolded in workDocument.FoldingStates.Where(s => foldingEnumerator.MoveNext())) { foldingEnumerator.Current.IsFolded = isFolded; } }
public RecentFileItem(WorkDocument workDocument, int index) { Index = index; WorkDocument = workDocument; DocumentFileName = workDocument.DocumentFileName.Replace("_", "__"); var command = new RoutedCommand($"OpenRecentFile{index}", typeof(ContextMenu)); Command = command; }
public static bool TryGetWorkingDocumentFor(string fileName, out WorkDocument workDocument) { if (fileName == null) { throw new ArgumentNullException(nameof(fileName)); } workDocument = Instance._workingDocuments.Values.FirstOrDefault(d => d.File != null && String.Equals(d.File.FullName.ToUpperInvariant(), fileName.ToUpperInvariant())); return(workDocument != null); }
private DocumentPage OpenExistingFile(string fileName) { if (!File.Exists(fileName)) { return(null); } var document = WorkDocument.IsSqlxFile(fileName) ? WorkDocumentCollection.LoadDocumentFromFile(fileName) : new WorkDocument { DocumentFileName = fileName }; return(OpenExistingWorkDocument(document)); }
public DocumentPage AddNewDocumentPage(WorkDocument workDocument = null) { var newDocumentPage = new DocumentPage(workDocument); _editorAdapters.Add(newDocumentPage.EditorAdapter); AddDocumentTabItemContextMenuCommandBindings(newDocumentPage); DocumentTabControl.Items.Insert(DocumentTabControl.Items.Count - 1, newDocumentPage.TabItem); DocumentTabControl.SelectedItem = newDocumentPage.TabItem; _findReplaceManager.CurrentEditor = newDocumentPage.EditorAdapter; return(newDocumentPage); }
public static void Initialize(WorkDocument initialDocument = null) { DocumentCursorPositions.Clear(); _lastDocumentIdentifier = null; _lastCursorPosition = -1; _currentIndex = 0; IsEnabled = true; if (initialDocument != null) { RegisterDocumentCursorPosition(initialDocument, initialDocument.CursorPosition); } }
public static void CloseDocument(WorkDocument workDocument) { ValidateWorkingDocument(workDocument); AddRecentDocument(workDocument); try { Instance._workingDocuments.Remove(workDocument.DocumentId); Save(); } catch (Exception e) { TraceLog.WriteLine("Close working document failed: " + e); } }
private DocumentPage OpenExistingWorkDocument(WorkDocument document) { DocumentPage documentPage; if (WorkDocumentCollection.TryGetWorkingDocumentFor(document.DocumentFileName, out var workDocument)) { documentPage = AllDocuments.Single(d => d.WorkDocument == workDocument); DocumentTabControl.SelectedItem = documentPage.TabItem; } else { WorkDocumentCollection.AddDocument(document); documentPage = AddNewDocumentPage(document); } return(documentPage); }
public static void RegisterDocumentCursorPosition(WorkDocument workDocument, int cursorPosition) { if (!IsEnabled) { return; } var isCursorAtAdjacentPosition = Math.Abs(cursorPosition - _lastCursorPosition) <= 1 && workDocument.DocumentId == _lastDocumentIdentifier; _lastDocumentIdentifier = workDocument.DocumentId; _lastCursorPosition = cursorPosition; if (isCursorAtAdjacentPosition) { return; } if (DocumentCursorPositions.Count > _currentIndex + 1) { var nextDocument = DocumentCursorPositions[_currentIndex + 1]; if (workDocument.Identifier == nextDocument.Document.Identifier && nextDocument.CursorPosition == cursorPosition) { _currentIndex++; return; } DocumentCursorPositions.RemoveRange(_currentIndex + 1, DocumentCursorPositions.Count - _currentIndex - 1); } _currentIndex = DocumentCursorPositions.Count; DocumentCursorPositions.Add( new DocumentCursorPosition { CursorPosition = cursorPosition, Document = workDocument }); }
public static void AddRecentDocument(WorkDocument workDocument) { if (workDocument.File == null || !workDocument.File.Exists) { return; } lock (Instance._recentFiles) { var existingIndex = FindRecentFileIndex(workDocument); if (existingIndex != -1) { Instance._recentFiles.RemoveAt(existingIndex); } Instance._recentFiles.Insert(0, workDocument.CloneAsRecent()); if (Instance._recentFiles.Count > MaxRecentDocumentCount) { Instance._recentFiles.RemoveRange(MaxRecentDocumentCount, Instance._recentFiles.Count - MaxRecentDocumentCount); } } }
private static int FindRecentFileIndex(WorkDocument workDocument) { return(Instance._recentFiles.FindIndex(f => String.Equals(f.DocumentFileName, workDocument.DocumentFileName, StringComparison.InvariantCultureIgnoreCase))); }
public void Store(WorkDocument workDocument) { workDocument.UpdateFoldingStates(FoldingManager.AllFoldings.Select(f => f.IsFolded)); }