15 changed files with 525 additions and 251 deletions
@ -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,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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue