Ejemplo n.º 1
0
        public bool SaveFile(FaTabStripItem f, FastColoredTextBox tb)
        {
            string fileName;

            if (f.Tag == null)
            {
                fileName = SaveFileAs(f);
                if (string.IsNullOrEmpty(fileName))
                {
                    return(false);
                }
            }
            else
            {
                fileName = f.Tag.ToString();
            }
            try
            {
                File.WriteAllText(fileName, tb.Text);
                tb.IsChanged = false;
                f.Title      = Path.GetFileName(fileName);
            }
            catch (Exception ex)
            {
                if (MessageBox.Show(ex.Message, @"Error Saving File", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                {
                    SaveFile(f);
                }
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /* Public methods */
        public void CreateTab(EventHandler <TextChangedEventArgs> textChanged, FileSystemInfo fileInfo = null)
        {
            var index = SettingsManager.ApplicationSettings.ApplicationWindow.Theme;
            var tb    = new FastColoredTextBox
            {
                Dock        = DockStyle.Fill,
                LeftPadding = 5,
                BorderStyle = BorderStyle.None,
                DelayedTextChangedInterval = 500,
                BackColor = index == 1 ? Color.Black : Color.White,
                ForeColor = index == 1 ? Color.Silver : Color.Black,
                Zoom      = SettingsManager.ApplicationSettings.EditorWindow.Zoom
            };

            tb.TextChangedDelayed += textChanged;
            tb.ZoomChanged        += OnZoomChanged;
            var fileName = fileInfo != null ? fileInfo.FullName : null;
            var caption  = !string.IsNullOrEmpty(fileName) ? Path.GetFileName(fileName) : "Untitled.txt";
            var tab      = new FaTabStripItem(caption, tb)
            {
                Tag = fileName
            };

            if (fileInfo != null)
            {
                tb.OpenFile(fileInfo.FullName);
                tb.Language = LanguageControl.GetSyntaxHighLightAuto(Path.GetExtension(fileInfo.FullName));
                tb.OnSyntaxHighlight(new TextChangedEventArgs(tb.Range));
            }
            _tabStrip.AddTab(tab);
            _tabStrip.SelectedItem = tab;
            tb.Focus();
        }
Ejemplo n.º 3
0
        public bool SaveFile(FaTabStripItem f)
        {
            if (f == null)
            {
                return(false);
            }
            var tb = (FastColoredTextBox)f.Controls[0];

            return(SaveFile(f, tb));
        }
Ejemplo n.º 4
0
 private string SaveFileAs(FaTabStripItem f)
 {
     using (var sfd = new SaveFileDialog {
         Title = string.Format(@"Select the filename to save {0} as...", f.Title)
     })
     {
         sfd.Filter      = FileFilters.GetFilters();
         sfd.FileName    = Path.GetFileNameWithoutExtension(f.Title);
         sfd.FilterIndex = FileFilters.GetExtensionIndex(string.Format("*{0}", Path.GetExtension(f.Title)));
         if (sfd.ShowDialog(_tabStrip.Parent) == DialogResult.Cancel)
         {
             return(string.Empty);
         }
         var fileName = sfd.FileName;
         f.Tag = fileName;
         System.Diagnostics.Debug.Print(fileName);
         return(fileName);
     }
 }
Ejemplo n.º 5
0
 public TabStripItemClosingEventArgs(FaTabStripItem item)
 {
     Cancel = false;
     Item   = item;
 }
Ejemplo n.º 6
0
 public TabStripItemChangedEventArgs(FaTabStripItem item, FaTabStripItemChangeTypes type)
 {
     _changeType = type;
     _itm        = item;
 }
Ejemplo n.º 7
0
 public override void Initialize(IComponent component)
 {
     base.Initialize(component);
     _tabStrip = component as FaTabStripItem;
 }