Esempio n. 1
0
        public void RemoveDocument(IDocumentTabViewModel document)
        {
            IDocumentTabViewModel newSelectedTab = DocumentTabs.SelectedDocument;

            if (DocumentTabs.SelectedDocument == document)
            {
                if (DocumentTabs.SelectedDocument != DocumentTabs.Documents.Last())
                {
                    newSelectedTab = DocumentTabs.Documents.SkipWhile(d => d == document).FirstOrDefault();
                }
                else
                {
                    newSelectedTab = DocumentTabs.Documents.Reverse().Skip(1).FirstOrDefault();
                }
            }

            DocumentTabs.SelectedDocument = newSelectedTab;

            DocumentTabs.Documents.Remove(document);

            if (DocumentTabs.TemporaryDocument == document)
            {
                DocumentTabs.TemporaryDocument = null;
            }
        }
Esempio n. 2
0
        public void AddDocument(IDocumentTabViewModel document)
        {
            DocumentTabs.Documents.Add(document);
            DocumentTabs.SelectedDocument = document;

            DocumentTabs.InvalidateSeperatorVisibility();
        }
        public void OpenDocument(IDocumentTabViewModel document, bool temporary)
        {
            if (document == null)
            {
                return;
            }

            if (Documents.Contains(document))
            {
                SelectedDocument = document;
            }
            else
            {
                if (TemporaryDocument != null)
                {
                    CloseDocument(TemporaryDocument);
                }

                Documents.Add(document);
                SelectedDocument = document;

                if (temporary)
                {
                    TemporaryDocument = document;
                }
            }

            InvalidateSeperatorVisibility();
        }
Esempio n. 4
0
        public static void AddOrSelectDocument <T>(this IShell me, T document) where T : IDocumentTabViewModel
        {
            IDocumentTabViewModel doc = me.Documents.FirstOrDefault(x => x.Equals(document));

            if (doc != null)
            {
                me.SelectedDocument = doc;
            }
            else
            {
                me.AddDocument(document);
            }
        }
Esempio n. 5
0
        public static void AddOrSelectDocument <T>(this IShell me, Func <T> factory) where T : IDocumentTabViewModel
        {
            IDocumentTabViewModel doc = me.Documents.FirstOrDefault(x => x is T);

            if (doc != default)
            {
                me.SelectedDocument = doc;
            }
            else
            {
                me.AddDocument(factory());
            }
        }
Esempio n. 6
0
        public void RemoveDocument(IDocumentTabViewModel document)
        {
            if (document == null)
            {
                return;
            }

            if (document is EditorViewModel doc)
            {
                doc.Editor?.Save();
            }

            DocumentTabs.CloseDocument(document);
        }
        public static T GetOrCreate <T>(this IShell me, Func <T> retrieveExisting) where T : IDocumentTabViewModel
        {
            T document = default;

            IDocumentTabViewModel doc = me.Documents.FirstOrDefault(x => x is T);

            if (doc != default)
            {
                document            = (T)doc;
                me.SelectedDocument = doc;
            }
            else
            {
                document = retrieveExisting();
                me.AddDocument(document);
            }

            return(document);
        }
        public static T GetOrCreate <T>(this IShell me) where T : IDocumentTabViewModel, new()
        {
            T document = default;

            IDocumentTabViewModel doc = me.Documents.FirstOrDefault(x => x is T);

            if (doc != default)
            {
                document            = (T)doc;
                me.SelectedDocument = doc;
            }
            else
            {
                document = new T();
                me.AddDocument(document);
            }

            return(document);
        }
Esempio n. 9
0
 public void RemoveDocument(IDocumentTabViewModel document)
 {
     throw new NotImplementedException();
 }
Esempio n. 10
0
        public void RemoveDocument(IDocumentTabViewModel document)
        {
            if (document == null)
            {
                return;
            }

            IDocumentTabViewModel newSelectedTab = DocumentTabs.SelectedDocument;

            if (DocumentTabs.SelectedDocument == document)
            {
                var index   = DocumentTabs.Documents.IndexOf(document);
                var current = index;

                bool foundTab = false;

                while (!foundTab)
                {
                    index++;

                    if (index < DocumentTabs.Documents.Count)
                    {
                        if (DocumentTabs.Documents[index].IsVisible)
                        {
                            foundTab       = true;
                            newSelectedTab = DocumentTabs.Documents[index];
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                index = current;

                while (!foundTab)
                {
                    index--;

                    if (index >= 0)
                    {
                        if (DocumentTabs.Documents[index].IsVisible)
                        {
                            foundTab       = true;
                            newSelectedTab = DocumentTabs.Documents[index];
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            DocumentTabs.SelectedDocument = newSelectedTab;

            document.IsVisible = false;

            if (document is EditorViewModel doc)
            {
                doc.Save();
            }

            if (DocumentTabs.TemporaryDocument == document)
            {
                DocumentTabs.TemporaryDocument = null;
            }

            if (DocumentTabs.Documents.OfType <EditorViewModel>().Where(d => !d.IsVisible).Count() == 5)
            {
                var toRemove = DocumentTabs.Documents.OfType <EditorViewModel>().Where(d => !d.IsVisible).First();

                DocumentTabs.Documents.Remove(toRemove);
                toRemove.OnClose();

                Dispatcher.UIThread.InvokeAsync(async() =>
                {
                    await Task.Delay(25);
                    GC.Collect();
                });
            }

            DocumentTabs.InvalidateSeperatorVisibility();
        }
        public void CloseDocument(IDocumentTabViewModel document)
        {
            if (!Documents.Contains(document))
            {
                return;
            }

            IDocumentTabViewModel newSelectedTab = SelectedDocument;

            if (SelectedDocument == document)
            {
                var index   = Documents.IndexOf(document);
                var current = index;

                bool foundTab = false;

                while (!foundTab)
                {
                    index++;

                    if (index < Documents.Count)
                    {
                        foundTab       = true;
                        newSelectedTab = Documents[index];
                        break;
                    }
                    else
                    {
                        break;
                    }
                }

                index = current;

                while (!foundTab)
                {
                    index--;

                    if (index >= 0)
                    {
                        foundTab       = true;
                        newSelectedTab = Documents[index];
                        break;
                    }
                    else if (index != current)
                    {
                        break;
                    }
                }

                if (foundTab)
                {
                    SelectedDocument = newSelectedTab;
                }
                else
                {
                    SelectedDocument = null;
                }
            }

            if (TemporaryDocument == document)
            {
                TemporaryDocument = null;
            }

            Documents.Remove(document);

            Dispatcher.UIThread.InvokeAsync(async() =>
            {
                await Task.Delay(25);
                GC.Collect();
            });

            InvalidateSeperatorVisibility();
        }
Esempio n. 12
0
 public void AddDocument(IDocumentTabViewModel document)
 {
     DocumentTabs.Documents.Add(document);
     DocumentTabs.SelectedDocument = document;
 }
Esempio n. 13
0
        public void RemoveDocument(IDocumentTabViewModel document)
        {
            IDocumentTabViewModel newSelectedTab = DocumentTabs.SelectedDocument;

            if (DocumentTabs.SelectedDocument == document)
            {
                if (DocumentTabs.SelectedDocument != DocumentTabs.Documents.Last())
                {
                    newSelectedTab = DocumentTabs.Documents.SkipWhile(d => d == document).FirstOrDefault();
                }
                else
                {
                    newSelectedTab = DocumentTabs.Documents.Reverse().Skip(1).FirstOrDefault();
                }
            }

            DocumentTabs.SelectedDocument = newSelectedTab;

            DocumentTabs.Documents.Remove(document);

            if (DocumentTabs.TemporaryDocument == document)
            {
                DocumentTabs.TemporaryDocument = null;
            }
        }
Esempio n. 14
0
 public void AddDocument(IDocumentTabViewModel document)
 {
     DocumentTabs.Documents.Add(document);
     DocumentTabs.SelectedDocument = document;
 }
Esempio n. 15
0
 public void AddDocument(IDocumentTabViewModel document, bool temporary = false)
 {
     DocumentTabs.OpenDocument(document, temporary);
 }