Browse Source

Change ContextActionsPopup, ContextActionsBulbPopup and the HiddenDefinition popup to open/close as the parent TextArea gains/loses focus.

Move ChangeMarkerMargin and related classes into own folder.
Remove C#-specific hack from HiddenDefinitionRenderer.
Do not return null from CreateHighlighter().
newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
f1b2220314
  1. 33
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpBracketSearcher.cs
  2. 3
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs
  3. 3
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  4. 7
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SearchForIssuesCommand.cs
  5. 3
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlSymbolSearch.cs
  6. 37
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  7. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditEditorUIService.cs
  8. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs
  9. 8
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/ChangeMarkerMargin.cs
  10. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/DefaultChangeWatcher.cs
  11. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/DiffControl.xaml
  12. 6
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/DiffControl.xaml.cs
  13. 0
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/DocumentSequence.cs
  14. 25
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/IChangeWatcher.cs
  15. 19
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/LineChangeInfo.cs
  16. 18
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs
  17. 24
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionsBulbPopup.cs
  18. 7
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionsControl.xaml.cs
  19. 58
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionsPopup.cs
  20. 75
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionsPopupBase.cs
  21. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionsRenderer.cs
  22. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/FindBaseClasses.cs
  23. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/FindDerivedClassesOrOverrides.cs
  24. 12
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionControl.xaml
  25. 27
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionControl.xaml.cs
  26. 103
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionRenderer.cs
  27. 86
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinitionRenderer.cs
  28. 0
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/CustomizingHighlighter.cs
  29. 128
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/FixedHighlighter.cs
  30. 0
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/MultiHighlighter.cs
  31. 0
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/SyntaxModeDoozer.cs
  32. 18
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Utils.cs
  33. 6
      src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs
  34. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs
  35. 18
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedLine.cs
  36. 12
      src/Main/Base/Project/Editor/IBracketSearcher.cs
  37. 5
      src/Main/Base/Project/Editor/IEditorControlService.cs
  38. 2
      src/Main/Base/Project/Editor/Search/SearchResultMatch.cs
  39. 10
      src/Main/Base/Project/Editor/Search/SearchResultsPad.cs
  40. 3
      src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs
  41. 24
      src/Main/Base/Project/Util/SharpDevelopExtensions.cs
  42. 67
      src/Main/ICSharpCode.Core.Presentation/ExtendedPopup.cs
  43. 1
      src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj
  44. 66
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ExtendedPopup.cs
  45. 1
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ICSharpCode.SharpDevelop.Widgets.csproj

33
src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpBracketSearcher.cs

@ -31,14 +31,41 @@ namespace CSharpBinding @@ -31,14 +31,41 @@ namespace CSharpBinding
if (index > -1)
otherOffset = SearchBracketBackward(document, offset - 2, openingBrackets[index], closingBrackets[index]);
if (otherOffset > -1)
return new BracketSearchResult(Math.Min(offset - 1, otherOffset), 1,
Math.Max(offset - 1, otherOffset), 1);
if (otherOffset > -1) {
var result = new BracketSearchResult(Math.Min(offset - 1, otherOffset), 1,
Math.Max(offset - 1, otherOffset), 1);
SearchDefinition(document, result);
return result;
}
}
return null;
}
void SearchDefinition(IDocument document, BracketSearchResult result)
{
if (document.GetCharAt(result.OpeningBracketOffset) != '{')
return;
// get line
var documentLine = document.GetLineByOffset(result.OpeningBracketOffset);
while (documentLine != null && IsBracketOnly(document, documentLine))
documentLine = documentLine.PreviousLine;
if (documentLine != null) {
result.DefinitionHeaderOffset = documentLine.Offset;
result.DefinitionHeaderLength = documentLine.Length;
}
}
bool IsBracketOnly(IDocument document, IDocumentLine documentLine)
{
string lineText = document.GetText(documentLine).Trim();
return lineText == "{" || string.IsNullOrEmpty(lineText)
|| lineText.StartsWith("//", StringComparison.Ordinal)
|| lineText.StartsWith("/*", StringComparison.Ordinal)
|| lineText.StartsWith("*", StringComparison.Ordinal)
|| lineText.StartsWith("'", StringComparison.Ordinal);
}
#region SearchBracket helper functions
static int ScanLineStart(IDocument document, int offset)
{

3
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs

@ -106,8 +106,7 @@ namespace CSharpBinding @@ -106,8 +106,7 @@ namespace CSharpBinding
if (document == null) {
document = new ReadOnlyDocument(textSource, fileName);
highlighter = SD.EditorControlService.CreateHighlighter(document);
if (highlighter != null)
highlighter.BeginHighlighting();
highlighter.BeginHighlighting();
}
Identifier identifier = node.GetChildByRole(Roles.Identifier);
if (!identifier.IsNull)

3
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs

@ -164,8 +164,7 @@ namespace CSharpBinding.Parser @@ -164,8 +164,7 @@ namespace CSharpBinding.Parser
if (document == null) {
document = new ReadOnlyDocument(fileContent, parseInfo.FileName);
highlighter = SD.EditorControlService.CreateHighlighter(document);
if (highlighter != null)
highlighter.BeginHighlighting();
highlighter.BeginHighlighting();
}
var region = new DomRegion(parseInfo.FileName, node.StartLocation, node.EndLocation);
int offset = document.GetOffset(node.StartLocation);

7
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SearchForIssuesCommand.cs

@ -161,9 +161,7 @@ namespace CSharpBinding.Refactoring @@ -161,9 +161,7 @@ namespace CSharpBinding.Refactoring
if (document == null) {
document = new ReadOnlyDocument(fileContent, fileName);
highlighter = SD.EditorControlService.CreateHighlighter(document);
if (highlighter != null) {
highlighter.BeginHighlighting();
}
highlighter.BeginHighlighting();
}
results.Add(SearchResultMatch.Create(document, issue.Start, issue.End, highlighter));
}
@ -237,8 +235,7 @@ namespace CSharpBinding.Refactoring @@ -237,8 +235,7 @@ namespace CSharpBinding.Refactoring
}
if (allIssues.Count > 0) {
using (var highlighter = SD.EditorControlService.CreateHighlighter(document)) {
if (highlighter != null)
highlighter.BeginHighlighting();
highlighter.BeginHighlighting();
return allIssues.Select(issue => SearchResultMatch.Create(document, issue.Start, issue.End, highlighter)).ToList();
}
} else {

3
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlSymbolSearch.cs

@ -93,8 +93,7 @@ namespace ICSharpCode.XamlBinding @@ -93,8 +93,7 @@ namespace ICSharpCode.XamlBinding
if (document == null) {
document = new ReadOnlyDocument(textSource, fileName);
highlighter = SD.EditorControlService.CreateHighlighter(document);
if (highlighter != null)
highlighter.BeginHighlighting();
highlighter.BeginHighlighting();
}
var result = resolver.Resolve(parseInfo, document.GetLocation(offset + entity.Name.Length / 2 + 1), compilation, cancellationToken);
int length = entity.Name.Length;

37
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -78,6 +78,15 @@ @@ -78,6 +78,15 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Src\ChangeMarkerMargin\ChangeMarkerMargin.cs" />
<Compile Include="Src\ChangeMarkerMargin\DefaultChangeWatcher.cs" />
<Compile Include="Src\ChangeMarkerMargin\DiffControl.xaml.cs">
<DependentUpon>DiffControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\ChangeMarkerMargin\DocumentSequence.cs" />
<Compile Include="Src\ChangeMarkerMargin\IChangeWatcher.cs" />
<Compile Include="Src\ChangeMarkerMargin\LineChangeInfo.cs" />
<Compile Include="Src\ContextActions\ContextActionOptionPanelDoozer.cs" />
<Compile Include="Src\ContextActions\ContextActionOptions.xaml.cs">
<DependentUpon>ContextActionOptions.xaml</DependentUpon>
@ -95,7 +104,6 @@ @@ -95,7 +104,6 @@
<DependentUpon>ContextActionsHeaderedControl.xaml</DependentUpon>
</Compile>
<Compile Include="Src\ContextActions\ContextActionsPopup.cs" />
<Compile Include="Src\ContextActions\ContextActionsPopupBase.cs" />
<Compile Include="Src\ContextActions\ContextActionsRenderer.cs" />
<Compile Include="Src\ContextActions\EditorActionsProvider.cs" />
<Compile Include="Src\ContextActions\ContextActionsViewModel.cs" />
@ -103,10 +111,13 @@ @@ -103,10 +111,13 @@
<Compile Include="Src\ContextActions\FindBaseClasses.cs" />
<Compile Include="Src\ContextActions\FindDerivedClassesOrOverrides.cs" />
<Compile Include="Src\ContextActions\GoToEntityAction.cs" />
<Compile Include="Src\DocumentSequence.cs" />
<Compile Include="Src\EnhancedScrollBar.cs" />
<Compile Include="Src\MultiHighlighter.cs" />
<Compile Include="Src\HiddenDefinitionRenderer.cs" />
<Compile Include="Src\SyntaxHighlighting\CustomizingHighlighter.cs" />
<Compile Include="Src\SyntaxHighlighting\FixedHighlighter.cs" />
<Compile Include="Src\SyntaxHighlighting\MultiHighlighter.cs" />
<Compile Include="Src\Snippets\CodeSnippetComparer.cs" />
<Compile Include="Src\SyntaxHighlighting\SyntaxModeDoozer.cs" />
<Compile Include="Src\Utils.cs" />
<Compile Include="Src\XmlDoc\DocumentationUIBuilder.cs" />
<Compile Include="Src\XmlDoc\XmlDocTooltipProvider.cs" />
@ -123,7 +134,6 @@ @@ -123,7 +134,6 @@
<Compile Include="Src\AvalonEditViewContent.cs" />
<Compile Include="Src\BracketHighlightRenderer.cs" />
<Compile Include="Src\CaretReferencesRenderer.cs" />
<Compile Include="Src\ChangeMarkerMargin.cs" />
<Compile Include="Src\ChooseEncodingDialog.xaml.cs">
<DependentUpon>ChooseEncodingDialog.xaml</DependentUpon>
<SubType>Code</SubType>
@ -132,19 +142,8 @@ @@ -132,19 +142,8 @@
<Compile Include="Src\CodeEditor.cs" />
<Compile Include="Src\CodeEditorAdapter.cs" />
<Compile Include="Src\CodeEditorView.cs" />
<Compile Include="Src\DefaultChangeWatcher.cs" />
<Compile Include="Src\DiffControl.xaml.cs">
<DependentUpon>DiffControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\ExpressionHighlightRenderer.cs" />
<Compile Include="Src\CaretHighlightAdorner.cs" />
<Compile Include="Src\HiddenDefinition\HiddenDefinitionControl.xaml.cs">
<DependentUpon>HiddenDefinitionControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\HiddenDefinition\HiddenDefinitionRenderer.cs" />
<Compile Include="Src\LineChangeInfo.cs" />
<Compile Include="Src\NewLineConsistencyCheck.cs" />
<Compile Include="Src\SearchPanelLocalization.cs" />
<Compile Include="Src\SharpDevelopTextEditor.cs" />
@ -157,7 +156,6 @@ @@ -157,7 +156,6 @@
<Compile Include="Src\Commands\SortSelectionCommand.cs" />
<Compile Include="Src\Commands\SurroundWithCommand.cs" />
<Compile Include="Src\CustomCommands.cs" />
<Compile Include="Src\CustomizingHighlighter.cs" />
<Compile Include="Src\CustomizedHighlightingColor.cs" />
<Compile Include="Src\DocumentPrinter.cs" />
<Compile Include="Src\InlineUIElementGenerator.cs" />
@ -204,7 +202,6 @@ @@ -204,7 +202,6 @@
<Compile Include="Src\SharpDevelopInsightWindow.cs">
</Compile>
<Compile Include="Src\StringToVisibilityConverter.cs" />
<Compile Include="Src\SyntaxModeDoozer.cs" />
<Compile Include="Src\TextMarkerService.cs" />
<EmbeddedResource Include="Resources\IncrementalSearchCursor.cur" />
<EmbeddedResource Include="Resources\ReverseIncrementalSearchCursor.cur" />
@ -213,12 +210,11 @@ @@ -213,12 +210,11 @@
<Resource Include="Src\ContextActions\pencil.png" />
</ItemGroup>
<ItemGroup>
<Page Include="Src\ChangeMarkerMargin\DiffControl.xaml" />
<Page Include="Src\ContextActions\ContextActionOptions.xaml" />
<Page Include="Src\ContextActions\ContextActionsBulbControl.xaml" />
<Page Include="Src\ContextActions\ContextActionsControl.xaml" />
<Page Include="Src\ContextActions\ContextActionsHeaderedControl.xaml" />
<Page Include="Src\DiffControl.xaml" />
<Page Include="Src\HiddenDefinition\HiddenDefinitionControl.xaml" />
<Page Include="Src\SharpDevelopCompletionWindow.xaml">
<DependentUpon>SharpDevelopCompletionWindow.cs</DependentUpon>
</Page>
@ -283,7 +279,8 @@ @@ -283,7 +279,8 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Src\ContextActions" />
<Folder Include="Src\HiddenDefinition" />
<Folder Include="Src\ChangeMarkerMargin" />
<Folder Include="Src\SyntaxHighlighting" />
<Folder Include="Src\XmlDoc" />
</ItemGroup>
</Project>

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditEditorUIService.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -35,7 +35,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// <inheritdoc />
public Point GetScreenPosition(int line, int column)
{
var positionInPixels = textView.PointToScreen(
var positionInPixels = textView.PointToScreen(
textView.GetVisualPosition(new TextViewPosition(line, column), VisualYPosition.LineBottom) - textView.ScrollOffset);
return positionInPixels.TransformFromDevice(textView);
}

4
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs

@ -37,10 +37,10 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -37,10 +37,10 @@ namespace ICSharpCode.AvalonEdit.AddIn
public IHighlighter CreateHighlighter(IDocument document)
{
if (document.FileName == null)
return null;
return new MultiHighlighter(document);
var def = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(document.FileName));
if (def == null)
return null;
return new MultiHighlighter(document);
List<IHighlighter> highlighters = new List<IHighlighter>();
var textDocument = document as TextDocument;
var readOnlyDocument = document as ReadOnlyDocument;

8
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs → src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/ChangeMarkerMargin.cs

@ -223,9 +223,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -223,9 +223,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
}
DiffControl differ = new DiffControl();
differ.CopyEditorSettings(editor);
differ.editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
differ.editor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
differ.CopyEditorSettingsAndHighlighting(editor);
differ.editor.Document.Text = oldText;
if (oldText == string.Empty) {
@ -257,8 +255,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -257,8 +255,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (tooltip.IsOpen)
tooltip.IsOpen = false;
tooltip.IsOpen = true;
tooltip.Closed += delegate {
if (marker != null) markerService.Remove(marker);
};
@ -267,6 +263,8 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -267,6 +263,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
TextView.GetVisualTopByDocumentLine(startLine) - TextView.ScrollOffset.Y;
tooltip.Placement = PlacementMode.Top;
tooltip.PlacementTarget = this.TextView;
tooltip.IsOpen = true;
}
}

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs → src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/DefaultChangeWatcher.cs

@ -4,13 +4,13 @@ @@ -4,13 +4,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Utils;
using ICSharpCode.Core;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Parser;
using ICSharpCode.SharpDevelop.Widgets.MyersDiff;
namespace ICSharpCode.AvalonEdit.AddIn

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DiffControl.xaml → src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/DiffControl.xaml

@ -13,6 +13,6 @@ @@ -13,6 +13,6 @@
Content="{sd:Localize ProjectComponent.ContextMenu.AddExistingFiles.Copy}"
ToolTip="{sd:Localize ProjectComponent.ContextMenu.AddExistingFiles.Copy}" />
</ToolBar>
<ae:TextEditor x:Name="editor" IsReadOnly="True" />
<ae:TextEditor x:Name="editor" IsReadOnly="True" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" />
</StackPanel>
</UserControl>

6
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DiffControl.xaml.cs → src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/DiffControl.xaml.cs

@ -44,8 +44,9 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -44,8 +44,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
}
}
public void CopyEditorSettings(TextEditor source)
public void CopyEditorSettingsAndHighlighting(TextEditor source)
{
editor.CopySettingsFrom(source);
string language = source.SyntaxHighlighting != null ? source.SyntaxHighlighting.Name : null;
editor.TextArea.TextView.LineTransformers.RemoveAll(x => x is HighlightingColorizer);
var customizedHighlighter = new CustomizingHighlighter(
@ -53,9 +54,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -53,9 +54,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
CustomizedHighlightingColor.FetchCustomizations(language)
);
editor.TextArea.TextView.LineTransformers.Insert(0, new HighlightingColorizer(customizedHighlighter));
CustomizingHighlighter.ApplyCustomizationsToDefaultElements(editor, CustomizedHighlightingColor.FetchCustomizations(language));
HighlightingOptions.ApplyToRendering(editor, CustomizedHighlightingColor.FetchCustomizations(language));
editor.TextArea.TextView.Redraw(); // manually redraw if default elements didn't change but customized highlightings did
}
}
}

0
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DocumentSequence.cs → src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/DocumentSequence.cs

25
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/IChangeWatcher.cs

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.Core;
using ICSharpCode.NRefactory.Editor;
namespace ICSharpCode.AvalonEdit.AddIn
{
public interface IChangeWatcher : IDisposable
{
event EventHandler ChangeOccurred;
/// <summary>
/// Returns the change information for a given line.
/// Pass 0 to get the changes before the first line.
/// </summary>
LineChangeInfo GetChange(int lineNumber);
void Initialize(IDocument document, FileName fileName);
string GetOldVersionFromLine(int lineNumber, out int newStartLine, out bool added);
bool GetNewVersionFromLine(int lineNumber, out int offset, out int length);
IDocument CurrentDocument { get; }
IDocument BaseDocument { get; }
}
}

19
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/LineChangeInfo.cs → src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin/LineChangeInfo.cs

@ -2,29 +2,10 @@ @@ -2,29 +2,10 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.Core;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Widgets.MyersDiff;
namespace ICSharpCode.AvalonEdit.AddIn
{
public interface IChangeWatcher : IDisposable
{
event EventHandler ChangeOccurred;
/// <summary>
/// Returns the change information for a given line.
/// Pass 0 to get the changes before the first line.
/// </summary>
LineChangeInfo GetChange(int lineNumber);
void Initialize(IDocument document, FileName fileName);
string GetOldVersionFromLine(int lineNumber, out int newStartLine, out bool added);
bool GetNewVersionFromLine(int lineNumber, out int offset, out int length);
IDocument CurrentDocument { get; }
IDocument BaseDocument { get; }
}
public struct LineChangeInfo : IEquatable<LineChangeInfo>
{
public static readonly LineChangeInfo EMPTY = new LineChangeInfo(ChangeType.None, 1, 1);

18
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs

@ -82,7 +82,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -82,7 +82,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
public virtual void Dispose()
{
contextActionsRenderer.Dispose();
hiddenDefinitionRenderer.Dispose();
hiddenDefinitionRenderer.ClosePopup();
}
public IList<IContextActionProvider> ContextActionProviders {
@ -131,8 +131,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -131,8 +131,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
this.bracketRenderer.SetHighlight(null);
}
if (CodeEditorOptions.Instance.ShowHiddenDefinitions) {
this.hiddenDefinitionRenderer.BracketSearchResult = bracketSearchResult;
this.hiddenDefinitionRenderer.Show();
this.hiddenDefinitionRenderer.Show(bracketSearchResult);
} else {
this.hiddenDefinitionRenderer.ClosePopup();
}
@ -524,19 +523,14 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -524,19 +523,14 @@ namespace ICSharpCode.AvalonEdit.AddIn
return null;
}
// TODO: move this into SharpDevelopTextEditor
public void UpdateCustomizedHighlighting()
{
string language = this.SyntaxHighlighting != null ? this.SyntaxHighlighting.Name : null;
CustomizingHighlighter.ApplyCustomizationsToDefaultElements(this, FetchCustomizations(language));
BracketHighlightRenderer.ApplyCustomizationsToRendering(this.bracketRenderer, FetchCustomizations(language));
HighlightingOptions.ApplyToRendering(this, FetchCustomizations(language));
var customizations = CustomizedHighlightingColor.FetchCustomizations(language);
CustomizingHighlighter.ApplyCustomizationsToDefaultElements(this, customizations);
BracketHighlightRenderer.ApplyCustomizationsToRendering(this.bracketRenderer, customizations);
HighlightingOptions.ApplyToRendering(this, customizations);
this.TextArea.TextView.Redraw(); // manually redraw if default elements didn't change but customized highlightings did
}
static IEnumerable<CustomizedHighlightingColor> FetchCustomizations(string languageName)
{
return CustomizedHighlightingColor.FetchCustomizations(languageName);
}
}
}

