示例#1
0
 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);
     }
 }
示例#3
0
        public static void AddDocument(WorkDocument workDocument)
        {
            ValidateWorkingDocument(workDocument);

            Instance._workingDocuments[workDocument.DocumentId] = workDocument;

            AddRecentDocument(workDocument);
        }
示例#4
0
        public static void RemoveRecentDocument(WorkDocument workDocument)
        {
            var index = FindRecentFileIndex(workDocument);

            if (index != -1)
            {
                Instance._recentFiles.RemoveAt(index);
            }
        }
示例#5
0
        public void Restore(WorkDocument workDocument)
        {
            var foldingEnumerator = FoldingManager.AllFoldings.GetEnumerator();

            foreach (var isFolded in workDocument.FoldingStates.Where(s => foldingEnumerator.MoveNext()))
            {
                foldingEnumerator.Current.IsFolded = isFolded;
            }
        }
示例#6
0
        public RecentFileItem(WorkDocument workDocument, int index)
        {
            Index            = index;
            WorkDocument     = workDocument;
            DocumentFileName = workDocument.DocumentFileName.Replace("_", "__");
            var command = new RoutedCommand($"OpenRecentFile{index}", typeof(ContextMenu));

            Command = command;
        }
示例#7
0
        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);
        }
示例#8
0
        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));
        }
示例#9
0
        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);
        }
示例#10
0
        public static void Initialize(WorkDocument initialDocument = null)
        {
            DocumentCursorPositions.Clear();
            _lastDocumentIdentifier = null;
            _lastCursorPosition     = -1;

            _currentIndex = 0;

            IsEnabled = true;

            if (initialDocument != null)
            {
                RegisterDocumentCursorPosition(initialDocument, initialDocument.CursorPosition);
            }
        }
示例#11
0
        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);
            }
        }
示例#12
0
        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);
        }
示例#13
0
        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
            });
        }
示例#14
0
        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);
                }
            }
        }
示例#15
0
 private static int FindRecentFileIndex(WorkDocument workDocument)
 {
     return(Instance._recentFiles.FindIndex(f => String.Equals(f.DocumentFileName, workDocument.DocumentFileName, StringComparison.InvariantCultureIgnoreCase)));
 }
示例#16
0
 public void Store(WorkDocument workDocument)
 {
     workDocument.UpdateFoldingStates(FoldingManager.AllFoldings.Select(f => f.IsFolded));
 }