Browse Source

Split ContextActionsControl to 2 different classes: one for Popup in the margin, one for "Derived classes" popup.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6339 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Martin Koníček 16 years ago
parent
commit
a842a3b8f5
  1. 3
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActionsRenderer.cs
  2. 7
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  3. 37
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml
  4. 57
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml.cs
  5. 53
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbPopup.cs
  6. 4
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHeaderedControl.xaml
  7. 33
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHeaderedControl.xaml.cs
  8. 65
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopup.cs
  9. 74
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopupBase.cs
  10. 6
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActionsHelper.cs

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

@ -26,7 +26,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -26,7 +26,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// <summary>
/// This popup is reused (closed and opened again).
/// </summary>
ContextActionsPopup popup = new ContextActionsPopup() { StaysOpen = true };
ContextActionsBulbPopup popup = new ContextActionsBulbPopup();
/// <summary>
/// Delays the available actions resolution so that it does not get called too often when user holds an arrow.
@ -87,7 +87,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -87,7 +87,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
return;
this.popup.Actions = new ContextActionsViewModel {
Title = "#",
//Image = ClassBrowserIconService.Class.ImageSource,
Actions = availableActionsVM
};

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

@ -331,10 +331,16 @@ @@ -331,10 +331,16 @@
<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\ContextActionsBulbControl.xaml.cs">
<DependentUpon>ContextActionsBulbControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsBulbPopup.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsHeaderedControl.xaml.cs">
<DependentUpon>ContextActionsHeaderedControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsPopupBase.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" />
@ -793,6 +799,7 @@ @@ -793,6 +799,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Page Include="Src\Services\RefactoringService\ContextActions\ContextActionsBulbControl.xaml" />
<Page Include="Src\Services\RefactoringService\ContextActions\ContextActionsControl.xaml" />
<Page Include="Src\Services\RefactoringService\ContextActions\ContextActionsHeaderedControl.xaml" />
<ProjectReference Include="..\..\..\Libraries\AvalonDock\AvalonDock\AvalonDock.csproj">

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

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
<UserControl x:Class="ICSharpCode.SharpDevelop.Refactoring.ContextActionsBulbControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ICSharpCode.SharpDevelop.Refactoring"
xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
<UserControl.Resources>
<SolidColorBrush x:Key="OuterBorderBrush" Color="#436C82"></SolidColorBrush>
</UserControl.Resources>
<Grid Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<!-- Header -->
<Border x:Name="Header" Grid.Row="0" Grid.Column="0" Padding="4" BorderThickness="1"
BorderBrush="{StaticResource OuterBorderBrush}" HorizontalAlignment="Left" MouseUp="Header_MouseUp">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#D6E9FF" Offset="0"/>
<GradientStop Color="#A3CEFF" Offset="0.5"/>
</LinearGradientBrush>
</Border.Background>
<StackPanel Orientation="Horizontal">
<TextBlock Text="###"></TextBlock>
</StackPanel>
</Border>
<!-- Content - TreeView -->
<local:ContextActionsControl x:Name="ActionsTreeView" Grid.Row="1" Grid.Column="0" DataContext="{Binding Actions}"></local:ContextActionsControl>
</Grid>
</UserControl>

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

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
// <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.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 ICSharpCode.SharpDevelop.Refactoring
{
/// <summary>
/// Interaction logic for ContextActionsBulbControl.xaml
/// </summary>
public partial class ContextActionsBulbControl : UserControl
{
public ContextActionsBulbControl()
{
InitializeComponent();
}
public event EventHandler ActionExecuted
{
add { this.ActionsTreeView.ActionExecuted += value; }
remove { this.ActionsTreeView.ActionExecuted -= value; }
}
bool isOpen;
public bool IsOpen {
get { return isOpen; }
set {
isOpen = value;
this.Header.Opacity = isOpen ? 1.0 : 0.5;
this.Header.BorderThickness = isOpen ? new Thickness(1, 1, 1, 0) : new Thickness(1);
this.ActionsTreeView.Visibility = isOpen ? Visibility.Visible : Visibility.Collapsed;
}
}
public new void Focus()
{
if (this.ActionsTreeView != null)
this.ActionsTreeView.Focus();
}
void Header_MouseUp(object sender, MouseButtonEventArgs e)
{
this.IsOpen = !this.IsOpen;
}
}
}

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

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
// <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 ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.SharpDevelop.Refactoring
{
/// <summary>
/// Description of ContextActionsBulbPopup.
/// </summary>
public class ContextActionsBulbPopup : ContextActionsPopupBase
{
public ContextActionsBulbPopup()
{
this.StaysOpen = true;
this.AllowsTransparency = true;
this.ActionsControl = new ContextActionsBulbControl();
// Close when any action excecuted
this.ActionsControl.ActionExecuted += delegate { this.Close(); };
}
public ContextActionsBulbControl ActionsControl
{
get { return (ContextActionsBulbControl)this.Child; }
set { this.Child = value; }
}
public ContextActionsViewModel Actions
{
get { return (ContextActionsViewModel)ActionsControl.DataContext; }
set {
ActionsControl.DataContext = value;
}
}
public bool IsDropdownOpen { get { return ActionsControl.IsOpen; } set {ActionsControl.IsOpen = value; } }
public new void Focus()
{
this.ActionsControl.Focus();
}
public void OpenAtLineStart(ITextEditor editor)
{
OpenAtPosition(editor, editor.Caret.Line, 1, false);
this.VerticalOffset -= 16;
}
}
}

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

