Browse Source

Context actions UI almost final.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6414 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Martin Koníček 15 years ago
parent
commit
6f541bcaf4
  1. 6
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActionsRenderer.cs
  2. 4
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  3. 29
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/BoolToVisibilityConverter.cs
  4. 43
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionCommand.cs
  5. 32
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionViewModel.cs
  6. 58
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml
  7. 24
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml.cs
  8. 4
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbPopup.cs
  9. 90
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbViewModel.cs
  10. 88
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml
  11. 29
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml.cs
  12. 12
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHeaderedControl.xaml
  13. 42
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHiddenViewModel.cs
  14. 9
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/EditorContext.cs

6
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActionsRenderer.cs

@ -102,7 +102,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -102,7 +102,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
return;
ClosePopup();
ContextActionsHiddenViewModel popupVM = BuildPopupViewModel(this.Editor);
ContextActionsBulbViewModel popupVM = BuildPopupViewModel(this.Editor);
//availableActionsVM.Title =
//availableActionsVM.Image =
if (popupVM.Actions.Count == 0)
@ -111,10 +111,10 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -111,10 +111,10 @@ namespace ICSharpCode.AvalonEdit.AddIn
this.popup.OpenAtLineStart(this.Editor);
}
ContextActionsHiddenViewModel BuildPopupViewModel(ITextEditor editor)
ContextActionsBulbViewModel BuildPopupViewModel(ITextEditor editor)
{
var actionsProvider = ContextActionsService.Instance.GetAvailableActions(editor);
return new ContextActionsHiddenViewModel(actionsProvider);
return new ContextActionsBulbViewModel(actionsProvider);
}
void CaretPositionChanged(object sender, EventArgs e)

4
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -331,6 +331,7 @@ @@ -331,6 +331,7 @@
<Compile Include="Src\Services\ParserService\ParserService.cs" />
<Compile Include="Src\Services\ProjectService\CompileModifiedProjectsOnly.cs" />
<Compile Include="Src\Services\ProjectService\SolutionConfigurationEventHandler.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\BoolToVisibilityConverter.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextAction.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsBulbControl.xaml.cs">
<DependentUpon>ContextActionsBulbControl.xaml</DependentUpon>
@ -341,13 +342,12 @@ @@ -341,13 +342,12 @@
<DependentUpon>ContextActionsHeaderedControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsHiddenViewModel.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsBulbViewModel.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsPopupBase.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsProvider.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsService.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\EditorContext.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\IContextAction.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionCommand.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsControl.xaml.cs">
<DependentUpon>ContextActionsControl.xaml</DependentUpon>
</Compile>

29
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/BoolToVisibilityConverter.cs

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Martin Konicek" email="martin.konicek@gmail.com"/>
// <version>$Revision: $</version>
// </file>
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace ICSharpCode.SharpDevelop.Refactoring
{
[ValueConversion(typeof(bool), typeof(Visibility))]
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool)value)
return Visibility.Visible;
return Visibility.Hidden;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}

43
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionCommand.cs

@ -1,43 +0,0 @@ @@ -1,43 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Martin Konicek" email="martin.konicek@gmail.com"/>
// <version>$Revision: $</version>
// </file>
using System;
using System.Windows.Input;
namespace ICSharpCode.SharpDevelop.Refactoring
{
/// <summary>
/// Just wraps <see cref="IContextAction"></see> inside a WPF Command to be used in XAML.
/// </summary>
public class ContextActionCommand : ICommand
{
IContextAction action;
public ContextActionCommand(IContextAction action)
{
if (action == null)
throw new ArgumentNullException("action");
this.action = action;
}
public event EventHandler CanExecuteChanged
{
// not supported - Context actions can always be executed
add { }
remove { }
}
public void Execute(object parameter)
{
this.action.Execute();
}
public bool CanExecute(object parameter)
{
return true;
}
}
}

32
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionViewModel.cs

@ -57,4 +57,36 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -57,4 +57,36 @@ namespace ICSharpCode.SharpDevelop.Refactoring
public ICommand ActionCommand { get; private set; }
}
/// <summary>
/// Just wraps <see cref="IContextAction"></see> inside a WPF Command to be used in XAML.
/// </summary>
public class ContextActionCommand : ICommand
{
IContextAction action;
public ContextActionCommand(IContextAction action)
{
if (action == null)
throw new ArgumentNullException("action");
this.action = action;
}
public event EventHandler CanExecuteChanged
{
// not supported - Context actions can always be executed
add { }
remove { }
}
public void Execute(object parameter)
{
this.action.Execute();
}
public bool CanExecute(object parameter)
{
return true;
}
}
}

58
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
<SolidColorBrush x:Key="OuterBorderBrush" Color="#436C82"></SolidColorBrush>
<BitmapImage x:Key="PencilImage" UriSource="pencil.png" />
<Geometry x:Key="DownArrowGeometry">M 0 0 L 2 3 L 4 0 Z</Geometry>
<local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<Style x:Key="ExpanderDownHeaderStyle"
TargetType="{x:Type ToggleButton}">
@ -17,7 +18,7 @@ @@ -17,7 +18,7 @@
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Padding="{TemplateBinding Control.Padding}">
<Grid>
<Border Name="headerBorder" Height="10" >
<Border Name="headerBorder" Height="8" >
<Path Name="arrow" Data="M1,1.5L4.5,5 8,1.5" Stroke="#888" StrokeThickness="2" HorizontalAlignment="Center" VerticalAlignment="Center" SnapsToDevicePixels="False" />
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
@ -71,16 +72,9 @@ @@ -71,16 +72,9 @@
Value="Stretch"/>
<Setter Property="BorderBrush"
Value="Transparent"/>
<Setter Property="BorderThickness"
Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Expander}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
CornerRadius="3"
SnapsToDevicePixels="true">
<DockPanel>
<ToggleButton x:Name="HeaderSite"
DockPanel.Dock="Top"
@ -109,7 +103,6 @@ @@ -109,7 +103,6 @@
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"/>
</DockPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded"
Value="true">
@ -129,6 +122,8 @@ @@ -129,6 +122,8 @@
</Style>
</UserControl.Resources>
<!-- Visual tree -->
<Grid Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
@ -172,13 +167,50 @@ @@ -172,13 +167,50 @@
<!-- Content -->
<Border x:Name="ContentBorder" Padding="0 0 8 8" Grid.Row="1" Grid.Column="0" MinWidth="200" Background="White">
<aero:SystemDropShadowChrome>
<Border BorderThickness="1" BorderBrush="{StaticResource OuterBorderBrush}" HorizontalAlignment="Stretch">
<Border BorderThickness="1" Padding="0" Margin="0" BorderBrush="{StaticResource OuterBorderBrush}">
<StackPanel Orientation="Vertical">
<local:ContextActionsControl x:Name="ActionsTreeView"
DataContext="{Binding Actions}" ActionVisibleChanged="ActionsTreeView_ActionVisibleChanged"></local:ContextActionsControl>
<Expander x:Name="HiddenActionsExpander" Expanded="Expander_Expanded" Grid.Row="2" Grid.Column="0">
DataContext="{Binding Actions}">
<local:ContextActionsControl.ItemTemplate>
<DataTemplate>
<DockPanel HorizontalAlignment="Stretch" LastChildFill="True">
<Image Source="{Binding Image}" Margin="3 2 4 2" DockPanel.Dock="Left" />
<!-- Command of every checkbox is the command on the main DataContext (ContextActionsBulbViewModel) -->
<CheckBox IsChecked="{Binding IsVisible}" VerticalAlignment="Center" DockPanel.Dock="Right"
Command="{Binding Path=DataContext.ActionVisibleChangedCommand,
RelativeSource={RelativeSource AncestorType={x:Type local:ContextActionsBulbControl}}}"
CommandParameter="{Binding}"
Visibility="{Binding DataContext.IsHiddenActionsExpanded,
RelativeSource={RelativeSource AncestorType={x:Type local:ContextActionsBulbControl}},
Converter={StaticResource BoolToVisibilityConverter}}"
Click="CheckBox_Click"
Focusable="False">
</CheckBox>
<TextBlock Text="{Binding Name}" Margin="0 2 20 2" />
</DockPanel>
</DataTemplate>
</local:ContextActionsControl.ItemTemplate>
</local:ContextActionsControl>
<Expander x:Name="HiddenActionsExpander" Expanded="Expander_Expanded"
IsExpanded="{Binding IsHiddenActionsExpanded}"
Grid.Row="2" Grid.Column="0" Margin="0">
<local:ContextActionsControl x:Name="HiddenActionsTreeView"
DataContext="{Binding HiddenActions}" ActionVisibleChanged="HiddenActionsTreeView_ActionVisibleChanged"></local:ContextActionsControl>
DataContext="{Binding HiddenActions}">
<local:ContextActionsControl.ItemTemplate>
<DataTemplate>
<DockPanel HorizontalAlignment="Stretch" LastChildFill="True">
<Image Source="{Binding Image}" Margin="3 2 4 2" DockPanel.Dock="Left" />
<CheckBox IsChecked="{Binding IsVisible}" VerticalAlignment="Center" DockPanel.Dock="Right"
Command="{Binding Path=DataContext.ActionVisibleChangedCommand,
RelativeSource={RelativeSource AncestorType={x:Type local:ContextActionsBulbControl}}}"
CommandParameter="{Binding}"
Click="CheckBox_Click"
Focusable="False"></CheckBox>
<TextBlock Text="{Binding Name}" Margin="0 2 20 2" />
</DockPanel>
</DataTemplate>
</local:ContextActionsControl.ItemTemplate>
</local:ContextActionsControl>
</Expander>
</StackPanel>
</Border>

