Exemplo n.º 1
0
 private void SaveFile(MyTab tab, string path)
 {
     tab.Content      = txtContent.Text;
     tab.Path         = path;
     using var writer = new StreamWriter(path, false);
     writer.Write(tab.Content);
     tab.Modified = false;
     tab.Title    = Path.GetFileName(path);
 }
Exemplo n.º 2
0
        public void CloseTab(MyTab tab)
        {
            if (!string.IsNullOrEmpty(tab.Path) && !RecentFiles.Contains(tab.Path))
            {
                RecentFiles.Add(tab.Path);
            }

            Tabs.Remove(tab);
        }
Exemplo n.º 3
0
        private void SaveAsFile(MyTab tab)
        {
            var dialog = new SaveFileDialog();

            dialog.Filter = "(*.txt)|*.txt|All Files (*.*)|*.*";
            var result = dialog.ShowDialog();

            if (result == true)
            {
                SaveFile(tab, dialog.FileName);
            }
        }
Exemplo n.º 4
0
        public void AddNewTab(string fileName = null, string content = null, string path = null)
        {
            var index = GetNextIndex();

            var tab = new MyTab()
            {
                Title   = fileName ?? "Tab" + index,
                Content = content,
                TabNo   = index,
                Path    = path
            };

            Tabs.Add(tab);
        }
Exemplo n.º 5
0
        private void CloseTab(MyTab tab)
        {
            if (tab == null)
            {
                return;
            }

            LockTabCreation = true;

            if (tab.Modified)
            {
                var result = MessageBox.Show("New file has been modified, save changes?", "Save Changes?", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);

                if (result == MessageBoxResult.Yes)
                {
                    if (tab.Path == null)
                    {
                        SaveAsFile(tab);
                    }
                    else
                    {
                        SaveFile(tab, tab.Path);
                    }
                }
                else if (result == MessageBoxResult.Cancel)
                {
                    return;
                }
            }

            TabManager.CloseTab(tab);

            JumpToLastTab();

            LockTabCreation = false;
        }