Lua Console - open selected file in lua writer dialog, implement drag & drop on lua writer (but fails because it doesn't allow drop on the edit box itself)

This commit is contained in:
adelikat 2012-07-22 20:25:53 +00:00
parent ed16f40529
commit 75bed1f242
3 changed files with 78 additions and 1 deletions

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -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();
}
}
}
}