-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use find results panel to show XML errors as well
Fixes #47
- Loading branch information
1 parent
52b99a9
commit 05a984e
Showing
15 changed files
with
308 additions
and
232 deletions.
There are no files selected for viewing
130 changes: 0 additions & 130 deletions
130
OfficeRibbonXEditor/Controls/FindAllResultsPanel.xaml.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Windows.Forms; | ||
using OfficeRibbonXEditor.Interfaces; | ||
using ScintillaNET; | ||
using UserControl = System.Windows.Controls.UserControl; | ||
|
||
namespace OfficeRibbonXEditor.Controls | ||
{ | ||
/// <summary> | ||
/// Interaction logic for ResultsPanel.xaml | ||
/// </summary> | ||
public partial class ResultsPanel : UserControl | ||
{ | ||
public ResultsPanel() | ||
{ | ||
this.InitializeComponent(); | ||
|
||
this.ResultsScintilla.Styles[ScintillaNET.Style.Default].Font = "Consolas"; | ||
this.ResultsScintilla.Styles[ScintillaNET.Style.Default].Size = 10; | ||
|
||
this.ResultsScintilla.ClearAll(); | ||
|
||
this.ResultsScintilla.Scintilla.KeyUp += this.FindResultsScintilla_KeyUp; | ||
this.ResultsScintilla.Scintilla.MouseClick += this.FindResultsScintilla_MouseClick; | ||
this.ResultsScintilla.Scintilla.MouseDoubleClick += this.FindResultsScintilla_MouseDoubleClick; | ||
} | ||
|
||
private IResultCollection Results { get; set; } | ||
|
||
public Scintilla Scintilla { get; set; } | ||
|
||
/// <summary> | ||
/// Updates the find all results panel | ||
/// </summary> | ||
/// <param name="editor">The Scintilla editor used to generate the find results.</param> | ||
/// <param name="results"></param> | ||
public void UpdateFindAllResults(IResultCollection results) | ||
{ | ||
this.Results = results; | ||
this.Results.AddToPanel(this.Scintilla, this.ResultsScintilla.Scintilla); | ||
} | ||
|
||
private void FindResultsScintilla_KeyUp(object sender, KeyEventArgs e) | ||
{ | ||
var pos = this.ResultsScintilla.CurrentPosition; | ||
this.Results.GoToPosition(pos, this.Scintilla, this.ResultsScintilla.Scintilla); | ||
} | ||
|
||
private void FindResultsScintilla_MouseClick(object sender, MouseEventArgs e) | ||
{ | ||
var pos = this.ResultsScintilla.CharPositionFromPointClose((e.Location).X, (e.Location).Y); | ||
if (pos == -1) | ||
{ | ||
return; | ||
} | ||
|
||
this.Results.GoToPosition(pos, this.Scintilla, this.ResultsScintilla.Scintilla); | ||
} | ||
|
||
private void FindResultsScintilla_MouseDoubleClick(object sender, MouseEventArgs e) | ||
{ | ||
var pos = this.ResultsScintilla.CharPositionFromPointClose((e.Location).X, (e.Location).Y); | ||
if (pos == -1) | ||
{ | ||
return; | ||
} | ||
|
||
this.Results.GoToPosition(pos, this.Scintilla, this.ResultsScintilla.Scintilla); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using ScintillaNET; | ||
|
||
namespace OfficeRibbonXEditor.Interfaces | ||
{ | ||
public interface IResultCollection | ||
{ | ||
void AddToPanel(Scintilla editor, Scintilla resultsPanel); | ||
|
||
void GoToPosition(int pos, Scintilla editor, Scintilla resultsPanel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using OfficeRibbonXEditor.Interfaces; | ||
using ScintillaNET; | ||
|
||
namespace OfficeRibbonXEditor.Models | ||
{ | ||
public class FindResults : IResultCollection | ||
{ | ||
public FindResults(IEnumerable<CharacterRange> items) | ||
{ | ||
this.Items = new List<CharacterRange>(items); | ||
} | ||
|
||
public List<CharacterRange> Items { get; } | ||
|
||
public void AddToPanel(Scintilla editor, Scintilla resultsPanel) | ||
{ | ||
resultsPanel.ClearAll(); | ||
|
||
var indicator = resultsPanel.Indicators[16]; | ||
indicator.ForeColor = Color.Red; | ||
indicator.Alpha = 100; | ||
indicator.Style = IndicatorStyle.RoundBox; | ||
indicator.Under = true; | ||
resultsPanel.IndicatorCurrent = indicator.Index; | ||
|
||
//Write lines | ||
foreach (var item in this.Items) | ||
{ | ||
var startLine = editor.LineFromPosition(item.cpMin); | ||
var endLine = editor.LineFromPosition(item.cpMax); | ||
|
||
if (startLine == endLine) | ||
{ | ||
var resultsLinePrefix = $"Line {startLine + 1}: "; | ||
|
||
resultsPanel.AppendText($"{resultsLinePrefix}{editor.Lines[startLine].Text}"); | ||
} | ||
} | ||
|
||
//Highlight | ||
var resultLineIndex = 0; | ||
foreach (var item in this.Items) | ||
{ | ||
var startLine = editor.LineFromPosition(item.cpMin); | ||
var endLine = editor.LineFromPosition(item.cpMax); | ||
|
||
if (startLine == endLine) | ||
{ | ||
var resultsLinePrefix = $"Line {startLine + 1}: "; | ||
|
||
var linePos = editor.Lines[startLine].Position; | ||
var startPosInLine = item.cpMin - linePos; | ||
|
||
var lastLineStartPos = resultsPanel.Lines[resultLineIndex].Position; | ||
|
||
resultsPanel.IndicatorFillRange(lastLineStartPos + resultsLinePrefix.Length + startPosInLine, item.cpMax - item.cpMin); | ||
|
||
resultLineIndex++; | ||
} | ||
} | ||
} | ||
|
||
public void GoToPosition(int pos, Scintilla editor, Scintilla resultsPanel) | ||
{ | ||
var selectedLine = resultsPanel.LineFromPosition(pos); | ||
|
||
var charRange = this.Items[selectedLine]; | ||
editor.GotoPosition(charRange.cpMax); | ||
editor.GotoPosition(charRange.cpMin); | ||
editor.SetSelection(charRange.cpMin, charRange.cpMax); | ||
editor.ScrollCaret(); | ||
editor.Focus(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace OfficeRibbonXEditor.Models | ||
{ | ||
public class XmlError | ||
{ | ||
public int LineNumber { get; set; } | ||
|
||
public int LinePosition { get; set; } | ||
|
||
public string Message { get; set; } | ||
} | ||
} |
Oops, something went wrong.