diff --git a/LPSParser/LPSParser.csproj b/LPSParser/LPSParser.csproj index f72e797..3c75602 100644 --- a/LPSParser/LPSParser.csproj +++ b/LPSParser/LPSParser.csproj @@ -185,12 +185,14 @@ - + + + diff --git a/LPSParser/ToolScript/ListStore.cs b/LPSParser/ToolScript/ListStore.cs new file mode 100644 index 0000000..46b044c --- /dev/null +++ b/LPSParser/ToolScript/ListStore.cs @@ -0,0 +1,48 @@ +using System; +using Gtk; +using GLib; + +namespace LPS.ToolScript +{ + public class ListStore : Gtk.ListStore + { + [Obsolete] + protected ListStore(GType gtype) + : base (gtype) + { + } + + public ListStore(IntPtr raw) + : base (raw) + { + } + + protected ListStore() + : base () + { + } + + public ListStore(params GLib.GType[] types) + : base (types) + { + } + + public ListStore(params Type[] types) + : base (types) + { + } + + public TreeIter GetIter(TreeView view, TreePath path) + { + TreeIter iter; + if(!GetIter(out iter, path)) + throw new InvalidOperationException("Cesta ve stromu není platná"); + return iter; + } + + public object GetValue(TreeView view, TreePath path, long index) + { + return this.GetValue(GetIter(view, path), (int)index); + } + } +} diff --git a/LPSParser/ToolScript/Parser/Expressions/Callable/FunctionExpression.cs b/LPSParser/ToolScript/Parser/Expressions/Callable/FunctionExpression.cs index c3ed721..88ce22e 100644 --- a/LPSParser/ToolScript/Parser/Expressions/Callable/FunctionExpression.cs +++ b/LPSParser/ToolScript/Parser/Expressions/Callable/FunctionExpression.cs @@ -89,9 +89,10 @@ public void Invoke(object sender, EventArgs args) } } - public EventHandler GetEventHandler(IExecutionContext CustomContext) + public Delegate GetEventHandler(Type EventHandlerType, IExecutionContext CustomContext) { - return new EventHandler((new EventHandlerHelper(this, CustomContext)).Invoke); + EventHandlerHelper helper = new EventHandlerHelper(this, CustomContext); + return Delegate.CreateDelegate(EventHandlerType, helper, typeof(EventHandlerHelper).GetMethod("Invoke")); } public override string ToString () diff --git a/LPSParser/ToolScript/Parser/Expressions/Callable/MethodWraper.cs b/LPSParser/ToolScript/Parser/Expressions/Callable/MethodWraper.cs index 2e45770..374b9b8 100644 --- a/LPSParser/ToolScript/Parser/Expressions/Callable/MethodWraper.cs +++ b/LPSParser/ToolScript/Parser/Expressions/Callable/MethodWraper.cs @@ -66,14 +66,14 @@ public object Execute (NamedArgumentList arguments) throw new InvalidOperationException(sb.ToString()); } - public EventHandler GetEventHandler (IExecutionContext CustomContext) + public Delegate GetEventHandler (Type EventHandlerType, IExecutionContext CustomContext) { if(Methods.Length != 1 || Methods[0].GetParameters().Length != 2) throw new Exception("Metoda nelze použít jako event handler"); - return new EventHandler(AsEventHandler); + return Delegate.CreateDelegate(EventHandlerType, this, typeof(MethodWraper).GetMethod("AsEventHandler")); } - private void AsEventHandler(object sender, EventArgs args) + public void AsEventHandler(object sender, EventArgs args) { Methods[0].Invoke(Instance, new object[] {sender, args}); } diff --git a/LPSParser/ToolScript/Parser/Interfaces/IFunction.cs b/LPSParser/ToolScript/Parser/Interfaces/IFunction.cs index 82c59ef..470ea5e 100644 --- a/LPSParser/ToolScript/Parser/Interfaces/IFunction.cs +++ b/LPSParser/ToolScript/Parser/Interfaces/IFunction.cs @@ -5,6 +5,6 @@ namespace LPS.ToolScript.Parser public interface IFunction { object Execute(NamedArgumentList arguments); - EventHandler GetEventHandler(IExecutionContext CustomContext); + Delegate GetEventHandler(Type EventHandlerType, IExecutionContext CustomContext); } } diff --git a/LPSParser/ToolScript/Parser/Window/StoreAndTreeView/ListStoreExpression.cs b/LPSParser/ToolScript/Parser/Window/StoreAndTreeView/ListStoreExpression.cs index a359758..c2d7b01 100644 --- a/LPSParser/ToolScript/Parser/Window/StoreAndTreeView/ListStoreExpression.cs +++ b/LPSParser/ToolScript/Parser/Window/StoreAndTreeView/ListStoreExpression.cs @@ -13,7 +13,7 @@ public ListStoreExpression(EvaluatedAttributeList Params, List("title", ""); + TreeViewColumn column; switch(this.ColumnType) { case "text": - return new TreeViewColumn(title, new CellRendererText(), "text", this.StoreIndex); + column = new TreeViewColumn(title, new CellRendererText(), "text", this.StoreIndex); + break; case "markup": - return new TreeViewColumn(title, new CellRendererText(), "markup", this.StoreIndex); + column = new TreeViewColumn(title, new CellRendererText(), "markup", this.StoreIndex); + break; default: throw new NotSupportedException("Sloupec typu '"+this.ColumnType+"' není podporován"); } + SetColumnAttributes(column, context); + return column; } } diff --git a/LPSParser/ToolScript/Parser/Window/WidgetBase.cs b/LPSParser/ToolScript/Parser/Window/WidgetBase.cs index 7d2e847..8f6a235 100644 --- a/LPSParser/ToolScript/Parser/Window/WidgetBase.cs +++ b/LPSParser/ToolScript/Parser/Window/WidgetBase.cs @@ -109,12 +109,14 @@ private bool SetGtkPropertyValue(MemberInfo member, object attrs) foreach(GLib.SignalAttribute signal in ev.GetCustomAttributes(typeof(GLib.SignalAttribute), true)) { object handler; - if(TryGetAttribute(typeof(object), signal.CName, out handler)) + if(TryGetAttribute(typeof(object), signal.CName.Replace('-','_'), out handler)) { if(handler is Delegate) ev.AddEventHandler(widget, (Delegate)handler); else if(handler is IFunction) - ev.AddEventHandler(widget, ((IFunction)handler).GetEventHandler(context)); + { + ev.AddEventHandler(widget, ((IFunction)handler).GetEventHandler(ev.EventHandlerType, context)); + } else throw new NotSupportedException(); return true; diff --git a/LPSParser/ToolScript/ToolScriptFunction.cs b/LPSParser/ToolScript/ToolScriptFunction.cs index 1f5b981..2818227 100644 --- a/LPSParser/ToolScript/ToolScriptFunction.cs +++ b/LPSParser/ToolScript/ToolScriptFunction.cs @@ -37,7 +37,7 @@ public virtual object Execute (NamedArgumentList arguments) return args.ReturnValue; } - public EventHandler GetEventHandler (IExecutionContext CustomContext) + public Delegate GetEventHandler (Type EventHandlerType, IExecutionContext CustomContext) { throw new NotImplementedException(); } diff --git a/LPSParser/ToolScript/TreeStore.cs b/LPSParser/ToolScript/TreeStore.cs new file mode 100644 index 0000000..d1b6710 --- /dev/null +++ b/LPSParser/ToolScript/TreeStore.cs @@ -0,0 +1,48 @@ +using System; +using GLib; +using Gtk; + +namespace LPS.ToolScript +{ + public class TreeStore : Gtk.TreeStore + { + [Obsolete] + protected TreeStore(GType gtype) + : base (gtype) + { + } + + public TreeStore(IntPtr raw) + : base (raw) + { + } + + protected TreeStore() + : base () + { + } + + public TreeStore(params GLib.GType[] types) + : base (types) + { + } + + public TreeStore(params Type[] types) + : base (types) + { + } + + public TreeIter GetIter(TreeView view, TreePath path) + { + TreeIter iter; + if(!GetIter(out iter, path)) + throw new InvalidOperationException("Cesta ve stromu není platná"); + return iter; + } + + public object GetValue(TreeView view, TreePath path, long index) + { + return this.GetValue(GetIter(view, path), (int)index); + } + } +} diff --git a/LPSUtil/Commands/CommandBase.cs b/LPSUtil/Commands/CommandBase.cs index 91ac3e3..9b6eb89 100644 --- a/LPSUtil/Commands/CommandBase.cs +++ b/LPSUtil/Commands/CommandBase.cs @@ -32,9 +32,9 @@ protected T Get(object[] parameters, int index) public abstract object Execute(IExecutionContext context, TextWriter Out, TextWriter Info, TextWriter Err, object[] Params); - public EventHandler GetEventHandler (IExecutionContext CustomContext) + public Delegate GetEventHandler(Type EventHandlerType, IExecutionContext CustomContext) { - throw new System.NotImplementedException (); + throw new NotImplementedException(); } public override string ToString () diff --git a/LPSUtil/UtilMainWindow.cs b/LPSUtil/UtilMainWindow.cs index 38b5cba..f57e2ec 100644 --- a/LPSUtil/UtilMainWindow.cs +++ b/LPSUtil/UtilMainWindow.cs @@ -24,7 +24,9 @@ public void AddCommand(ICommand cmd) public UtilMainWindow() : base(Gtk.WindowType.Toplevel) { this.Build(); - + + GLib.ExceptionManager.UnhandledException += UnhandledException; + this.WindowPosition = WindowPosition.Center; this.WidthRequest = 800; this.HeightRequest = 500; @@ -52,6 +54,18 @@ public UtilMainWindow() : base(Gtk.WindowType.Toplevel) Instance = this; } + void UnhandledException(GLib.UnhandledExceptionArgs args) + { + if(args.IsTerminating) + return; + TextBuffer buffer = this.outputView.Buffer; + TextMark mark = buffer.CreateMark(null, buffer.EndIter, true); + WriteBufferWithTag("error", "Vyjímka v obsluze signálu:\n{0}\n",args.ExceptionObject); + outputView.ScrollToMark(mark, 0.0, true, 0.0, 0.0); + + args.ExitApplication = false; + } + public void InitCmds() { AddCommand(new LoginCommand("login"));