Skip to content

Commit

Permalink
プラグインのインターフェイスを整備、通知プラグインの表示画面作成
Browse files Browse the repository at this point in the history
  • Loading branch information
Grabacr07 committed Aug 9, 2014
1 parent 815e5e1 commit 99b3d1f
Show file tree
Hide file tree
Showing 33 changed files with 909 additions and 65 deletions.
15 changes: 4 additions & 11 deletions Grabacr07.KanColleViewer/Composition/IPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@

namespace Grabacr07.KanColleViewer.Composition
{
/// <summary>
/// KanColleViewer プラグインの機能を公開します。
/// </summary>
public interface IPlugin
{
/// <summary>
/// プラグインの設定画面を取得します。
/// </summary>
/// <returns></returns>
/// <returns>プラグインの設定画面に表示する UI 要素。</returns>
object GetSettingsView();
}

public interface IPluginMetadata
{
string Name { get; }

[DefaultValue("1.0")]
string Version { get; }

string Author { get; }
}
}
33 changes: 33 additions & 0 deletions Grabacr07.KanColleViewer/Composition/IPluginMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Grabacr07.KanColleViewer.Composition
{
/// <summary>
/// KanColleViewer プラグインのメタデータを公開します。
/// </summary>
public interface IPluginMetadata
{
/// <summary>
/// プラグインのタイトルを取得します。
/// </summary>
string Title { get; }

/// <summary>
/// プラグインが提供する機能を簡潔に説明するテキストを取得します。
/// </summary>
string Description { get; }

/// <summary>
/// プラグインのバージョンを取得します。
/// </summary>
string Version { get; }

/// <summary>
/// プラグインの開発者を取得します。
/// </summary>
string Author { get; }
}
}
14 changes: 7 additions & 7 deletions Grabacr07.KanColleViewer/Composition/PluginHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ public class PluginHost : IDisposable
/// プラグインによって提供される通知機能を表すオブジェクトのシーケンスを取得します。
/// </summary>
/// <value>プラグインによって提供される通知機能を表すオブジェクトのシーケンス。</value>
[ImportMany(typeof(INotifier))]
public IEnumerable<INotifier> Notifiers { get; set; }
[ImportMany]
public IEnumerable<Lazy<INotifier, IPluginMetadata>> Notifiers { get; set; }

/// <summary>
/// プラグインによって提供される
/// プラグインによって提供されるツール機能を表すオブジェクトのシーケンスを取得します。
/// </summary>
[ImportMany(typeof(IToolPlugin))]
public IEnumerable<IToolPlugin> Tools { get; set; }
[ImportMany]
public IEnumerable<Lazy<IToolPlugin, IPluginMetadata>> Tools { get; set; }

/// <summary>
/// インポートされたプラグインのシーケンスを取得します。
/// </summary>
[ImportMany(typeof(IPlugin))]
[ImportMany]
public IEnumerable<Lazy<IPlugin, IPluginMetadata>> Plugins { get; set; }


Expand Down Expand Up @@ -92,7 +92,7 @@ public void Initialize()
/// <returns>ロードされている全ての通知機能を集約して操作するオブジェクト。</returns>
public INotifier GetNotifier()
{
return new AggregateNotifier(this.Notifiers);
return new AggregateNotifier(this.Notifiers.Select(x => x.Value));
}
}
}
14 changes: 13 additions & 1 deletion Grabacr07.KanColleViewer/KanColleViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<Reference Include="Livet.Extensions">
<HintPath>..\packages\LivetExtensions.1.1.0.0\lib\net45\Livet.Extensions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Expression.Drawing" />
<Reference Include="Microsoft.Expression.Drawing, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Expression.Interactions, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\LivetCask.1.1.0.0\lib\net45\Microsoft.Expression.Interactions.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -124,6 +124,7 @@
</ApplicationDefinition>
<Compile Include="Composition\AggregateNotifier.cs" />
<Compile Include="Composition\INotifier.cs" />
<Compile Include="Composition\IPluginMetadata.cs" />
<Compile Include="Composition\IToolPlugin.cs" />
<Compile Include="Composition\NotifyType.cs" />
<Compile Include="Composition\PluginHost.cs" />
Expand All @@ -149,6 +150,10 @@
<Compile Include="ViewModels\Catalogs\SlotItemViewModel.cs" />
<Compile Include="ViewModels\Catalogs\SortableColumnViewModel.cs" />
<Compile Include="ViewModels\Catalogs\ShipCatalogSortWorker.cs" />
<Compile Include="ViewModels\Composition\NotifierViewModel.cs" />
<Compile Include="ViewModels\Composition\PluginViewModel.cs" />
<Compile Include="ViewModels\Composition\PluginViewModelBase.cs" />
<Compile Include="ViewModels\Composition\ToolViewModel.cs" />
<Compile Include="ViewModels\Contents\AdmiralViewModel.cs" />
<Compile Include="ViewModels\Contents\BuildingDockViewModel.cs" />
<Compile Include="ViewModels\Contents\CreatedSlotItemViewModel.cs" />
Expand Down Expand Up @@ -254,6 +259,9 @@
<Compile Include="Views\Settings\Others.xaml.cs">
<DependentUpon>Others.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Settings\PluginInfo.xaml.cs">
<DependentUpon>PluginInfo.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Settings\VersionInfo.xaml.cs">
<DependentUpon>VersionInfo.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -430,6 +438,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Settings\PluginInfo.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Settings\VersionInfo.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Grabacr07.KanColleViewer.Composition;

