Lua Console - implementing changes tracking and asking to save changes

This commit is contained in:
adelikat 2012-03-17 22:23:52 +00:00
parent 97f32bde91
commit 300f68e8b7
2 changed files with 35 additions and 10 deletions

View File

@ -371,6 +371,7 @@
this.moveUpToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.U)));
this.moveUpToolStripMenuItem.Size = new System.Drawing.Size(195, 22);
this.moveUpToolStripMenuItem.Text = "Move &Up";
this.moveUpToolStripMenuItem.Click += new System.EventHandler(this.moveUpToolStripMenuItem_Click_1);
//
// moveDownToolStripMenuItem
//
@ -379,6 +380,7 @@
this.moveDownToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D)));
this.moveDownToolStripMenuItem.Size = new System.Drawing.Size(195, 22);
this.moveDownToolStripMenuItem.Text = "Move &Down";
this.moveDownToolStripMenuItem.Click += new System.EventHandler(this.moveDownToolStripMenuItem_Click_1);
//
// selectAllToolStripMenuItem
//

View File

@ -20,6 +20,7 @@ namespace BizHawk.MultiClient
//TODO: restore column width on restore default settings
//TODO: load scripts from recent scripts menu
//TODO: context menu & main menu - Edit is grayed out if seperator is highlighted
//Stop all scripts should be grayed if all lua scripts are disabled
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight;
@ -27,7 +28,7 @@ namespace BizHawk.MultiClient
List<LuaFiles> luaList = new List<LuaFiles>();
public LuaImplementation LuaImp;
string lastLuaFile = "";
bool changes = true; //TODO
bool changes = false;
private List<LuaFiles> GetLuaFileList()
{
@ -89,6 +90,7 @@ namespace BizHawk.MultiClient
luaList[x].Enabled = false;
LuaImp.Close();
LuaImp = new LuaImplementation(this);
changes = true;
}
private void StopAllScripts()
@ -97,6 +99,7 @@ namespace BizHawk.MultiClient
luaList[x].Enabled = false;
LuaImp.Close();
LuaImp = new LuaImplementation(this);
changes = true;
}
public void Restart()
@ -168,6 +171,7 @@ namespace BizHawk.MultiClient
LuaListView.Refresh();
Global.Config.RecentLua.Add(path);
LuaImp.DoLuaFile(path);
changes = true;
}
private void OpenLuaFile()
@ -215,6 +219,7 @@ namespace BizHawk.MultiClient
LuaListView.Refresh();
UpdateNumberOfScripts();
RunLuaScripts();
changes = true;
}
private void RunLuaScripts()
@ -297,12 +302,18 @@ namespace BizHawk.MultiClient
private void NewLuaSession(bool suppressAsk)
{
//TODO: ask save
StopAllScripts();
ClearOutput();
luaList.Clear();
DisplayLuaList();
UpdateNumberOfScripts();
bool result = true;
if (changes) result = AskSave();
if (result == true || suppressAsk)
{
StopAllScripts();
ClearOutput();
luaList.Clear();
DisplayLuaList();
UpdateNumberOfScripts();
changes = false;
}
}
private void turnOffAllScriptsToolStripMenuItem_Click(object sender, EventArgs e)
@ -328,7 +339,7 @@ namespace BizHawk.MultiClient
private void RemoveScript()
{
if (luaList.Count == 0) return;
//Changes();
changes = true;
ListView.SelectedIndexCollection indexes = LuaListView.SelectedIndices;
if (indexes.Count > 0)
{
@ -368,6 +379,7 @@ namespace BizHawk.MultiClient
luaList.Add(f);
DisplayLuaList();
LuaListView.Refresh();
changes = true;
}
private void insertSeperatorToolStripMenuItem1_Click(object sender, EventArgs e)
@ -752,7 +764,8 @@ namespace BizHawk.MultiClient
SaveSession(file.FullName);
currentSessionFile = file.FullName;
AddText('\n' + Path.GetFileName(currentSessionFile) + " saved.");
//Global.Config.Recent.RecentWatches.Add(file.FullName);
Global.Config.RecentLuaSession.Add(file.FullName);
changes = false;
}
}
@ -784,7 +797,7 @@ namespace BizHawk.MultiClient
private void fileToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{
if (string.Compare(currentSessionFile, "") == 0) // || !changes) //TODO: changes
if (string.Compare(currentSessionFile, "") == 0 || !changes)
{
saveToolStripMenuItem.Enabled = false;
}
@ -873,5 +886,15 @@ namespace BizHawk.MultiClient
}
return true;
}
private void moveUpToolStripMenuItem_Click_1(object sender, EventArgs e)
{
MoveUp();
}
private void moveDownToolStripMenuItem_Click_1(object sender, EventArgs e)
{
MoveDown();
}
}
}