Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6339 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
10 changed files with 237 additions and 102 deletions
@ -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> |
||||||
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue