Ejemplo n.º 1
0
        public void SaveScriptAs()
        {
            string objName = ObjectNameInEditor;

            if (!String.IsNullOrEmpty(objName))
            {
                saveFileDialog1.FileName = objName;
            }
            else
            {
                if (!String.IsNullOrEmpty(_fileName))
                {
                    saveFileDialog1.FileName = new FileInfo(_fileName).Name;
                }
            }

            if (saveFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }


            _textEditor.SaveFile(saveFileDialog1.FileName);
            _fileName            = saveFileDialog1.FileName;
            statLblFileName.Text = _fileName;

            FileInfo fi = new FileInfo(_fileName);

            this.TabText = fi.Name;
            this.Text    = this.TabText;
        }
Ejemplo n.º 2
0
        public bool Save()
        {
            if (string.IsNullOrEmpty(FilePath))
            {
                return(SaveAs());
            }

            textEditorControl.SaveFile(FilePath);
            Modified = false;
            return(true);
        }
Ejemplo n.º 3
0
        public override void SaveFile()
        {
            if (ContentName != null)
            {
                if (watcher != null)
                {
                    this.watcher.EnableRaisingEvents = false;
                }

                textEditorControl.SaveFile(ContentName);
                IsDirty = false;

                SetWatcher();
            }
        }
