Skip to content

Commit

Permalink
Fix PluginUIElement for Contacts UI Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrster committed Apr 4, 2017
1 parent 4aeb0e5 commit 784cf66
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 94 deletions.
36 changes: 36 additions & 0 deletions ContactPoint.BaseDesign/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions ContactPoint.BaseDesign/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,16 @@
<data name="close1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\close1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ContactsListForm_Name" xml:space="preserve">
<value>Name</value>
</data>
<data name="ContactsListForm_Company" xml:space="preserve">
<value>Company</value>
</data>
<data name="ContactsListForm_Phone_numbers" xml:space="preserve">
<value>Phone numbers</value>
</data>
<data name="ContactsListForm_Note" xml:space="preserve">
<value>Note</value>
</data>
</root>
5 changes: 5 additions & 0 deletions ContactPoint.Core/PluginManager/PluginCheckedUIElement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ContactPoint.Common;
using ContactPoint.Common.PluginManager;

namespace ContactPoint.Core.PluginManager
Expand All @@ -17,24 +18,28 @@ protected sealed override void ExecuteCheckedCommand(object sender, bool checked
}
catch (NotImplementedException)
{
Logger.LogNotice($"Failed to execute checked command for '{sender}', checked value is '{checkedValue}', data is '{data}'");
try
{
InternalExecute(sender);
}
catch (NotImplementedException)
{
Logger.LogNotice($"Failed to re-execute checked command for '{sender}' only");
throw new NotImplementedException();
}
}
}

protected virtual void InternalExecute(object sender)
{
Logger.LogError("Invalid PluginCheckedUIElement instance - method 'InternalExecute(sender)' is not implemented");
throw new NotImplementedException();
}

protected virtual void InternalExecute(object sender, object data)
{
Logger.LogError("Invalid PluginCheckedUIElement instance - method 'InternalExecute(sender, data)' is not implemented");
throw new NotImplementedException();
}
}
Expand Down
5 changes: 5 additions & 0 deletions ContactPoint.Core/PluginManager/PluginUIElement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ContactPoint.Common;
using ContactPoint.Common.PluginManager;

namespace ContactPoint.Core.PluginManager
Expand All @@ -17,24 +18,28 @@ protected sealed override void ExecuteCommand(object sender, object data)
}
catch (NotImplementedException)
{
Logger.LogNotice($"Failed to execute checked command for '{sender}', data is '{data}'");
try
{
InternalExecute(sender);
}
catch (NotImplementedException)
{
Logger.LogNotice($"Failed to re-execute checked command for '{sender}' only");
throw new NotImplementedException();
}
}
}

protected virtual void InternalExecute(object sender)
{
Logger.LogError("Invalid PluginUIElement instance - method 'InternalExecute(sender)' is not implemented");
throw new NotImplementedException();
}

protected virtual void InternalExecute(object sender, object data)
{
Logger.LogError("Invalid PluginUIElement instance - method 'InternalExecute(sender, data)' is not implemented");
throw new NotImplementedException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>..\..\Binaries\Plugins\ContactsUI\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -43,6 +43,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RegisterForComInterop>false</RegisterForComInterop>
<Prefer32Bit>false</Prefer32Bit>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
Expand Down Expand Up @@ -92,6 +93,7 @@
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ContactsCommand.cs" />
<Compile Include="ContactsUiService.cs" />
<Compile Include="Controls\AddPhoneEmailControl.cs">
<SubType>UserControl</SubType>
Expand Down
48 changes: 48 additions & 0 deletions ContactPoint.Plugins.ContactsUi/ContactsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using ContactPoint.Common.PluginManager;
using ContactPoint.Core.PluginManager;
using ContactPoint.Plugins.ContactsUi.Forms;

namespace ContactPoint.Plugins.ContactsUi
{
internal class ContactsCommand : PluginUIElementBase
{
private static ContactsListForm _formInstance;

public ContactsCommand(IPlugin plugin) : base(plugin)
{ }

public override Guid ActionCode { get; } = new Guid("{F024D728-831F-4F9B-BD13-E156B3CF484A}");

public override Bitmap Image => Properties.Resources.contacts1;
public override string Text => "Contacts";
public override IEnumerable<IPluginUIElement> Childrens => null;
public override bool ShowInMenu => true;
public override bool ShowInToolBar => true;
public override bool ShowInNotifyMenu => true;

protected override void ExecuteCommand(object sender, object data)
{
lock (this)
{
if (_formInstance == null)
{
_formInstance = new ContactsListForm(Plugin.PluginManager.Core.ContactsManager);
_formInstance.Closing += FormInstanceClosing;
}

_formInstance.Show();
}
}

private void FormInstanceClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
lock (this)
{
_formInstance = null;
}
}
}
}
90 changes: 5 additions & 85 deletions ContactPoint.Plugins.ContactsUi/ContactsUiService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using ContactPoint.Common.PluginManager;
using ContactPoint.Core.PluginManager;
using ContactPoint.Plugins.ContactsUi.Forms;

namespace ContactPoint.Plugins.ContactsUi
{
Expand All @@ -17,91 +12,16 @@ public class ContactsUiService : Plugin
public ContactsUiService(IPluginManager pluginManager)
: base(pluginManager)
{
_uiElements = new IPluginUIElement[] {new ContactsCommand(this)};
_uiElements = new IPluginUIElement[] { new ContactsCommand(this) };
}

public override IEnumerable<IPluginUIElement> UIElements
{
get { return _uiElements; }
}
public override IEnumerable<IPluginUIElement> UIElements => _uiElements;
public override bool IsStarted => true;

public override void Start()
{
}
{ }

public override void Stop()
{
}

public override bool IsStarted
{
get { return true; }
}
}

internal class ContactsCommand : PluginUIElement
{
private readonly Guid _actionCode = new Guid("{F024D728-831F-4F9B-BD13-E156B3CF484A}");
private static ContactsListForm _formInstance = null;

public ContactsCommand(IPlugin plugin) : base(plugin)
{ }

public override Bitmap Image
{
get { return Properties.Resources.contacts1; }
}

public override string Text
{
get { return "Contacts"; }
}

public override IEnumerable<IPluginUIElement> Childrens
{
get { return null; }
}

public override Guid ActionCode
{
get { return _actionCode; }
}

public override bool ShowInMenu
{
get { return true; }
}

public override bool ShowInToolBar
{
get { return true; }
}

public override bool ShowInNotifyMenu
{
get { return true; }
}

protected override void InternalExecute(object sender)
{
lock (this)
{
if (_formInstance == null)
{
_formInstance = new ContactsListForm(Plugin.PluginManager.Core.ContactsManager);
_formInstance.Closing += FormInstanceClosing;
}
}

_formInstance.Show();
}

void FormInstanceClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
lock (this)
{
_formInstance = null;
}
}
}
}
21 changes: 13 additions & 8 deletions ContactPoint.Plugins.ContactsUi/Forms/ContactsListForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using ContactPoint.BaseDesign.Components;
using ContactPoint.BaseDesign.Properties;
using ContactPoint.Common.Contacts;
using ContactPoint.Common.Contacts.Local;
using ContactPoint.Plugins.ContactsUi.ViewModels;
Expand All @@ -14,7 +15,7 @@ namespace ContactPoint.Plugins.ContactsUi.Forms
public partial class ContactsListForm : KryptonForm
{
private readonly IContactsManager _contactsManager;
private AdvancedBindingSource<ContactViewModel> _bindingSource;
private readonly AdvancedBindingSource<ContactViewModel> _bindingSource;
private readonly Dictionary<long, ContactViewModel> _contactViewModels = new Dictionary<long, ContactViewModel>();

public ContactsListForm(IContactsManager contactsManager)
Expand All @@ -31,11 +32,11 @@ public ContactsListForm(IContactsManager contactsManager)

dataGridView.Columns.Clear();
dataGridView.Columns.AddRange(
new DataGridViewTextBoxColumn() { HeaderText = "Name", Name = "ShowedName", SortMode = DataGridViewColumnSortMode.NotSortable, Width = 250, DataPropertyName = "ShowedName" },
new DataGridViewTextBoxColumn() { HeaderText = "Company", Name = "Company", SortMode = DataGridViewColumnSortMode.NotSortable, Width = 100, DataPropertyName = "Company" },
new DataGridViewTextBoxColumn() { HeaderText = "Phone numbers", Name = "PhoneNumbersString", SortMode = DataGridViewColumnSortMode.NotSortable, Width = 250, DataPropertyName = "PhoneNumbersString" },
//new DataGridViewTagsColumns() { HeaderText = "Tags", Name = "Tags", SortMode = DataGridViewColumnSortMode.NotSortable, Width = 300, DataPropertyName = "TagLocals" },
new DataGridViewTextBoxColumn() { HeaderText = "Note", Name = "Note", SortMode = DataGridViewColumnSortMode.NotSortable, DataPropertyName = "Note", AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill }
new DataGridViewTextBoxColumn { HeaderText = Resources.ContactsListForm_Name, Name = "ShowedName", SortMode = DataGridViewColumnSortMode.NotSortable, Width = 250, DataPropertyName = "ShowedName" },
new DataGridViewTextBoxColumn { HeaderText = Resources.ContactsListForm_Company, Name = Resources.ContactsListForm_Company, SortMode = DataGridViewColumnSortMode.NotSortable, Width = 100, DataPropertyName = Resources.ContactsListForm_Company },
new DataGridViewTextBoxColumn { HeaderText = Resources.ContactsListForm_Phone_numbers, Name = "PhoneNumbersString", SortMode = DataGridViewColumnSortMode.NotSortable, Width = 250, DataPropertyName = "PhoneNumbersString" },
//new DataGridViewTagsColumns { HeaderText = "Tags", Name = "Tags", SortMode = DataGridViewColumnSortMode.NotSortable, Width = 300, DataPropertyName = "TagLocals" },
new DataGridViewTextBoxColumn { HeaderText = Resources.ContactsListForm_Note, Name = Resources.ContactsListForm_Note, SortMode = DataGridViewColumnSortMode.NotSortable, DataPropertyName = Resources.ContactsListForm_Note, AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill }
);

dataGridView.DataSource = _bindingSource;
Expand Down Expand Up @@ -176,14 +177,18 @@ public void ReloadContacts()
{
if (textBoxSearch.Text.Length > 0)
{
var filterParts = textBoxSearch.Text.Split(new[] { ' ' });
var filterParts = textBoxSearch.Text.Split(' ');

dataGridView.DataSource = new ObservableCollection<ContactViewModel>(
_contactsManager.Contacts.Where(x => filterParts.All(f => MatchTag(f, x) || MatchPhone(f, x) || MatchAll(f, x))).Select(GetContactViewModel)
_contactsManager.Contacts
.Where(x => filterParts.All(f => MatchTag(f, x) || MatchPhone(f, x) || MatchAll(f, x)))
.Select(GetContactViewModel)
);
}
else
{
dataGridView.DataSource = new ObservableCollection<ContactViewModel>(_contactsManager.Contacts.Select(GetContactViewModel));
}
}

private bool MatchAll(string pattern, IContact contact)
Expand Down

0 comments on commit 784cf66

Please sign in to comment.