Esempio n. 1
0
        public void CloseSilently()
        {
            var lastSelectedIndex = _owner.SelectedIndex;
            var removingIndex     = 0;

            for (var i = 0; i < OwnerTabCollection.Count; i++)
            {
                if (!ReferenceEquals(OwnerTabCollection[i], this))
                {
                    continue;
                }

                removingIndex = i;
                break;
            }

            _owner.SelectedIndex = removingIndex;


            if (removingIndex > lastSelectedIndex)
            {
                _owner.SelectedIndex = lastSelectedIndex;
            }
            else
            {
                _owner.SelectedIndex = lastSelectedIndex - 1;
            }

            IsSelected = false;
            RemoveFileWatcher();
            OwnerTabCollection.Remove(this);
        }
Esempio n. 2
0
 private void CloseAllExceptMeImpl(object o)
 {
     foreach (var t in OwnerTabCollection.ToList())
     {
         if (!ReferenceEquals(t, this))
         {
             t.Close();
         }
     }
 }
Esempio n. 3
0
        public bool Close(bool canCancel = true)
        {
            var lastSelectedIndex = _owner.SelectedIndex;
            var removingIndex     = 0;

            for (var i = 0; i < OwnerTabCollection.Count; i++)
            {
                if (!ReferenceEquals(OwnerTabCollection[i], this))
                {
                    continue;
                }

                removingIndex = i;
                break;
            }

            _owner.SelectedIndex = removingIndex;

            var canceled = false;

            if (ChangesPending)
            {
                var buttons = canCancel ? MessageBoxButton.YesNoCancel : MessageBoxButton.YesNo;
                MessageBoxResult r;
                if (MemoryOnly)
                {
                    r = MessageBox.Show(Application.Current.MainWindow,
                                        "Would you like to save this tab to a file before closing?", "Save Changes",
                                        buttons, MessageBoxImage.Question);

                    if (r == MessageBoxResult.Yes)
                    {
                        try
                        {
                            if (!SaveTabToNewFile())
                            {
                                canceled = true;
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(Application.Current.MainWindow,
                                            e.Message, "Could Not Save File", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else if (r == MessageBoxResult.Cancel)
                    {
                        canceled = true;
                    }
                }
                else
                {
                    r = MessageBox.Show(Application.Current.MainWindow,
                                        "Would you like to save this tab before closing?",
                                        "Save Changes To \"" + FilePath + "\"",
                                        buttons, MessageBoxImage.Question);

                    if (r == MessageBoxResult.Yes)
                    {
                        try
                        {
                            if (!SaveOpenFileTab())
                            {
                                canceled = true;
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(Application.Current.MainWindow,
                                            e.Message, "Could Not Save File", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else if (r == MessageBoxResult.Cancel)
                    {
                        canceled = true;
                    }
                }
            }


            if (canceled)
            {
                return(false);
            }

            if (removingIndex > lastSelectedIndex)
            {
                _owner.SelectedIndex = lastSelectedIndex;
            }
            else
            {
                _owner.SelectedIndex = lastSelectedIndex - 1;
            }

            IsSelected = false;
            RemoveFileWatcher();
            OwnerTabCollection.Remove(this);

            return(true);
        }