void NewToolStripMenuItemClick(object sender, EventArgs e) { py_editor_doc_page doc_page = new py_editor_doc_page(StandardContextMenuStrip); TabPage new_page = new TabPage(); new_page.Controls.Add(doc_page); doc_page.Dock = DockStyle.Fill; DocPagesContainer.SuspendLayout(); { DocPagesContainer.TabPages.Add(new_page); DocPagesContainer.SelectTab(new_page); //new_page.UseVisualStyleBackColor = true; } DocPagesContainer.ResumeLayout(); doc_page.script_filename = null; doc_page.script_text_box.Text = ""; doc_page.script_text_box.Focus(); doc_page.TextChangedEvent += new EventHandler(text_changed); doc_page.SelectionChangedEvent += new EventHandler(selection_changed); doc_page.UpdateLnColMsgEvent += new EventHandler(update_ln_col_status_msg); update_tab_page_text(new_page, true); update_undo_redo(); update_cut_copy_paste_delete(); update_status_msg("new script"); }
void delete_page(TabPage _tab_page, bool _force_delete) { py_editor_doc_page doc_page = _tab_page.Controls[0] as py_editor_doc_page; if (_force_delete == false && doc_page.get_data_changed_flag()) { if (message_box("All unsaved data will be lost!\nDo you want to save the script?", _tab_page.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (doc_page.script_filename == null) { saveFileDialog.ShowDialog(); } else { save_script(_tab_page); } } } DocPagesContainer.TabPages.Remove(_tab_page); doc_page.TextChangedEvent -= text_changed; doc_page.SelectionChangedEvent -= selection_changed; doc_page.UpdateLnColMsgEvent -= update_ln_col_status_msg; doc_page.destroy(); update_status_msg("script deleted"); }
void update_undo_redo() { py_editor_doc_page doc_page = get_active_script(); if (doc_page != null) { undoToolStripButton.Enabled = undoToolStripMenuItem.Enabled = doc_page.script_text_box.CanUndo; redoToolStripButton.Enabled = redoToolStripMenuItem.Enabled = doc_page.script_text_box.CanRedo; } }
void update_tab_page_text(TabPage _tab_page, bool _force_update) { bool has_data_changed_mark = (_tab_page.Text.IndexOf("*") >= 0); py_editor_doc_page doc_page = _tab_page.Controls[0] as py_editor_doc_page; if (doc_page.get_data_changed_flag() != has_data_changed_mark || _force_update == true) { _tab_page.Text = get_doc_page_filename(doc_page) + (doc_page.get_data_changed_flag() ? "*":""); } }
void DeleteToolStripMenuItemClick(object sender, EventArgs e) { py_editor_doc_page doc_page = get_active_script(); if (doc_page != null) { doc_page.script_text_box.SelectedText = ""; } else { update_status_msg(CONST_NO_SCRIPT_MSG); } }
void DocPagesContainerSelectedIndexChanged(object sender, EventArgs e) { update_cut_copy_paste_delete(); update_undo_redo(); update_ln_col_status_msg(sender, e); py_editor_doc_page doc_page = get_active_script(); if (doc_page != null) { doc_page.script_text_box.Focus(); } }
void py_editorShown(object sender, EventArgs e) { py_editor_doc_page doc_page = get_active_script(); if (doc_page != null) { doc_page.first_init(); doc_page.script_text_box.Focus(); } if (Type.GetType("Mono.Runtime") != null) { message_box("It's not recommended to use the editor for script editing under Mono due to buggy implementation of RichTextBox. You can load your script into the editor and to any other editor where you can edit it. Then in this editor you can press Ctrl+R (reload script) and F5 (run script).", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
void RedoToolStripMenuItemClick(object sender, EventArgs e) { py_editor_doc_page doc_page = get_active_script(); if (doc_page != null) { doc_page.script_text_box.Redo(); update_undo_redo(); } else { update_status_msg(CONST_NO_SCRIPT_MSG); } }
void LoadOk_Event(object sender, System.ComponentModel.CancelEventArgs e) { py_editor_doc_page doc_page = get_active_script(); if (doc_page != null) { doc_page.script_filename = (( FileDialog )sender).FileName; load_script(doc_page); } else { update_status_msg(CONST_NO_SCRIPT_MSG); } }
void update_ln_col_status_msg(object sender, EventArgs e) { py_editor_doc_page doc_page = get_active_script(); //sender as py_editor_doc_page; if (doc_page != null) { int column = doc_page.script_text_box.SelectionStart - doc_page.script_text_box.GetFirstCharIndexOfCurrentLine() + 1; int row = doc_page.script_text_box.GetLineFromCharIndex(doc_page.script_text_box.GetFirstCharIndexOfCurrentLine()) + 1; toolStripLnCol.Text = "ln " + row.ToString() + " col " + column.ToString(); } else { toolStripLnCol.Text = ""; } }
void load_script(py_editor_doc_page _doc_page) { try { _doc_page.script_text_box.Text = File.ReadAllText(_doc_page.script_filename); _doc_page.reset_data_changed_flag(); update_tab_page_text(DocPagesContainer.SelectedTab, true); update_status_msg("loaded"); } catch (System.Exception _err) { message_box(_err.Message, "Script Loading Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void RunToolStripMenuItemClick(object sender, EventArgs e) { py_editor_doc_page doc_page = get_active_script(); if (doc_page != null) { SaveAllToolStripMenuItemClick(null, null); try { update_status_msg("script is running..."); OutputTextBox.Text = ""; doc_page.script_text_box.Focus(); ScriptSource src = m_py_engine.CreateScriptSourceFromString(doc_page.script_text_box.Text, get_doc_page_filename(doc_page), SourceCodeKind.File); object res = src.Execute(m_py_scope); if (res != null) { OutputTextBox.Text += res.ToString(); } OutputTextBox.Text += "\nScript execution success!"; } catch (Exception _err) { OutputTextBox.Text += "Script execution failed!\n\n"; update_status_msg("error"); OutputTextBox.Text += m_py_engine.GetService <ExceptionOperations>().FormatException(_err); return; } update_status_msg("ok!.."); } else { update_status_msg(CONST_NO_SCRIPT_MSG); } }
void ReloadToolStripMenuItemClick(object sender, EventArgs e) { py_editor_doc_page doc_page = get_active_script(); if (doc_page != null) { if (doc_page.script_filename != null) { load_script(doc_page); } else { update_status_msg("no file to reload!"); } } else { update_status_msg(CONST_NO_SCRIPT_MSG); } }
void SaveToolStripMenuItemClick(object sender, EventArgs e) { py_editor_doc_page doc_page = get_active_script(); if (doc_page != null) { if (doc_page.script_filename == null) { saveFileDialog.ShowDialog(); } else { save_script(DocPagesContainer.SelectedTab); } } else { update_status_msg(CONST_NO_SCRIPT_MSG); } }
void update_cut_copy_paste_delete() { py_editor_doc_page doc_page = get_active_script(); if (doc_page != null) { deleteToolStripButton.Enabled = deleteToolStripMenuItem.Enabled = deleteToolStripMenuItem1.Enabled = copyToolStripButton.Enabled = copyToolStripMenuItem.Enabled = copyToolStripMenuItem1.Enabled = cutToolStripButton.Enabled = cutToolStripMenuItem.Enabled = cutToolStripMenuItem1.Enabled = (doc_page.script_text_box.SelectedText.Length > 0); } pasteToolStripButton.Enabled = pasteToolStripMenuItem.Enabled = pasteToolStripMenuItem1.Enabled = Clipboard.ContainsText(); }
void save_script(TabPage _tab_page, string _filename = null) { try { py_editor_doc_page doc_page = _tab_page.Controls[0] as py_editor_doc_page; string filename = (_filename != null) ? _filename:doc_page.script_filename; File.WriteAllText(filename, doc_page.script_text_box.Text); doc_page.script_filename = filename; doc_page.reset_data_changed_flag(); update_tab_page_text(_tab_page, true); update_status_msg("saved"); } catch (System.Exception _err) { message_box(_err.Message, "Script Saving Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
string get_doc_page_filename(py_editor_doc_page _doc_page) { return(_doc_page.script_filename != null?Path.GetFileName(_doc_page.script_filename) : "UNTITLED"); }