/// <summary> /// evaluates all commands that follow in the list until /// <paramref name="lastEntry"/> is reached. /// </summary> public void EvaluateCommandsUntil(WorksheetEntry lastEntry) { List <WorksheetEntry> EntriesToEvaluate = new List <WorksheetEntry>(); for (WorksheetEntry next = this; next != null && next != lastEntry; next = next.m_next) { //EntriesToEvaluate.Add(next); next.EvaluateCommand(); } /* * var asyncExe = new Task(delegate () { * foreach (var entry in EntriesToEvaluate) { * m_owner.Invoke(new Action(delegate () { * entry.Command.Focus(); * entry.EvaluateCommand(); * })); * while (m_EvaluationInProgress) { * System.Threading.Thread.Sleep(100); * } * } * }); * * asyncExe.Start(); */ }
/// <summary> /// creates a new document /// </summary> private void New() { if (CheckAltered()) { if (this.CommandsListHead != null) { this.CommandsListHead.Destroy(); this.CurrentCommand = null; } this.currentDocument = new Document(); this.currentDocument.CommandAndResult.Add(new Document.Tuple { Command = "restart" }); this.currentDocument.CommandAndResult.Add(new Document.Tuple()); this.CommandsListHead = new WorksheetEntry(this, this.currentDocument); this.CommandsListHead.EvaluateAllCommands(); this.CurrentCommand = this.CommandsListHead; this.DocumentPath = null; this.altered = false; ResetCommandQueue(); } }
private void Open(string fileName) { if (this.CommandsListHead != null) { this.CommandsListHead.Destroy(); this.CurrentCommand = null; } ResetCommandQueue(); try { if (fileName.ToLowerInvariant().EndsWith(".tex")) { // try to load as LaTeX // ++++++++++++++++++++ List <string> dummy; this.DocumentPath = fileName; LatexIO.SplitTexFile(fileName, out dummy, out this.currentDocument); //this.TeXlinkFilename = fileName; //this.MenuItem_Bws2Tex.Enabled = true; } else { // try to load as LaTeX // ++++++++++++++++++++ this.currentDocument = Document.Deserialize(fileName); this.Altered = false; this.m_DocumentPath = fileName; } } catch (Exception e) { MessageBox.Show(this, e.GetType().Name + ":\n" + e.Message, "Error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this.currentDocument.CommandAndResult.Count <= 0) { this.currentDocument.CommandAndResult.Add(new Document.Tuple { Command = "\"Empty document - lets try restart?\"" }); } this.DocumentPath = this.m_DocumentPath; this.CommandsListHead = new WorksheetEntry(this, this.currentDocument); this.CurrentCommand = this.CommandsListHead; //this.CommandsListHead.ResizeAll(); string workingDirectory = Path.GetDirectoryName(fileName); if (workingDirectory != null && workingDirectory.Length > 0 && Directory.Exists(workingDirectory)) { Directory.SetCurrentDirectory(workingDirectory); } }
/// <summary> /// Creates a worksheet logic from a <see cref="Document"/>; recursively; /// </summary> private WorksheetEntry(Worksheet o, WorksheetEntry p, Document doc, int i) : this(o, doc, p, null, doc.CommandAndResult[i].Command, doc.CommandAndResult[i].InterpreterTextOutput) // perform recursion { Debug.Assert(this.Index == i); if (this.Index < doc.CommandAndResult.Count - 1) { new WorksheetEntry(o, this, doc, i + 1); } }
public WorksheetEntry Delete() { //if (m_EvaluationInProgress) // return null; if (m_prev == null && m_next == null) { // Last statement cannot be deleted Console.Beep(); return(this); } m_doc.CommandAndResult.RemoveAt(Index); this.m_owner.Altered = true; WorksheetEntry newFocus = null; if (m_prev != null) { m_prev.m_next = this.m_next; newFocus = m_prev; } if (m_next != null) { m_next.m_prev = this.m_prev; newFocus = m_next; m_next.Index--; } Deleted = true; //m_owner.DocumentPanel.Controls.Remove(Prompt); m_owner.DocumentPanel.Controls.Remove(Command); m_owner.DocumentPanel.Controls.Remove(Result); m_owner.DocumentPanel.Controls.Remove(GraphicsResult); this.ResizeAll(); newFocus.Command.Focus(); m_owner.ClientRectPanel.ScrollControlIntoView(newFocus.Command); return(newFocus); }
/// <summary> /// inserts an object into the linked list, after this object; /// </summary> /// <param name="cmdString"></param> /// <returns>the newly created object</returns> public WorksheetEntry InsertAfter(string cmdString) { //if (m_EvaluationInProgress) // return null; WorksheetEntry newEntry; if (m_next != null) { // insert var old_next = this.m_next; newEntry = new WorksheetEntry(m_owner, this.m_doc, this, this.m_next, cmdString, null); { int currentZoom = this.Command.Zoom; newEntry.Command_ZoomChanged_locked = true; newEntry.Command.Zoom = currentZoom; newEntry.Result.Zoom = currentZoom; newEntry.Command_ZoomChanged_locked = false; } Debug.Assert(object.ReferenceEquals(m_next, newEntry)); Debug.Assert(object.ReferenceEquals(newEntry.m_prev, this)); Debug.Assert(object.ReferenceEquals(old_next.m_prev, newEntry)); Debug.Assert(object.ReferenceEquals(newEntry.m_next, old_next)); m_doc.CommandAndResult.Insert(newEntry.Index, new Document.Tuple()); } else { // just add at the end newEntry = new WorksheetEntry(m_owner, this.m_doc, this, null, cmdString, null); Debug.Assert(object.ReferenceEquals(m_next, newEntry)); Debug.Assert(object.ReferenceEquals(newEntry.m_prev, this)); m_doc.CommandAndResult.Add(new Document.Tuple()); Debug.Assert(newEntry.Index == m_doc.CommandAndResult.Count - 1); } this.ResizeAll(); m_owner.Altered = true; return(newEntry); }
/// <summary> /// private constructor /// </summary> private WorksheetEntry(Worksheet o, Document doc, WorksheetEntry p, WorksheetEntry n, string commandStr, string resultStr) { m_doc = doc; m_owner = o; if (p != null) { this.m_prev = p; p.m_next = this; } if (n != null) { this.m_next = n; n.m_prev = this; } if (m_prev != null) { this.Index = m_prev.Index + 1; } m_owner.DocumentPanel.SuspendLayout(); m_owner.BlockResizeClient = true; { this.GlowAnimationTimer = new System.Windows.Forms.Timer(this.m_owner.components); this.GlowAnimationTimer.Interval = 40; // 25 fps this.GlowAnimationTimer.Tick += new System.EventHandler(this.GlowAnimationTimer_Tick); } { Command = new FastColoredTextBox(); m_owner.DocumentPanel.Controls.Add(Command); Command.AutoCompleteBracketsList = new char[] { '(', ')', '{', '}', '[', ']', '\"', '\"', '\'', '\'' }; Command.AutoIndentExistingLines = false; Command.AutoScrollMinSize = new System.Drawing.Size(284, 285); Command.BackBrush = null; Command.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; //Command.CharHeight = 15; //Command.CharWidth = 7; Command.Cursor = System.Windows.Forms.Cursors.IBeam; Command.DelayedEventsInterval = 200; Command.DelayedTextChangedInterval = 500; Command.DisabledColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180))))); Font fa = m_owner.CommandFont; Font fb = new Font("Courier New", 12.0F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0))); Command.Font = fb; Command.WordWrapMode = WordWrapMode.CharWrapControlWidth; //Command.WordWrapMode = WordWrapMode.CharWrapPreferredWidth; Command.WordWrap = true; Command.ImeMode = System.Windows.Forms.ImeMode.Off; Command.IsReplaceMode = false; Command.Location = new System.Drawing.Point(0, 24); Command.Name = "fctb"; Command.Paddings = new System.Windows.Forms.Padding(0); Command.PreferredLineWidth = 80; Command.ReservedCountOfLineNumberChars = 3; Command.SelectionColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(255))))); //Command.ServiceColors = ((FastColoredTextBoxNS.ServiceColors)(resources.GetObject("fctb.ServiceColors"))); Command.Size = new System.Drawing.Size(346, 311); Command.TabIndex = 3; Command.Text = commandStr != null ? commandStr : ""; Command.Zoom = 100; Command.SelectionChangedDelayed += new System.EventHandler(Command_SelectionChangedDelayed); Command.AutoIndentNeeded += this.Command_AutoIndentNeeded; Command.LineRemoved += this.Command_LineRemoved; Command.LineInserted += this.Command_LineInserted; Command.TextChanged += this.Command_TextChanged; Command.ZoomChanged += this.ZoomChanged; Command.SelectionChanged += this.SelectionChanged; Command.Language = Language.CSharp; Command.OnSyntaxHighlight(new TextChangedEventArgs(Command.Range)); Command.GotFocus += Command_GotFocus; Command.KeyDown += this.KeyDown; // Map redo action to Ctrl+Y (as in most editors) Command.HotkeysMapping.Add(Keys.Control | Keys.Y, FCTBAction.Redo); } { AutoCompleteBox = new AutocompleteMenu(this.Command); AutoCompleteBox.MinFragmentLength = 2; AutoCompleteBox.Items.MaximumSize = new System.Drawing.Size(200, 300); AutoCompleteBox.Items.Width = 200; AutoCompleteBox.Items.SetAutocompleteItems( new DynamicAutoCompleteList(m_owner)); } { m_owner.BlockTextChanged = true; Result = new FastColoredTextBox(); m_owner.DocumentPanel.Controls.Add(Result); Result.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; Result.Cursor = System.Windows.Forms.Cursors.IBeam; Result.DisabledColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180))))); Result.Font = new Font("Courier New", 12.0F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0))); Result.WordWrapMode = WordWrapMode.CharWrapControlWidth; Result.WordWrap = true; Result.Paddings = new System.Windows.Forms.Padding(0); Result.ShowLineNumbers = false; Result.SelectionColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(255))))); Result.Zoom = 100; Result.ZoomChanged += this.ZoomChanged; Result.MouseWheel += Scroll; Result.TextChanged += Result_TextChanged; Result.GotFocus += Result_GotFocus; Result.KeyDown += KeyDown; Result.SelectionChanged += this.SelectionChanged; Result.BackColor = Color.White; Result.BackBrush = null; Result.ForeColor = Color.DarkBlue; Result.BorderStyle = BorderStyle.None; m_defaultResultCharHeight = Result.CharHeight; Result.Text = resultStr != null ? resultStr : ""; // This seems to be the only way to tell FastColoredTextBox to // be of zero height if empty Result.CharHeight = Result.Text.IsNullOrEmpty() ? 0 : m_defaultResultCharHeight; Result.ReadOnly = true; m_owner.BlockTextChanged = false; } { GraphicsResult = new PictureBox(); m_owner.DocumentPanel.Controls.Add(GraphicsResult); GraphicsResult.SizeMode = PictureBoxSizeMode.Zoom; GraphicsResult.Visible = false; // only activated in special cases. } m_owner.DocumentPanel.ResumeLayout(); //Command.Show(); //Result.Show(); Resize(); m_owner.BlockResizeClient = false; }