24
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionsBulbPopup.cs

@ -2,22 +2,37 @@ @@ -2,22 +2,37 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows;
using System.Windows.Input;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Widgets;
namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
{
/// <summary>
/// The popup for context actions.
/// </summary>
public class ContextActionsBulbPopup : ContextActionsPopupBase
public class ContextActionsBulbPopup : ExtendedPopup
{
public ContextActionsBulbPopup()
public ContextActionsBulbPopup(UIElement parent) : base(parent)
{
this.StaysOpen = true;
this.AllowsTransparency = true;
this.ChildControl = new ContextActionsBulbControl();
// Close when any action excecuted
this.ChildControl.ActionExecuted += delegate { this.Close(); };
this.ChildControl.ActionExecuted += delegate { Close(); };
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Key == Key.Escape)
this.IsOpenIfFocused = false;
}
public void Close()
{
this.IsOpenIfFocused = false;
}
private ContextActionsBulbControl ChildControl
@ -47,8 +62,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions @@ -47,8 +62,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
public void OpenAtLineStart(ITextEditor editor)
{
OpenAtPosition(editor, editor.Caret.Line, 1, false);
ContextActionsPopup.SetPosition(this, editor, editor.Caret.Line, 1);
this.VerticalOffset -= 16;
this.IsOpenIfFocused = true;
}
}
}

7
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionsControl.xaml.cs

@ -24,9 +24,10 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions @@ -24,9 +24,10 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
public new void Focus()
{
var firstButton = WpfTreeNavigation.TryFindChild<Button>(this);
if (firstButton == null)
return;
firstButton.Focus();
if (firstButton != null)
firstButton.Focus();
else
TreeView.Focus();
}
void TreeViewLoaded(object sender, RoutedEventArgs e)

58
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionsPopup.cs

@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
using System;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
@ -11,15 +13,10 @@ using ICSharpCode.SharpDevelop.Gui; @@ -11,15 +13,10 @@ using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
{
/// <summary>
/// Description of ContextActionsPopup.
/// Pop-up menu for context actions; used for Find derived classes (F6) and commands that open popups.
/// </summary>
public class ContextActionsPopup : ContextActionsPopupBase
public class ContextActionsPopup : Popup
{
/// <summary>
/// DOM Entity (IClass, IMember etc.) for which this popup is displayed.
/// </summary>
public IEntity Symbol { get; set; }
public ContextActionsPopup()
{
// Close on lost focus
@ -27,7 +24,14 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions @@ -27,7 +24,14 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
this.AllowsTransparency = true;
this.ActionsControl = new ContextActionsHeaderedControl();
// Close when any action excecuted
this.ActionsControl.ActionExecuted += delegate { this.Close(); };
this.ActionsControl.ActionExecuted += delegate { this.IsOpen = false; };
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Key == Key.Escape)
this.IsOpen = false;
}
public ContextActionsHeaderedControl ActionsControl
@ -51,24 +55,38 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions @@ -51,24 +55,38 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
public void OpenAtCaretAndFocus()
{
ITextEditor currentEditor = GetCurrentEditor();
ITextEditor currentEditor = SD.GetActiveViewContentService<ITextEditor>();
if (currentEditor == null) {
OpenAtMousePosition();
return;
this.Placement = PlacementMode.MousePoint;
} else {
SetPosition(this, currentEditor, currentEditor.Caret.Line, currentEditor.Caret.Column, true);
}
OpenAtPosition(currentEditor, currentEditor.Caret.Line, currentEditor.Caret.Column, true);
this.IsOpen = true;
this.Focus();
}
ITextEditor GetCurrentEditor()
{
return SD.GetActiveViewContentService<ITextEditor>();
}
void OpenAtMousePosition()
public static void SetPosition(Popup popup, ITextEditor editor, int line, int column, bool openAtWordStart = false)
{
this.Placement = PlacementMode.MousePoint;
this.Open();
var editorUIService = editor == null ? null : editor.GetService(typeof(IEditorUIService)) as IEditorUIService;
if (editorUIService != null) {
var document = editor.Document;
int offset = document.GetOffset(line, column);
if (openAtWordStart) {
int wordStart = document.FindPrevWordStart(offset);
if (wordStart != -1) {
var wordStartLocation = document.GetLocation(wordStart);
line = wordStartLocation.Line;
column = wordStartLocation.Column;
}
}
var caretScreenPos = editorUIService.GetScreenPosition(line, column);
popup.HorizontalOffset = caretScreenPos.X;
popup.VerticalOffset = caretScreenPos.Y;
popup.Placement = PlacementMode.Absolute;
} else {
// if no editor information, open at mouse positions
popup.Placement = PlacementMode.MousePoint;
}
}
}
}

75
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionsPopupBase.cs

@ -1,75 +0,0 @@ @@ -1,75 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.Core.Presentation;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
{
/// <summary>
/// Description of ContextActionsPopupBase.
/// </summary>
public abstract class ContextActionsPopupBase : ExtendedPopup
{
protected ContextActionsPopupBase()
{
this.KeyDown += OnKeyDown;
this.UseLayoutRounding = true;
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);
}
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.GetOffset(line, column);
if (openAtWordStart) {
int wordStart = document.FindPrevWordStart(offset);
if (wordStart != -1) {
var wordStartLocation = document.GetLocation(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();
}
}
}

4
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionsRenderer.cs

@ -76,7 +76,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions @@ -76,7 +76,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
{
if (e.Key == Key.T && Keyboard.Modifiers == ModifierKeys.Control) {
if (popup == null)
popup = new ContextActionsBulbPopup();
popup = new ContextActionsBulbPopup(editorView.TextArea);
if (popup.IsOpen && popup.ViewModel != null && popup.ViewModel.Actions != null && popup.ViewModel.Actions.Count > 0) {
popup.IsDropdownOpen = true;
popup.Focus();
@ -135,7 +135,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions @@ -135,7 +135,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
if (popupVM.Actions.Count == 0)
return;
if (popup == null)
popup = new ContextActionsBulbPopup();
popup = new ContextActionsBulbPopup(editorView.TextArea);
this.popup.ViewModel = popupVM;
this.popup.OpenAtLineStart(this.Editor);
}

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/FindBaseClasses.cs

@ -34,7 +34,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions @@ -34,7 +34,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
popupViewModel.Title = MenuService.ConvertLabel(StringParser.Parse(
"${res:SharpDevelop.Refactoring.BaseClassesOf}", new StringTagPair("Name", @class.Name)));
popupViewModel.Actions = BuildListViewModel(baseClassList);
return new ContextActionsPopup { Actions = popupViewModel, Symbol = @class };
return new ContextActionsPopup { Actions = popupViewModel };
}
static ObservableCollection<ContextActionViewModel> BuildListViewModel(IEnumerable<ITypeDefinition> classList)

4
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/FindDerivedClassesOrOverrides.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions @@ -40,7 +40,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
popupViewModel.Title = MenuService.ConvertLabel(StringParser.Parse(
"${res:SharpDevelop.Refactoring.ClassesDerivingFrom}", new StringTagPair("Name", baseClass.Name)));
popupViewModel.Actions = BuildTreeViewModel(derivedClassesTree.Children);
return new ContextActionsPopup { Actions = popupViewModel, Symbol = baseClass };
return new ContextActionsPopup { Actions = popupViewModel };
}
static ObservableCollection<ContextActionViewModel> BuildTreeViewModel(IEnumerable<ITreeNode<ITypeDefinition>> classTree)
@ -61,7 +61,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions @@ -61,7 +61,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
new StringTagPair("Name", member.FullName))
)};
popupViewModel.Actions = new OverridesPopupTreeViewModelBuilder(member).BuildTreeViewModel(derivedClassesTree.Children);
return new ContextActionsPopup { Actions = popupViewModel, Symbol = member };
return new ContextActionsPopup { Actions = popupViewModel };
}
class OverridesPopupTreeViewModelBuilder

12
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionControl.xaml

@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<UserControl
x:Class="ICSharpCode.AvalonEdit.AddIn.HiddenDefinition.HiddenDefinitionControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:core="http://icsharpcode.net/sharpdevelop/core" xmlns:local="clr-namespace:ICSharpCode.AvalonEdit.AddIn.Options"
Background="#FFFFE7">
<Border BorderBrush="Black"
BorderThickness="1"
Background="Transparent">
<StackPanel Background="Transparent">
<TextBlock x:Name="DefinitionTextBlock"/>
</StackPanel>
</Border>
</UserControl>

27
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionControl.xaml.cs

@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ICSharpCode.AvalonEdit.AddIn.Options;
namespace ICSharpCode.AvalonEdit.AddIn.HiddenDefinition
{
public partial class HiddenDefinitionControl : UserControl
{
public HiddenDefinitionControl()
{
InitializeComponent();
DefinitionTextBlock.FontFamily = new FontFamily(CodeEditorOptions.Instance.FontFamily);
DefinitionTextBlock.FontSize = CodeEditorOptions.Instance.FontSize;
}
public string DefinitionText {
get { return this.DefinitionTextBlock.Text; }
set { this.DefinitionTextBlock.Text = value; }
}
}
}

103
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionRenderer.cs

@ -1,103 +0,0 @@ @@ -1,103 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows.Controls.Primitives;
using ICSharpCode.Core.Presentation;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.AvalonEdit.AddIn.HiddenDefinition
{
public class HiddenDefinitionRenderer : IDisposable
{
private CodeEditorView editor;
private ExtendedPopup popup = new ExtendedPopup();
private HiddenDefinitionControl control;
public HiddenDefinitionRenderer(CodeEditorView editorView)
{
this.editor = editorView;
control = new HiddenDefinitionControl();
SD.Workbench.ActiveContentChanged += WorkbenchSingleton_Workbench_ActiveContentChanged;
}
public BracketSearchResult BracketSearchResult { get; set; }
public void Dispose()
{
SD.Workbench.ActiveContentChanged -= WorkbenchSingleton_Workbench_ActiveContentChanged;
ClosePopup();
popup = null;
}
public void ClosePopup()
{
if (popup != null && popup.IsOpen)
popup.IsOpen = false;
}
public void Show()
{
ClosePopup();
if (BracketSearchResult == null) return;
// verify if we have a open bracket
if (this.editor.Document.GetCharAt(BracketSearchResult.OpeningBracketOffset) != '{')
return;
var line = GetLineText(BracketSearchResult.OpeningBracketOffset);
if(line == null) return;
control.DefinitionText = line;
popup.Child = control;
popup.HorizontalOffset = 70;
popup.Placement = PlacementMode.Relative;
popup.PlacementTarget = editor.TextArea;
popup.IsOpen = true;
}
/// <summary>
/// Gets the line text near the offset.
/// </summary>
/// <param name="offset">Offset.</param>
/// <returns></returns>
private string GetLineText(int offset)
{
if (!editor.TextArea.TextView.VisualLinesValid)
return null;
// get line
var documentLine = editor.Document.GetLineByOffset(offset);
string documentText = editor.Document.Text;
string lineText = string.Empty;
int off, length;
do {
if (documentLine == null || documentLine.IsDeleted) return null;
off = documentLine.Offset;
length = documentLine.Length;
lineText = documentText.Substring(off, length).Trim();
documentLine = documentLine.PreviousLine;
}
while (lineText == "{" || string.IsNullOrEmpty(lineText) ||
lineText.StartsWith("//") || lineText.StartsWith("/*") ||
lineText.StartsWith("*") || lineText.StartsWith("'"));
// check whether the line is visible
if (editor.TextArea.TextView.VisualLines[0].StartOffset > off) {
return this.editor.TextArea.TextView.Document.GetText(off, length);
}
return null;
}
private void WorkbenchSingleton_Workbench_ActiveContentChanged(object sender, EventArgs e)
{
ClosePopup();
}
}
}

86
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinitionRenderer.cs

@ -0,0 +1,86 @@ @@ -0,0 +1,86 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Widgets;
namespace ICSharpCode.AvalonEdit.AddIn.HiddenDefinition
{
public class HiddenDefinitionRenderer
{
readonly CodeEditorView editor;
ExtendedPopup popup;
int currentStartOffset;
public HiddenDefinitionRenderer(CodeEditorView editorView)
{
this.editor = editorView;
}
void textView_VisualLinesChanged(object sender, EventArgs e)
{
// This event is registered only while the popup exists
var textView = editor.TextArea.TextView;
VisualLine visualLine = textView.VisualLines.FirstOrDefault();
popup.IsOpenIfFocused = visualLine != null && visualLine.StartOffset > currentStartOffset;
}
public void ClosePopup()
{
if (popup != null) {
editor.TextArea.TextView.VisualLinesChanged -= textView_VisualLinesChanged;
popup.IsOpenIfFocused = false;
popup = null;
}
}
public void Show(BracketSearchResult bracketSearchResult)
{
ClosePopup();
if (bracketSearchResult == null || bracketSearchResult.DefinitionHeaderLength == 0)
return;
int startOffset = bracketSearchResult.DefinitionHeaderOffset;
int endOffset = startOffset + bracketSearchResult.DefinitionHeaderLength;
// show whole line even if the definition is only a part:
DocumentLine firstLine = editor.Document.GetLineByOffset(startOffset);
DocumentLine lastLine = editor.Document.GetLineByOffset(endOffset);
TextEditor popupEditor = new TextEditor();
popupEditor.IsReadOnly = true;
popupEditor.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
popupEditor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
popupEditor.CopySettingsFrom(editor);
IHighlighter oldHighlighter = editor.GetRequiredService<IHighlighter>();
FixedHighlighter newHighlighter = FixedHighlighter.CreateView(oldHighlighter, firstLine.Offset, lastLine.EndOffset);
popupEditor.Document = (TextDocument)newHighlighter.Document;
popupEditor.TextArea.TextView.LineTransformers.Add(new HighlightingColorizer(newHighlighter));
popup = new ExtendedPopup(editor.TextArea);
const double borderThickness = 1;
popup.Child = new Border() {
Child = popupEditor,
BorderBrush = editor.TextArea.Foreground,
BorderThickness = new Thickness(borderThickness)
};
popup.HorizontalOffset = -borderThickness - editor.TextArea.TextView.ScrollOffset.X;
popup.Placement = PlacementMode.Top;
popup.PlacementTarget = editor.TextArea.TextView;
this.currentStartOffset = firstLine.Offset;
editor.TextArea.TextView.VisualLinesChanged += textView_VisualLinesChanged;
if (editor.TextArea.TextView.VisualLinesValid)
textView_VisualLinesChanged(null, null); // open popup if necessary
}
}
}

0
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizingHighlighter.cs → src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/CustomizingHighlighter.cs

128
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/FixedHighlighter.cs

@ -0,0 +1,128 @@ @@ -0,0 +1,128 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
namespace ICSharpCode.AvalonEdit.AddIn
{
/// <summary>
/// IHighlighter implementation that returns a fixed set of HighlightedLines.
/// </summary>
public class FixedHighlighter : IHighlighter
{
/// <summary>
/// Creates a new <see cref="FixedHighlighter"/> for a copy of a portion
/// of the input document (including the original highlighting).
/// </summary>
public static FixedHighlighter CreateView(IHighlighter highlighter, int offset, int endOffset)
{
var oldDocument = highlighter.Document;
// ReadOnlyDocument would be better; but displaying the view in AvalonEdit
// requires a TextDocument
var newDocument = new TextDocument(oldDocument.CreateSnapshot(offset, endOffset - offset));
var oldStartLine = oldDocument.GetLineByOffset(offset);
var oldEndLine = oldDocument.GetLineByOffset(endOffset);
int oldStartLineNumber = oldStartLine.LineNumber;
HighlightedLine[] newLines = new HighlightedLine[oldEndLine.LineNumber - oldStartLineNumber + 1];
highlighter.BeginHighlighting();
try {
for (int i = 0; i < newLines.Length; i++) {
HighlightedLine oldHighlightedLine = highlighter.HighlightLine(oldStartLineNumber + i);
IDocumentLine newLine = newDocument.GetLineByNumber(1 + i);
HighlightedLine newHighlightedLine = new HighlightedLine(newDocument, newLine);
MoveSections(oldHighlightedLine.Sections, -offset, newLine.Offset, newLine.EndOffset, newHighlightedLine.Sections);
newHighlightedLine.ValidateInvariants();
newLines[i] = newHighlightedLine;
}
} finally {
highlighter.EndHighlighting();
}
return new FixedHighlighter(newDocument, newLines);
}
/// <summary>
/// Moves the section start by <paramref name="delta"/> positions;
/// and removes the sections outside the (newLineStart,newLineEnd) range.
/// </summary>
static void MoveSections(IEnumerable<HighlightedSection> sections, int delta, int newLineStart, int newLineEnd, IList<HighlightedSection> result)
{
foreach (var section in sections) {
int newOffset = section.Offset + delta;
int newEndOffset = section.Offset + section.Length + delta;
newOffset = newOffset.CoerceValue(newLineStart, newLineEnd);
newEndOffset = newEndOffset.CoerceValue(newLineStart, newLineEnd);
if (newOffset < newLineEnd && newEndOffset > newLineStart) {
result.Add(
new HighlightedSection {
Offset = newOffset,
Length = newEndOffset - newOffset,
Color = section.Color
});
}
}
}
readonly IDocument document;
readonly HighlightedLine[] lines;
public FixedHighlighter(IDocument document, HighlightedLine[] lines)
{
if (lines.Length != document.LineCount)
throw new ArgumentException("Wrong number of highlighted lines");
this.document = document;
this.lines = lines;
}
event HighlightingStateChangedEventHandler IHighlighter.HighlightingStateChanged {
add { }
remove { }
}
public IDocument Document {
get { return document; }
}
HighlightingColor IHighlighter.DefaultTextColor {
get { return null; }
}
IEnumerable<HighlightingColor> IHighlighter.GetColorStack(int lineNumber)
{
return Enumerable.Empty<HighlightingColor>();
}
public HighlightedLine HighlightLine(int lineNumber)
{
return lines[lineNumber - 1];
}
void IHighlighter.UpdateHighlightingState(int lineNumber)
{
}
void IHighlighter.BeginHighlighting()
{
}
void IHighlighter.EndHighlighting()
{
}
HighlightingColor IHighlighter.GetNamedColor(string name)
{
return null;
}
void IDisposable.Dispose()
{
}
}
}

0
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/MultiHighlighter.cs → src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/MultiHighlighter.cs

0
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxModeDoozer.cs → src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/SyntaxModeDoozer.cs