24
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml.cs

@ -33,9 +33,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -33,9 +33,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring
remove { this.ActionsTreeView.ActionExecuted -= value; }
}
public new ContextActionsHiddenViewModel DataContext
public new ContextActionsBulbViewModel DataContext
{
get { return (ContextActionsHiddenViewModel)base.DataContext; }
get { return (ContextActionsBulbViewModel)base.DataContext; }
set { base.DataContext = value; }
}
@ -69,26 +69,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -69,26 +69,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring
this.IsOpen = !this.IsOpen;
}
void ActionsTreeView_ActionVisibleChanged(object sender, ContextActionViewModelEventArgs e)
{
var clickedAction = e.Action;
this.DataContext.Model.SetVisible(clickedAction.Action, false);
// this.DataContext.Actions.Remove(clickedAction);
// this.DataContext.HiddenActions.Add(clickedAction);
}
void HiddenActionsTreeView_ActionVisibleChanged(object sender, ContextActionViewModelEventArgs e)
void Expander_Expanded(object sender, RoutedEventArgs e)
{
var clickedAction = e.Action;
this.DataContext.Model.SetVisible(clickedAction.Action, true);
// this.DataContext.HiddenActions.Remove(clickedAction);
// this.DataContext.Actions.Add(clickedAction);
this.DataContext.LoadHiddenActions();
}
void Expander_Expanded(object sender, RoutedEventArgs e)
void CheckBox_Click(object sender, RoutedEventArgs e)
{
this.DataContext.LoadHiddenActions();
e.Handled = true;
}
}
}

4
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbPopup.cs

@ -29,9 +29,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -29,9 +29,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring
set { this.Child = value; }
}
public ContextActionsHiddenViewModel ViewModel
public ContextActionsBulbViewModel ViewModel
{
get { return (ContextActionsHiddenViewModel)this.DataContext; }
get { return (ContextActionsBulbViewModel)this.DataContext; }
set { this.DataContext = value; }
}

90
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbViewModel.cs

@ -0,0 +1,90 @@ @@ -0,0 +1,90 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Martin Konicek" email="martin.konicek@gmail.com"/>
// <version>$Revision: $</version>
// </file>
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
namespace ICSharpCode.SharpDevelop.Refactoring
{
/// <summary>
/// Description of ContextActionsHiddenViewModel.
/// </summary>
public class ContextActionsBulbViewModel : ContextActionsViewModel, INotifyPropertyChanged
{
public EditorActionsProvider Model { get; private set; }
public ObservableCollection<ContextActionViewModel> HiddenActions { get; set; }
bool isHiddenActionsExpanded;
public bool IsHiddenActionsExpanded {
get { return isHiddenActionsExpanded; }
set {
isHiddenActionsExpanded = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("IsHiddenActionsExpanded"));
}
}
public ContextActionsBulbViewModel(EditorActionsProvider model)
{
this.Model = model;
this.Actions = new ObservableCollection<ContextActionViewModel>(
model.GetVisibleActions().Select(a => new ContextActionViewModel(a) { IsVisible = true } ));
this.HiddenActions = new ObservableCollection<ContextActionViewModel>();
this.ActionVisibleChangedCommand = new ActionVisibleChangedCommand(model);
}
bool hiddenActionsLoaded = false;
public void LoadHiddenActions()
{
if (hiddenActionsLoaded)
return;
this.HiddenActions.AddRange(
Model.GetHiddenActions().Select(a => new ContextActionViewModel(a) { IsVisible = false } ));
hiddenActionsLoaded = true;
}
public ActionVisibleChangedCommand ActionVisibleChangedCommand { get; private set; }
public event PropertyChangedEventHandler PropertyChanged;
}
public class ActionVisibleChangedCommand : ICommand
{
public EditorActionsProvider Model { get; private set; }
public ActionVisibleChangedCommand(EditorActionsProvider model)
{
if (model == null)
throw new ArgumentNullException("model");
this.Model = model;
}
public event EventHandler CanExecuteChanged
{
// not supported - Checkbox can be always clicked
add { }
remove { }
}
public void Execute(object parameter)
{
var clickedAction = (ContextActionViewModel)parameter;
this.Model.SetVisible(clickedAction.Action, clickedAction.IsVisible);
}
public bool CanExecute(object parameter)
{
return true;
}
}
}

