예제 #1
0
        /// <summary>
        /// Reloads an editable document
        /// </summary>
        public void Reload(Boolean showQuestion)
        {
            if (!this.IsEditable)
            {
                return;
            }
            if (showQuestion)
            {
                String dlgTitle = TextHelper.GetString("Title.ConfirmDialog");
                String message  = TextHelper.GetString("Info.AreYouSureToReload");
                if (MessageBox.Show(Globals.MainForm, message, " " + dlgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
            }
            Globals.MainForm.ReloadingDocument = true;
            Int32     position = this.SciControl.CurrentPos;
            TextEvent te       = new TextEvent(EventType.FileReload, this.FileName);

            EventManager.DispatchEvent(Globals.MainForm, te);
            if (!te.Handled)
            {
                EncodingFileInfo info = FileHelper.GetEncodingFileInfo(this.FileName);
                if (info.CodePage == -1)
                {
                    Globals.MainForm.ReloadingDocument = false;
                    return; // If the files is locked, stop.
                }
                Encoding encoding = Encoding.GetEncoding(info.CodePage);
                this.SciControl.IsReadOnly = false;
                this.SciControl.Encoding   = encoding;
                this.SciControl.Text       = info.Contents;
                this.SciControl.IsReadOnly = FileHelper.FileIsReadOnly(this.FileName);
                this.SciControl.SetSel(position, position);
                this.SciControl.EmptyUndoBuffer();
                int lineCount = SciControl.LineCount;
                foreach (var lineNum in this.bookmarks)
                {
                    if (lineNum < 0)
                    {
                        continue;
                    }
                    if (lineNum >= lineCount)
                    {
                        if (!MarkerManager.HasMarker(SciControl, 0, lineCount - 1))
                        {
                            MarkerManager.ToggleMarker(SciControl, 0, lineCount - 1);
                        }
                    }
                    else
                    {
                        MarkerManager.ToggleMarker(SciControl, 0, lineNum);
                    }
                }
                this.InitBookmarks();
                this.fileInfo = new FileInfo(this.FileName);
            }
            Globals.MainForm.OnDocumentReload(this);
        }