示例#1
0
        /// <summary>
        /// Saves an editable document
        /// </summary>
        public void Save(String file)
        {
            if (!this.IsEditable)
            {
                return;
            }
            if (!this.IsUntitled && FileHelper.FileIsReadOnly(this.FileName))
            {
                String dlgTitle = TextHelper.GetString("Title.ConfirmDialog");
                String message  = TextHelper.GetString("Info.MakeReadOnlyWritable");
                if (MessageBox.Show(Globals.MainForm, message, dlgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    ScintillaManager.MakeFileWritable(this.SciControl);
                }
                else
                {
                    return;
                }
            }
            Boolean otherFile = (this.SciControl.FileName != file);

            if (otherFile)
            {
                RecoveryManager.RemoveTemporaryFile(this.FileName);
                TextEvent close = new TextEvent(EventType.FileClose, this.FileName);
                EventManager.DispatchEvent(this, close);
            }
            TextEvent saving = new TextEvent(EventType.FileSaving, file);

            EventManager.DispatchEvent(this, saving);
            if (!saving.Handled)
            {
                this.UpdateDocumentIcon(file);
                this.SciControl.FileName = file;
                ScintillaManager.CleanUpCode(this.SciControl);
                DataEvent de = new DataEvent(EventType.FileEncode, file, this.SciControl.Text);
                EventManager.DispatchEvent(this, de); // Lets ask if a plugin wants to encode and save the data..
                if (!de.Handled)
                {
                    FileHelper.WriteFile(file, this.SciControl.Text, this.SciControl.Encoding, this.SciControl.SaveBOM);
                }
                this.IsModified = false;
                this.SciControl.SetSavePoint();
                RecoveryManager.RemoveTemporaryFile(this.FileName);
                this.fileInfo = new FileInfo(this.FileName);
                if (otherFile)
                {
                    ScintillaManager.UpdateControlSyntax(this.SciControl);
                    Globals.MainForm.OnFileSave(this, true);
                }
                else
                {
                    Globals.MainForm.OnFileSave(this, false);
                }
            }
            this.UpdateToolTipText();
            this.UpdateTabText();
        }