Skip to content

Commit

Permalink
change module and service evant handling:
Browse files Browse the repository at this point in the history
* 'sender' is now PluginManager instance
* custom EventArgs classes including the IService or ILanguageModule instances
  • Loading branch information
maul.esel committed Apr 27, 2012
1 parent b51fdab commit cf5e286
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 35 deletions.
2 changes: 2 additions & 0 deletions ChameleonCoder.Core/ChameleonCoder.Core.csproj
Expand Up @@ -72,8 +72,10 @@
<Compile Include="Plugins\IRichContentFactory.cs" />
<Compile Include="Plugins\IService.cs" />
<Compile Include="Plugins\ITemplate.cs" />
<Compile Include="Plugins\ModuleEventArgs.cs" />
<Compile Include="Plugins\NoWrapperTemplateAttribute.cs" />
<Compile Include="Plugins\PluginManager.cs" />
<Compile Include="Plugins\ServiceEventArgs.cs" />
<Compile Include="Plugins\Syntax\IProvideSyntaxInfo.cs" />
<Compile Include="Plugins\Syntax\SyntaxElement.cs" />
<Compile Include="Plugins\TemplateDefaultNameAttribute.cs" />
Expand Down
21 changes: 21 additions & 0 deletions ChameleonCoder.Core/Plugins/ModuleEventArgs.cs
@@ -0,0 +1,21 @@
using System.Runtime.InteropServices;

namespace ChameleonCoder.Plugins
{
[ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual)]
public class ModuleEventArgs : System.EventArgs
{
internal ModuleEventArgs(ILanguageModule module)
{
moduleInstance = module;
}

public ILanguageModule Module
{
get { return moduleInstance; }
}

[ComVisible(false)]
private readonly ILanguageModule moduleInstance = null;
}
}
40 changes: 20 additions & 20 deletions ChameleonCoder.Core/Plugins/PluginManager.cs
Expand Up @@ -14,14 +14,14 @@ namespace ChameleonCoder.Plugins
/// </summary>
/// <param name="sender">the LanguageModule raising the event</param>
/// <param name="e">additional data</param>
public delegate void LanguageModuleEventHandler(object sender, EventArgs e);
public delegate void LanguageModuleEventHandler(object sender, ModuleEventArgs e);

/// <summary>
/// a delegate for Service Events
/// </summary>
/// <param name="sender">the service raising the event</param>
/// <param name="e">additional data</param>
public delegate void ServiceEventHandler(object sender, EventArgs e);
public delegate void ServiceEventHandler(object sender, ServiceEventArgs e);

#endregion

Expand Down Expand Up @@ -220,7 +220,7 @@ public void LoadModule(Guid id)
ILanguageModule module;
if (Modules.TryGetValue(id, out module))
{
OnModuleLoad(module, new EventArgs());
OnModuleLoad(module);

module.Load();
ActiveModule = module;
Expand All @@ -238,7 +238,7 @@ public void LoadModule(Guid id)
module.Name, module.Version, module.Author, module.About);
*/

OnModuleLoaded(module, new EventArgs());
OnModuleLoaded(module);
}
else
throw new ArgumentException("this module is not registered!\nGuid: " + id.ToString("b"));
Expand All @@ -254,7 +254,7 @@ public void UnloadModule()
throw new InvalidOperationException("Module cannot be unloaded: no module loaded!");

ILanguageModule module = ActiveModule;
OnModuleUnload(ActiveModule, new EventArgs());
OnModuleUnload(ActiveModule);

ActiveModule.Unload();
ActiveModule = null;
Expand All @@ -270,7 +270,7 @@ public void UnloadModule()
ChameleonCoderApp.Window.CurrentModule.Text = string.Empty;
*/

OnModuleUnloaded(module, new EventArgs());
OnModuleUnloaded(module);
}

/// <summary>
Expand Down Expand Up @@ -337,7 +337,7 @@ public void CallService(Guid id)
{
IService service = GetService(id);

OnServiceExecute(service, new EventArgs());
OnServiceExecute(service);

/*
* moved to Mainwindow using event handler for IF.ServiceExecute
Expand All @@ -355,7 +355,7 @@ public void CallService(Guid id)
ChameleonCoderApp.Window.CurrentAction.Text = string.Empty;
*/

OnServiceExecuted(service, new EventArgs());
OnServiceExecuted(service);
}

/// <summary>
Expand Down Expand Up @@ -498,11 +498,11 @@ public bool IsRichContentFactoryRegistered(IRichContentFactory factory)
/// <param name="sender">the module raising the event</param>
/// <param name="e">additional data</param>
[ComVisible(false)]
internal void OnModuleLoad(ILanguageModule sender, EventArgs e)
internal void OnModuleLoad(ILanguageModule module)
{
LanguageModuleEventHandler handler = ModuleLoad;
if (handler != null)
handler(sender, e);
handler(this, new ModuleEventArgs(module));
}

/// <summary>
Expand All @@ -511,11 +511,11 @@ internal void OnModuleLoad(ILanguageModule sender, EventArgs e)
/// <param name="sender">the module raising the event</param>
/// <param name="e">additional data</param>
[ComVisible(false)]
internal void OnModuleLoaded(ILanguageModule sender, EventArgs e)
internal void OnModuleLoaded(ILanguageModule module)
{
LanguageModuleEventHandler handler = ModuleLoaded;
if (handler != null)
handler(sender, e);
handler(this, new ModuleEventArgs(module));
}