88
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:ICSharpCode.SharpDevelop.Refactoring"
xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
<!--The treeview with Context actions. Accepts IEnumerable<ContextActionViewModel> as its DataContext.-->
@ -49,34 +50,35 @@ @@ -49,34 +50,35 @@
</Setter>
</Style>
</UserControl.Resources>
<TreeView x:Name="TreeView" ItemsSource="{Binding}" BorderThickness="0">
<TreeView.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="White"/>
</LinearGradientBrush>
</TreeView.Background>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeViewItem">
<StackPanel>
<!-- ActionButtonClick is used just to close the Popup -->
<Button Command="{Binding ActionCommand}" Style="{StaticResource ClearButton}" Click="ActionButtonClick">
<Border SnapsToDevicePixels="True">
<ContentPresenter Content="{TemplateBinding HeaderedContentControl.Header}" ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}" ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}" ContentSource="Header" Name="PART_Header"
HorizontalAlignment="Stretch" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</Border>
</Button>
<Border Padding="14 0 0 0">
<ItemsPresenter Name="ItemsHost" />
<TreeView x:Name="TreeView" ItemsSource="{Binding}" BorderThickness="0"
ItemTemplate="{Binding Path=ItemTemplate, RelativeSource={RelativeSource AncestorType={x:Type local:ContextActionsControl}}}">
<TreeView.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="White"/>
</LinearGradientBrush>
</TreeView.Background>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeViewItem">
<StackPanel>
<!-- ActionButtonClick event is used just to close the Popup -->
<Button Command="{Binding ActionCommand}" Style="{StaticResource ClearButton}" Click="ActionButtonClick">
<Border SnapsToDevicePixels="True">
<ContentPresenter Content="{TemplateBinding HeaderedContentControl.Header}" ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}" ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}" ContentSource="Header" Name="PART_Header"
HorizontalAlignment="Stretch" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</Border>
</StackPanel>
<ControlTemplate.Triggers>
<!-- Disable collapsing -->
<!--<Trigger Property="TreeViewItem.IsExpanded">
</Button>
<Border Padding="14 0 0 0">
<ItemsPresenter Name="ItemsHost" />
</Border>
</StackPanel>
<ControlTemplate.Triggers>
<!-- Disable collapsing -->
<!--<Trigger Property="TreeViewItem.IsExpanded">
<Setter Property="UIElement.Visibility" TargetName="ItemsHost">
<Setter.Value>
<x:Static Member="Visibility.Collapsed" />
@ -86,26 +88,16 @@ @@ -86,26 +88,16 @@
<s:Boolean>False</s:Boolean>
</Trigger.Value>
</Trigger>-->
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- Make all items expanded -->
<Setter Property="IsExpanded" Value="True"></Setter>
<!-- Make items not focusable so that contained button (not the TreeViewItem) gets focus on Down arrow -->
<Setter Property="Focusable" Value="False"></Setter>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding ChildActions}">
<DockPanel HorizontalAlignment="Stretch" LastChildFill="True">
<Image Source="{Binding Image}" Margin="3 2 4 2" />
<CheckBox IsChecked="{Binding IsVisible}" DockPanel.Dock="Right" VerticalAlignment="Center" Click="CheckBox_Click" Checked="CheckBox_Changed" Unchecked="CheckBox_Changed" />
<TextBlock Text="{Binding Comment}" Foreground="Gray" TextAlignment="Right" DockPanel.Dock="Right"/>
<TextBlock Text="{Binding Name}" Margin="0 2 20 2" />
</DockPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- Make all items expanded -->
<Setter Property="IsExpanded" Value="True"></Setter>
<!-- Make items not focusable so that contained button (not the TreeViewItem) gets focus on Down arrow -->
<Setter Property="Focusable" Value="False"></Setter>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
</UserControl>

