fix null exception

This commit is contained in:
Jaex 2015-02-16 16:21:19 +02:00
parent a128cb9c0b
commit 395be0d69c
4 changed files with 29 additions and 11 deletions

View file

@ -23,6 +23,7 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
using ShareX.HelpersLib.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -34,6 +35,18 @@ namespace ShareX.HelpersLib
{
public partial class AutomateForm : Form
{
public string Script
{
get
{
return rtbInput.Text;
}
set
{
rtbInput.Text = value;
}
}
private FunctionManager functionManager = new FunctionManager();
private Tokenizer tokenizer = new Tokenizer();
private bool isWorking;
@ -43,8 +56,9 @@ public AutomateForm()
InitializeComponent();
Icon = ShareXResources.Icon;
tokenizer.Keywords = FunctionManager.Functions.Select(x => x.Key).ToArray();
Tokenize();
cbFunctions.Items.AddRange(tokenizer.Keywords);
cbFunctions.SelectedIndex = 0;
Tokenize();
}
private void rtbInput_TextChanged(object sender, EventArgs e)
@ -110,8 +124,8 @@ private void btnRun_Click(object sender, EventArgs e)
btnRun.Enabled = false;
string[] lines = rtbInput.Lines;
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
bw.DoWork += bw_DoWork;
bw.RunWorkerCompleted += bw_RunWorkerCompleted;
bw.RunWorkerAsync(lines);
}
}
@ -127,7 +141,7 @@ private void bw_DoWork(object sender, DoWorkEventArgs e)
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(ex.ToString(), Resources.ExportImportControl_Serialize_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

View file

@ -119,9 +119,9 @@
</resheader>
<data name="rtbInput.Text" xml:space="preserve">
<value>Wait 2000
Goto TestFunction
Call TestFunction
5 KeyPress key_z
3 Goto MyFunction
3 Call MyFunction
KeyPress return
Func TestFunction

View file

@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
@ -44,7 +45,7 @@ public Function()
public void Run()
{
Console.WriteLine(string.Format("{0}({1})", Name, string.Join(", ", Parameters)));
Debug.WriteLine("{0}({1})", Name, string.Join(", ", Parameters));
for (int i = 0; i < Loop; i++)
{
@ -61,7 +62,7 @@ protected virtual void Method()
}
}
public class Function_Goto : Function
public class Function_Call : Function
{
public override void Prepare()
{

View file

@ -35,10 +35,10 @@ public class FunctionManager
public static readonly Dictionary<string, Type> Functions = new Dictionary<string, Type>()
{
{ "Func", typeof(Function) },
{ "Goto", typeof(Function_Goto) },
{ "Call", typeof(Function_Call) },
{ "Wait", typeof(Function_Wait) },
{ "KeyDown", typeof(Function_KeyDown) },
{ "KeyUp", typeof(Function_KeyDown) },
{ "KeyUp", typeof(Function_KeyUp) },
{ "KeyPress", typeof(Function_KeyPress) },
{ "KeyPressText", typeof(Function_KeyPressText) },
{ "MouseDown", typeof(Function_MouseDown) },
@ -124,7 +124,10 @@ public bool Compile(string[] lines)
foreach (Function function in FunctionList)
{
function.Prepare();
if (function != null)
{
function.Prepare();
}
}
return true;