Browse Source

ResourceToolkit: Added a ToolBarCheckBox to the unused resource keys view to filter out the ICSharpCode.Core host application resources. Improved performance when the list view is filled.

ToolBarCheckBox: Expose the caller and set the owner of the MenuCommand.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1885 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Christian Hornung 19 years ago
parent
commit
5f78877937
  1. BIN
      data/resources/StringResources.de.resources
  2. BIN
      data/resources/StringResources.es-mx.resources
  3. BIN
      data/resources/StringResources.es.resources
  4. BIN
      data/resources/StringResources.hu.resources
  5. BIN
      data/resources/StringResources.nl.resources
  6. 13
      src/AddIns/Misc/ResourceToolkit/Project/Hornung.ResourceToolkit.addin
  7. 5
      src/AddIns/Misc/ResourceToolkit/Project/ResourceToolkit.csproj
  8. 62
      src/AddIns/Misc/ResourceToolkit/Project/Src/Conditions/SolutionContainsProjectOrReferenceConditionEvaluator.cs
  9. 24
      src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/IFilter.cs
  10. 31
      src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/IFilterHost.cs
  11. 49
      src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/UnusedResourceKeysCommands.cs
  12. 125
      src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/UnusedResourceKeysViewContent.cs
  13. 7
      src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/ICSharpCodeCoreResourceResolver.cs
  14. 7
      src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/ToolBarItem/Gui/ToolBarCheckBox.cs
  15. BIN
      src/Main/StartUp/Project/Resources/StringResources.resources

BIN
data/resources/StringResources.de.resources

Binary file not shown.

BIN
data/resources/StringResources.es-mx.resources

Binary file not shown.

BIN
data/resources/StringResources.es.resources

Binary file not shown.

BIN
data/resources/StringResources.hu.resources

Binary file not shown.

BIN
data/resources/StringResources.nl.resources

Binary file not shown.

13
src/AddIns/Misc/ResourceToolkit/Project/Hornung.ResourceToolkit.addin

@ -10,12 +10,12 @@ @@ -10,12 +10,12 @@
</Manifest>
<Runtime>
<Import assembly = "Hornung.ResourceToolkit.dll"/>
<Import assembly = "Hornung.ResourceToolkit.dll">
<ConditionEvaluator name="SolutionContainsProjectOrReference" class="Hornung.ResourceToolkit.Conditions.SolutionContainsProjectOrReferenceConditionEvaluator"/>
</Import>
<Import assembly = ":ICSharpCode.SharpDevelop"/>
</Runtime>
<StringResources file = "Resources\StringResources.resources" />
<!-- Code completion -->
<Path name = "/AddIns/DefaultTextEditor/CodeCompletion">
@ -74,6 +74,13 @@ @@ -74,6 +74,13 @@
<!-- Unused resource keys toolbar -->
<Path name="/AddIns/ResourceToolkit/ViewContent/UnusedResourceKeys/Toolbar">
<Condition name="SolutionContainsProjectOrReference" itemName="ICSharpCode.Core" action="Exclude">
<ToolbarItem id = "HideICSharpCodeCoreHostResources"
type = "CheckBox"
label = "${res:Hornung.ResourceToolkit.UnusedResourceKeys.HideICSharpCodeCoreHostResourcesTitle}"
tooltip = "${res:Hornung.ResourceToolkit.UnusedResourceKeys.HideICSharpCodeCoreHostResourcesTooltip}"
class = "Hornung.ResourceToolkit.Gui.UnusedResourceKeysHideICSharpCodeCoreHostResourcesCommand" />
</Condition>
</Path>
<!-- Unused resource keys context menu -->

5
src/AddIns/Misc/ResourceToolkit/Project/ResourceToolkit.csproj

@ -85,6 +85,10 @@ @@ -85,6 +85,10 @@
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Src\Conditions\SolutionContainsProjectOrReferenceConditionEvaluator.cs" />
<Compile Include="Src\Gui\UnusedResourceKeysCommands.cs" />
<Compile Include="Src\Gui\IFilter.cs" />
<Compile Include="Src\Gui\IFilterHost.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj">
@ -126,6 +130,7 @@ @@ -126,6 +130,7 @@
<Name>NRefactory</Name>
<Private>False</Private>
</ProjectReference>
<Folder Include="Src\Conditions" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