namespace Grabacr07.KanColleViewer.ViewModels.Composition
{
public class NotifierViewModel : PluginViewModelBase<INotifier>
{
#region ErrorMessage 変更通知プロパティ

private string _ErrorMessage;

public string ErrorMessage
{
get { return this._ErrorMessage; }
set
{
if (this._ErrorMessage != value)
{
this._ErrorMessage = value;
this.RaisePropertyChanged();
}
}
}

#endregion

public NotifierViewModel(Lazy<INotifier, IPluginMetadata> plugin) : base(plugin)
{
this.ErrorMessage = null;
}

public void Test()
{
this.Plugin.Show(NotifyType.Other, "テスト", "これはテスト通知です。", App.ViewModelRoot.Activate, ex => this.ErrorMessage = ex.Message);
}
}
}
14 changes: 14 additions & 0 deletions Grabacr07.KanColleViewer/ViewModels/Composition/PluginViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Grabacr07.KanColleViewer.Composition;

namespace Grabacr07.KanColleViewer.ViewModels.Composition
{
public class PluginViewModel : PluginViewModelBase<IPlugin>
{
public PluginViewModel(Lazy<IPlugin, IPluginMetadata> plugin) : base(plugin) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Grabacr07.KanColleViewer.Composition;
using Livet;

namespace Grabacr07.KanColleViewer.ViewModels.Composition
{
public abstract class PluginViewModelBase<TPlugin> : ViewModel where TPlugin : IPlugin
{
protected TPlugin Plugin { get; private set; }

private IPluginMetadata Metadata { get; set; }


public string Title
{
get { return this.Metadata.Title; }
}

public string Description
{
get { return this.Metadata.Description; }
}

public string Author
{
get { return this.Metadata.Author; }
}

public string Version
{
get { return this.Metadata.Version; }
}


protected PluginViewModelBase(Lazy<TPlugin, IPluginMetadata> plugin)
{
this.Plugin = plugin.Value;
this.Metadata = plugin.Metadata;
}
}
}
29 changes: 29 additions & 0 deletions Grabacr07.KanColleViewer/ViewModels/Composition/ToolViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Grabacr07.KanColleViewer.Composition;

namespace Grabacr07.KanColleViewer.ViewModels.Composition
{
public class ToolViewModel : PluginViewModelBase<IToolPlugin>
{
public ToolViewModel(Lazy<IToolPlugin, IPluginMetadata> plugin) : base(plugin) { }

public string ToolName
{
get { return this.Plugin.ToolName; }
}

public object View
{
get { return this.Plugin.GetToolView(); }
}

public override string ToString()
{
return this.Title;
}
}
}
27 changes: 2 additions & 25 deletions Grabacr07.KanColleViewer/ViewModels/Contents/ToolsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Grabacr07.KanColleViewer.Composition;
using Grabacr07.KanColleViewer.ViewModels.Composition;
using Grabacr07.KanColleWrapper;
using Livet;

Expand Down Expand Up @@ -62,29 +64,4 @@ public ToolsViewModel()
this.SelectedTool = this.Tools.FirstOrDefault();
}
}

public class ToolViewModel : ViewModel
{
private readonly IToolPlugin plugin;

public string Name
{
get { return this.plugin.ToolName; }
}

public object View
{
get { return this.plugin.GetToolView(); }
}

public ToolViewModel(IToolPlugin plugin)
{
this.plugin = plugin;
}

public override string ToString()
{
return this.Name;
}
}
}
Loading

0 comments on commit 99b3d1f

Please sign in to comment.