Skip to content

Commit

Permalink
Add GoTo Project tag for Preprocessor.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuehuang010 committed Dec 19, 2023
1 parent 951e5be commit f2ff7f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/StructuredLogViewer/Controls/TextViewerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<a:TextEditor.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy" Click="copyMenu_Click" />
<MenuItem x:Name="gotoProjectMenu" Header="Goto including Project" Click="gotoProjectFoldingMenu_Click" Visibility="Collapsed"/>
</ContextMenu>
</a:TextEditor.ContextMenu>
</a:TextEditor>
Expand Down
24 changes: 22 additions & 2 deletions src/StructuredLogViewer/Controls/TextViewerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ private void OnSettingData(object sender, DataObjectSettingDataEventArgs e)
DisplaySource(lineNumber, column);

if (IsXml)
{
ImportLinkHighlighter.Install(textEditor, sourceFilePath, navigationHelper);
}
}

protected override void OnKeyUp(KeyEventArgs e)
{
// Mark Ctrl+F handle to not steal focus from search panel
if (e.Key == Key.F && Keyboard.Modifiers == ModifierKeys.Control)
if (e.Key == Key.F && Keyboard.Modifiers == ModifierKeys.Control)
{
e.Handled = true;
}
Expand Down Expand Up @@ -203,6 +205,8 @@ void SetColor(string name, string hex)

var foldingStrategy = new XmlFoldingStrategy();
foldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);

gotoProjectMenu.Visibility = Visibility.Visible;
}
else if (!looksLikeXml && IsXml)
{
Expand Down Expand Up @@ -259,7 +263,7 @@ void save_Click(object sender, RoutedEventArgs e)
Title = "Save file as...",
FileName = Path.GetFileName(filePath)
};

var result = saveFileDialog.ShowDialog(Application.Current.MainWindow);

if (result is true)
Expand Down Expand Up @@ -312,5 +316,21 @@ private void copyMenu_Click(object sender, RoutedEventArgs e)
{
textEditor.Copy();
}

private void gotoProjectFoldingMenu_Click(object sender, RoutedEventArgs e)
{
var selectionStart = textEditor.SelectionStart;
if (selectionStart > 0)
{
selectionStart--;
}

var projFolding = foldingManager.GetFoldingsContaining(selectionStart)?.LastOrDefault(f => f.Title == "<Project>");
if (projFolding != null)
{
textEditor.Select(projFolding.StartOffset, projFolding.Title.Length);
textEditor.ScrollTo(textEditor.Document.GetLineByOffset(projFolding.StartOffset).LineNumber, 0);
}
}
}
}

0 comments on commit f2ff7f6

Please sign in to comment.