29
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml.cs

@ -58,30 +58,13 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -58,30 +58,13 @@ namespace ICSharpCode.SharpDevelop.Refactoring
return null;
}
public event EventHandler<ContextActionViewModelEventArgs> ActionVisibleChanged;
public static readonly DependencyProperty ItemTemplateProperty =
DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(ContextActionsControl),
new FrameworkPropertyMetadata());
void CheckBox_Changed(object sender, RoutedEventArgs e)
{
var contextActionVM = (ContextActionViewModel)((CheckBox)sender).DataContext;
if (ActionVisibleChanged != null)
ActionVisibleChanged(sender, new ContextActionViewModelEventArgs(contextActionVM));
}
void CheckBox_Click(object sender, RoutedEventArgs e)
{
e.Handled = true;
}
}
public class ContextActionViewModelEventArgs : EventArgs
{
public ContextActionViewModel Action { get; private set; }
public ContextActionViewModelEventArgs(ContextActionViewModel action)
{
if (action == null)
throw new ArgumentNullException("action");
this.Action = action;
public DataTemplate ItemTemplate {
get { return (DataTemplate)GetValue(ItemTemplateProperty); }
set { SetValue(ItemTemplateProperty, value); }
}
}
}

12
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHeaderedControl.xaml

@ -36,7 +36,17 @@ @@ -36,7 +36,17 @@
<aero:SystemDropShadowChrome>
<Border BorderThickness="1" BorderBrush="{StaticResource OuterBorderBrush}" HorizontalAlignment="Stretch">
<!-- Content - TreeView -->
<local:ContextActionsControl x:Name="ActionsTreeView" DataContext="{Binding Actions}"></local:ContextActionsControl>
<local:ContextActionsControl x:Name="ActionsTreeView" DataContext="{Binding Actions}">
<local:ContextActionsControl.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding ChildActions}">
<DockPanel HorizontalAlignment="Stretch" LastChildFill="True">
<Image Source="{Binding Image}" Margin="3 2 4 2" DockPanel.Dock="Left" />
<TextBlock Text="{Binding Comment}" Foreground="Gray" TextAlignment="Right" DockPanel.Dock="Right"/>
<TextBlock Text="{Binding Name}" Margin="0 2 20 2" />
</DockPanel>
</HierarchicalDataTemplate>
</local:ContextActionsControl.ItemTemplate>
</local:ContextActionsControl>
</Border>
</aero:SystemDropShadowChrome>
</Border>

42
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHiddenViewModel.cs

@ -1,42 +0,0 @@ @@ -1,42 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Martin Konicek" email="martin.konicek@gmail.com"/>
// <version>$Revision: $</version>
// </file>
using System;
using System.Collections.ObjectModel;
using System.Linq;
namespace ICSharpCode.SharpDevelop.Refactoring
{
/// <summary>
/// Description of ContextActionsHiddenViewModel.
/// </summary>
public class ContextActionsHiddenViewModel : ContextActionsViewModel
{
public EditorActionsProvider Model { get; private set; }
public ObservableCollection<ContextActionViewModel> HiddenActions { get; set; }
public ContextActionsHiddenViewModel(EditorActionsProvider model)
{
this.Model = model;
this.Actions = new ObservableCollection<ContextActionViewModel>(
model.GetVisibleActions().Select(a => new ContextActionViewModel(a) { IsVisible = true } ));
this.HiddenActions = new ObservableCollection<ContextActionViewModel>();
}
bool hiddenActionsLoaded = false;
public void LoadHiddenActions()
{
if (hiddenActionsLoaded)
return;
this.HiddenActions.AddRange(
Model.GetHiddenActions().Select(a => new ContextActionViewModel(a) { IsVisible = false } ));
hiddenActionsLoaded = true;
}
}
}

9
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/EditorContext.cs

@ -200,7 +200,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -200,7 +200,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (currentLine == null)
return null;
var snippetParser = GetSnippetParser(editor);
return snippetParser.Parse(currentLine.Text);
if (snippetParser == null)
return null;
try {
return snippetParser.Parse(currentLine.Text);
}
catch {
return null;
}
}
SnippetParser GetSnippetParser(ITextEditor editor)

Loading…
Cancel
Save