62
src/AddIns/Misc/ResourceToolkit/Project/Src/Conditions/SolutionContainsProjectOrReferenceConditionEvaluator.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
namespace Hornung.ResourceToolkit.Conditions
{
/// <summary>
/// Checks whether a solution is open and contains a either a project or a
/// reference with the specified name.
/// </summary>
/// <attribute name="itemName">
/// The name of the project or reference to find.
/// </attribute>
/// <example title="Check whether the open solution uses ICSharpCode.Core">
/// &lt;Condition name = "SolutionContainsProjectOrReference" itemName = "ICSharpCode.Core"&gt;
/// </example>
public class SolutionContainsProjectOrReferenceConditionEvaluator : IConditionEvaluator
{
public bool IsValid(object caller, Condition condition)
{
if (ProjectService.OpenSolution == null) {
return false;
}
foreach (IProject p in ProjectService.OpenSolution.Projects) {
// Check project name
if (p.Name.Equals(condition.Properties["itemName"], StringComparison.InvariantCultureIgnoreCase)) {
return true;
}
// Check references
foreach (ProjectItem pi in p.Items) {
ReferenceProjectItem rpi = pi as ReferenceProjectItem;
if (rpi != null) {
if (rpi.Name.Equals(condition.Properties["itemName"], StringComparison.InvariantCultureIgnoreCase)) {
return true;
}
}
}
}
return false;
}
/// <summary>
/// Initalizes a new instance of the <see cref="SolutionContainsProjectOrReferenceConditionEvaluator"/> class.
/// </summary>
public SolutionContainsProjectOrReferenceConditionEvaluator()
{
}
}
}

24
src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/IFilter.cs

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
namespace Hornung.ResourceToolkit.Gui
{
/// <summary>
/// Describes an object that applies a filter condition to items.
/// </summary>
public interface IFilter<T>
{
/// <summary>
/// Determines if the specified item matches the current filter criteria.
/// </summary>
/// <param name="item">The item to test.</param>
/// <returns><c>true</c>, if the specified item matches the current filter criteria, otherwise <c>false</c>.</returns>
bool IsMatch(T item);
}
}

31
src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/IFilterHost.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
namespace Hornung.ResourceToolkit.Gui
{
/// <summary>
/// Describes an object that can filter items by registering
/// one or more <see cref="IFilter"/> objects.
/// </summary>
public interface IFilterHost<T>
{
/// <summary>
/// Registers a new filter with the filter host, if the filter is not already registered,
/// or signals that the filter condition of the specified filter has changed.
/// </summary>
/// <param name="filter">The filter to be registered.</param>
void RegisterFilter(IFilter<T> filter);
/// <summary>
/// Removes the specified filter from the filter host, if it is currently registered there.
/// </summary>
/// <param name="filter">The filter to be removed.</param>
void UnregisterFilter(IFilter<T> filter);
}
}

49
src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/UnusedResourceKeysCommands.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using Hornung.ResourceToolkit.Resolver;
namespace Hornung.ResourceToolkit.Gui
{
/// <summary>
/// Hides or shows the ICSharpCode.Core host resources in an UnusedResourceKeysViewContent.
/// </summary>
public class UnusedResourceKeysHideICSharpCodeCoreHostResourcesCommand : AbstractCheckableMenuCommand, IFilter<KeyValuePair<string, string>>
{
string icSharpCodeCoreHostResourceFileName;
public override void Run()
{
base.Run();
IFilterHost<KeyValuePair<string, string>> host = ((ToolBarCheckBox)this.Owner).Caller as IFilterHost<KeyValuePair<string, string>>;
if (host != null) {
if (this.IsChecked) {
this.icSharpCodeCoreHostResourceFileName = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceFileName(null);
host.RegisterFilter(this);
} else {
host.UnregisterFilter(this);
}
}
}
/// <summary>
/// Determines if the specified item matches the current filter criteria.
/// </summary>
/// <param name="item">The item to test.</param>
/// <returns><c>true</c>, if the specified item matches the current filter criteria, otherwise <c>false</c>.</returns>
public bool IsMatch(KeyValuePair<string, string> item)
{
return !FileUtility.IsEqualFileName(item.Value, this.icSharpCodeCoreHostResourceFileName);
}
}
}

125
src/AddIns/Misc/ResourceToolkit/Project/Src/Gui/UnusedResourceKeysViewContent.cs