/// <summary>
Expand All @@ -524,11 +524,11 @@ internal void OnModuleLoaded(ILanguageModule sender, EventArgs e)
/// <param name="sender">the module raising the event</param>
/// <param name="e">additional data</param>
[ComVisible(false)]
internal void OnModuleUnload(ILanguageModule sender, EventArgs e)
internal void OnModuleUnload(ILanguageModule module)
{
LanguageModuleEventHandler handler = ModuleUnload;
if (handler != null)
handler(sender, e);
handler(this, new ModuleEventArgs(module));
}

/// <summary>
Expand All @@ -537,11 +537,11 @@ internal void OnModuleUnload(ILanguageModule sender, EventArgs e)
/// <param name="sender">the module raising the event</param>
/// <param name="e">additional data</param>
[ComVisible(false)]
internal void OnModuleUnloaded(ILanguageModule sender, EventArgs e)
internal void OnModuleUnloaded(ILanguageModule module)
{
LanguageModuleEventHandler handler = ModuleUnloaded;
if (handler != null)
handler(sender, e);
handler(this, new ModuleEventArgs(module));
}

/// <summary>
Expand All @@ -550,11 +550,11 @@ internal void OnModuleUnloaded(ILanguageModule sender, EventArgs e)
/// <param name="sender">the service raising the event</param>
/// <param name="e">additional data</param>
[ComVisible(false)]
internal void OnServiceExecute(IService sender, EventArgs e)
internal void OnServiceExecute(IService service)
{
ServiceEventHandler handler = ServiceExecute;
if (handler != null)
handler(sender, e);
handler(this, new ServiceEventArgs(service));
}

/// <summary>
Expand All @@ -563,11 +563,11 @@ internal void OnServiceExecute(IService sender, EventArgs e)
/// <param name="sender">the service raising the event</param>
/// <param name="e">additional data</param>
[ComVisible(false)]
internal void OnServiceExecuted(IService sender, EventArgs e)
internal void OnServiceExecuted(IService service)
{
ServiceEventHandler handler = ServiceExecuted;
if (handler != null)
handler(sender, e);
handler(this, new ServiceEventArgs(service));
}

#endregion
Expand Down
21 changes: 21 additions & 0 deletions ChameleonCoder.Core/Plugins/ServiceEventArgs.cs
@@ -0,0 +1,21 @@
using System.Runtime.InteropServices;

namespace ChameleonCoder.Plugins
{
[ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual)]
public class ServiceEventArgs : System.EventArgs
{
internal ServiceEventArgs(IService service)
{
serviceInstance = service;
}

public IService Service
{
get { return serviceInstance; }
}

[ComVisible(false)]
private readonly IService serviceInstance = null;
}
}
26 changes: 11 additions & 15 deletions ChameleonCoder/MainWindow.xaml.cs
Expand Up @@ -117,27 +117,25 @@ private void FilterChanged(object sender, RoutedEventArgs e)
}

#region temp
private void ModuleLoaded(object sender, EventArgs e)
private void ModuleLoaded(object sender, Plugins.ModuleEventArgs e)
{
var module = sender as Plugins.ILanguageModule;
if (module != null)
if (e.Module != null)
{
if (!ChameleonCoderApp.RunningApp.Dispatcher.CheckAccess())
{
ChameleonCoderApp.RunningApp.Dispatcher.BeginInvoke(new Action(() =>
CurrentModule.Text = string.Format(Properties.Resources.ModuleInfo,
module.Name, module.Version, module.Author, module.About)));
e.Module.Name, e.Module.Version, e.Module.Author, e.Module.About)));
}
else
CurrentModule.Text = string.Format(Properties.Resources.ModuleInfo,
module.Name, module.Version, module.Author, module.About);
e.Module.Name, e.Module.Version, e.Module.Author, e.Module.About);
}
}

private void ModuleUnloaded(object sender, EventArgs e)
private void ModuleUnloaded(object sender, Plugins.ModuleEventArgs e)
{
var module = sender as Plugins.ILanguageModule;
if (module != null)
if (e.Module != null)
{
if (!ChameleonCoderApp.RunningApp.Dispatcher.CheckAccess())
{
Expand All @@ -149,20 +147,18 @@ private void ModuleUnloaded(object sender, EventArgs e)
}
}

private void ServiceExecute(object sender, EventArgs e)
private void ServiceExecute(object sender, Plugins.ServiceEventArgs e)
{
var service = sender as Plugins.IService;
if (service != null)
if (e.Service != null)
{
CurrentActionProgress.IsIndeterminate = true;
CurrentAction.Text = string.Format(Properties.Resources.ServiceInfo, service.Name, service.Version, service.Author, service.About);
CurrentAction.Text = string.Format(Properties.Resources.ServiceInfo, e.Service.Name, e.Service.Version, e.Service.Author, e.Service.About);
}
}

private void ServiceExecuted(object sender, EventArgs e)
private void ServiceExecuted(object sender, Plugins.ServiceEventArgs e)
{
var service = sender as Plugins.IService;
if (service != null)
if (e.Service != null)
{
CurrentActionProgress.IsIndeterminate = false;
CurrentAction.Text = string.Empty;
Expand Down

0 comments on commit cf5e286

Please sign in to comment.