28 changed files with 2028 additions and 371 deletions
@ -0,0 +1,50 @@ |
|||||||
|
// 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.Runtime.InteropServices; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Interop; |
||||||
|
using System.Windows.Media.Imaging; |
||||||
|
|
||||||
|
namespace ResourceEditor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Bitmap conversion extensions for WinForms -> WPF
|
||||||
|
/// </summary>
|
||||||
|
public static class BitmapExtensions |
||||||
|
{ |
||||||
|
[DllImport("gdi32.dll")] |
||||||
|
[return: MarshalAs(UnmanagedType.Bool)] |
||||||
|
public static extern bool DeleteObject(IntPtr hObject); |
||||||
|
|
||||||
|
public static BitmapSource ToBitmapSource(this System.Drawing.Bitmap bitmap) |
||||||
|
{ |
||||||
|
BitmapSource bs; |
||||||
|
IntPtr hBitmap = bitmap.GetHbitmap(); |
||||||
|
try { |
||||||
|
bs = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, |
||||||
|
Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); |
||||||
|
bs.Freeze(); |
||||||
|
} finally { |
||||||
|
DeleteObject(hBitmap); |
||||||
|
} |
||||||
|
return bs; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,107 @@ |
|||||||
|
// 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.Linq; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ResourceEditor.ViewModels; |
||||||
|
|
||||||
|
namespace ResourceEditor.Commands |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Represents a <see cref="ResourceEditor.ViewModels.ResourceItem"/>-related command.
|
||||||
|
/// </summary>
|
||||||
|
public class ResourceItemCommand : SimpleCommand |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Defines whether this command supports multiselection of items.
|
||||||
|
/// If not, command will be disabled by default, when more than 1 item is selected.
|
||||||
|
/// </summary>
|
||||||
|
public virtual bool SupportsMultiSelections { |
||||||
|
get { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns list of resource item types for which this command may be enabled or <c>null</c> to allow any type.
|
||||||
|
/// </summary>
|
||||||
|
public virtual IEnumerable<ResourceItemEditorType> AllowedTypes { |
||||||
|
get { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override bool CanExecute(object parameter) |
||||||
|
{ |
||||||
|
if (ResourceEditor == null) |
||||||
|
return false; |
||||||
|
|
||||||
|
var selectedResourceItems = GetSelectedItems(); |
||||||
|
if (!selectedResourceItems.Any()) |
||||||
|
return false; |
||||||
|
if (!SupportsMultiSelections && (selectedResourceItems.Count() > 1)) |
||||||
|
return false; |
||||||
|
|
||||||
|
return CanExecuteWithResourceItems(selectedResourceItems); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks whether this command can be executed for the current set of selected resource items.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="resourceItems">List of selected resource items. Will always contain at least one element.</param>
|
||||||
|
/// <returns><c>True</c>, when command can be executed, <c>false</c> otherwise.</returns>
|
||||||
|
public virtual bool CanExecuteWithResourceItems(IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems) |
||||||
|
{ |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(object parameter) |
||||||
|
{ |
||||||
|
var selectedResourceItems = GetSelectedItems(); |
||||||
|
if (!selectedResourceItems.Any()) |
||||||
|
return; |
||||||
|
if (!SupportsMultiSelections && (selectedResourceItems.Count() > 1)) |
||||||
|
return; |
||||||
|
ExecuteWithResourceItems(selectedResourceItems); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes command for the given set of selected resource items.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="resourceItems">List of selected resource items. Will always contain at least one element.</param>
|
||||||
|
public virtual void ExecuteWithResourceItems(IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public ResourceEditorViewModel ResourceEditor { |
||||||
|
get { |
||||||
|
return ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
IEnumerable<ResourceEditor.ViewModels.ResourceItem> GetSelectedItems() |
||||||
|
{ |
||||||
|
var editor = ResourceEditor; |
||||||
|
if (editor != null) |
||||||
|
return editor.SelectedItems.OfType<ResourceEditor.ViewModels.ResourceItem>() ?? new ResourceEditor.ViewModels.ResourceItem[0]; |
||||||
|
return new ResourceEditor.ViewModels.ResourceItem[0]; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,481 @@ |
|||||||
|
// 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; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Collections.ObjectModel; |
||||||
|
using System.Collections.Specialized; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using System.IO; |
||||||
|
using System.Linq; |
||||||
|
using System.Resources; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Input; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.SharpDevelop.Project.Commands; |
||||||
|
using ResourceEditor.Views; |
||||||
|
|
||||||
|
namespace ResourceEditor.ViewModels |
||||||
|
{ |
||||||
|
public class ChangedDirtyStateEventArgs : EventArgs |
||||||
|
{ |
||||||
|
public ChangedDirtyStateEventArgs(bool isDirty) |
||||||
|
{ |
||||||
|
this.IsDirty = isDirty; |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsDirty { |
||||||
|
get; |
||||||
|
private set; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Main view model for resource editor.
|
||||||
|
/// </summary>
|
||||||
|
public class ResourceEditorViewModel : DependencyObject |
||||||
|
{ |
||||||
|
readonly ObservableCollection<ResourceItem> resourceItems; |
||||||
|
readonly HashSet<string> resourceItemNames; |
||||||
|
readonly ObservableCollection<ResourceItem> metadataItems; |
||||||
|
readonly Dictionary<ResourceItemEditorType, IResourceItemView> itemViews; |
||||||
|
bool longUpdateRunning; |
||||||
|
ResourceItem editedResourceItem; |
||||||
|
string originalNameOfEditedItem; |
||||||
|
|
||||||
|
IResourceEditorView view; |
||||||
|
|
||||||
|
public event EventHandler<ChangedDirtyStateEventArgs> DirtyStateChanged; |
||||||
|
|
||||||
|
public static readonly DependencyProperty SearchTermProperty = |
||||||
|
DependencyProperty.Register("SearchTerm", typeof(string), typeof(ResourceEditorViewModel), |
||||||
|
new FrameworkPropertyMetadata()); |
||||||
|
|
||||||
|
public string SearchTerm { |
||||||
|
get { return (string) GetValue(SearchTermProperty); } |
||||||
|
set { SetValue(SearchTermProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
public IList SelectedItems { |
||||||
|
get { |
||||||
|
if (view != null) { |
||||||
|
return view.SelectedItems; |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public ResourceEditorViewModel() |
||||||
|
{ |
||||||
|
resourceItems = new ObservableCollection<ResourceItem>(); |
||||||
|
resourceItemNames = new HashSet<string>(); |
||||||
|
metadataItems = new ObservableCollection<ResourceItem>(); |
||||||
|
itemViews = new Dictionary<ResourceItemEditorType, IResourceItemView>(); |
||||||
|
} |
||||||
|
|
||||||
|
public ObservableCollection<ResourceItem> ResourceItems { |
||||||
|
get { |
||||||
|
return resourceItems; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks whether a resource name is existing in currently open file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Resource name to check.</param>
|
||||||
|
/// <returns><c>True</c> if name exists, <c>false</c> otherwise.</returns>
|
||||||
|
public bool ContainsResourceName(string name) |
||||||
|
{ |
||||||
|
return resourceItemNames.Contains(name); |
||||||
|
} |
||||||
|
|
||||||
|
public void AddItemView(ResourceItemEditorType itemType, IResourceItemView view) |
||||||
|
{ |
||||||
|
itemViews[itemType] = view; |
||||||
|
} |
||||||
|
|
||||||
|
public IResourceEditorView View { |
||||||
|
get { |
||||||
|
return view; |
||||||
|
} |
||||||
|
set { |
||||||
|
if (view != null) { |
||||||
|
view.SelectionChanged -= View_SelectionChanged; |
||||||
|
view.EditingStarted -= View_EditingStarted; |
||||||
|
view.EditingFinished -= View_EditingFinished; |
||||||
|
view.EditingCancelled -= View_EditingCancelled; |
||||||
|
ResourceItems.CollectionChanged -= ResourceItems_CollectionChanged; |
||||||
|
} |
||||||
|
|
||||||
|
view = value; |
||||||
|
if (view != null) { |
||||||
|
// Bind this model to new view
|
||||||
|
view.DataContext = this; |
||||||
|
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, (s, e) => Cut(), (s, e) => e.CanExecute = EnableCut)); |
||||||
|
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, (s, e) => Copy(), (s, e) => e.CanExecute = EnableCopy)); |
||||||
|
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, (s, e) => Paste(), (s, e) => e.CanExecute = EnablePaste)); |
||||||
|
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, (s, e) => Delete(), (s, e) => e.CanExecute = EnableDelete)); |
||||||
|
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, (s, e) => SelectAll(), (s, e) => e.CanExecute = EnableSelectAll)); |
||||||
|
|
||||||
|
view.FilterPredicate = resourceItem => { |
||||||
|
if (SearchTerm != null) |
||||||
|
return resourceItem.Name.IndexOf(SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0; |
||||||
|
return true; |
||||||
|
}; |
||||||
|
view.SelectionChanged += View_SelectionChanged; |
||||||
|
view.EditingStarted += View_EditingStarted; |
||||||
|
view.EditingFinished += View_EditingFinished; |
||||||
|
view.EditingCancelled += View_EditingCancelled; |
||||||
|
ResourceItems.CollectionChanged += ResourceItems_CollectionChanged; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void ResourceItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) |
||||||
|
{ |
||||||
|
switch (e.Action) { |
||||||
|
case NotifyCollectionChangedAction.Remove: |
||||||
|
if (e.OldItems != null) { |
||||||
|
var oldItems = e.OldItems.OfType<ResourceItem>(); |
||||||
|
foreach (var item in oldItems) { |
||||||
|
resourceItemNames.Remove(item.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
break; |
||||||
|
case NotifyCollectionChangedAction.Add: |
||||||
|
if (e.NewItems != null) { |
||||||
|
var newItems = e.NewItems.OfType<ResourceItem>(); |
||||||
|
foreach (var item in newItems) { |
||||||
|
if (!resourceItemNames.Contains(item.Name)) |
||||||
|
resourceItemNames.Add(item.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
break; |
||||||
|
case NotifyCollectionChangedAction.Reset: |
||||||
|
resourceItemNames.Clear(); |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
// Changes in collection of ResourceItems => make dirty
|
||||||
|
MakeDirty(); |
||||||
|
} |
||||||
|
|
||||||
|
void View_SelectionChanged(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
if (longUpdateRunning) |
||||||
|
return; |
||||||
|
|
||||||
|
ResourceItem selectedItem = SelectedItems.OfType<ResourceItem>().FirstOrDefault(); |
||||||
|
if (selectedItem != null) { |
||||||
|
if (itemViews.ContainsKey(selectedItem.ResourceType)) { |
||||||
|
var itemView = itemViews[selectedItem.ResourceType]; |
||||||
|
itemView.ResourceItem = selectedItem; |
||||||
|
view.SetItemView(itemView); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void OnChangedDirtyState(bool isDirty) |
||||||
|
{ |
||||||
|
if (DirtyStateChanged != null) { |
||||||
|
DirtyStateChanged(this, new ChangedDirtyStateEventArgs(isDirty)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void MakeDirty() |
||||||
|
{ |
||||||
|
OnChangedDirtyState(true); |
||||||
|
} |
||||||
|
|
||||||
|
public void StartEditing() |
||||||
|
{ |
||||||
|
// if (editedResourceItem != null) {
|
||||||
|
// editedResourceItem.IsEditing = false;
|
||||||
|
// editedResourceItem = null;
|
||||||
|
// originalNameOfEditedItem = null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Start editing currently selected item
|
||||||
|
var firstSelectedItem = SelectedItems.OfType<ResourceItem>().FirstOrDefault(); |
||||||
|
if (firstSelectedItem != null) { |
||||||
|
editedResourceItem = firstSelectedItem; |
||||||
|
originalNameOfEditedItem = editedResourceItem.Name; |
||||||
|
firstSelectedItem.IsEditing = true; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void View_EditingStarted(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
StartEditing(); |
||||||
|
} |
||||||
|
|
||||||
|
void View_EditingFinished(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
// if (editedResourceItem != null) {
|
||||||
|
// editedResourceItem.IsEditing = false;
|
||||||
|
// editedResourceItem = null;
|
||||||
|
// originalNameOfEditedItem = null;
|
||||||
|
// MakeDirty();
|
||||||
|
// }
|
||||||
|
} |
||||||
|
|
||||||
|
void View_EditingCancelled(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
// if (editedResourceItem != null) {
|
||||||
|
// editedResourceItem.IsEditing = false;
|
||||||
|
// editedResourceItem.Name = originalNameOfEditedItem;
|
||||||
|
// editedResourceItem = null;
|
||||||
|
// originalNameOfEditedItem = null;
|
||||||
|
// }
|
||||||
|
} |
||||||
|
|
||||||
|
void StartUpdate() |
||||||
|
{ |
||||||
|
// When loading many items at once, temporarily unbind view from model
|
||||||
|
view.DataContext = null; |
||||||
|
} |
||||||
|
|
||||||
|
void EndUpdate() |
||||||
|
{ |
||||||
|
view.DataContext = this; |
||||||
|
} |
||||||
|
|
||||||
|
public void LoadFile(FileName filename, Stream stream) |
||||||
|
{ |
||||||
|
StartUpdate(); |
||||||
|
|
||||||
|
resourceItems.Clear(); |
||||||
|
metadataItems.Clear(); |
||||||
|
switch (Path.GetExtension(filename).ToLowerInvariant()) { |
||||||
|
case ".resx": |
||||||
|
ResXResourceReader rx = new ResXResourceReader(stream); |
||||||
|
ITypeResolutionService typeResolver = null; |
||||||
|
rx.BasePath = Path.GetDirectoryName(filename); |
||||||
|
rx.UseResXDataNodes = true; |
||||||
|
IDictionaryEnumerator n = rx.GetEnumerator(); |
||||||
|
while (n.MoveNext()) { |
||||||
|
ResXDataNode node = (ResXDataNode) n.Value; |
||||||
|
resourceItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver), node.Comment)); |
||||||
|
} |
||||||
|
|
||||||
|
n = rx.GetMetadataEnumerator(); |
||||||
|
while (n.MoveNext()) { |
||||||
|
ResXDataNode node = (ResXDataNode) n.Value; |
||||||
|
metadataItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver))); |
||||||
|
} |
||||||
|
|
||||||
|
rx.Close(); |
||||||
|
break; |
||||||
|
case ".resources": |
||||||
|
ResourceReader rr = null; |
||||||
|
try { |
||||||
|
rr = new ResourceReader(stream); |
||||||
|
foreach (DictionaryEntry entry in rr) { |
||||||
|
resourceItems.Add(new ResourceItem(this, entry.Key.ToString(), entry.Value)); |
||||||
|
} |
||||||
|
} finally { |
||||||
|
if (rr != null) { |
||||||
|
rr.Close(); |
||||||
|
} |
||||||
|
} |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
EndUpdate(); |
||||||
|
} |
||||||
|
|
||||||
|
public void SaveFile(FileName filename, Stream stream) |
||||||
|
{ |
||||||
|
switch (Path.GetExtension(filename).ToLowerInvariant()) { |
||||||
|
case ".resx": |
||||||
|
// write XML resource
|
||||||
|
ResXResourceWriter rxw = new ResXResourceWriter(stream, t => ResXConverter.ConvertTypeName(t, filename)); |
||||||
|
foreach (ResourceItem entry in resourceItems) { |
||||||
|
if (entry != null) { |
||||||
|
rxw.AddResource(entry.ToResXDataNode(t => ResXConverter.ConvertTypeName(t, filename))); |
||||||
|
} |
||||||
|
} |
||||||
|
foreach (ResourceItem entry in metadataItems) { |
||||||
|
if (entry != null) { |
||||||
|
rxw.AddMetadata(entry.Name, entry.ResourceValue); |
||||||
|
} |
||||||
|
} |
||||||
|
rxw.Generate(); |
||||||
|
rxw.Close(); |
||||||
|
break; |
||||||
|
default: |
||||||
|
// write default resource
|
||||||
|
ResourceWriter rw = new ResourceWriter(stream); |
||||||
|
foreach (ResourceItem entry in resourceItems) { |
||||||
|
rw.AddResource(entry.Name, entry.ResourceValue); |
||||||
|
} |
||||||
|
rw.Generate(); |
||||||
|
rw.Close(); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#region Standard clipboard commands
|
||||||
|
|
||||||
|
public bool EnableCut { |
||||||
|
get { |
||||||
|
return SelectedItems.Count > 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool EnableCopy { |
||||||
|
get { |
||||||
|
return SelectedItems.Count > 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool EnablePaste { |
||||||
|
get { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool EnableDelete { |
||||||
|
get { |
||||||
|
return SelectedItems.Count > 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool EnableSelectAll { |
||||||
|
get { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void Cut() |
||||||
|
{ |
||||||
|
// if (resourceEditor.ResourceList.WriteProtected || resourceEditor.ResourceList.SelectedItems.Count < 1)
|
||||||
|
// return;
|
||||||
|
if (SelectedItems.Count == 0) |
||||||
|
return; |
||||||
|
|
||||||
|
Hashtable tmphash = new Hashtable(); |
||||||
|
foreach (var selectedItem in SelectedItems.OfType<ResourceItem>().ToList()) { |
||||||
|
tmphash.Add(selectedItem.Name, selectedItem.ResourceValue); |
||||||
|
resourceItems.Remove(selectedItem); |
||||||
|
} |
||||||
|
SD.Clipboard.SetDataObject(tmphash); |
||||||
|
} |
||||||
|
|
||||||
|
public void Copy() |
||||||
|
{ |
||||||
|
if (SelectedItems.Count == 0) |
||||||
|
return; |
||||||
|
|
||||||
|
Hashtable tmphash = new Hashtable(); |
||||||
|
foreach (var selectedItem in SelectedItems.OfType<ResourceItem>().ToList()) { |
||||||
|
object resourceValue = GetClonedResource(selectedItem.ResourceValue); |
||||||
|
tmphash.Add(selectedItem.Name, resourceValue); |
||||||
|
} |
||||||
|
SD.Clipboard.SetDataObject(tmphash); |
||||||
|
} |
||||||
|
|
||||||
|
public void Paste() |
||||||
|
{ |
||||||
|
// if (resourceEditor.ResourceList.WriteProtected) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
IDataObject dob = Clipboard.GetDataObject(); |
||||||
|
if (dob == null) |
||||||
|
return; |
||||||
|
|
||||||
|
if (dob.GetDataPresent(typeof(Hashtable).FullName)) { |
||||||
|
Hashtable tmphash = (Hashtable) dob.GetData(typeof(Hashtable)); |
||||||
|
foreach (DictionaryEntry entry in tmphash) { |
||||||
|
object resourceValue = GetClonedResource(entry.Value); |
||||||
|
ResourceItem item; |
||||||
|
|
||||||
|
if (!resourceItemNames.Contains((string) entry.Key)) { |
||||||
|
item = new ResourceItem(this, entry.Key.ToString(), resourceValue); |
||||||
|
} else { |
||||||
|
int count = 1; |
||||||
|
string newNameBase = entry.Key + " "; |
||||||
|
string newName = newNameBase + count; |
||||||
|
|
||||||
|
while (resourceItemNames.Contains(newName)) { |
||||||
|
count++; |
||||||
|
newName = newNameBase + count; |
||||||
|
} |
||||||
|
item = new ResourceItem(this, newName, resourceValue); |
||||||
|
} |
||||||
|
resourceItems.Add(item); |
||||||
|
// TODO Set selection to new element?
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clones a resource if the <paramref name="resource"/>
|
||||||
|
/// is cloneable.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="resource">A resource to clone.</param>
|
||||||
|
/// <returns>A cloned resource if the object implements
|
||||||
|
/// the ICloneable interface, otherwise the
|
||||||
|
/// <paramref name="resource"/> object.</returns>
|
||||||
|
object GetClonedResource(object resource) |
||||||
|
{ |
||||||
|
object clonedResource = null; |
||||||
|
|
||||||
|
ICloneable cloneableResource = resource as ICloneable; |
||||||
|
if (cloneableResource != null) { |
||||||
|
clonedResource = cloneableResource.Clone(); |
||||||
|
} else { |
||||||
|
clonedResource = resource; |
||||||
|
} |
||||||
|
|
||||||
|
return clonedResource; |
||||||
|
} |
||||||
|
|
||||||
|
public void Delete() |
||||||
|
{ |
||||||
|
// if (resourceList.WriteProtected || resourceList.SelectedItems.Count == 0)
|
||||||
|
// return;
|
||||||
|
|
||||||
|
if (SelectedItems.Count > 0) { |
||||||
|
if (!SD.MessageService.AskQuestion("${res:ResourceEditor.DeleteEntry.Confirm}", "${res:ResourceEditor.DeleteEntry.Title}")) |
||||||
|
return; |
||||||
|
|
||||||
|
foreach (var item in SelectedItems.OfType<ResourceItem>().ToList()) { |
||||||
|
resourceItems.Remove(item); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void SelectAll() |
||||||
|
{ |
||||||
|
longUpdateRunning = true; |
||||||
|
foreach (var i in resourceItems) |
||||||
|
SelectedItems.Add(i); |
||||||
|
longUpdateRunning = false; |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,245 @@ |
|||||||
|
// 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.ComponentModel; |
||||||
|
using System.Drawing; |
||||||
|
using System.Resources; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
|
||||||
|
namespace ResourceEditor.ViewModels |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Defines the type of resource item supported by editor.
|
||||||
|
/// </summary>
|
||||||
|
public enum ResourceItemEditorType |
||||||
|
{ |
||||||
|
Unknown, |
||||||
|
String, |
||||||
|
Boolean, |
||||||
|
Bitmap, |
||||||
|
Icon, |
||||||
|
Cursor, |
||||||
|
Binary |
||||||
|
} |
||||||
|
|
||||||
|
public class ResourceItem : DependencyObject |
||||||
|
{ |
||||||
|
ResourceItemEditorType resourceType; |
||||||
|
ResourceEditorViewModel resourceEditor; |
||||||
|
string nameBeforeEditing; |
||||||
|
|
||||||
|
public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue) |
||||||
|
{ |
||||||
|
this.resourceEditor = resourceEditor; |
||||||
|
this.Name = name; |
||||||
|
this.ResourceValue = resourceValue; |
||||||
|
this.resourceType = GetResourceTypeFromValue(resourceValue); |
||||||
|
} |
||||||
|
|
||||||
|
public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue, string comment) |
||||||
|
{ |
||||||
|
this.resourceEditor = resourceEditor; |
||||||
|
this.Name = name; |
||||||
|
this.ResourceValue = resourceValue; |
||||||
|
this.resourceType = GetResourceTypeFromValue(resourceValue); |
||||||
|
this.Comment = comment; |
||||||
|
} |
||||||
|
|
||||||
|
public static readonly DependencyProperty NameProperty = |
||||||
|
DependencyProperty.Register("Name", typeof(string), typeof(ResourceItem), |
||||||
|
new FrameworkPropertyMetadata()); |
||||||
|
|
||||||
|
public string Name { |
||||||
|
get { return (string)GetValue(NameProperty); } |
||||||
|
set { SetValue(NameProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
public static readonly DependencyProperty ResourceValueProperty = |
||||||
|
DependencyProperty.Register("ResourceValue", typeof(object), typeof(ResourceItem), |
||||||
|
new FrameworkPropertyMetadata()); |
||||||
|
|
||||||
|
public object ResourceValue { |
||||||
|
get { return (object)GetValue(ResourceValueProperty); } |
||||||
|
set { SetValue(ResourceValueProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
public string DisplayedResourceType { |
||||||
|
get { |
||||||
|
return ResourceValue == null ? "(Nothing/null)" : ResourceValue.GetType().FullName; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public ResourceItemEditorType ResourceType { |
||||||
|
get { |
||||||
|
return resourceType; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static readonly DependencyProperty IsEditingProperty = |
||||||
|
DependencyProperty.Register("IsEditing", typeof(bool), typeof(ResourceItem), |
||||||
|
new FrameworkPropertyMetadata()); |
||||||
|
|
||||||
|
public bool IsEditing { |
||||||
|
get { return (bool)GetValue(IsEditingProperty); } |
||||||
|
set { SetValue(IsEditingProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) |
||||||
|
{ |
||||||
|
base.OnPropertyChanged(e); |
||||||
|
|
||||||
|
if (e.Property == IsEditingProperty) { |
||||||
|
bool previouslyEditing = (bool)e.OldValue; |
||||||
|
bool isEditing = (bool)e.NewValue; |
||||||
|
if (!previouslyEditing && isEditing) { |
||||||
|
// Save initial name to compare it later on cancellation
|
||||||
|
nameBeforeEditing = Name; |
||||||
|
} 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)) { |
||||||
|
resourceEditor.MakeDirty(); |
||||||
|
} else { |
||||||
|
// New name was not valid, revert it to the value before editing
|
||||||
|
Name = nameBeforeEditing; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
resourceEditor.MakeDirty(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ResourceItemEditorType GetResourceTypeFromValue(object val) |
||||||
|
{ |
||||||
|
if (this.ResourceValue == null) { |
||||||
|
return ResourceItemEditorType.Unknown; |
||||||
|
} |
||||||
|
switch (this.ResourceValue.GetType().ToString()) { |
||||||
|
case "System.String": |
||||||
|
return ResourceItemEditorType.String; |
||||||
|
case "System.Drawing.Bitmap": |
||||||
|
return ResourceItemEditorType.Bitmap; |
||||||
|
case "System.Drawing.Icon": |
||||||
|
return ResourceItemEditorType.Icon; |
||||||
|
case "System.Windows.Forms.Cursor": |
||||||
|
return ResourceItemEditorType.Cursor; |
||||||
|
case "System.Byte[]": |
||||||
|
return ResourceItemEditorType.Binary; |
||||||
|
case "System.Boolean": |
||||||
|
return ResourceItemEditorType.Boolean; |
||||||
|
default: |
||||||
|
return ResourceItemEditorType.Unknown; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string Content { |
||||||
|
get { |
||||||
|
return ToString(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static readonly DependencyProperty CommentProperty = |
||||||
|
DependencyProperty.Register("Comment", typeof(string), typeof(ResourceItem), |
||||||
|
new FrameworkPropertyMetadata()); |
||||||
|
|
||||||
|
public string Comment { |
||||||
|
get { return (string)GetValue(CommentProperty); } |
||||||
|
set { SetValue(CommentProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
public override string ToString() |
||||||
|
{ |
||||||
|
if (ResourceValue == null) { |
||||||
|
return "(Nothing/null)"; |
||||||
|
} |
||||||
|
|
||||||
|
string type = ResourceValue.GetType().FullName; |
||||||
|
string tmp = String.Empty; |
||||||
|
|
||||||
|
switch (type) { |
||||||
|
case "System.String": |
||||||
|
tmp = ResourceValue.ToString(); |
||||||
|
break; |
||||||
|
case "System.Byte[]": |
||||||
|
tmp = "[Size = " + ((byte[])ResourceValue).Length + "]"; |
||||||
|
break; |
||||||
|
case "System.Drawing.Bitmap": |
||||||
|
Bitmap bmp = ResourceValue as Bitmap; |
||||||
|
tmp = "[Width = " + bmp.Size.Width + ", Height = " + bmp.Size.Height + "]"; |
||||||
|
break; |
||||||
|
case "System.Drawing.Icon": |
||||||
|
Icon icon = ResourceValue as Icon; |
||||||
|
tmp = "[Width = " + icon.Size.Width + ", Height = " + icon.Size.Height + "]"; |
||||||
|
break; |
||||||
|
case "System.Windows.Forms.Cursor": |
||||||
|
Cursor c = ResourceValue as Cursor; |
||||||
|
tmp = "[Width = " + c.Size.Width + ", Height = " + c.Size.Height + "]"; |
||||||
|
break; |
||||||
|
case "System.Boolean": |
||||||
|
tmp = ResourceValue.ToString(); |
||||||
|
break; |
||||||
|
default: |
||||||
|
tmp = ResourceValue.ToString(); |
||||||
|
break; |
||||||
|
} |
||||||
|
return tmp; |
||||||
|
} |
||||||
|
|
||||||
|
public ResXDataNode ToResXDataNode(Func<Type, string> typeNameConverter = null) |
||||||
|
{ |
||||||
|
var node = new ResXDataNode(Name, ResourceValue, typeNameConverter) { |
||||||
|
Comment = Comment |
||||||
|
}; |
||||||
|
return node; |
||||||
|
} |
||||||
|
|
||||||
|
public bool UpdateFromFile() |
||||||
|
{ |
||||||
|
var fileDialog = new Microsoft.Win32.OpenFileDialog(); |
||||||
|
fileDialog.AddExtension = true; |
||||||
|
fileDialog.Filter = "All files (*.*)|*.*"; |
||||||
|
fileDialog.CheckFileExists = true; |
||||||
|
|
||||||
|
if (fileDialog.ShowDialog().Value) { |
||||||
|
object newValue = null; |
||||||
|
switch (resourceType) { |
||||||
|
case ResourceItemEditorType.Bitmap: |
||||||
|
try { |
||||||
|
newValue = new Bitmap(fileDialog.FileName); |
||||||
|
} catch { |
||||||
|
SD.MessageService.ShowWarning("Can't load bitmap file."); |
||||||
|
return false; |
||||||
|
} |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
if (newValue != null) { |
||||||
|
ResourceValue = newValue; |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
<UserControl x:Class="ResourceEditor.Views.BinaryView" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||||
|
<Grid> |
||||||
|
|
||||||
|
</Grid> |
||||||
|
</UserControl> |
||||||
@ -0,0 +1,41 @@ |
|||||||
|
// 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 |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for BinaryView.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class BinaryView : UserControl |
||||||
|
{ |
||||||
|
public BinaryView() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
<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> |
||||||
|
</UserControl> |
||||||
@ -0,0 +1,41 @@ |
|||||||
|
// 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 |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for BooleanView.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class BooleanView : UserControl |
||||||
|
{ |
||||||
|
public BooleanView() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,58 @@ |
|||||||
|
// 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; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Collections.ObjectModel; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Input; |
||||||
|
|
||||||
|
namespace ResourceEditor.Views |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Base interface for resource editor main views.
|
||||||
|
/// </summary>
|
||||||
|
public interface IResourceEditorView |
||||||
|
{ |
||||||
|
CommandBindingCollection CommandBindings { |
||||||
|
get; |
||||||
|
} |
||||||
|
|
||||||
|
event EventHandler SelectionChanged; |
||||||
|
IList SelectedItems { |
||||||
|
get; |
||||||
|
} |
||||||
|
|
||||||
|
event EventHandler EditingStarted; |
||||||
|
event EventHandler EditingFinished; |
||||||
|
event EventHandler EditingCancelled; |
||||||
|
|
||||||
|
void SetItemView(IResourceItemView view); |
||||||
|
|
||||||
|
object DataContext { |
||||||
|
get; |
||||||
|
set; |
||||||
|
} |
||||||
|
|
||||||
|
Predicate<ResourceEditor.ViewModels.ResourceItem> FilterPredicate { |
||||||
|
get; |
||||||
|
set; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,19 @@ |
|||||||
|
<UserControl x:Class="ResourceEditor.Views.ImageViewBase" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||||
|
<Grid> |
||||||
|
<Grid.RowDefinitions> |
||||||
|
<RowDefinition Height="Auto" /> |
||||||
|
<RowDefinition Height="*" /> |
||||||
|
</Grid.RowDefinitions> |
||||||
|
|
||||||
|
<Button Grid.Row="0" Content="{Binding UpdateLinkText}" Margin="2,2,2,2" HorizontalAlignment="Left" Click="Button_Click" /> |
||||||
|
<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Margin="0,0,0,0"> |
||||||
|
<Image |
||||||
|
Name="imagePreview" |
||||||
|
Source="{Binding DisplayedImage}" |
||||||
|
Stretch="None" |
||||||
|
HorizontalAlignment="Center" VerticalAlignment="Center" /> |
||||||
|
</ScrollViewer> |
||||||
|
</Grid> |
||||||
|
</UserControl> |
||||||
@ -0,0 +1,101 @@ |
|||||||
|
// 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; |
||||||
|
using System.Windows.Media.Imaging; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ResourceEditor.ViewModels; |
||||||
|
|
||||||
|
namespace ResourceEditor.Views |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for ImageViewBase.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class ImageViewBase : UserControl, IResourceItemView |
||||||
|
{ |
||||||
|
ResourceEditor.ViewModels.ResourceItem resourceItem; |
||||||
|
|
||||||
|
public ImageViewBase() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
DataContext = this; |
||||||
|
} |
||||||
|
|
||||||
|
public static readonly DependencyProperty DisplayedImageProperty = |
||||||
|
DependencyProperty.Register("DisplayedImage", typeof(object), typeof(ImageViewBase), |
||||||
|
new FrameworkPropertyMetadata()); |
||||||
|
|
||||||
|
public object DisplayedImage { |
||||||
|
get { return (object)GetValue(DisplayedImageProperty); } |
||||||
|
set { SetValue(DisplayedImageProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
public static readonly DependencyProperty UpdateLinkTextProperty = |
||||||
|
DependencyProperty.Register("UpdateLinkText", typeof(string), typeof(ImageViewBase), |
||||||
|
new FrameworkPropertyMetadata()); |
||||||
|
|
||||||
|
public string UpdateLinkText { |
||||||
|
get { return (string)GetValue(UpdateLinkTextProperty); } |
||||||
|
set { SetValue(UpdateLinkTextProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
public FrameworkElement UIControl { |
||||||
|
get { |
||||||
|
return this; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public ResourceEditor.ViewModels.ResourceItem ResourceItem { |
||||||
|
get { |
||||||
|
return resourceItem; |
||||||
|
} |
||||||
|
set { |
||||||
|
resourceItem = value; |
||||||
|
UpdateLinkText = ""; |
||||||
|
if (resourceItem != null) { |
||||||
|
switch (resourceItem.ResourceType) { |
||||||
|
case ResourceItemEditorType.Bitmap: |
||||||
|
var gdiBitmap = resourceItem.ResourceValue as System.Drawing.Bitmap; |
||||||
|
if (gdiBitmap != null) { |
||||||
|
DisplayedImage = gdiBitmap.ToBitmapSource(); |
||||||
|
UpdateLinkText = SD.ResourceService.GetString("ResourceEditor.BitmapView.UpdateBitmap"); |
||||||
|
} |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void Button_Click(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
if (resourceItem != null) { |
||||||
|
if (resourceItem.UpdateFromFile()) { |
||||||
|
ResourceItem = resourceItem; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
<UserControl x:Class="ResourceEditor.Views.InPlaceEditLabel" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||||
|
<Grid Margin="0,0,0,0"> |
||||||
|
<TextBlock Name="readOnlyTextBlock" Text="{Binding Text, Mode=TwoWay}" VerticalAlignment="Top" Margin="0,0,0,0" /> |
||||||
|
<TextBox |
||||||
|
Name="editingTextBox" |
||||||
|
Text="{Binding Text, Mode=TwoWay}" |
||||||
|
VerticalAlignment="Top" |
||||||
|
Margin="0,0,0,0" |
||||||
|
IsVisibleChanged="EditingTextBox_IsVisibleChanged" |
||||||
|
LostFocus="EditingTextBox_LostFocus" /> |
||||||
|
</Grid> |
||||||
|
</UserControl> |
||||||
@ -0,0 +1,112 @@ |
|||||||
|
// 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 |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for InPlaceEditLabel.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class InPlaceEditLabel : UserControl |
||||||
|
{ |
||||||
|
string textBeforeEditing; |
||||||
|
|
||||||
|
public InPlaceEditLabel() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
editingTextBox.Visibility = Visibility.Collapsed; |
||||||
|
readOnlyTextBlock.Visibility = Visibility.Visible; |
||||||
|
readOnlyTextBlock.DataContext = this; |
||||||
|
editingTextBox.DataContext = this; |
||||||
|
} |
||||||
|
|
||||||
|
public static readonly DependencyProperty TextProperty = |
||||||
|
DependencyProperty.Register("Text", typeof(string), typeof(InPlaceEditLabel), |
||||||
|
new FrameworkPropertyMetadata()); |
||||||
|
|
||||||
|
public string Text { |
||||||
|
get { return (string)GetValue(TextProperty); } |
||||||
|
set { SetValue(TextProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
public static readonly DependencyProperty IsEditingProperty = |
||||||
|
DependencyProperty.Register("IsEditing", typeof(bool), typeof(InPlaceEditLabel), |
||||||
|
new FrameworkPropertyMetadata()); |
||||||
|
|
||||||
|
public bool IsEditing { |
||||||
|
get { return (bool)GetValue(IsEditingProperty); } |
||||||
|
set { SetValue(IsEditingProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) |
||||||
|
{ |
||||||
|
base.OnPropertyChanged(e); |
||||||
|
|
||||||
|
if (e.Property == IsEditingProperty) { |
||||||
|
if ((bool)e.NewValue) { |
||||||
|
editingTextBox.Visibility = Visibility.Visible; |
||||||
|
readOnlyTextBlock.Visibility = Visibility.Collapsed; |
||||||
|
editingTextBox.Focus(); |
||||||
|
textBeforeEditing = this.Text; |
||||||
|
editingTextBox.SelectAll(); |
||||||
|
} else { |
||||||
|
editingTextBox.Visibility = Visibility.Collapsed; |
||||||
|
readOnlyTextBlock.Visibility = Visibility.Visible; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnKeyUp(KeyEventArgs e) |
||||||
|
{ |
||||||
|
base.OnKeyUp(e); |
||||||
|
|
||||||
|
if (e.Key == Key.Enter) { |
||||||
|
IsEditing = false; |
||||||
|
} else if (e.Key == Key.Escape) { |
||||||
|
// Cancel editing and restore original text
|
||||||
|
this.Text = textBeforeEditing; |
||||||
|
IsEditing = false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void EditingTextBox_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) |
||||||
|
{ |
||||||
|
if ((bool)e.NewValue) { |
||||||
|
// Auto-select whole text as soon as TextBox becomes visible
|
||||||
|
// editingTextBox.Focus();
|
||||||
|
// editingTextBox.SelectAll();
|
||||||
|
// textBeforeEditing = this.Text;
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void EditingTextBox_LostFocus(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
// When losing focus, also stop editing
|
||||||
|
IsEditing = false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,159 @@ |
|||||||
|
<UserControl x:Class="ResourceEditor.Views.ResourceEditorView" |
||||||
|
xmlns:resvm="clr-namespace:ResourceEditor.ViewModels" |
||||||
|
xmlns:resv="clr-namespace:ResourceEditor.Views" |
||||||
|
xmlns:core="clr-namespace:ICSharpCode.Core.Presentation;assembly=ICSharpCode.Core.Presentation" |
||||||
|
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase" |
||||||
|
xmlns:sys="clr-namespace:System;assembly=System" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||||
|
|
||||||
|
<UserControl.Resources> |
||||||
|
<resv:ResourceItemIcons x:Key="resourceItemIcons" /> |
||||||
|
|
||||||
|
<CollectionViewSource |
||||||
|
x:Key="resourceItemListViewSource" |
||||||
|
Source="{Binding ResourceItems}" |
||||||
|
Filter="CollectionViewSource_Filter"> |
||||||
|
<CollectionViewSource.SortDescriptions> |
||||||
|
<scm:SortDescription PropertyName="Name"/> |
||||||
|
</CollectionViewSource.SortDescriptions> |
||||||
|
</CollectionViewSource> |
||||||
|
|
||||||
|
<Style x:Key="listViewItemStyle" TargetType="{x:Type ListViewItem}"> |
||||||
|
<Setter Property="HorizontalContentAlignment" Value="Stretch" /> |
||||||
|
<Setter Property="VerticalContentAlignment" Value="Stretch" /> |
||||||
|
</Style> |
||||||
|
|
||||||
|
<DataTemplate x:Key="resourceItemNameTemplate" DataType="{x:Type resvm:ResourceItem}"> |
||||||
|
<Border BorderBrush="LightGray" BorderThickness="0,0,1,1" Margin="-6,-2,-6,-2"> |
||||||
|
<Grid Margin="6,2,6,2"> |
||||||
|
<Grid.ColumnDefinitions> |
||||||
|
<ColumnDefinition Width="Auto" /> |
||||||
|
<ColumnDefinition Width="*" /> |
||||||
|
</Grid.ColumnDefinitions> |
||||||
|
|
||||||
|
<Image Grid.Column="0" Width="16" Height="16" VerticalAlignment="Top" Margin="0,0,3,0"> |
||||||
|
<Image.Style> |
||||||
|
<Style TargetType="Image"> |
||||||
|
<Style.Triggers> |
||||||
|
<DataTrigger Binding="{Binding ResourceType}" Value="String"> |
||||||
|
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=StringResourceIcon}" /> |
||||||
|
</DataTrigger> |
||||||
|
<DataTrigger Binding="{Binding ResourceType}" Value="Boolean"> |
||||||
|
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=BooleanResourceIcon}" /> |
||||||
|
</DataTrigger> |
||||||
|
<DataTrigger Binding="{Binding ResourceType}" Value="Bitmap"> |
||||||
|
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=BitmapResourceIcon}" /> |
||||||
|
</DataTrigger> |
||||||
|
<DataTrigger Binding="{Binding ResourceType}" Value="Icon"> |
||||||
|
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=IconResourceIcon}" /> |
||||||
|
</DataTrigger> |
||||||
|
<DataTrigger Binding="{Binding ResourceType}" Value="Cursor"> |
||||||
|
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=CursorResourceIcon}" /> |
||||||
|
</DataTrigger> |
||||||
|
<DataTrigger Binding="{Binding ResourceType}" Value="Binary"> |
||||||
|
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=BinaryResourceIcon}" /> |
||||||
|
</DataTrigger> |
||||||
|
<DataTrigger Binding="{Binding ResourceType}" Value="Unknown"> |
||||||
|
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=UnknownResourceIcon}" /> |
||||||
|
</DataTrigger> |
||||||
|
</Style.Triggers> |
||||||
|
</Style> |
||||||
|
</Image.Style> |
||||||
|
</Image> |
||||||
|
<resv:InPlaceEditLabel Grid.Column="1" |
||||||
|
Text="{Binding Name, Mode=TwoWay}" |
||||||
|
VerticalAlignment="Top" |
||||||
|
Margin="0,0,0,0" |
||||||
|
MinWidth="300" |
||||||
|
IsEditing="{Binding IsEditing, Mode=TwoWay}"> |
||||||
|
</resv:InPlaceEditLabel> |
||||||
|
</Grid> |
||||||
|
</Border> |
||||||
|
</DataTemplate> |
||||||
|
|
||||||
|
<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" /> |
||||||
|
</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" /> |
||||||
|
</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" /> |
||||||
|
</Border> |
||||||
|
</DataTemplate> |
||||||
|
</UserControl.Resources> |
||||||
|
|
||||||
|
<Grid> |
||||||
|
<Grid.RowDefinitions> |
||||||
|
<RowDefinition Height="Auto" /> |
||||||
|
<RowDefinition Height="*" /> |
||||||
|
<RowDefinition Height="Auto" /> |
||||||
|
<RowDefinition Height=".2*" /> |
||||||
|
</Grid.RowDefinitions> |
||||||
|
|
||||||
|
<Grid Grid.Row="0"> |
||||||
|
<Grid.ColumnDefinitions> |
||||||
|
<ColumnDefinition Width="Auto" /> |
||||||
|
<ColumnDefinition Width="*" /> |
||||||
|
<ColumnDefinition Width="Auto" /> |
||||||
|
</Grid.ColumnDefinitions> |
||||||
|
|
||||||
|
<TextBlock Grid.Column="0" Text="Filter:" Margin="3,2,5,2" VerticalAlignment="Center" /> |
||||||
|
<TextBox |
||||||
|
Grid.Column="1" |
||||||
|
Name="searchTermTextBox" |
||||||
|
Text="{Binding SearchTerm, UpdateSourceTrigger=PropertyChanged}" |
||||||
|
Margin="0,2,3,2" |
||||||
|
VerticalAlignment="Center" |
||||||
|
KeyUp="FilterTextBox_KeyUp" /> |
||||||
|
<Button |
||||||
|
Grid.Column="2" |
||||||
|
Click="UpdateFilterButton_Click" |
||||||
|
Margin="0,2,3,2" |
||||||
|
Content="{core:Localize Global.UpdateButtonText}" /> |
||||||
|
</Grid> |
||||||
|
|
||||||
|
<ListView |
||||||
|
Name="resourceItemsListView" |
||||||
|
Grid.Row="1" |
||||||
|
ItemsSource="{Binding Source={StaticResource resourceItemListViewSource}}" |
||||||
|
ItemContainerStyle="{StaticResource listViewItemStyle}" |
||||||
|
MouseRightButtonUp="ListView_MouseRightButtonUp" |
||||||
|
KeyUp="ResourceItemsListView_KeyUp" |
||||||
|
SelectionChanged="ListView_SelectionChanged"> |
||||||
|
<ListView.View> |
||||||
|
<GridView> |
||||||
|
<GridViewColumn |
||||||
|
Header="{core:Localize Global.Name}" |
||||||
|
CellTemplate="{StaticResource resourceItemNameTemplate}" /> |
||||||
|
<GridViewColumn |
||||||
|
Header="{core:Localize ResourceEditor.ResourceEdit.TypeColumn}" |
||||||
|
CellTemplate="{StaticResource resourceItemTypeTemplate}" /> |
||||||
|
<GridViewColumn |
||||||
|
Header="{core:Localize ResourceEditor.ResourceEdit.ContentColumn}" |
||||||
|
CellTemplate="{StaticResource resourceItemContentTemplate}" /> |
||||||
|
<GridViewColumn |
||||||
|
Header="{core:Localize ResourceEditor.ResourceEdit.CommentColumn}" |
||||||
|
CellTemplate="{StaticResource resourceItemCommentTemplate}" /> |
||||||
|
</GridView> |
||||||
|
</ListView.View> |
||||||
|
</ListView> |
||||||
|
|
||||||
|
<GridSplitter |
||||||
|
Grid.Row="2" |
||||||
|
Height="5" |
||||||
|
HorizontalAlignment="Stretch" |
||||||
|
VerticalAlignment="Stretch"/> |
||||||
|
|
||||||
|
<Grid Grid.Row="3" Name="resourceItemViewGrid"></Grid> |
||||||
|
</Grid> |
||||||
|
|
||||||
|
</UserControl> |
||||||
@ -0,0 +1,203 @@ |
|||||||
|
// 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; |
||||||
|
using System.Linq; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Data; |
||||||
|
using System.Windows.Input; |
||||||
|
using ICSharpCode.Core.Presentation; |
||||||
|
using ResourceEditor.ViewModels; |
||||||
|
|
||||||
|
namespace ResourceEditor.Views |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// TextBox implementation for in-place editing of resource item fields.
|
||||||
|
/// </summary>
|
||||||
|
public class InPlaceEditTextBox : TextBox |
||||||
|
{ |
||||||
|
string textBeforeEditing; |
||||||
|
|
||||||
|
public static readonly DependencyProperty IsEditingProperty = |
||||||
|
DependencyProperty.Register("IsEditing", typeof(bool), typeof(InPlaceEditTextBox), |
||||||
|
new FrameworkPropertyMetadata()); |
||||||
|
|
||||||
|
public bool IsEditing { |
||||||
|
get { return (bool) GetValue(IsEditingProperty); } |
||||||
|
set { SetValue(IsEditingProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
public InPlaceEditTextBox() : base() |
||||||
|
{ |
||||||
|
this.Visibility = Visibility.Collapsed; |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) |
||||||
|
{ |
||||||
|
base.OnPropertyChanged(e); |
||||||
|
|
||||||
|
if (e.Property == IsEditingProperty) { |
||||||
|
if ((bool) e.NewValue) { |
||||||
|
this.Visibility = Visibility.Visible; |
||||||
|
} else { |
||||||
|
this.Visibility = Visibility.Collapsed; |
||||||
|
} |
||||||
|
} |
||||||
|
if (e.Property == VisibilityProperty) { |
||||||
|
if ((Visibility) e.NewValue == Visibility.Visible) { |
||||||
|
// Auto-select whole text as soon as TextBox becomes visible
|
||||||
|
this.Focus(); |
||||||
|
this.SelectAll(); |
||||||
|
textBeforeEditing = this.Text; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnKeyUp(KeyEventArgs e) |
||||||
|
{ |
||||||
|
base.OnKeyUp(e); |
||||||
|
|
||||||
|
if (e.Key == Key.Enter) { |
||||||
|
IsEditing = false; |
||||||
|
} else if (e.Key == Key.Escape) { |
||||||
|
// Cancel editing and restore original text
|
||||||
|
this.Text = textBeforeEditing; |
||||||
|
IsEditing = false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnLostFocus(RoutedEventArgs e) |
||||||
|
{ |
||||||
|
base.OnLostFocus(e); |
||||||
|
|
||||||
|
// When losing focus, also stop editing
|
||||||
|
IsEditing = false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for ResourceEditorView.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class ResourceEditorView : UserControl, IResourceEditorView |
||||||
|
{ |
||||||
|
readonly CollectionViewSource itemCollectionViewSource; |
||||||
|
|
||||||
|
public event EventHandler SelectionChanged; |
||||||
|
public event EventHandler EditingStarted; |
||||||
|
public event EventHandler EditingFinished; |
||||||
|
public event EventHandler EditingCancelled; |
||||||
|
|
||||||
|
public ResourceEditorView() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
itemCollectionViewSource = (CollectionViewSource) this.Resources["resourceItemListViewSource"]; |
||||||
|
} |
||||||
|
|
||||||
|
public IList SelectedItems { |
||||||
|
get { |
||||||
|
return resourceItemsListView.SelectedItems; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void SetItemView(IResourceItemView view) |
||||||
|
{ |
||||||
|
resourceItemViewGrid.Children.Clear(); |
||||||
|
view.UIControl.Visibility = Visibility.Visible; |
||||||
|
resourceItemViewGrid.Children.Add(view.UIControl); |
||||||
|
} |
||||||
|
|
||||||
|
public Predicate<ResourceEditor.ViewModels.ResourceItem> FilterPredicate { |
||||||
|
get; |
||||||
|
set; |
||||||
|
} |
||||||
|
|
||||||
|
void ListView_MouseRightButtonUp(object sender, MouseButtonEventArgs e) |
||||||
|
{ |
||||||
|
MenuService.ShowContextMenu(this, null, "/SharpDevelop/ResourceEditor/ResourceList/ContextMenu"); |
||||||
|
} |
||||||
|
|
||||||
|
void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) |
||||||
|
{ |
||||||
|
if (SelectionChanged != null) { |
||||||
|
SelectionChanged(this, new EventArgs()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void CollectionViewSource_Filter(object sender, FilterEventArgs e) |
||||||
|
{ |
||||||
|
if (FilterPredicate == null) { |
||||||
|
// No filtering without predicate
|
||||||
|
e.Accepted = true; |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
var resourceItem = e.Item as ResourceEditor.ViewModels.ResourceItem; |
||||||
|
if (resourceItem == null) { |
||||||
|
// Away with non-ResourceItems (shouldn't happen anyway)
|
||||||
|
e.Accepted = false; |
||||||
|
return; |
||||||
|
} |
||||||
|
e.Accepted = FilterPredicate(resourceItem); |
||||||
|
} |
||||||
|
|
||||||
|
void FilterTextBox_KeyUp(object sender, KeyEventArgs e) |
||||||
|
{ |
||||||
|
if (e.Key == Key.Enter) { |
||||||
|
// Apply filter text on Enter key
|
||||||
|
UpdateFilter(); |
||||||
|
} else if (e.Key == Key.Escape) { |
||||||
|
// Clear the filter text on Esc key
|
||||||
|
searchTermTextBox.Clear(); |
||||||
|
UpdateFilter(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void UpdateFilterButton_Click(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
UpdateFilter(); |
||||||
|
} |
||||||
|
|
||||||
|
void UpdateFilter() |
||||||
|
{ |
||||||
|
// Update CollectionViewSource to re-evaluate filter predicate
|
||||||
|
itemCollectionViewSource.View.Refresh(); |
||||||
|
} |
||||||
|
|
||||||
|
void ResourceItemsListView_KeyUp(object sender, KeyEventArgs e) |
||||||
|
{ |
||||||
|
/*if (e.Key == Key.Enter) { |
||||||
|
if (EditingFinished != null) { |
||||||
|
EditingFinished(this, new EventArgs()); |
||||||
|
} |
||||||
|
} else if (e.Key == Key.Escape) { |
||||||
|
if (EditingCancelled != null) { |
||||||
|
EditingCancelled(this, new EventArgs()); |
||||||
|
} |
||||||
|
} else*/ |
||||||
|
if (e.Key == Key.F2) { |
||||||
|
if (EditingStarted != null) { |
||||||
|
EditingStarted(this, new EventArgs()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
e.Handled = false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,76 @@ |
|||||||
|
// 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.Windows.Media; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
|
||||||
|
namespace ResourceEditor.Views |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Provides resource icons for different <see cref="ResourceEditor.ViewModels.ResourceItem"/> types.
|
||||||
|
/// </summary>
|
||||||
|
public class ResourceItemIcons |
||||||
|
{ |
||||||
|
public ResourceItemIcons() |
||||||
|
{ |
||||||
|
UnknownResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.obj"); |
||||||
|
StringResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.string"); |
||||||
|
BooleanResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.obj"); |
||||||
|
BitmapResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.bmp"); |
||||||
|
IconResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.icon"); |
||||||
|
CursorResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.cursor"); |
||||||
|
BinaryResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.bin"); |
||||||
|
} |
||||||
|
|
||||||
|
public ImageSource UnknownResourceIcon { |
||||||
|
get; |
||||||
|
private set; |
||||||
|
} |
||||||
|
|
||||||
|
public ImageSource StringResourceIcon { |
||||||
|
get; |
||||||
|
private set; |
||||||
|
} |
||||||
|
|
||||||
|
public ImageSource BooleanResourceIcon { |
||||||
|
get; |
||||||
|
private set; |
||||||
|
} |
||||||
|
|
||||||
|
public ImageSource BitmapResourceIcon { |
||||||
|
get; |
||||||
|
private set; |
||||||
|
} |
||||||
|
|
||||||
|
public ImageSource IconResourceIcon { |
||||||
|
get; |
||||||
|
private set; |
||||||
|
} |
||||||
|
|
||||||
|
public ImageSource CursorResourceIcon { |
||||||
|
get; |
||||||
|
private set; |
||||||
|
} |
||||||
|
|
||||||
|
public ImageSource BinaryResourceIcon { |
||||||
|
get; |
||||||
|
private set; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
<UserControl x:Class="ResourceEditor.Views.TextView" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||||
|
<Grid> |
||||||
|
<TextBox |
||||||
|
Margin="0,0,0,0" |
||||||
|
Text="{Binding Path=ResourceValue, UpdateSourceTrigger=PropertyChanged}" |
||||||
|
TextWrapping="Wrap" |
||||||
|
AcceptsReturn="True" |
||||||
|
VerticalScrollBarVisibility="Auto" /> |
||||||
|
</Grid> |
||||||
|
</UserControl> |
||||||
@ -0,0 +1,56 @@ |
|||||||
|
// 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 |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for TextView.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class TextView : UserControl, IResourceItemView |
||||||
|
{ |
||||||
|
public TextView() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
} |
||||||
|
|
||||||
|
public FrameworkElement UIControl { |
||||||
|
get { |
||||||
|
return this; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public ResourceEditor.ViewModels.ResourceItem ResourceItem { |
||||||
|
get { |
||||||
|
return DataContext as ViewModels.ResourceItem; |
||||||
|
} |
||||||
|
set { |
||||||
|
DataContext = value; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue