Browse Source

- Re-introduced BinaryView and BooleanView in ResourceEditor.

- Added resource strings for some labels not localized until now.
- Added error messages shown to user in some error cases.
- Ctrl+F in list now jumps to filter text box.
pull/567/head
Andreas Weizel 11 years ago
parent
commit
0cc5009c8a
  1. 15
      data/resources/StringResources.resx
  2. 5
      src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.addin
  3. 1
      src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj
  4. 38
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddBooleanEntryCommand.cs
  5. 12
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs
  6. 2
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs
  7. 2
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEditorDisplayBinding.cs
  8. 23
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs
  9. 31
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs
  10. 23
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml
  11. 104
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml.cs
  12. 24
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml
  13. 38
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml.cs
  14. 2
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml.cs
  15. 2
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml
  16. 5
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml.cs

15
data/resources/StringResources.resx

@ -6331,7 +6331,7 @@ Removed the end part of the original message ", reason '${Message}'" since this @@ -6331,7 +6331,7 @@ Removed the end part of the original message ", reason '${Message}'" since this
</data>
<data name="ResourceEditor.BitmapView.UpdateBitmap" xml:space="preserve">
<value>Update bitmap ...</value>
<comment>Text for the link label that make it possible to update the stored bitmap</comment>
<comment>Text for the button that makes it possible to update the stored bitmap</comment>
</data>
<data name="ResourceEditor.DeleteEntry.Confirm" xml:space="preserve">
<value>Do you really want to delete the selected resource(s)?</value>
@ -8237,4 +8237,17 @@ a line break</value> @@ -8237,4 +8237,17 @@ a line break</value>
<data name="MainWindow.Windows.TaskList.CurrentClass" xml:space="preserve">
<value>Class/Module</value>
</data>
<data name="ResourceEditor.BitmapView.UpdateIcon" xml:space="preserve">
<value>Update icon ...</value>
<comment>Text for the button that makes it possible to update the stored icon</comment>
</data>
<data name="ResourceEditor.Messages.CantLoadResourceFromFile" xml:space="preserve">
<value>Can't load resource from file: {0}</value>
</data>
<data name="ResourceEditor.ResourceEdit.ContextMenu.AddBooleanEntry" xml:space="preserve">
<value>Add &amp;boolean entry</value>
</data>
<data name="ResourceEditor.Filter" xml:space="preserve">
<value>Filter:</value>
</data>
</root>

5
src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.addin

@ -30,8 +30,11 @@ @@ -30,8 +30,11 @@
<Path name="/SharpDevelop/ResourceEditor/ResourceList/ContextMenu">
<MenuItem id="AddStringEntry"
label="${res:ResourceEditor.ResourceEdit.ContextMenu.AddStringEntry}"
class="ResourceEditor.Commands.AddStringCommand"
class="ResourceEditor.Commands.AddStringEntryCommand"
shortcut = "Insert" />
<MenuItem id="AddBooleanEntry"
label="${res:ResourceEditor.ResourceEdit.ContextMenu.AddBooleanEntry}"
class="ResourceEditor.Commands.AddBooleanEntryCommand" />
<MenuItem id="AddFile"
label="${res:ResourceEditor.ResourceEdit.ContextMenu.AddFiles}"

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

@ -58,6 +58,7 @@ @@ -58,6 +58,7 @@
<ItemGroup>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\BitmapExtensions.cs" />
<Compile Include="Src\Commands\AddBooleanEntryCommand.cs" />
<Compile Include="Src\Commands\AddNewFileCommand.cs" />
<Compile Include="Src\Commands\AddStringEntryCommand.cs" />
<Compile Include="Src\Commands\CopyResourceNameCommand.cs" />

38
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddBooleanEntryCommand.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
// 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.Linq;
using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands
{
class AddBooleanEntryCommand : ResourceItemCommand
{
public override bool EmptySelectionAllowed {
get {
return true;
}
}
public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceItem> resourceItems)
{
ResourceEditor.AddBooleanEntry();
}
}
}

12
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs

@ -21,6 +21,7 @@ using System.IO; @@ -21,6 +21,7 @@ using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using Microsoft.Win32;
using ResourceEditor.ViewModels;
@ -80,13 +81,15 @@ namespace ResourceEditor.Commands @@ -80,13 +81,15 @@ namespace ResourceEditor.Commands
case ".CUR":
try {
return new System.Windows.Forms.Cursor(name);
} catch {
} catch (Exception ex) {
SD.MessageService.ShowWarningFormatted("${res:ResourceEditor.Messages.CantLoadResourceFromFile}", ex.Message);
return null;
}
case ".ICO":
try {
return new System.Drawing.Icon(name);
} catch {
} catch (Exception ex) {
SD.MessageService.ShowWarningFormatted("${res:ResourceEditor.Messages.CantLoadResourceFromFile}", ex.Message);
return null;
}
default:
@ -118,9 +121,8 @@ namespace ResourceEditor.Commands @@ -118,9 +121,8 @@ namespace ResourceEditor.Commands
d = r.ReadBytes((int)s.Length);
s.Close();
return d;
} catch (Exception) {
string message = ResourceService.GetString("ResourceEditor.Messages.CantLoadResource");
MessageService.ShowWarning(message + " " + name + ".");
} catch (Exception ex) {
SD.MessageService.ShowWarningFormatted("${res:ResourceEditor.Messages.CantLoadResourceFromFile}", ex.Message);
}
break;
}

2
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs

@ -22,7 +22,7 @@ using ResourceEditor.ViewModels; @@ -22,7 +22,7 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands
{
class AddStringCommand : ResourceItemCommand
class AddStringEntryCommand : ResourceItemCommand
{
public override bool EmptySelectionAllowed {
get {

2
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEditorDisplayBinding.cs

@ -69,6 +69,8 @@ namespace ResourceEditor @@ -69,6 +69,8 @@ namespace ResourceEditor
resourceEditor.AddItemView(ResourceItemEditorType.String, new TextView());
resourceEditor.AddItemView(ResourceItemEditorType.Bitmap, new ImageViewBase());
resourceEditor.AddItemView(ResourceItemEditorType.Icon, new ImageViewBase());
resourceEditor.AddItemView(ResourceItemEditorType.Binary, new BinaryView());
resourceEditor.AddItemView(ResourceItemEditorType.Boolean, new BooleanView());
resourceEditor.DirtyStateChanged += (sender, e) => {
if (e.IsDirty)
SetDirty(sender, new EventArgs());

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

@ -267,6 +267,29 @@ namespace ResourceEditor.ViewModels @@ -267,6 +267,29 @@ namespace ResourceEditor.ViewModels
StartEditing();
}
public void AddBooleanEntry()
{
int count = 1;
string newNameBase = "New boolean entry ";
string newName = newNameBase + count;
while (ContainsResourceName(newName)) {
count++;
newName = newNameBase + count;
}
var selectedItem = GetSelectedItems().FirstOrDefault();
ResourceItem item = new ResourceItem(this, newName, false);
item.IsNew = true;
if (selectedItem != null)
item.SortingCriteria = selectedItem.Name;
else
item.SortingCriteria = item.Name;
ResourceItems.Add(item);
SelectItem(item);
StartEditing();
}
void StartUpdate()
{
// When loading many items at once, temporarily unbind view from model

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

@ -134,7 +134,7 @@ namespace ResourceEditor.ViewModels @@ -134,7 +134,7 @@ namespace ResourceEditor.ViewModels
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property.Name == ResourceValueProperty.Name) {
// Update content property as well
RaisePropertyChanged("Content");
@ -148,13 +148,18 @@ namespace ResourceEditor.ViewModels @@ -148,13 +148,18 @@ namespace ResourceEditor.ViewModels
} else if (previouslyEditing && !isEditing) {
// Make dirty, if name has changed after finishing edit
if (nameBeforeEditing != Name) {
// Check if new name is valid
if (!String.IsNullOrEmpty(Name) && !resourceEditor.ContainsResourceName(Name)) {
// New name
if (String.IsNullOrEmpty(Name)) {
// Empty name is not valid -> revert silently
Name = nameBeforeEditing;
} else if (resourceEditor.ContainsResourceName(Name)) {
// Resource names must be unique -> revert and show message
SD.MessageService.ShowWarning("${res:ResourceEditor.ResourceList.KeyAlreadyDefinedWarning}");
Name = nameBeforeEditing;
} else {
// New name seems to be valid
SortingCriteria = Name;
resourceEditor.MakeDirty();
} else {
// New name was not valid, revert it to the value before editing
Name = nameBeforeEditing;
}
}
IsNew = false;
@ -263,13 +268,21 @@ namespace ResourceEditor.ViewModels @@ -263,13 +268,21 @@ namespace ResourceEditor.ViewModels
case ResourceItemEditorType.Bitmap:
try {
newValue = new Bitmap(fileDialog.FileName);
} catch {
SD.MessageService.ShowWarning("Can't load bitmap file.");
} catch (Exception ex) {
SD.MessageService.ShowWarningFormatted("${res:ResourceEditor.Messages.CantLoadResourceFromFile}", ex.Message);
return false;
}
break;
case ResourceItemEditorType.Icon:
try {
newValue = new Icon(fileDialog.FileName);
} catch (Exception ex) {
SD.MessageService.ShowWarningFormatted("${res:ResourceEditor.Messages.CantLoadResourceFromFile}", ex.Message);
return false;
}
break;
}
if (newValue != null) {
ResourceValue = newValue;
return true;

23
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml

@ -1,7 +1,26 @@ @@ -1,7 +1,26 @@
<UserControl x:Class="ResourceEditor.Views.BinaryView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:resvm="clr-namespace:ResourceEditor.ViewModels"
xmlns:resv="clr-namespace:ResourceEditor.Views"
xmlns:core="clr-namespace:ICSharpCode.Core.Presentation;assembly=ICSharpCode.Core.Presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox Name="binaryDataTextBox"
Grid.Row="0"
Text="{Binding DisplayedByteData}"
Margin="0,0,0,0"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled"
IsReadOnly="True"
IsReadOnlyCaretVisible="True" />
<CheckBox Grid.Row="1"
Margin="5,5,5,5"
Content="{core:Localize ResourceEditor.ResourceEdit.ShowAsHexDump}"
IsChecked="{Binding ViewHexDump, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
</UserControl>

104
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml.cs

@ -17,25 +17,119 @@ @@ -17,25 +17,119 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.SharpDevelop;
using ResourceEditor.ViewModels;
namespace ResourceEditor.Views
{
/// <summary>
/// Interaction logic for BinaryView.xaml
/// </summary>
public partial class BinaryView : UserControl
public partial class BinaryView : UserControl, IResourceItemView
{
ResourceItem resourceItem;
readonly ASCIIEncoding encoding = new ASCIIEncoding();
readonly Regex regex = new Regex(@"\p{Cc}");
public BinaryView()
{
InitializeComponent();
this.DataContext = this;
// Make the TextBox look like any other code window
binaryDataTextBox.FontFamily = new FontFamily(SD.EditorControlService.GlobalOptions.FontFamily);
binaryDataTextBox.FontSize = SD.EditorControlService.GlobalOptions.FontSize;
}
public static readonly DependencyProperty ViewHexDumpProperty =
DependencyProperty.Register("ViewHexDump", typeof(bool), typeof(BinaryView),
new FrameworkPropertyMetadata());
public bool ViewHexDump {
get { return (bool)GetValue(ViewHexDumpProperty); }
set { SetValue(ViewHexDumpProperty, value); }
}
public static readonly DependencyProperty DisplayedByteDataProperty =
DependencyProperty.Register("DisplayedByteData", typeof(string), typeof(BinaryView),
new FrameworkPropertyMetadata());
public string DisplayedByteData {
get { return (string)GetValue(DisplayedByteDataProperty); }
set { SetValue(DisplayedByteDataProperty, value); }
}
#region IResourceItemView implementation
public ResourceItem ResourceItem {
get {
return resourceItem;
}
set {
resourceItem = value;
UpdateDisplayedData();
}
}
public FrameworkElement UIControl {
get {
return this;
}
}
#endregion
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property.Name == ViewHexDumpProperty.Name) {
UpdateDisplayedData();
}
}
void UpdateDisplayedData()
{
if (ResourceItem == null) {
return;
}
byte[] bytes = (byte[])ResourceItem.ResourceValue;
string regText = encoding.GetString(bytes).Replace("\x0", ".");
if (ViewHexDump) {
// Hex Dump
StringBuilder sb = new StringBuilder();
string byteString = BitConverter.ToString(bytes).Replace("-", " ");
string stext = regex.Replace(regText, ".");
DisplayedByteData = "";
int max = bytes.Length;
int last = max % 16;
int i = 0;
int count = 16;
do {
sb.Append(String.Format("{0:X8} ", i) +
byteString.Substring(i * 3, (count * 3) - 1) + " " +
stext.Substring(i, count) + "\r\n");
i += 16;
if (i >= (max - last)) {
count = last;
}
} while (i < max);
DisplayedByteData = sb.ToString();
} else {
// Regular Text
DisplayedByteData = regText;
}
}
}
}

24
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml

@ -1,7 +1,21 @@ @@ -1,7 +1,21 @@
<UserControl x:Class="ResourceEditor.Views.BooleanView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
</Grid>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Vertical">
<RadioButton
Name="falseValueRadioButton"
GroupName="BooleanResourceValue"
Content="False"
IsThreeState="False"
Margin="3,3,3,3"
Click="RadioButtonValueChanged" />
<RadioButton
Name="trueValueRadioButton"
GroupName="BooleanResourceValue"
Content="True"
IsThreeState="False"
Margin="3,3,3,3"
Click="RadioButtonValueChanged" />
</StackPanel>
</UserControl>

38
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml.cs

@ -17,25 +17,49 @@ @@ -17,25 +17,49 @@
// 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;
using ResourceEditor.ViewModels;
namespace ResourceEditor.Views
{
/// <summary>
/// Interaction logic for BooleanView.xaml
/// </summary>
public partial class BooleanView : UserControl
public partial class BooleanView : UserControl, IResourceItemView
{
ResourceItem resourceItem;
public BooleanView()
{
InitializeComponent();
}
#region IResourceItemView implementation
public ResourceItem ResourceItem {
get {
return resourceItem;
}
set {
resourceItem = value;
trueValueRadioButton.IsChecked = (resourceItem.ResourceValue as bool?) ?? false;
falseValueRadioButton.IsChecked = !trueValueRadioButton.IsChecked;
}
}
public FrameworkElement UIControl {
get {
return this;
}
}
#endregion
void RadioButtonValueChanged(object sender, RoutedEventArgs e)
{
// Update value of resource item
resourceItem.ResourceValue = trueValueRadioButton.IsChecked;
}
}
}

2
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml.cs

@ -81,7 +81,7 @@ namespace ResourceEditor.Views @@ -81,7 +81,7 @@ namespace ResourceEditor.Views
var gdiIcon = resourceItem.ResourceValue as System.Drawing.Icon;
if (gdiIcon != null) {
DisplayedImage = gdiIcon.ToImageSource();
UpdateLinkText = SD.ResourceService.GetString("ResourceEditor.BitmapView.UpdateBitmap");
UpdateLinkText = SD.ResourceService.GetString("ResourceEditor.BitmapView.UpdateIcon");
}
break;
}

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

@ -106,7 +106,7 @@ @@ -106,7 +106,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Filter:" Margin="3,2,5,2" VerticalAlignment="Center" />
<TextBlock Grid.Column="0" Text="{core:Localize ResourceEditor.Filter}" Margin="3,2,5,2" VerticalAlignment="Center" />
<TextBox
Grid.Column="1"
Name="searchTermTextBox"

5
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml.cs

@ -42,7 +42,7 @@ namespace ResourceEditor.Views @@ -42,7 +42,7 @@ namespace ResourceEditor.Views
public ResourceEditorView()
{
InitializeComponent();
itemCollectionViewSource = (CollectionViewSource) this.Resources["resourceItemListViewSource"];
itemCollectionViewSource = (CollectionViewSource)this.Resources["resourceItemListViewSource"];
}
public IList SelectedItems {
@ -136,6 +136,9 @@ namespace ResourceEditor.Views @@ -136,6 +136,9 @@ namespace ResourceEditor.Views
AddingNewItemRequested(this, new EventArgs());
}
}
if ((e.Key == Key.F) && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) {
searchTermTextBox.Focus();
}
e.Handled = false;
}

Loading…
Cancel
Save