예제 #1
0
        /// <summary>
        /// Adds a new scintilla control to the document
        /// </summary>
        public void AddEditorControls(String file, String text, Int32 codepage)
        {
            this.editor                       = ScintillaManager.CreateControl(file, text, codepage);
            this.editor.Dock                  = DockStyle.Fill;
            this.editor2                      = ScintillaManager.CreateControl(file, text, codepage);
            this.editor2.Dock                 = DockStyle.Fill;
            this.splitContainer               = new SplitContainer();
            this.splitContainer.Name          = "fdSplitView";
            this.splitContainer.SplitterWidth = ScaleHelper.Scale(this.splitContainer.SplitterWidth);
            this.splitContainer.Orientation   = Orientation.Horizontal;
            this.splitContainer.BackColor     = SystemColors.Control;
            this.splitContainer.Panel1.Controls.Add(this.editor);
            this.splitContainer.Panel2.Controls.Add(this.editor2);
            this.splitContainer.Dock            = DockStyle.Fill;
            this.splitContainer.Panel2Collapsed = true;
            Int32 oldDoc = this.editor.DocPointer;

            this.editor2.DocPointer    = oldDoc;
            this.editor.SavePointLeft += delegate
            {
                Globals.MainForm.OnDocumentModify(this);
            };
            this.editor.SavePointReached += delegate
            {
                this.editor.MarkerDeleteAll(2);
                this.IsModified = false;
            };
            this.editor.FocusChanged  += new FocusHandler(this.EditorFocusChanged);
            this.editor2.FocusChanged += new FocusHandler(this.EditorFocusChanged);
            this.editor.UpdateSync    += new UpdateSyncHandler(this.EditorUpdateSync);
            this.editor2.UpdateSync   += new UpdateSyncHandler(this.EditorUpdateSync);
            this.Controls.Add(this.splitContainer);
        }
예제 #2
0
        public void FixtureSetUp()
        {
            mainForm                 = new MainForm();
            settings                 = Substitute.For <ISettings>();
            settings.UseTabs         = true;
            settings.IndentSize      = 4;
            settings.SmartIndentType = SmartIndent.CPP;
            settings.TabIndents      = true;
            settings.TabWidth        = 4;
            doc = Substitute.For <ITabbedDocument>();
            mainForm.Settings        = settings;
            mainForm.CurrentDocument = doc;
            mainForm.StandaloneMode  = true;
            PluginBase.Initialize(mainForm);
            ScintillaManager.LoadConfiguration();
            var pluginMain = Substitute.For <ASCompletion.PluginMain>();
            var pluginUI   = new PluginUI(pluginMain);

            pluginMain.MenuItems.Returns(new List <ToolStripItem>());
            pluginMain.Settings.Returns(new GeneralSettings());
            pluginMain.Panel.Returns(pluginUI);
            #region ASContext.GlobalInit(pluginMain);
            var method = typeof(ASContext).GetMethod("GlobalInit", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);
            method.Invoke(null, new[] { pluginMain });
            #endregion
            ASContext.Context = Substitute.For <IASContext>();
            Sci = GetBaseScintillaControl();
            doc.SciControl.Returns(Sci);
        }
예제 #3
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();
        }
예제 #4
0
        /// <summary>
        /// Syncs both of the scintilla editors
        /// </summary>
        private void EditorUpdateSync(ScintillaControl sender)
        {
            if (!this.IsEditable)
            {
                return;
            }
            ScintillaControl e1 = editor;
            ScintillaControl e2 = editor2;

            if (sender == editor2)
            {
                e1 = editor2;
                e2 = editor;
            }
            e2.UpdateSync -= new UpdateSyncHandler(this.EditorUpdateSync);
            ScintillaManager.UpdateSyncProps(e1, e2);
            ScintillaManager.ApplySciSettings(e2);
            e2.UpdateSync += new UpdateSyncHandler(this.EditorUpdateSync);
            Globals.MainForm.RefreshUI();
        }
예제 #5
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.CodePage   = ScintillaManager.SelectCodePage(info.CodePage);
                this.SciControl.Text       = info.Contents;
                this.SciControl.IsReadOnly = FileHelper.FileIsReadOnly(this.FileName);
                this.SciControl.SetSel(position, position);
                this.SciControl.EmptyUndoBuffer();
                this.SciControl.Focus();
                this.InitBookmarks();
            }
            Globals.MainForm.OnDocumentReload(this);
        }