diff --git a/BizHawk.MultiClient/tools/LuaConsole.cs b/BizHawk.MultiClient/tools/LuaConsole.cs index 9fe70a3d73..68f8673dd9 100644 --- a/BizHawk.MultiClient/tools/LuaConsole.cs +++ b/BizHawk.MultiClient/tools/LuaConsole.cs @@ -1238,8 +1238,36 @@ namespace BizHawk.MultiClient } private void DoLuaWriter() + { + ListView.SelectedIndexCollection indexes = LuaListView.SelectedIndices; + if (indexes.Count == 0) + return; + + if (indexes.Count > 0) + { + //If/When we want multiple file editing + /* + for (int x = 0; x < indexes.Count; x++) + { + var item = luaList[indexes[x]]; + if (!item.IsSeparator) + { + OpenLuaWriter(luaList[indexes[x]].Path); + } + } + */ + var item = luaList[indexes[0]]; + if (!item.IsSeparator) + { + OpenLuaWriter(luaList[indexes[0]].Path); + } + } + } + + private void OpenLuaWriter(string path) { LuaWriter writer = new LuaWriter(); + writer.CurrentFile = path; writer.Show(); } } diff --git a/BizHawk.MultiClient/tools/LuaWriter.Designer.cs b/BizHawk.MultiClient/tools/LuaWriter.Designer.cs index 6254eb6eca..608a7f758a 100644 --- a/BizHawk.MultiClient/tools/LuaWriter.Designer.cs +++ b/BizHawk.MultiClient/tools/LuaWriter.Designer.cs @@ -29,7 +29,7 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - this.LuaText = new LuaWriterBox(); + this.LuaText = new BizHawk.MultiClient.LuaWriterBox(); this.timer = new System.Windows.Forms.Timer(this.components); this.SuspendLayout(); // @@ -52,6 +52,7 @@ // // 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(843, 441); @@ -59,6 +60,8 @@ this.Name = "LuaWriter"; this.Text = "LuaWriter"; this.Load += new System.EventHandler(this.LuaWriter_Load); + this.DragDrop += new System.Windows.Forms.DragEventHandler(this.LuaWriter_DragDrop); + this.DragEnter += new System.Windows.Forms.DragEventHandler(this.LuaWriter_DragEnter); this.ResumeLayout(false); } diff --git a/BizHawk.MultiClient/tools/LuaWriter.cs b/BizHawk.MultiClient/tools/LuaWriter.cs index 3b0589151d..4a6558ac17 100644 --- a/BizHawk.MultiClient/tools/LuaWriter.cs +++ b/BizHawk.MultiClient/tools/LuaWriter.cs @@ -7,11 +7,13 @@ using System.Linq; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions; +using System.IO; namespace BizHawk.MultiClient { public partial class LuaWriter : Form { + public string CurrentFile = ""; public Regex keyWords = new Regex("and|break|do|else|if|end|false|for|function|in|local|nil|not|or|repeat|return|then|true|until|while|elseif"); public LuaWriter() { @@ -163,7 +165,51 @@ namespace BizHawk.MultiClient private void LuaWriter_Load(object sender, EventArgs e) { + if (!String.IsNullOrWhiteSpace(CurrentFile)) + { + LoadCurrentFile(); + } + } + private void LoadCurrentFile() + { + var file = new FileInfo(CurrentFile); + if (file.Exists == false) + { + return; + } + + using (StreamReader sr = file.OpenText()) + { + StringBuilder luaText = new StringBuilder(); + string s = ""; + while ((s = sr.ReadLine()) != null) + { + luaText.Append(s); + luaText.Append('\n'); + } + + if (luaText.Length > 0) + { + LuaText.Text = luaText.ToString(); + } + } + } + + private void LuaWriter_DragEnter(object sender, DragEventArgs e) + { + e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None; string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); + } + + private void LuaWriter_DragDrop(object sender, DragEventArgs e) + { + string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); + if (Path.GetExtension(filePaths[0]) == (".lua") || Path.GetExtension(filePaths[0]) == (".txt")) + { + //TODO: save changes + CurrentFile = filePaths[0]; + LoadCurrentFile(); + } } } } \ No newline at end of file