Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6162 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
28 changed files with 402 additions and 54 deletions
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
// <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; |
||||
using System.Windows.Threading; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; |
||||
using ICSharpCode.SharpDevelop.Refactoring; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Renders Popup with context actions on the left side of the current line in the editor.
|
||||
/// </summary>
|
||||
public class ContextActionsRenderer |
||||
{ |
||||
readonly CodeEditorView editorView; |
||||
ITextEditor Editor { get { return this.editorView.Adapter; } } |
||||
/// <summary>
|
||||
/// This popup is reused (closed and opened again).
|
||||
/// </summary>
|
||||
ContextActionsPopup popup = new ContextActionsPopup() { StaysOpen = true }; |
||||
|
||||
/// <summary>
|
||||
/// Delays the available actions resolution so that it does not get called too often when user holds an arrow.
|
||||
/// </summary>
|
||||
DispatcherTimer delayMoveTimer; |
||||
const int delayMoveMilliseconds = 100; |
||||
|
||||
public ContextActionsRenderer(CodeEditorView editor) |
||||
{ |
||||
if (editor == null) |
||||
throw new ArgumentNullException("editor"); |
||||
this.editorView = editor; |
||||
|
||||
this.editorView.TextArea.Caret.PositionChanged += CaretPositionChanged; |
||||
|
||||
editor.TextArea.TextView.ScrollOffsetChanged += ScrollChanged; |
||||
this.delayMoveTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(delayMoveMilliseconds) }; |
||||
this.delayMoveTimer.Stop(); |
||||
this.delayMoveTimer.Tick += TimerMoveTick; |
||||
} |
||||
|
||||
void ScrollChanged(object sender, EventArgs e) |
||||
{ |
||||
this.popup.Close(); |
||||
} |
||||
|
||||
void TimerMoveTick(object sender, EventArgs e) |
||||
{ |
||||
this.delayMoveTimer.Stop(); |
||||
|
||||
var availableActions = ContextActionsService.Instance.GetAvailableActions(this.Editor); |
||||
var availableActionsVM = new ObservableCollection<ContextActionViewModel>( |
||||
availableActions.Select(a => new ContextActionViewModel(a))); |
||||
if (availableActionsVM.Count == 0) |
||||
return; |
||||
|
||||
this.popup.Actions = new ContextActionsViewModel { |
||||
Title = "Actions", |
||||
Actions = availableActionsVM |
||||
}; |
||||
this.popup.OpenAtLineStart(this.Editor); |
||||
} |
||||
|
||||
void CaretPositionChanged(object sender, EventArgs e) |
||||
{ |
||||
this.popup.Close(); |
||||
this.popup.Actions = null; |
||||
this.delayMoveTimer.Stop(); |
||||
this.delayMoveTimer.Start(); |
||||
} |
||||
} |
||||
} |
@ -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.Collections.Generic; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; |
||||
using ICSharpCode.SharpDevelop.Refactoring; |
||||
|
||||
namespace SharpRefactoring.ContextActions |
||||
{ |
||||
/// <summary>
|
||||
/// Description of AddUsing.
|
||||
/// </summary>
|
||||
public class AddUsingProvider : IContextActionsProvider |
||||
{ |
||||
public IEnumerable<IContextAction> GetAvailableActions(ITextEditor editor) |
||||
{ |
||||
yield break; |
||||
} |
||||
} |
||||
|
||||
public class AddUsingAction |
||||
{ |
||||
} |
||||
} |
@ -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.Collections.Generic; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; |
||||
using ICSharpCode.SharpDevelop.Refactoring; |
||||
|
||||
namespace SharpRefactoring.ContextActions |
||||
{ |
||||
/// <summary>
|
||||
/// Description of GenerateMember.
|
||||
/// </summary>
|
||||
public class GenerateMemberProvider : IContextActionsProvider |
||||
{ |
||||
public IEnumerable<IContextAction> GetAvailableActions(ITextEditor editor) |
||||
{ |
||||
yield break; |
||||
} |
||||
} |
||||
|
||||
public class GenerateMemberAction |
||||
{ |
||||
} |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
// <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.Windows; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; |
||||
using ICSharpCode.SharpDevelop.Refactoring; |
||||
|
||||
namespace SharpRefactoring.ContextActions |
||||
{ |
||||
/// <summary>
|
||||
/// Description of ImplementAbstractClass.
|
||||
/// </summary>
|
||||
public class ImplementAbstractClassProvider : IContextActionsProvider |
||||
{ |
||||
public IEnumerable<IContextAction> GetAvailableActions(ITextEditor editor) |
||||
{ |
||||
var currentLine = editor.Document.GetLine(editor.Caret.Line); |
||||
yield break; |
||||
} |
||||
} |
||||
|
||||
public class ImplementAbstractClassAction : IContextAction |
||||
{ |
||||
public string Title { |
||||
get { return "Dummy implement abstract class"; } |
||||
} |
||||
|
||||
public void Execute() |
||||
{ |
||||
MessageBox.Show("Dummy implement abstract class"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
// <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.Windows; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; |
||||
using ICSharpCode.SharpDevelop.Refactoring; |
||||
|
||||
namespace SharpRefactoring.ContextActions |
||||
{ |
||||
/// <summary>
|
||||
/// Description of ImplementInterface.
|
||||
/// </summary>
|
||||
public class ImplementInterfaceProvider : IContextActionsProvider |
||||
{ |
||||
public IEnumerable<IContextAction> GetAvailableActions(ITextEditor editor) |
||||
{ |
||||
var currentLine = editor.Document.GetLine(editor.Caret.Line); |
||||
yield break; |
||||
} |
||||
} |
||||
|
||||
public class ImplementInterfaceAction : IContextAction |
||||
{ |
||||
public string Title { |
||||
get { return "Dummy implement interface"; } |
||||
} |
||||
|
||||
public void Execute() |
||||
{ |
||||
MessageBox.Show("Dummy implement interface"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
// <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.Linq; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Refactoring; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit |
||||
{ |
||||
/// <summary>
|
||||
/// Provides context actions available for current line of the editor.
|
||||
/// </summary>
|
||||
public sealed class ContextActionsService |
||||
{ |
||||
private static ContextActionsService instance = new ContextActionsService(); |
||||
|
||||
public static ContextActionsService Instance { |
||||
get { |
||||
return instance; |
||||
} |
||||
} |
||||
|
||||
List<IContextActionsProvider> providers; |
||||
|
||||
private ContextActionsService() |
||||
{ |
||||
this.providers = AddInTree.BuildItems<IContextActionsProvider>("/SharpDevelop/ViewContent/AvalonEdit/ContextActionProviders", null, false); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets actions available for current line of the editor.
|
||||
/// </summary>
|
||||
public IEnumerable<IContextAction> GetAvailableActions(ITextEditor editor) |
||||
{ |
||||
// could run providers in parallel
|
||||
foreach (var provider in this.providers) { |
||||
foreach (var action in provider.GetAvailableActions(editor)) { |
||||
yield return action; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
// <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 ICSharpCode.SharpDevelop.Refactoring; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit |
||||
{ |
||||
/// <summary>
|
||||
/// Provides <see cref="ContextAction" />s to appear in a popup on the left side of the editor.
|
||||
/// </summary>
|
||||
public interface IContextActionsProvider |
||||
{ |
||||
/// <summary>
|
||||
/// Gets actions available for current line of the editor.
|
||||
/// </summary>
|
||||
IEnumerable<IContextAction> GetAvailableActions(ITextEditor editor); |
||||
} |
||||
} |
Loading…
Reference in new issue