18
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Utils.cs

@ -5,6 +5,7 @@ using System; @@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using ICSharpCode.AvalonEdit.AddIn.Options;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.SharpDevelop.Widgets.MyersDiff;
@ -27,5 +28,22 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -27,5 +28,22 @@ namespace ICSharpCode.AvalonEdit.AddIn
}
return map;
}
/// <summary>
/// Copies editor options and default element customizations.
/// Does not copy the syntax highlighting.
/// </summary>
public static void CopySettingsFrom(this TextEditor editor, TextEditor source)
{
editor.Options = source.Options;
string language = source.SyntaxHighlighting != null ? source.SyntaxHighlighting.Name : null;
CustomizingHighlighter.ApplyCustomizationsToDefaultElements(editor, CustomizedHighlightingColor.FetchCustomizations(language));
HighlightingOptions.ApplyToRendering(editor, CustomizedHighlightingColor.FetchCustomizations(language));
}
static IEnumerable<CustomizedHighlightingColor> FetchCustomizations(string languageName)
{
return CustomizedHighlightingColor.FetchCustomizations(languageName);
}
}
}

6
src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs

@ -206,14 +206,12 @@ namespace SearchAndReplace @@ -206,14 +206,12 @@ namespace SearchAndReplace
if (document == null) {
document = new ReadOnlyDocument(source, fileName);
highlighter = SD.EditorControlService.CreateHighlighter(document);
if (highlighter != null)
highlighter.BeginHighlighting();
highlighter.BeginHighlighting();
}
var start = document.GetLocation(result.Offset);
var end = document.GetLocation(result.Offset + result.Length);
var builder = SearchResultsPad.CreateInlineBuilder(start, end, document, highlighter);
var defaultTextColor = highlighter != null ? highlighter.DefaultTextColor : null;
results.Add(new AvalonEditSearchResultMatch(fileName, start, end, result.Offset, result.Length, builder, defaultTextColor, result));
results.Add(new AvalonEditSearchResultMatch(fileName, start, end, result.Offset, result.Length, builder, highlighter.DefaultTextColor, result));
}
if (highlighter != null) {
highlighter.Dispose();

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs

@ -94,7 +94,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -94,7 +94,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
{
if (color == null)
throw new ArgumentNullException("color");
if (color.Foreground == null && color.FontStyle == null && color.FontWeight == null) {
if (color.Foreground == null && color.Background == null && color.FontStyle == null && color.FontWeight == null) {
// Optimization: don't split the HighlightingState when we're not changing
// any property. For example, the "Punctuation" color in C# is
// empty by default.

18
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedLine.cs

@ -50,8 +50,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -50,8 +50,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting
/// </summary>
public IList<HighlightedSection> Sections { get; private set; }
[Conditional("DEBUG")]
void ValidateInvariants()
/// <summary>
/// Validates that the sections are sorted correctly, and that they are not overlapping.
/// </summary>
/// <seealso cref="Sections"/>
public void ValidateInvariants()
{
var line = this;
int lineStartOffset = line.DocumentLine.Offset;
@ -81,8 +84,10 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -81,8 +84,10 @@ namespace ICSharpCode.AvalonEdit.Highlighting
{
if (additionalLine == null)
return;
#if DEBUG
ValidateInvariants();
additionalLine.ValidateInvariants();
#endif
int pos = 0;
Stack<int> activeSectionEndOffsets = new Stack<int>();
@ -124,7 +129,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -124,7 +129,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting
Insert(ref i, ref newSectionStart, newSection.Offset + newSection.Length, newSection.Color, insertionStack);
}
#if DEBUG
ValidateInvariants();
#endif
}
void Insert(ref int pos, ref int newSectionStart, int insertionEndPos, HighlightingColor color, Stack<int> insertionStack)
@ -268,12 +275,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -268,12 +275,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
int startOffset = DocumentLine.Offset;
// copy only the foreground and background colors
foreach (HighlightedSection section in Sections) {
if (section.Color.Foreground != null) {
builder.SetForeground(section.Offset - startOffset, section.Length, section.Color.Foreground.GetBrush(null));
}
if (section.Color.Background != null) {
builder.SetBackground(section.Offset - startOffset, section.Length, section.Color.Background.GetBrush(null));
}
builder.SetHighlighting(section.Offset - startOffset, section.Length, section.Color);
}
return builder;
}

12
src/Main/Base/Project/Editor/IBracketSearcher.cs

@ -41,6 +41,18 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -41,6 +41,18 @@ namespace ICSharpCode.SharpDevelop.Editor
public int ClosingBracketLength { get; private set; }
/// <summary>
/// Gets/Sets the offset of the definition belonging to the brackets.
/// The definition header gets shown by the <see cref="HiddenDefinitionRenderer"/>.
/// </summary>
public int DefinitionHeaderOffset { get; set; }
/// <summary>
/// Gets/Sets the length of the definition header belonging to the brackets.
/// The definition header gets shown by the <see cref="HiddenDefinitionRenderer"/>.
/// </summary>
public int DefinitionHeaderLength { get; set; }
public BracketSearchResult(int openingBracketOffset, int openingBracketLength,
int closingBracketOffset, int closingBracketLength)
{

5
src/Main/Base/Project/Editor/IEditorControlService.cs

@ -18,6 +18,11 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -18,6 +18,11 @@ namespace ICSharpCode.SharpDevelop.Editor
{
ITextEditor CreateEditor(out object control);
ITextEditorOptions GlobalOptions { get; }
/// <summary>
/// Creates a highlighter for the specified document.
/// This method never returns null.
/// </summary>
IHighlighter CreateHighlighter(IDocument document);
}

2
src/Main/Base/Project/Editor/Search/SearchResultMatch.cs

@ -80,7 +80,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search @@ -80,7 +80,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
int startOffset = document.GetOffset(startLocation);
int endOffset = document.GetOffset(endLocation);
var inlineBuilder = SearchResultsPad.CreateInlineBuilder(startLocation, endLocation, document, highlighter);
var defaultTextColor = highlighter != null ? highlighter.DefaultTextColor : null;
var defaultTextColor = highlighter.DefaultTextColor;
return new SearchResultMatch(FileName.Create(document.FileName),
startLocation, endLocation,
startOffset, endOffset - startOffset,

10
src/Main/Base/Project/Editor/Search/SearchResultsPad.cs

@ -152,12 +152,10 @@ namespace ICSharpCode.SharpDevelop.Editor.Search @@ -152,12 +152,10 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
public static HighlightedInlineBuilder CreateInlineBuilder(TextLocation startPosition, TextLocation endPosition, IDocument document, IHighlighter highlighter)
{
if (startPosition.Line >= 1 && startPosition.Line <= document.LineCount) {
HighlightedInlineBuilder inlineBuilder;
if (highlighter != null) {
inlineBuilder = highlighter.HighlightLine(startPosition.Line).ToInlineBuilder();
} else {
inlineBuilder = new HighlightedInlineBuilder(document.GetText(document.GetLineByNumber(startPosition.Line)));
}
var inlineBuilder = highlighter.HighlightLine(startPosition.Line).ToInlineBuilder();
// reset bold/italics
inlineBuilder.SetFontWeight(0, inlineBuilder.Text.Length, FontWeights.Normal);
inlineBuilder.SetFontStyle(0, inlineBuilder.Text.Length, FontStyles.Normal);
// now highlight the match in bold
if (startPosition.Column >= 1) {

3
src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs

@ -354,8 +354,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -354,8 +354,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
buffer = SD.FileService.GetFileContent(r.FileName);
document = new ReadOnlyDocument(buffer, r.FileName);
highlighter = SD.EditorControlService.CreateHighlighter(document);
if (highlighter != null)
highlighter.BeginHighlighting();
highlighter.BeginHighlighting();
}
var start = r.StartLocation;
var end = r.EndLocation;

24
src/Main/Base/Project/Util/SharpDevelopExtensions.cs

@ -93,6 +93,30 @@ namespace ICSharpCode.SharpDevelop @@ -93,6 +93,30 @@ namespace ICSharpCode.SharpDevelop
}
#endregion
#region CoerceValue
/// <summary>
/// Forces the value to stay between mininum and maximum.
/// </summary>
/// <returns>minimum, if value is less than minimum.
/// Maximum, if value is greater than maximum.
/// Otherwise, value.</returns>
public static double CoerceValue(this double value, double minimum, double maximum)
{
return Math.Max(Math.Min(value, maximum), minimum);
}
/// <summary>
/// Forces the value to stay between mininum and maximum.
/// </summary>
/// <returns>minimum, if value is less than minimum.
/// Maximum, if value is greater than maximum.
/// Otherwise, value.</returns>
public static int CoerceValue(this int value, int minimum, int maximum)
{
return Math.Max(Math.Min(value, maximum), minimum);
}
#endregion
#region Collections
/// <summary>
/// Obsolete. Please use a regular foreach loop instead. ForEach() is executed for its side-effects, and side-effects mix poorly with a functional programming style.

67
src/Main/ICSharpCode.Core.Presentation/ExtendedPopup.cs

@ -1,67 +0,0 @@ @@ -1,67 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Interop;
namespace ICSharpCode.Core.Presentation
{
/// <summary>
/// Extends WPF popup to prevent it from being the topmost window on the screen.
/// </summary>
public class ExtendedPopup : Popup
{
IntPtr hwnd;
protected override void OnOpened(EventArgs e)
{
hwnd = ((HwndSource)PresentationSource.FromVisual(Child)).Handle;
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, NoChangeFlags);
Application.Current.Activated += ApplicationActivated;
Application.Current.Deactivated += ApplicationDeactivated;
}
protected override void OnClosed(EventArgs e)
{
Application.Current.Activated -= ApplicationActivated;
Application.Current.Deactivated -= ApplicationDeactivated;
}
void ApplicationActivated(object sender, EventArgs e)
{
LoggingService.Debug("Application activated!");
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, NoChangeFlags | SWP_SHOWWINDOW);
}
void ApplicationDeactivated(object sender, EventArgs e)
{
LoggingService.Debug("Application deactivated!");
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, NoChangeFlags | SWP_HIDEWINDOW);
}
#region Win32 API
// for all possible flags see http://msdn.microsoft.com/en-us/library/ms633545%28VS.85%29.aspx
const int SWP_NOSIZE = 0x0001;
const int SWP_NOMOVE = 0x0002;
const int SWP_NOACTIVATE = 0x0010;
const int SWP_SHOWWINDOW = 0x0040;
const int SWP_HIDEWINDOW = 0x0080;
// SWP_NOACTIVATE fixes SD-1728 - http://bugtracker.sharpdevelop.net/Default.aspx?p=4&i=1728
static readonly uint NoChangeFlags = SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE;
static readonly IntPtr HWND_TOP = new IntPtr(0);
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
[DllImport("user32.dll", SetLastError=true, EntryPoint="SetWindowPos")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
#endregion
}
}

1
src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

@ -71,7 +71,6 @@ @@ -71,7 +71,6 @@
<Compile Include="..\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ExtendedPopup.cs" />
<Compile Include="GlobalStyles.cs" />
<Compile Include="Menu\MenuCheckBox.cs" />
<Compile Include="NotBoolConverter.cs" />

66
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ExtendedPopup.cs

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows;
using System.Windows.Controls.Primitives;
namespace ICSharpCode.SharpDevelop.Widgets
{
/// <summary>
/// A popup that is only visible while the parent control or the popup itself has the keyboard focus.
/// </summary>
public class ExtendedPopup : Popup
{
readonly UIElement parent;
public ExtendedPopup(UIElement parent)
{
if (parent == null)
throw new ArgumentNullException("parent");
this.parent = parent;
}
/// <summary>
/// Gets whether the popup is currently visible.
/// </summary>
public new bool IsOpen {
get { return base.IsOpen; }
// Prevent consumers from accessing the setter directly
}
bool openIfFocused;
public bool IsOpenIfFocused {
get { return openIfFocused; }
set {
if (openIfFocused != value) {
openIfFocused = value;
if (value) {
parent.IsKeyboardFocusedChanged += parent_IsKeyboardFocusedChanged;
} else {
parent.IsKeyboardFocusedChanged -= parent_IsKeyboardFocusedChanged;
}
OpenOrClose();
}
}
}
void parent_IsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e)
{
OpenOrClose();
}
protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
{
base.OnIsKeyboardFocusWithinChanged(e);
OpenOrClose();
}
void OpenOrClose()
{
bool newIsOpen = openIfFocused && (parent.IsKeyboardFocused || this.IsKeyboardFocusWithin);
base.IsOpen = newIsOpen;
}
}
}

1
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ICSharpCode.SharpDevelop.Widgets.csproj

@ -72,6 +72,7 @@ @@ -72,6 +72,7 @@
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="CustomWindowsFormsHost.cs" />
<Compile Include="DragListener.cs" />
<Compile Include="ExtendedPopup.cs" />
<Compile Include="ListViewSorting\AbstractListViewParseableColumnComparer.cs" />
<Compile Include="ListViewSorting\AbstractListViewSubItemComparer.cs" />
<Compile Include="ListViewSorting\ListViewIntegerParseColumnComparer.cs" />

Loading…
Cancel
Save