@ -18,8 +18,8 @@ @@ -18,8 +18,8 @@
</Grid.ColumnDefinitions>
<!-- Header -->
<Border x:Name="Header" Grid.Row="0" Grid.Column="0" Padding="4" BorderThickness="1"
BorderBrush="{StaticResource OuterBorderBrush}" HorizontalAlignment="Left" MouseUp="Header_MouseUp">
<Border x:Name="Header" Grid.Row="0" Grid.Column="0" Padding="4" BorderThickness="1 1 1 0"
BorderBrush="{StaticResource OuterBorderBrush}" HorizontalAlignment="Left">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#D6E9FF" Offset="0"/>

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

@ -24,31 +24,6 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -24,31 +24,6 @@ namespace ICSharpCode.SharpDevelop.Refactoring
public ContextActionsHeaderedControl()
{
InitializeComponent();
this.IsAlwaysOpen = false;
this.IsOpen = false;
}
bool isAlwaysOpen;
public bool IsAlwaysOpen {
get { return isAlwaysOpen; }
set {
isAlwaysOpen = value;
if (value)
IsOpen = true;
}
}
bool isOpen;
public bool IsOpen {
get { return isOpen; }
set {
if (IsAlwaysOpen && !value)
throw new InvalidOperationException("Cannot set IsOpen to false when IsAlwaysOpen is true");
isOpen = value;
this.Header.Opacity = isOpen ? 1.0 : 0.5;
this.Header.BorderThickness = isOpen ? new Thickness(1, 1, 1, 0) : new Thickness(1);
this.ActionsTreeView.Visibility = isOpen ? Visibility.Visible : Visibility.Collapsed;
}
}
public event EventHandler ActionExecuted
@ -62,13 +37,5 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -62,13 +37,5 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (this.ActionsTreeView != null)
this.ActionsTreeView.Focus();
}
void Header_MouseUp(object sender, MouseButtonEventArgs e)
{
if (!this.IsAlwaysOpen)
{
this.IsOpen = !this.IsOpen;
}
}
}
}

65
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopup.cs

@ -16,29 +16,19 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -16,29 +16,19 @@ namespace ICSharpCode.SharpDevelop.Refactoring
/// <summary>
/// Description of ContextActionsPopup.
/// </summary>
public class ContextActionsPopup : Popup
public class ContextActionsPopup : ContextActionsPopupBase
{
public ContextActionsPopup()
{
this.StaysOpen = false;
// Close on lost focus
this.StaysOpen = false;
this.AllowsTransparency = true;
this.ActionsControl = new ContextActionsHeaderedControl();
// Close when any action excecuted
this.ActionsControl.ActionExecuted += delegate { this.Close(); };
this.KeyDown += new KeyEventHandler(ContextActionsPopup_KeyDown);
}
void ContextActionsPopup_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
Close();
}
public bool IsDropdownOpen { get { return ActionsControl.IsOpen; } set {ActionsControl.IsOpen = value; } }
public bool IsDropdownAlwaysOpen { get { return ActionsControl.IsAlwaysOpen; } set {ActionsControl.IsAlwaysOpen = value; } }
ContextActionsHeaderedControl ActionsControl
public ContextActionsHeaderedControl ActionsControl
{
get { return (ContextActionsHeaderedControl)this.Child; }
set { this.Child = value; }
@ -57,16 +47,6 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -57,16 +47,6 @@ namespace ICSharpCode.SharpDevelop.Refactoring
this.ActionsControl.Focus();
}
public void Open()
{
this.IsOpen = true;
}
public void Close()
{
this.IsOpen = false;
}
public void OpenAtCaretAndFocus()
{
OpenAtMousePosition();
@ -74,49 +54,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -74,49 +54,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring
this.Focus();
}
public void OpenAtLineStart(ITextEditor editor)
{
OpenAtPosition(editor, editor.Caret.Line, 1, false);
this.VerticalOffset -= 16;
}
void OpenAtMousePosition()
{
this.Placement = PlacementMode.MousePoint;
this.Open();
}
void OpenAtPosition(ITextEditor editor, int line, int column, bool openAtWordStart)
{
var editorUIService = editor == null ? null : editor.GetService(typeof(IEditorUIService)) as IEditorUIService;
if (editorUIService != null) {
var document = editor.Document;
int offset = document.PositionToOffset(line, column);
if (openAtWordStart) {
int wordStart = document.FindPrevWordStart(offset);
if (wordStart != -1) {
var wordStartLocation = document.OffsetToPosition(wordStart);
line = wordStartLocation.Line;
column = wordStartLocation.Column;
}
}
this.Placement = PlacementMode.Absolute;
try
{
var caretScreenPos = editorUIService.GetScreenPosition(line, column);
this.HorizontalOffset = caretScreenPos.X;
this.VerticalOffset = caretScreenPos.Y;
}
catch
{
this.Placement = PlacementMode.MousePoint;
}
} else {
// if no editor information, open at mouse positions
this.Placement = PlacementMode.MousePoint;
}
this.Open();
}
}
}

