Browse Source

add highlighting for filtered items in ResourceEditor; filter by Content and Comment columns as well

pull/567/head
Siegfried Pammer 11 years ago
parent
commit
0d92381d74
  1. 3
      src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj
  2. 10
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs
  3. 84
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs
  4. 5
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml
  5. 22
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml.cs
  6. 7
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml
  7. 55
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/RichTextBlock.cs

3
src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj

@ -92,6 +92,9 @@ @@ -92,6 +92,9 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Views\ResourceItemIcons.cs" />
<Compile Include="Src\Views\RichTextBlock.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Views\TextView.xaml.cs">
<DependentUpon>TextView.xaml</DependentUpon>
<SubType>Code</SubType>

10
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs

@ -143,8 +143,14 @@ namespace ResourceEditor.ViewModels @@ -143,8 +143,14 @@ namespace ResourceEditor.ViewModels
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, (s, e) => SelectAll(), (s, e) => e.CanExecute = EnableSelectAll));
view.FilterPredicate = resourceItem => {
if (!resourceItem.IsNew && (SearchTerm != null))
return resourceItem.Name.IndexOf(SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0;
if (!resourceItem.IsNew && (SearchTerm != null)) {
bool isMatch = resourceItem.Name.IndexOf(SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0
|| ((resourceItem.Content ?? "").IndexOf(SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0)
|| ((resourceItem.Comment ?? "").IndexOf(SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0);
if (isMatch)
resourceItem.Highlight(SearchTerm);
return isMatch;
}
return true;
};
view.SelectionChanged += View_SelectionChanged;

84
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs

@ -21,6 +21,7 @@ using System.ComponentModel; @@ -21,6 +21,7 @@ using System.ComponentModel;
using System.Drawing;
using System.Resources;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop;
@ -45,6 +46,7 @@ namespace ResourceEditor.ViewModels @@ -45,6 +46,7 @@ namespace ResourceEditor.ViewModels
ResourceItemEditorType resourceType;
ResourceEditorViewModel resourceEditor;
string nameBeforeEditing;
string highlightText;
public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue)
{
@ -80,13 +82,27 @@ namespace ResourceEditor.ViewModels @@ -80,13 +82,27 @@ namespace ResourceEditor.ViewModels
public static readonly DependencyProperty NameProperty =
DependencyProperty.Register("Name", typeof(string), typeof(ResourceItem),
new FrameworkPropertyMetadata());
new FrameworkPropertyMetadata(NamePropertyChanged));
static void NamePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
((ResourceItem)obj).Highlight(((ResourceItem)obj).highlightText);
}
public string Name {
get { return (string)GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
public static readonly DependencyProperty DisplayNameProperty =
DependencyProperty.Register("DisplayName", typeof(object), typeof(ResourceItem),
new FrameworkPropertyMetadata());
public object DisplayName {
get { return (object)GetValue(DisplayNameProperty); }
set { SetValue(DisplayNameProperty, value); }
}
public static readonly DependencyProperty SortingCriteriaProperty =
DependencyProperty.Register("SortingCriteria", typeof(string), typeof(ResourceItem),
new FrameworkPropertyMetadata());
@ -102,7 +118,7 @@ namespace ResourceEditor.ViewModels @@ -102,7 +118,7 @@ namespace ResourceEditor.ViewModels
public object ResourceValue {
get { return (object)GetValue(ResourceValueProperty); }
set { SetValue(ResourceValueProperty, value); }
set { SetValue(ResourceValueProperty, value); Highlight(highlightText); }
}
public string DisplayedResourceType {
@ -135,9 +151,16 @@ namespace ResourceEditor.ViewModels @@ -135,9 +151,16 @@ namespace ResourceEditor.ViewModels
{
base.OnPropertyChanged(e);
if (e.Property.Name == DisplayNameProperty.Name
|| e.Property.Name == RichContentProperty.Name
|| e.Property.Name == RichCommentProperty.Name) {
return;
}
if (e.Property.Name == ResourceValueProperty.Name) {
// Update content property as well
RaisePropertyChanged("Content");
Highlight(highlightText);
}
if (e.Property.Name == IsEditingProperty.Name) {
bool previouslyEditing = (bool)e.OldValue;
@ -200,14 +223,32 @@ namespace ResourceEditor.ViewModels @@ -200,14 +223,32 @@ namespace ResourceEditor.ViewModels
}
}
public static readonly DependencyProperty RichContentProperty =
DependencyProperty.Register("RichContent", typeof(object), typeof(ResourceItem),
new FrameworkPropertyMetadata());
public object RichContent {
get { return (object)GetValue(RichContentProperty); }
set { SetValue(RichContentProperty, value); }
}
public static readonly DependencyProperty CommentProperty =
DependencyProperty.Register("Comment", typeof(string), typeof(ResourceItem),
new FrameworkPropertyMetadata());
new FrameworkPropertyMetadata(""));
public string Comment {
get { return (string)GetValue(CommentProperty); }
set { SetValue(CommentProperty, value); }
}
public static readonly DependencyProperty RichCommentProperty =
DependencyProperty.Register("RichComment", typeof(object), typeof(ResourceItem),
new FrameworkPropertyMetadata());
public object RichComment {
get { return (object)GetValue(RichCommentProperty); }
set { SetValue(RichCommentProperty, value); }
}
public override string ToString()
{
@ -299,5 +340,42 @@ namespace ResourceEditor.ViewModels @@ -299,5 +340,42 @@ namespace ResourceEditor.ViewModels
return false;
}
public void Highlight(string text)
{
this.highlightText = text;
if (string.IsNullOrEmpty(text)) {
DisplayName = Name;
RichContent = Content;
RichComment = Comment;
} else {
DisplayName = CreateSpan(Name, text);
RichContent = CreateSpan(Content ?? "", text);
RichComment = CreateSpan(Comment ?? "", text);
}
RaisePropertyChanged("DisplayName");
RaisePropertyChanged("RichContent");
RaisePropertyChanged("RichComment");
}
Span CreateSpan(string text, string matchText)
{
int startIndex = 0;
int match;
var span = new Span();
do {
match = text.IndexOf(matchText, startIndex, StringComparison.OrdinalIgnoreCase);
if (match > -1) {
span.Inlines.Add(new Run(text.Substring(startIndex, match - startIndex)));
span.Inlines.Add(new Span(new Run(text.Substring(match, matchText.Length))) {
Background = System.Windows.Media.Brushes.Yellow
});
} else {
span.Inlines.Add(new Run(text.Substring(startIndex, text.Length - startIndex)));
}
startIndex = match + matchText.Length;
} while (match > -1);
return span;
}
}
}

5
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml

@ -1,11 +1,12 @@ @@ -1,11 +1,12 @@
<UserControl x:Class="ResourceEditor.Views.InPlaceEditLabel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:resv="clr-namespace:ResourceEditor.Views"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Margin="0,0,0,0">
<TextBlock Name="readOnlyTextBlock" Text="{Binding Path=Text, Mode=TwoWay}" VerticalAlignment="Top" Margin="0,0,0,0" />
<TextBlock Name="readOnlyTextBlock" VerticalAlignment="Top" Margin="0,0,0,0" />
<TextBox
Name="editingTextBox"
Text="{Binding Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding Text}"
VerticalAlignment="Top"
Margin="0,0,0,0"
TextChanged="EditingTextBox_TextChanged"

22
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
namespace ResourceEditor.Views
@ -36,7 +37,6 @@ namespace ResourceEditor.Views @@ -36,7 +37,6 @@ namespace ResourceEditor.Views
InitializeComponent();
editingTextBox.Visibility = Visibility.Collapsed;
readOnlyTextBlock.Visibility = Visibility.Visible;
readOnlyTextBlock.DataContext = this;
editingTextBox.DataContext = this;
}
@ -49,6 +49,26 @@ namespace ResourceEditor.Views @@ -49,6 +49,26 @@ namespace ResourceEditor.Views
set { SetValue(TextProperty, value); }
}
public static readonly DependencyProperty DisplayTextProperty =
DependencyProperty.Register("DisplayText", typeof(object), typeof(InPlaceEditLabel),
new FrameworkPropertyMetadata(OnDisplayTextChanged));
static void OnDisplayTextChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var textBlock = ((InPlaceEditLabel)obj).readOnlyTextBlock;
if (e.NewValue is Span) {
textBlock.Inlines.Clear();
textBlock.Inlines.Add((Span)e.NewValue);
} else {
textBlock.Text = e.NewValue.ToString();
}
}
public object DisplayText {
get { return (object)GetValue(DisplayTextProperty); }
set { SetValue(DisplayTextProperty, value); }
}
public static readonly DependencyProperty IsEditingProperty =
DependencyProperty.Register("IsEditing", typeof(bool), typeof(InPlaceEditLabel),
new FrameworkPropertyMetadata());

7
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml

@ -63,6 +63,7 @@ @@ -63,6 +63,7 @@
</Image>
<resv:InPlaceEditLabel Grid.Column="1"
Text="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
DisplayText="{Binding DisplayName}"
VerticalAlignment="Top"
Margin="0,0,0,0"
MinWidth="300"
@ -74,19 +75,19 @@ @@ -74,19 +75,19 @@
<DataTemplate x:Key="resourceItemTypeTemplate" DataType="{x:Type resvm:ResourceItem}">
<Border BorderBrush="LightGray" BorderThickness="0,0,1,1" Margin="-6,-2,-6,-2">
<TextBlock Text="{Binding DisplayedResourceType}" Margin="6,2,6,2" />
<resv:RichTextBlock Content="{Binding DisplayedResourceType}" Margin="6,2,6,2" />
</Border>
</DataTemplate>
<DataTemplate x:Key="resourceItemContentTemplate" DataType="{x:Type resvm:ResourceItem}">
<Border BorderBrush="LightGray" BorderThickness="0,0,1,1" Margin="-6,-2,-6,-2">
<TextBlock Text="{Binding Content}" Margin="6,2,6,2" />
<resv:RichTextBlock Content="{Binding RichContent}" Margin="6,2,6,2" />
</Border>
</DataTemplate>
<DataTemplate x:Key="resourceItemCommentTemplate" DataType="{x:Type resvm:ResourceItem}">
<Border BorderBrush="LightGray" BorderThickness="0,0,1,1" Margin="-6,-2,-6,-2">
<TextBlock Text="{Binding Comment}" Margin="6,2,6,2" MinWidth="300" />
<resv:RichTextBlock Content="{Binding RichComment}" Margin="6,2,6,2" MinWidth="300" />
</Border>
</DataTemplate>
</UserControl.Resources>

55
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/RichTextBlock.cs

@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace ResourceEditor.Views
{
public class RichTextBlock : TextBlock
{
public static readonly DependencyProperty ContentProperty =
DependencyProperty.Register("Content", typeof(object), typeof(RichTextBlock),
new FrameworkPropertyMetadata(OnContentChanged));
public object Content {
get { return (object)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}
static void OnContentChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var instance = ((RichTextBlock)obj);
if (e.NewValue is Inline) {
instance.Inlines.Clear();
instance.Inlines.Add((Inline)e.NewValue);
} else if (e.NewValue != null) {
instance.Text = e.NewValue.ToString();
} else {
instance.Text = null;
}
}
}
}
Loading…
Cancel
Save