LuaConsole now updates when a new Luascript is saved in the LuaWriter.
LineNumbers can now be shown in the Writer, only updates when a selectionchanged event occurs, not on the scrolling of the screen. Option to toggle LineNumbers on and off -MightyMar
This commit is contained in:
parent
7560367f4e
commit
0a494c386e
|
@ -586,6 +586,7 @@ namespace BizHawk.Client.Common
|
|||
public string LuaWriterFont = "Courier New";
|
||||
public float LuaWriterZoom = 1;
|
||||
public bool LuaWriterStartEmpty = false;
|
||||
public bool LuaShowLineNumbers = false;
|
||||
}
|
||||
|
||||
// these are used in the defctrl.json or wherever
|
||||
|
|
|
@ -513,9 +513,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
return true;
|
||||
}
|
||||
|
||||
private static void OpenLuaWriter(string path)
|
||||
private void OpenLuaWriter(string path)
|
||||
{
|
||||
var writer = new LuaWriter { CurrentFile = path };
|
||||
var writer = new LuaWriter(this) { CurrentFile = path };
|
||||
writer.Show();
|
||||
}
|
||||
|
||||
|
|
|
@ -54,15 +54,17 @@
|
|||
this.fontToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.syntaxHighlightingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.backgroundColorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.lineNumbersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.startWithEmptyScriptToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.restoreSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.MessageLabel = new System.Windows.Forms.Label();
|
||||
this.AutoCompleteView = new System.Windows.Forms.ListView();
|
||||
this.Suggestion = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.PositionLabel = new System.Windows.Forms.Label();
|
||||
this.ZoomLabel = new System.Windows.Forms.Label();
|
||||
this.LuaText = new BizHawk.Client.EmuHawk.LuaWriterBox();
|
||||
this.Suggestion = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.LuaLineTextBox = new System.Windows.Forms.RichTextBox();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
|
@ -81,7 +83,7 @@
|
|||
this.configToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(474, 24);
|
||||
this.menuStrip1.Size = new System.Drawing.Size(846, 24);
|
||||
this.menuStrip1.TabIndex = 1;
|
||||
this.menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
|
@ -244,6 +246,7 @@
|
|||
this.fontToolStripMenuItem,
|
||||
this.syntaxHighlightingToolStripMenuItem,
|
||||
this.backgroundColorToolStripMenuItem,
|
||||
this.lineNumbersToolStripMenuItem,
|
||||
this.toolStripSeparator5,
|
||||
this.startWithEmptyScriptToolStripMenuItem,
|
||||
this.restoreSettingsToolStripMenuItem});
|
||||
|
@ -272,6 +275,14 @@
|
|||
this.backgroundColorToolStripMenuItem.Text = "Background Color";
|
||||
this.backgroundColorToolStripMenuItem.Click += new System.EventHandler(this.backgroundColorToolStripMenuItem_Click);
|
||||
//
|
||||
// lineNumbersToolStripMenuItem
|
||||
//
|
||||
this.lineNumbersToolStripMenuItem.CheckOnClick = true;
|
||||
this.lineNumbersToolStripMenuItem.Name = "lineNumbersToolStripMenuItem";
|
||||
this.lineNumbersToolStripMenuItem.Size = new System.Drawing.Size(196, 22);
|
||||
this.lineNumbersToolStripMenuItem.Text = "Show Linenumbers";
|
||||
this.lineNumbersToolStripMenuItem.Click += new System.EventHandler(this.toolStripMenuItem1_Click);
|
||||
//
|
||||
// toolStripSeparator5
|
||||
//
|
||||
this.toolStripSeparator5.Name = "toolStripSeparator5";
|
||||
|
@ -295,7 +306,7 @@
|
|||
//
|
||||
this.MessageLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.MessageLabel.AutoSize = true;
|
||||
this.MessageLabel.Location = new System.Drawing.Point(15, 424);
|
||||
this.MessageLabel.Location = new System.Drawing.Point(15, 484);
|
||||
this.MessageLabel.Name = "MessageLabel";
|
||||
this.MessageLabel.Size = new System.Drawing.Size(91, 13);
|
||||
this.MessageLabel.TabIndex = 2;
|
||||
|
@ -312,7 +323,7 @@
|
|||
this.AutoCompleteView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
|
||||
this.AutoCompleteView.HideSelection = false;
|
||||
this.AutoCompleteView.HoverSelection = true;
|
||||
this.AutoCompleteView.Location = new System.Drawing.Point(324, 322);
|
||||
this.AutoCompleteView.Location = new System.Drawing.Point(696, 382);
|
||||
this.AutoCompleteView.MultiSelect = false;
|
||||
this.AutoCompleteView.Name = "AutoCompleteView";
|
||||
this.AutoCompleteView.Size = new System.Drawing.Size(121, 97);
|
||||
|
@ -323,6 +334,10 @@
|
|||
this.AutoCompleteView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.AutoComplete_KeyDown);
|
||||
this.AutoCompleteView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.AutoCompleteView_MouseDoubleClick);
|
||||
//
|
||||
// Suggestion
|
||||
//
|
||||
this.Suggestion.Width = 114;
|
||||
//
|
||||
// PositionLabel
|
||||
//
|
||||
this.PositionLabel.AutoSize = true;
|
||||
|
@ -349,28 +364,41 @@
|
|||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.LuaText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.LuaText.EnableAutoDragDrop = true;
|
||||
this.LuaText.Location = new System.Drawing.Point(15, 50);
|
||||
this.LuaText.Location = new System.Drawing.Point(63, 50);
|
||||
this.LuaText.Name = "LuaText";
|
||||
this.LuaText.Size = new System.Drawing.Size(444, 369);
|
||||
this.LuaText.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
|
||||
this.LuaText.Size = new System.Drawing.Size(768, 429);
|
||||
this.LuaText.TabIndex = 0;
|
||||
this.LuaText.Text = "";
|
||||
this.LuaText.WordWrap = false;
|
||||
this.LuaText.SelectionChanged += new System.EventHandler(this.LuaText_SelectionChanged);
|
||||
this.LuaText.VScroll += new System.EventHandler(this.LuaText_VScroll);
|
||||
this.LuaText.TextChanged += new System.EventHandler(this.LuaText_TextChanged);
|
||||
this.LuaText.KeyDown += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyDown);
|
||||
this.LuaText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyUp);
|
||||
this.LuaText.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.LuaText_PreviewKeyDown);
|
||||
//
|
||||
// Suggestion
|
||||
// LuaLineTextBox
|
||||
//
|
||||
this.Suggestion.Width = 114;
|
||||
this.LuaLineTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.LuaLineTextBox.BackColor = System.Drawing.SystemColors.ScrollBar;
|
||||
this.LuaLineTextBox.Location = new System.Drawing.Point(0, 50);
|
||||
this.LuaLineTextBox.Name = "LuaLineTextBox";
|
||||
this.LuaLineTextBox.ReadOnly = true;
|
||||
this.LuaLineTextBox.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
|
||||
this.LuaLineTextBox.Size = new System.Drawing.Size(60, 429);
|
||||
this.LuaLineTextBox.TabIndex = 6;
|
||||
this.LuaLineTextBox.Text = "";
|
||||
this.LuaLineTextBox.Visible = false;
|
||||
//
|
||||
// LuaWriter
|
||||
//
|
||||
this.AllowDrop = true;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(474, 441);
|
||||
this.ClientSize = new System.Drawing.Size(846, 501);
|
||||
this.Controls.Add(this.LuaLineTextBox);
|
||||
this.Controls.Add(this.AutoCompleteView);
|
||||
this.Controls.Add(this.ZoomLabel);
|
||||
this.Controls.Add(this.PositionLabel);
|
||||
|
@ -428,5 +456,7 @@
|
|||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator5;
|
||||
private System.Windows.Forms.ToolStripMenuItem backgroundColorToolStripMenuItem;
|
||||
private System.Windows.Forms.ColumnHeader Suggestion;
|
||||
private System.Windows.Forms.RichTextBox LuaLineTextBox;
|
||||
private System.Windows.Forms.ToolStripMenuItem lineNumbersToolStripMenuItem;
|
||||
}
|
||||
}
|
|
@ -15,13 +15,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
public partial class LuaWriter : Form
|
||||
{
|
||||
//TODO:
|
||||
//ability to save new script (currently causes an exception)
|
||||
//New scripts should be added to lua console automatically
|
||||
//Loads of exceptions when closing the writer, primarily in System.Windows.Forms.dll and mscorlib.dll
|
||||
|
||||
//ability to save new script (currently causes an exception) - done
|
||||
//New scripts should be added to lua console automatically - done
|
||||
//make functions is string part of string or comment since the actual way of validating it isn't correct
|
||||
//Save fontstyle to config
|
||||
//Line numbers
|
||||
//Save fontstyle to config - done
|
||||
//Line numbersjn
|
||||
//Option to toggle line numbers
|
||||
//Auto-complete drop down on functions in libraries
|
||||
//Auto-complete drop down on functions in libraries - done
|
||||
//intellisense on library functions
|
||||
//Option to turn off basic lua script
|
||||
//Tool strip
|
||||
|
@ -38,13 +40,24 @@ namespace BizHawk.Client.EmuHawk
|
|||
private bool redo;
|
||||
private bool hasChanged;
|
||||
private bool ProcessingText;
|
||||
|
||||
private bool isFirst;
|
||||
private bool DisableEvent;
|
||||
private int lastLineofText;
|
||||
private int lineIndex;
|
||||
private int previousFirstVisibleChar;
|
||||
|
||||
private readonly char[] Symbols = { '+', '-', '*', '/', '%', '^', '#', '=', '<', '>', '(', ')', '{', '}', '[', ']', ';', ':', ',', '.' };
|
||||
private List<int[]> pos = new List<int[]>();
|
||||
private LuaConsole _owner;
|
||||
|
||||
public LuaWriter()
|
||||
public LuaWriter(LuaConsole owner)
|
||||
{
|
||||
InitializeComponent();
|
||||
isFirst = true;
|
||||
_owner = owner;
|
||||
LuaText.MouseWheel += LuaText_MouseWheel;
|
||||
lineNumbersToolStripMenuItem.Checked = Global.Config.LuaShowLineNumbers;
|
||||
}
|
||||
|
||||
void LuaText_MouseWheel(object sender, MouseEventArgs e)
|
||||
|
@ -54,15 +67,26 @@ namespace BizHawk.Client.EmuHawk
|
|||
Double Zoom;
|
||||
if ((LuaText.ZoomFactor == 0.1F && e.Delta < 0) || (LuaText.ZoomFactor == 5.0F && e.Delta > 0))
|
||||
{
|
||||
Zoom = (LuaText.ZoomFactor*100);
|
||||
Zoom = (LuaText.ZoomFactor * 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
Zoom = (LuaText.ZoomFactor*100) + e.Delta/12;
|
||||
Zoom = (LuaText.ZoomFactor * 100) + e.Delta / 12;
|
||||
}
|
||||
|
||||
ZoomLabel.Text = string.Format("Zoom: {0:0}%", Zoom);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
//UpdateLineTextBox();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LuaText_VScroll(object sender, EventArgs e)
|
||||
{
|
||||
//UpdateLineTextBox();
|
||||
}
|
||||
|
||||
private void timer_Tick(object sender, EventArgs e)
|
||||
|
@ -71,7 +95,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// ProcessText(); // Commenting out until it's fixed to not scroll everything all the time
|
||||
hasChanged = false;
|
||||
}
|
||||
|
@ -102,6 +125,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
ProcessingText = false;
|
||||
LuaText.InhibitPaint = false;
|
||||
LuaText.Refresh();
|
||||
isFirst = false;
|
||||
ShowLuaLineNumbersTextBox();
|
||||
}
|
||||
|
||||
private void AddNumbers()
|
||||
|
@ -452,11 +477,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
private void LoadFont()
|
||||
{
|
||||
LuaText.Font = new Font(Global.Config.LuaWriterFont, Global.Config.LuaWriterFontSize);
|
||||
LuaLineTextBox.Font = new Font(Global.Config.LuaWriterFont, Global.Config.LuaWriterFontSize);
|
||||
}
|
||||
|
||||
private void LuaWriter_Load(object sender, EventArgs e)
|
||||
{
|
||||
//LuaTextFont;
|
||||
|
||||
ProcessingText = true;
|
||||
LuaText.SelectionTabs = new[] { 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360, 380, 400, 420, 480, 500, 520, 540, 560, 580, 600 }; //adelikat: What a goofy way to have to do this
|
||||
LoadFont();
|
||||
|
@ -612,6 +639,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
private void LuaText_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
HasTextChanged();
|
||||
}
|
||||
|
||||
private void HasTextChanged ()
|
||||
{
|
||||
if (!ProcessingText)
|
||||
{
|
||||
|
@ -640,9 +673,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
DialogResult result = f.ShowDialog();
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
LuaText.Font = f.Font;
|
||||
Global.Config.LuaWriterFont = f.Font.Name;
|
||||
Global.Config.LuaWriterFontSize = f.Font.Size;
|
||||
LoadFont();
|
||||
ProcessText(); //Re-update coloring and such when font changes
|
||||
}
|
||||
}
|
||||
|
@ -812,35 +845,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
private void SelectNextItem(bool Next)
|
||||
{
|
||||
|
||||
if (AutoCompleteView.SelectedItems.Count > 0)
|
||||
{
|
||||
if (Next)
|
||||
{
|
||||
if (AutoCompleteView.FocusedItem == AutoCompleteView.Items[AutoCompleteView.Items.Count - 1])
|
||||
return;
|
||||
|
||||
AutoCompleteView.FocusedItem = AutoCompleteView.Items[AutoCompleteView.Items.IndexOf(AutoCompleteView.SelectedItems[0]) + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AutoCompleteView.FocusedItem == AutoCompleteView.Items[0])
|
||||
return;
|
||||
|
||||
AutoCompleteView.FocusedItem = AutoCompleteView.Items[AutoCompleteView.Items.IndexOf(AutoCompleteView.SelectedItems[0]) - 1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Next)
|
||||
AutoCompleteView.FocusedItem = AutoCompleteView.Items[0];
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
private string CurrentWord()
|
||||
{
|
||||
int last = LuaText.SelectionStart;
|
||||
|
@ -915,8 +919,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
private void LuaText_SelectionChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!DisableEvent && Global.Config.LuaShowLineNumbers && !isFirst)
|
||||
{
|
||||
UpdateLineNumber();
|
||||
ShowLuaLineNumbersTextBox();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLineNumber()
|
||||
|
@ -931,6 +939,50 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
private void UpdateLineTextBox()
|
||||
{
|
||||
DisableEvent = true;
|
||||
int currentLocation = LuaText.SelectionStart;
|
||||
int firstVisibleChar = LuaText.GetCharIndexFromPosition(new Point(0,0));
|
||||
LuaText.Select(firstVisibleChar, 0);
|
||||
|
||||
|
||||
if (lastLineofText != LuaText.GetLineFromCharIndex(LuaText.TextLength) || previousFirstVisibleChar != LuaText.GetCharIndexFromPosition(new Point(0, 0)))
|
||||
{
|
||||
previousFirstVisibleChar = firstVisibleChar;
|
||||
lastLineofText = LuaText.GetLineFromCharIndex(LuaText.TextLength);
|
||||
lineIndex = LuaText.GetLineFromCharIndex(firstVisibleChar);
|
||||
if (LuaText.GetLineFromCharIndex(currentLocation) == lastLineofText)
|
||||
{
|
||||
lineIndex++;
|
||||
}
|
||||
|
||||
LuaLineTextBox.Text = String.Empty;
|
||||
for (int i = lineIndex + 1; i <= LuaText.GetLineFromCharIndex(LuaText.TextLength) + 1; i++)
|
||||
{
|
||||
if (i < 10)
|
||||
{
|
||||
LuaLineTextBox.Text += "00" + i;
|
||||
}
|
||||
else if (i >= 10 && i < 100)
|
||||
{
|
||||
LuaLineTextBox.Text += "0" + i;
|
||||
}
|
||||
else
|
||||
{
|
||||
LuaLineTextBox.Text += i;
|
||||
}
|
||||
if (i != LuaText.GetLineFromCharIndex(LuaText.TextLength) + 1)
|
||||
{
|
||||
LuaLineTextBox.Text += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
LuaText.Select(currentLocation, 0);
|
||||
DisableEvent = false;
|
||||
}
|
||||
|
||||
private void LuaText_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
||||
{
|
||||
|
||||
|
@ -938,12 +990,21 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
//TODO: check for changes and ask save
|
||||
Close();
|
||||
}
|
||||
|
||||
private void LuaWriter_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (changes)
|
||||
{
|
||||
var result = MessageBox.Show("Save changes to this Document?", "Lua Writer", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
SaveScript();
|
||||
_owner.LoadLuaFile(CurrentFile);
|
||||
}
|
||||
}
|
||||
|
||||
Global.Config.LuaWriterZoom = LuaText.ZoomFactor;
|
||||
Global.Config.LuaWriterStartEmpty = startWithEmptyScriptToolStripMenuItem.Checked;
|
||||
Global.Config.LuaWriterBackColor = LuaText.BackColor.ToArgb();
|
||||
|
@ -1075,5 +1136,21 @@ namespace BizHawk.Client.EmuHawk
|
|||
redoToolStripMenuItem.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void toolStripMenuItem1_Click(object sender, EventArgs e)
|
||||
{
|
||||
Global.Config.LuaShowLineNumbers = !Global.Config.LuaShowLineNumbers;
|
||||
lineNumbersToolStripMenuItem.Checked = Global.Config.LuaShowLineNumbers;
|
||||
ShowLuaLineNumbersTextBox();
|
||||
}
|
||||
|
||||
private void ShowLuaLineNumbersTextBox()
|
||||
{
|
||||
LuaLineTextBox.Visible = Global.Config.LuaShowLineNumbers ;
|
||||
if (LuaLineTextBox.Visible)
|
||||
{
|
||||
UpdateLineTextBox();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue