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

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

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

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

@ -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 @@
// <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
public ICommand ActionCommand { get; private set; } 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 @@
<SolidColorBrush x:Key="OuterBorderBrush" Color="#436C82"></SolidColorBrush> <SolidColorBrush x:Key="OuterBorderBrush" Color="#436C82"></SolidColorBrush>
<BitmapImage x:Key="PencilImage" UriSource="pencil.png" /> <BitmapImage x:Key="PencilImage" UriSource="pencil.png" />
<Geometry x:Key="DownArrowGeometry">M 0 0 L 2 3 L 4 0 Z</Geometry> <Geometry x:Key="DownArrowGeometry">M 0 0 L 2 3 L 4 0 Z</Geometry>
<local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<Style x:Key="ExpanderDownHeaderStyle" <Style x:Key="ExpanderDownHeaderStyle"
TargetType="{x:Type ToggleButton}"> TargetType="{x:Type ToggleButton}">
@ -17,7 +18,7 @@
<ControlTemplate TargetType="{x:Type ToggleButton}"> <ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Padding="{TemplateBinding Control.Padding}"> <Border Padding="{TemplateBinding Control.Padding}">
<Grid> <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" /> <Path Name="arrow" Data="M1,1.5L4.5,5 8,1.5" Stroke="#888" StrokeThickness="2" HorizontalAlignment="Center" VerticalAlignment="Center" SnapsToDevicePixels="False" />
<Border.Background> <Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
@ -71,16 +72,9 @@
Value="Stretch"/> Value="Stretch"/>
<Setter Property="BorderBrush" <Setter Property="BorderBrush"
Value="Transparent"/> Value="Transparent"/>
<Setter Property="BorderThickness"
Value="1"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Expander}"> <ControlTemplate TargetType="{x:Type Expander}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
CornerRadius="3"
SnapsToDevicePixels="true">
<DockPanel> <DockPanel>
<ToggleButton x:Name="HeaderSite" <ToggleButton x:Name="HeaderSite"
DockPanel.Dock="Top" DockPanel.Dock="Top"
@ -109,7 +103,6 @@
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"/> Margin="{TemplateBinding Padding}"/>
</DockPanel> </DockPanel>
</Border>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsExpanded" <Trigger Property="IsExpanded"
Value="true"> Value="true">
@ -129,6 +122,8 @@
</Style> </Style>
</UserControl.Resources> </UserControl.Resources>
<!-- Visual tree -->
<Grid Background="Transparent"> <Grid Background="Transparent">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition></RowDefinition> <RowDefinition></RowDefinition>
@ -172,13 +167,50 @@
<!-- Content --> <!-- Content -->
<Border x:Name="ContentBorder" Padding="0 0 8 8" Grid.Row="1" Grid.Column="0" MinWidth="200" Background="White"> <Border x:Name="ContentBorder" Padding="0 0 8 8" Grid.Row="1" Grid.Column="0" MinWidth="200" Background="White">
<aero:SystemDropShadowChrome> <aero:SystemDropShadowChrome>
<Border BorderThickness="1" BorderBrush="{StaticResource OuterBorderBrush}" HorizontalAlignment="Stretch"> <Border BorderThickness="1" Padding="0" Margin="0" BorderBrush="{StaticResource OuterBorderBrush}">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<local:ContextActionsControl x:Name="ActionsTreeView" <local:ContextActionsControl x:Name="ActionsTreeView"
DataContext="{Binding Actions}" ActionVisibleChanged="ActionsTreeView_ActionVisibleChanged"></local:ContextActionsControl> DataContext="{Binding Actions}">
<Expander x:Name="HiddenActionsExpander" Expanded="Expander_Expanded" Grid.Row="2" Grid.Column="0"> <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" <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> </Expander>
</StackPanel> </StackPanel>
</Border> </Border>

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

@ -33,9 +33,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring
remove { this.ActionsTreeView.ActionExecuted -= value; } 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; } set { base.DataContext = value; }
} }
@ -69,26 +69,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring
this.IsOpen = !this.IsOpen; this.IsOpen = !this.IsOpen;
} }
void ActionsTreeView_ActionVisibleChanged(object sender, ContextActionViewModelEventArgs e) void Expander_Expanded(object sender, RoutedEventArgs 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)
{ {
var clickedAction = e.Action; this.DataContext.LoadHiddenActions();
this.DataContext.Model.SetVisible(clickedAction.Action, true);
// this.DataContext.HiddenActions.Remove(clickedAction);
// this.DataContext.Actions.Add(clickedAction);
} }
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
set { this.Child = value; } set { this.Child = value; }
} }
public ContextActionsHiddenViewModel ViewModel public ContextActionsBulbViewModel ViewModel
{ {
get { return (ContextActionsHiddenViewModel)this.DataContext; } get { return (ContextActionsBulbViewModel)this.DataContext; }
set { this.DataContext = value; } set { this.DataContext = value; }
} }

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

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

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

@ -58,30 +58,13 @@ namespace ICSharpCode.SharpDevelop.Refactoring
return null; 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) public DataTemplate ItemTemplate {
{ get { return (DataTemplate)GetValue(ItemTemplateProperty); }
var contextActionVM = (ContextActionViewModel)((CheckBox)sender).DataContext; set { SetValue(ItemTemplateProperty, value); }
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;
} }
} }
} }

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

@ -36,7 +36,17 @@
<aero:SystemDropShadowChrome> <aero:SystemDropShadowChrome>
<Border BorderThickness="1" BorderBrush="{StaticResource OuterBorderBrush}" HorizontalAlignment="Stretch"> <Border BorderThickness="1" BorderBrush="{StaticResource OuterBorderBrush}" HorizontalAlignment="Stretch">
<!-- Content - TreeView --> <!-- 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> </Border>
</aero:SystemDropShadowChrome> </aero:SystemDropShadowChrome>
</Border> </Border>

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

@ -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
if (currentLine == null) if (currentLine == null)
return null; return null;
var snippetParser = GetSnippetParser(editor); 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) SnippetParser GetSnippetParser(ITextEditor editor)

Loading…
Cancel
Save