@ -22,11 +22,12 @@ namespace Hornung.ResourceToolkit.Gui @@ -22,11 +22,12 @@ namespace Hornung.ResourceToolkit.Gui
/// <summary>
/// Displays unused resource keys in a list and allows the user to delete them.
/// </summary>
public class UnusedResourceKeysViewContent : AbstractViewContent, IClipboardHandler
public class UnusedResourceKeysViewContent : AbstractViewContent, IClipboardHandler, IFilterHost<KeyValuePair<string, string>>
{
readonly ICollection<KeyValuePair<string, string>> unusedKeys;
Panel panel;
ListView listView;
ToolStrip toolStrip;
public override System.Windows.Forms.Control Control {
get {
@ -74,7 +75,6 @@ namespace Hornung.ResourceToolkit.Gui @@ -74,7 +75,6 @@ namespace Hornung.ResourceToolkit.Gui
this.ListView.Columns.Add(StringParser.Parse("${res:Hornung.ResourceToolkit.FileName}"), 60);
this.ListView.Columns.Add(StringParser.Parse("${res:Hornung.ResourceToolkit.Key}"), 140);
this.ListView.Columns.Add(StringParser.Parse("${res:Hornung.ResourceToolkit.Value}"), 140);
this.ListView.CheckBoxes = true;
this.ListView.View = View.Details;
this.ListView.FullRowSelect = true;
this.ListView.ShowItemToolTips = true;
@ -90,9 +90,10 @@ namespace Hornung.ResourceToolkit.Gui @@ -90,9 +90,10 @@ namespace Hornung.ResourceToolkit.Gui
this.ListView.HandleCreated += this.ListViewHandleCreated;
this.ListView.ContextMenuStrip = MenuService.CreateContextMenu(this, "/AddIns/ResourceToolkit/ViewContent/UnusedResourceKeys/ListViewContextMenu");
ToolStrip toolStrip = ToolbarService.CreateToolStrip(this, "/AddIns/ResourceToolkit/ViewContent/UnusedResourceKeys/Toolbar");
toolStrip.Dock = DockStyle.Top;
toolStrip.Stretch = true;
this.toolStrip = ToolbarService.CreateToolStrip(this, "/AddIns/ResourceToolkit/ViewContent/UnusedResourceKeys/Toolbar");
this.toolStrip.Dock = DockStyle.Top;
this.toolStrip.Stretch = true;
this.toolStrip.VisibleChanged += this.ToolStripVisibleChanged;
this.panel.Controls.Add(this.ListView);
this.panel.Controls.Add(toolStrip);
@ -102,16 +103,32 @@ namespace Hornung.ResourceToolkit.Gui @@ -102,16 +103,32 @@ namespace Hornung.ResourceToolkit.Gui
void ListViewHandleCreated(object sender, EventArgs e)
{
this.ListView.HandleCreated -= this.ListViewHandleCreated;
this.ListView.BeginInvoke(new Action<ICollection<KeyValuePair<string, string>>>(this.FillListView), this.UnusedKeys);
this.FillListView();
}
void ToolStripVisibleChanged(object sender, EventArgs e)
{
if (this.toolStrip.Visible) {
this.toolStrip.VisibleChanged -= this.ToolStripVisibleChanged;
ToolbarService.UpdateToolbar(this.toolStrip);
}
}
public override void Dispose()
{
this.panel.Controls.Clear();
this.ListView.Dispose();
this.listView = null;
this.panel.Dispose();
this.panel = null;
if (this.toolStrip != null) {
this.toolStrip.Dispose();
this.toolStrip = null;
}
if (this.listView != null) {
this.listView.Dispose();
this.listView = null;
}
if (this.panel != null) {
this.panel.Dispose();
this.panel = null;
}
base.Dispose();
}
@ -127,25 +144,47 @@ namespace Hornung.ResourceToolkit.Gui @@ -127,25 +144,47 @@ namespace Hornung.ResourceToolkit.Gui
}
}
bool fillListViewQueued = false;
/// <summary>
/// Fills the list view with the specified resource keys.
/// Fills the list view with all unused resource keys that match the current filter after processing the message queue.
/// </summary>
/// <param name="resources">A collection of key/value pairs where the values are the resource file names and the keys are the resource keys.</param>
public void FillListView(ICollection<KeyValuePair<string, string>> resources)
public void FillListView()
{
if (!this.fillListViewQueued) {
this.fillListViewQueued = true;
this.ListView.BeginInvoke(new MethodInvoker(this.FillListViewInternal));
}
}
/// <summary>
/// Fills the list view with all unused resource keys that match the current filter.
/// </summary>
void FillListViewInternal()
{
Application.DoEvents();
Cursor oldCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
try {
this.ListView.Items.Clear();
this.ListView.Groups.Clear();
// Suspend sorting to improve performance
System.Collections.IComparer comparer = this.ListView.ListViewItemSorter;
this.ListView.ListViewItemSorter = null;
this.ListView.BeginUpdate();
Dictionary<string, ListViewGroup> fileGroups = new Dictionary<string, ListViewGroup>();
// Create the ListViewItems.
foreach (KeyValuePair<string, string> entry in resources) {
foreach (KeyValuePair<string, string> entry in this.UnusedKeys) {
// Skip if any filter rejects this item.
if (!this.ItemMatchesCurrentFilter(entry)) {
continue;
}
IResourceFileContent c = ResourceFileContentRegistry.GetResourceFileContent(entry.Value);
object o;
@ -172,13 +211,71 @@ namespace Hornung.ResourceToolkit.Gui @@ -172,13 +211,71 @@ namespace Hornung.ResourceToolkit.Gui
this.ListView.Items.Add(item);
}
this.ListView.ListViewItemSorter = comparer;
this.ListView.EndUpdate();
} finally {
this.fillListViewQueued = false;
Cursor.Current = oldCursor;
}
}
#region Filter
readonly List<IFilter<KeyValuePair<string, string>>> filters = new List<IFilter<KeyValuePair<string, string>>>();
/// <summary>
/// Registers a new filter with the filter host, if the filter is not already registered,
/// or signals that the filter condition of the specified filter has changed.
/// </summary>
/// <param name="filter">The filter to be registered.</param>
/// <exception cref="ArgumentNullException">The <paramref name="filter"/> parameter is <c>null</c>.</exception>
public void RegisterFilter(IFilter<KeyValuePair<string, string>> filter)
{
if (filter == null) {
throw new ArgumentNullException("filter");
}
if (!this.filters.Contains(filter)) {
this.filters.Add(filter);
}
this.FillListView();
}
/// <summary>
/// Removes the specified filter from the filter host, if it is currently registered there.
/// </summary>
/// <param name="filter">The filter to be removed.</param>
/// <exception cref="ArgumentNullException">The <paramref name="filter"/> parameter is <c>null</c>.</exception>
public void UnregisterFilter(IFilter<KeyValuePair<string, string>> filter)
{
if (filter == null) {
throw new ArgumentNullException("filter");
}
this.filters.Remove(filter);
this.FillListView();
}
/// <summary>
/// Determines whether the specified resource should be included in the list
/// according to the current filter.
/// </summary>
/// <returns><c>true</c>, if the resource should be included in the list view, otherwise <c>false</c>.</returns>
bool ItemMatchesCurrentFilter(KeyValuePair<string, string> item)
{
foreach (IFilter<KeyValuePair<string, string>> filter in this.filters) {
if (!filter.IsMatch(item)) {
return false;
}
}
return true;
}
#endregion
// ********************************************************************************************************************************
#region IClipboardHandler implementation

7
src/AddIns/Misc/ResourceToolkit/Project/Src/Resolver/ICSharpCodeCoreResourceResolver.cs

@ -223,9 +223,6 @@ namespace Hornung.ResourceToolkit.Resolver @@ -223,9 +223,6 @@ namespace Hornung.ResourceToolkit.Resolver
public static string GetICSharpCodeCoreHostResourceFileName(string sourceFileName)
{
IProject project = ProjectFileDictionaryService.GetProjectForFile(sourceFileName);
if (project == null || String.IsNullOrEmpty(project.Directory)) {
return null;
}
// Get SD directory using the reference to ICSharpCode.Core
string coreAssemblyFullPath = GetICSharpCodeCoreFullPath(project);
@ -261,6 +258,10 @@ namespace Hornung.ResourceToolkit.Resolver @@ -261,6 +258,10 @@ namespace Hornung.ResourceToolkit.Resolver
static string GetICSharpCodeCoreFullPath(IProject sourceProject)
{
if (sourceProject == null) {
return null;
}
string coreAssemblyFullPath = null;
if (sourceProject.Name.Equals("ICSharpCode.Core", StringComparison.InvariantCultureIgnoreCase)) {

7
src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/ToolBarItem/Gui/ToolBarCheckBox.cs

@ -23,6 +23,12 @@ namespace ICSharpCode.Core @@ -23,6 +23,12 @@ namespace ICSharpCode.Core
}
}
public object Caller {
get {
return caller;
}
}
public string Description {
get {
return description;
@ -50,6 +56,7 @@ namespace ICSharpCode.Core @@ -50,6 +56,7 @@ namespace ICSharpCode.Core
if (menuCommand == null) {
MessageService.ShowError("Can't create toolbar checkbox : " + codon.Id);
}
menuCommand.Owner = this;
if (codon.Properties.Contains("label")){
Text = StringParser.Parse(codon.Properties["label"]);

BIN
src/Main/StartUp/Project/Resources/StringResources.resources

Binary file not shown.
Loading…
Cancel
Save