74
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopupBase.cs

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
// <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.Controls.Primitives;
using System.Windows.Input;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.SharpDevelop.Refactoring
{
/// <summary>
/// Description of ContextActionsPopupBase.
/// </summary>
public abstract class ContextActionsPopupBase : Popup
{
protected ContextActionsPopupBase()
{
this.KeyDown += OnKeyDown;
}
void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
Close();
}
public void Open()
{
this.IsOpen = true;
}
public void Close()
{
this.IsOpen = false;
}
protected void OpenAtPosition(ITextEditor editor, int line, int column, bool openAtWordStart)
{
var editorUIService = editor == null ? null : editor.GetService(typeof(IEditorUIService)) as IEditorUIService;
if (editorUIService != null) {
var document = editor.Document;
int offset = document.PositionToOffset(line, column);
if (openAtWordStart) {
int wordStart = document.FindPrevWordStart(offset);
if (wordStart != -1) {
var wordStartLocation = document.OffsetToPosition(wordStart);
line = wordStartLocation.Line;
column = wordStartLocation.Column;
}
}
this.Placement = PlacementMode.Absolute;
try
{
var caretScreenPos = editorUIService.GetScreenPosition(line, column);
this.HorizontalOffset = caretScreenPos.X;
this.VerticalOffset = caretScreenPos.Y;
}
catch
{
this.Placement = PlacementMode.MousePoint;
}
} else {
// if no editor information, open at mouse positions
this.Placement = PlacementMode.MousePoint;
}
this.Open();
}
}
}

6
src/Main/Base/Project/Src/Services/RefactoringService/ContextActionsHelper.cs

@ -27,7 +27,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -27,7 +27,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
var popupViewModel = new ContextActionsViewModel { Title = MenuService.ConvertLabel(StringParser.Parse(
"${res:SharpDevelop.Refactoring.ClassesDerivingFrom}", new StringTagPair("Name", baseClass.Name)))};
popupViewModel.Actions = new PopupTreeViewModelBuilder().BuildTreeViewModel(derivedClassesTree);
return new ContextActionsPopup { Actions = popupViewModel, IsDropdownAlwaysOpen = true };
return new ContextActionsPopup { Actions = popupViewModel };
}
public static ContextActionsPopup MakePopupWithBaseClasses(IClass @class)
@ -40,7 +40,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -40,7 +40,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
var popupViewModel = new ContextActionsViewModel { Title = MenuService.ConvertLabel(StringParser.Parse(
"${res:SharpDevelop.Refactoring.BaseClassesOf}", new StringTagPair("Name", @class.Name)))};
popupViewModel.Actions = new PopupListViewModelBuilder().BuildListViewModel(baseClassList);
return new ContextActionsPopup { Actions = popupViewModel, IsDropdownAlwaysOpen = true };
return new ContextActionsPopup { Actions = popupViewModel };
}
public static ContextActionsPopup MakePopupWithOverrides(IMember member)
@ -49,7 +49,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -49,7 +49,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
var popupViewModel = new ContextActionsViewModel { Title = MenuService.ConvertLabel(StringParser.Parse(
"${res:SharpDevelop.Refactoring.OverridesOf}", new string[,] {{ "Name", member.FullyQualifiedName }}))};
popupViewModel.Actions = new OverridesPopupTreeViewModelBuilder(member).BuildTreeViewModel(derivedClassesTree);
return new ContextActionsPopup { Actions = popupViewModel, IsDropdownAlwaysOpen = true };
return new ContextActionsPopup { Actions = popupViewModel };
}
class PopupViewModelBuilder

Loading…
Cancel
Save