|
|
|
@ -18,7 +18,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
@@ -18,7 +18,7 @@ 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 |
|
|
|
|
public sealed class ContextActionsRenderer : IDisposable |
|
|
|
|
{ |
|
|
|
|
readonly CodeEditorView editorView; |
|
|
|
|
ITextEditor Editor { get { return this.editorView.Adapter; } } |
|
|
|
@ -36,12 +36,11 @@ namespace ICSharpCode.AvalonEdit.AddIn
@@ -36,12 +36,11 @@ namespace ICSharpCode.AvalonEdit.AddIn
|
|
|
|
|
public bool IsEnabled |
|
|
|
|
{ |
|
|
|
|
get { |
|
|
|
|
try { |
|
|
|
|
string fileName = this.Editor.FileName; |
|
|
|
|
return fileName.EndsWith(".cs") || fileName.EndsWith(".vb"); |
|
|
|
|
} catch { |
|
|
|
|
if (String.IsNullOrEmpty(fileName)) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return fileName.EndsWith(".cs", StringComparison.OrdinalIgnoreCase) |
|
|
|
|
|| fileName.EndsWith(".vb", StringComparison.OrdinalIgnoreCase); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -59,10 +58,16 @@ namespace ICSharpCode.AvalonEdit.AddIn
@@ -59,10 +58,16 @@ namespace ICSharpCode.AvalonEdit.AddIn
|
|
|
|
|
this.delayMoveTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(delayMoveMilliseconds) }; |
|
|
|
|
this.delayMoveTimer.Stop(); |
|
|
|
|
this.delayMoveTimer.Tick += TimerMoveTick; |
|
|
|
|
WorkbenchSingleton.Workbench.ViewClosed += WorkbenchSingleton_Workbench_ViewClosed; |
|
|
|
|
WorkbenchSingleton.Workbench.ActiveViewContentChanged += WorkbenchSingleton_Workbench_ActiveViewContentChanged; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
{ |
|
|
|
|
ClosePopup(); |
|
|
|
|
WorkbenchSingleton.Workbench.ActiveViewContentChanged -= WorkbenchSingleton_Workbench_ActiveViewContentChanged; |
|
|
|
|
delayMoveTimer.Stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ContextActionsRenderer_KeyDown(object sender, KeyEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (this.popup == null) |
|
|
|
@ -131,26 +136,14 @@ namespace ICSharpCode.AvalonEdit.AddIn
@@ -131,26 +136,14 @@ namespace ICSharpCode.AvalonEdit.AddIn
|
|
|
|
|
this.popup.IsHiddenActionsExpanded = false; |
|
|
|
|
this.popup.ViewModel = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WorkbenchSingleton_Workbench_ViewClosed(object sender, ViewContentEventArgs e) |
|
|
|
|
{ |
|
|
|
|
try { |
|
|
|
|
// prevent memory leaks
|
|
|
|
|
if (e.Content.PrimaryFileName == this.Editor.FileName) { |
|
|
|
|
WorkbenchSingleton.Workbench.ViewClosed -= WorkbenchSingleton_Workbench_ViewClosed; |
|
|
|
|
WorkbenchSingleton.Workbench.ActiveViewContentChanged -= WorkbenchSingleton_Workbench_ActiveViewContentChanged; |
|
|
|
|
} |
|
|
|
|
} catch {} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WorkbenchSingleton_Workbench_ActiveViewContentChanged(object sender, EventArgs e) |
|
|
|
|
{ |
|
|
|
|
ClosePopup(); |
|
|
|
|
try { |
|
|
|
|
// open the popup again if in current file
|
|
|
|
|
if (((IViewContent)WorkbenchSingleton.Workbench.ActiveContent).PrimaryFileName == this.Editor.FileName) |
|
|
|
|
IViewContent activeViewContent = WorkbenchSingleton.Workbench.ActiveViewContent; |
|
|
|
|
if (activeViewContent != null && activeViewContent.PrimaryFileName == this.Editor.FileName) |
|
|
|
|
CaretPositionChanged(this, EventArgs.Empty); |
|
|
|
|
} catch {} |
|
|
|
|
else // otherwise close popup
|
|
|
|
|
ClosePopup(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|