Ejemplo n.º 4
0
        private bool DoSaveAs(TextEditorControl editor)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.FileName = editor.FileName;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    editor.SaveFile(saveFileDialog.FileName);
                    editor.Parent.Text = Path.GetFileName(editor.FileName);
                    SetModifiedFlag(editor, false);

                    // The syntax highlighting strategy doesn't change
                    // automatically, so do it manually.
                    editor.Document.HighlightingStrategy =
                        HighlightingStrategyFactory.CreateHighlightingStrategyForFile(editor.FileName);
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().Name);
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        public override void Run()
        {
            TabPage page = WorkbenchSingleton.Workbench.FileTabControl.SelectedTab;

            if (page != null)
            {
                if (page.Text.EndsWith("*"))                  //当前文件已经被修改过
                {
                    DialogResult result = MessageBox.Show("是否保存对文件 " + page.Text.Substring(0, page.Text.Length - 1) + " 的修改?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                    if (result == DialogResult.Yes)
                    {
                        TextEditorControl textEditor = WorkbenchSingleton.Workbench.FileTabControl.SelectedTab.Controls[0] as TextEditorControl;
                        textEditor.SaveFile(page.Tag.ToString());
                        WorkbenchSingleton.Workbench.FileTabControl.TabPages.Remove(page);
                    }
                    else if (result == DialogResult.No)
                    {
                        WorkbenchSingleton.Workbench.FileTabControl.TabPages.Remove(page);
                    }
                }
                else
                {
                    WorkbenchSingleton.Workbench.FileTabControl.TabPages.Remove(page);
                }
            }
            else
            {
                MessageBox.Show("没有要关闭的文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Called when new file was created and added to project.
        /// </summary>
        /// <param name="file">File descriptor.</param>
        /// <param name="exists">True if file already exists in file system (just adding, without creating).</param>
        /// <returns>Form control as IDE document content.</returns>
        public Control onNewFile(IdeProject.File file, bool exists)
        {
            // create text editor control that will be able to edit our scripts.
            TextEditorControl editor = new TextEditorControl();

            editor.Dock       = DockStyle.Fill;
            editor.IsReadOnly = false;
            // here we can inject syntax highlighting for Tiny BASIC language.
            try
            {
                editor.SetHighlighting("TinyBASIC");
            }
            catch (Exception exc)
            {
                while (exc.InnerException != null)
                {
                    exc = exc.InnerException;
                }
                MessageBox.Show(@"Error occurred during Syntax Highlight binding to code editor:" + Environment.NewLine + exc.Message, Constants.NAME + @" Plugin Exception");
            }
            editor.Encoding = Encoding.ASCII; // make sure that we wants to use ASCII encoding.
            if (!exists)
            {
                // setup editor content and save it to file if file does not exists.
                editor.Text = Constants.FILE_TEMPLATE;
                editor.SaveFile(mBridge.GetProjectPath() + @"\" + file.relativePath);
            }
            else
            {
                // or load file to editor otherwise.
                editor.LoadFile(mBridge.GetProjectPath() + @"\" + file.relativePath);
            }
            editor.Encoding = Encoding.ASCII;
            return(editor);
        }
Ejemplo n.º 7
0
        public void SaveFile(string file)
        {
            var cfg = Globals.LoadConfiguration();
            EditorConfigurationSection section = cfg.GetEditorConfiguration();

            if (section?.TrailingWhitespace?.Value ?? false)
            {
                TrimTrailingWhitespace();
            }

            openFile  = file;
            saved     = true;
            this.Text = this.Text.Replace("*", "");

            this.Text = Path.GetFileName(file);
            textEditorControl.SaveFile(file);

            ILanguageStrategy lang = LanguageManager.GetLanguageStrategyForFile(file);

            if (lang != null)
            {
                textEditorControl.Document.FoldingManager.FoldingStrategy = lang.FoldingStrategy;
                textEditorControl.Document.HighlightingStrategy           = lang.HighlightingStrategy;
                completionKeyHandler.CompletionDataProvider = lang.CompletionData;
            }
        }
Ejemplo n.º 8
0
        public bool SaveContentAs(string saveHint, TextEditorControl textEditor)
        {
            if (textEditor == null)
            {
                throw new NullParameterException("TextEditor parameter is null!");
            }

            if (!String.IsNullOrEmpty(saveHint))
            {
                _saveDialog.FileName = saveHint;
            }

            if (_saveDialog.ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            textEditor.SaveFile(_saveDialog.FileName);

            _fileName = _saveDialog.FileName;
            FileInfo fi = new FileInfo(_fileName);

            _hint = fi.Name;
            return(true);
        }
Ejemplo n.º 9
0
        private DialogResult SaveDocument(bool showDialog)
        {
            bool isHtml = false;

            if (this is HTMLDoc)
            {
                isHtml = true;
            }
            if (!isHtml && txtEditCtl == null)
            {
                return(DialogResult.Ignore);
            }
            DialogResult dr = DialogResult.OK;

            if (m_fileName == null || m_fileName == string.Empty)
            {
                showDialog = true;
            }
            else
            {
                m_fileName = m_fileName.Replace("*", "");
            }
            if (showDialog)
            {
                ArrayList arl = ShowSaveFileDialog(m_fileName, m_DialogTitle, m_DialogTypeFilter, InitialDirectory);
                dr = (DialogResult)arl[0];
                if (dr == DialogResult.OK)
                {
                    m_fileName = ((string)arl[1]).Replace("*", "");
                }
            }
            if (dr == DialogResult.OK)
            {
                Cursor.Current = Cursors.WaitCursor;
                if (!isHtml && txtEditCtl != null)
                {
                    txtEditCtl.SaveFile(m_fileName);
                }
                else if (isHtml)
                {
                    string html = ((HTMLDoc)this).HTMLText;
                    File.WriteAllText(m_fileName, html);
                }

                InitialDirectory = Path.GetDirectoryName(m_fileName);
                this.TabText     = Path.GetFileName(m_fileName);
                this.Text        = Path.GetFileName(m_fileName);
                TextChanged      = false;
                Cursor.Current   = Cursors.Default;
            }
            return(dr);
        }
Ejemplo n.º 10
0
        private void SaveAs(TabPage tab_page)
        {
            this.saveFileDialog1.Filter = "Markdown files (*.md)|*.md|All files (*.*)|*.*";
            if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                TextEditorControl text_editor = ((TextEditorControl)tab_page.Controls.Find("textEditorControl1", true).FirstOrDefault());
                text_editor.SaveFile(this.saveFileDialog1.FileName);

                this.Text            = this.saveFileDialog1.FileName + " - PureMarkdown";
                tab_page.Text        = this.saveFileDialog1.FileName.Substring(saveFileDialog1.FileName.LastIndexOf('\\') + 1);
                tab_page.ToolTipText = this.saveFileDialog1.FileName;
            }
        }
Ejemplo n.º 11
0
 public void SaveFile(string path)
 {
     textEditorControl.SaveFile(path);
     hasSomethingOnDisk = true;
     if (IsSavingNecessary == true)
     {
         IsSavingNecessary = false; // will update tab name
     }
     else
     {
         UpdateTabName();
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Called when project file is saved.
        /// </summary>
        /// <param name="file">File descriptor.</param>
        /// <param name="control">IDE document content control.</param>
        /// <returns>Form control as IDE document content.</returns>
        public bool onSaveFile(IdeProject.File file, Control control)
        {
            if (!(control is TextEditorControl))
            {
                return(false);
            }
            TextEditorControl editor = control as TextEditorControl;

            editor.Encoding = Encoding.ASCII;
            editor.SaveFile(mBridge.GetProjectPath() + @"\" + file.relativePath);
            editor.Encoding = Encoding.ASCII;
            return(true);
        }
Ejemplo n.º 13
0
        public Boolean save()
        {
            if (IsNew)
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.FileName = safePatch;
                saveFileDialog.Filter   = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";

                DialogResult result = saveFileDialog.ShowDialog(editor);
                saveFileDialog.Dispose();

                if (result == DialogResult.OK)
                {
                    patch     = saveFileDialog.FileName;
                    safePatch = Path.GetFileName(patch);

                    textBox.SaveFile(patch);
                    Modified = false;
                    IsNew    = false;
                }
                else if (result == DialogResult.Cancel)
                {
                    return(false);
                }
            }
            else
            {
                textBox.SaveFile(patch);
                Modified = false;
            }

            editor.save.Enabled    = false;
            editor.saveAll.Enabled = false;

            redoUndoPos = 0;

            return(true);
        }
Ejemplo n.º 14
0
        public override void Run()
        {
            TabPage currentPage = WorkbenchSingleton.Workbench.FileTabControl.SelectedTab;

            if (currentPage != null)
            {
                TextEditorControl textEditor = currentPage.Controls[0] as TextEditorControl;
                textEditor.SaveFile(currentPage.Tag.ToString());
                if (currentPage.Text.EndsWith("*"))
                {
                    currentPage.Text = currentPage.Text.Substring(0, currentPage.Text.Length - 1);
                }
            }
        }
Ejemplo n.º 15
0
        public override void Run()
        {
            if (WorkbenchSingleton.Workbench.FileTabControl.TabPages.Count <= 0)              //判断是否有要关闭的文件
            {
                MessageBox.Show("没有要关闭的文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            bool haveDirtyFile = false;

            foreach (TabPage page in WorkbenchSingleton.Workbench.FileTabControl.TabPages)
            {
                if (page.Text.EndsWith("*"))
                {
                    haveDirtyFile = true;
                    break;
                }
            }
            if (haveDirtyFile)             //判断是否至少有一个修改过的文件
            {
                DialogResult result = MessageBox.Show("是否保存对所有文件的修改?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)                //保存所有的文件并关闭
                {
                    foreach (TabPage page in WorkbenchSingleton.Workbench.FileTabControl.TabPages)
                    {
                        TextEditorControl textEditor = WorkbenchSingleton.Workbench.FileTabControl.SelectedTab.Controls[0] as TextEditorControl;
                        textEditor.SaveFile(page.Tag.ToString());
                        WorkbenchSingleton.Workbench.FileTabControl.TabPages.Remove(page);
                    }
                }
                else if (result == DialogResult.No)                //直接关闭所有文件
                {
                    foreach (TabPage page in WorkbenchSingleton.Workbench.FileTabControl.TabPages)
                    {
                        WorkbenchSingleton.Workbench.FileTabControl.TabPages.Remove(page);
                    }
                }
                else if (result == DialogResult.Cancel)
                {
                    return;
                }
            }
            //如果全部文件都没修改过,则直接删除
            foreach (TabPage page in WorkbenchSingleton.Workbench.FileTabControl.TabPages)
            {
                WorkbenchSingleton.Workbench.FileTabControl.TabPages.Remove(page);
            }
        }
Ejemplo n.º 16
0
        //void SaveAs()
        //{
        //    TextEditorControl editor = ActiveEditor;
        //    if (editor != null)
        //    {
        //        using (SaveFileDialog dialog = new SaveFileDialog())
        //        {
        //            dialog.Filter = SharpPadFileFilter;
        //            dialog.FilterIndex = 0;
        //            if (DialogResult.OK == dialog.ShowDialog())
        //            {
        //                editor.SaveFile(dialog.FileName);
        //                editor.FileName = dialog.FileName;
        //            }
        //        }
        //    }
        //}

        void miSave_Click(object sender, System.EventArgs e)
        {
            TextEditorControl editor = ActiveEditor;

            if (editor != null)
            {
                if (editor.FileName != null)
                {
                    editor.SaveFile(editor.FileName);
                }
                else
                {
                    //SaveAs();
                }
            }
        }
Ejemplo n.º 17
0
        public virtual bool SaveContentToFile(string filePath, TextEditorControl textEditor)
        {
            if (textEditor == null)
            {
                throw new NullParameterException("TextEditor parameter is null!");
            }


            FireBeforeSavedContentToFile(filePath);
            textEditor.SaveFile(filePath);
            ContentType = EditorContentType.File;
            _filePath   = filePath;
            FileInfo fi = new FileInfo(_filePath);

            _hint = fi.Name;
            return(true);
        }
Ejemplo n.º 18
0
        private void SaveFile(TabPage tab_page)
        {
            if (tab_page.Text.Contains("未命名"))
            {
                SaveAs(tab_page);
            }
            else
            {
                TextEditorControl text_editor = ((TextEditorControl)tab_page.Controls.Find("textEditorControl1", true).FirstOrDefault());
                text_editor.SaveFile(tab_page.ToolTipText);

                if (tab_page.Text.IndexOf('*', 0) == 0)
                {
                    tab_page.Text = tab_page.Text.Remove(0, 2);
                }
            }
        }
Ejemplo n.º 19
0
        void SaveAs()
        {
            TextEditorControl editor = ActiveEditor;

            if (editor != null)
            {
                using (SaveFileDialog dialog = new SaveFileDialog())
                {
                    dialog.Filter      = SharpPadFileFilter;
                    dialog.FilterIndex = 0;
                    if (DialogResult.OK == dialog.ShowDialog())
                    {
                        editor.SaveFile(dialog.FileName);
                        editor.FileName = dialog.FileName;
                    }
                }
            }
        }
Ejemplo n.º 20
0
 private bool DoSave(TextEditorControl editor)
 {
     if (string.IsNullOrEmpty(editor.FileName))
     {
         return(DoSaveAs(editor));
     }
     else
     {
         try {
             editor.SaveFile(editor.FileName);
             SetModifiedFlag(editor, false);
             return(true);
         } catch (Exception ex) {
             MessageBox.Show(ex.Message, ex.GetType().Name);
             return(false);
         }
     }
 }
Ejemplo n.º 21
0
 public override void Run()
 {
     if (WorkbenchSingleton.Workbench.FileTabControl.TabPages.Count <= 0)
     {
         MessageBox.Show("没有要保存的文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return;
     }
     foreach (TabPage page in WorkbenchSingleton.Workbench.FileTabControl.TabPages)
     {
         TextEditorControl textEditor = page.Controls[0] as TextEditorControl;
         string            s          = page.Tag.ToString();
         textEditor.SaveFile(s);
         if (page.Text.EndsWith("*"))
         {
             page.Text = page.Text.Substring(0, page.Text.Length - 1);
         }
     }
 }
Ejemplo n.º 22
0
        public virtual bool SaveContent(string saveHint, TextEditorControl textEditor)
        {
            if (textEditor == null)
            {
                throw new NullParameterException("TextEditor parameter is null!");
            }

            if (String.IsNullOrEmpty(_filePath) || !File.Exists(_filePath))
            {
                return(SaveContentAs(saveHint, textEditor));
            }

            textEditor.SaveFile(_filePath);
            ContentType = EditorContentType.File;
            FileInfo fi = new FileInfo(_filePath);

            _hint = fi.Name;
            return(true);
        }
Ejemplo n.º 23
0
        public bool SaveContent(string saveHint, TextEditorControl textEditor)
        {
            if (textEditor == null)
            {
                throw new NullParameterException("TextEditor parameter is null!");
            }


            if (String.IsNullOrEmpty(_fileName))
            {
                return(SaveContentAs(saveHint, textEditor));
            }


            textEditor.SaveFile(_fileName);
            FileInfo fi = new FileInfo(_fileName);

            _hint = fi.Name;
            return(true);
        }
Ejemplo n.º 24
0
        public void SaveFile(string file)
        {
            if (SettingsManager.Settings.ReadValue <bool>("RemoveTrailingWhitespace") == true)
            {
                TrimTrailingWhitespace();
            }

            openFile  = file;
            saved     = true;
            this.Text = this.Text.Replace("*", "");

            this.Text = Path.GetFileName(file);
            textEditorControl.SaveFile(file);

            ILanguageStrategy lang = LanguageManager.GetLanguageStrategyForFile(file);

            if (lang != null)
            {
                textEditorControl.Document.FoldingManager.FoldingStrategy = lang.FoldingStrategy;
                textEditorControl.Document.HighlightingStrategy           = lang.HighlightingStrategy;
                completionKeyHandler.CompletionDataProvider = lang.CompletionData;
            }
        }
Ejemplo n.º 25
0
 public bool SaveToFile(string fileName)
 {
     _textEditor.SaveFile(fileName);
     return(true);
 }
Ejemplo n.º 26
0
 public void SaveFile(string path)
 {
     textEditorControl.SaveFile(path);
     saved = true;
 }
Ejemplo n.º 27
0
 private void PropertyForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     editor.SaveFile(editor.FileName);
 }