Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go to line function #61

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions SkEditor/Controls/MainMenuControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@
<ui:SymbolIcon Symbol="Comment"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{DynamicResource MenuHeaderGoToLine}" Name="MenuItemGoToLine" InputGesture="Ctrl+G" HotKey="Ctrl+G">
<MenuItem.Icon>
<ui:SymbolIcon Symbol="Find"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{DynamicResource MenuHeaderDelete}" Name="MenuItemDelete" InputGesture="Delete">
<MenuItem.Icon>
<ui:SymbolIcon Symbol="Delete"/>
Expand Down
1 change: 1 addition & 0 deletions SkEditor/Controls/MainMenuControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private void AssignCommands()

MenuItemDuplicate.Command = new RelayCommand(() => CustomCommandsHandler.OnDuplicateCommandExecuted(ApiVault.Get().GetTextEditor().TextArea));
MenuItemComment.Command = new RelayCommand(() => CustomCommandsHandler.OnCommentCommandExecuted(ApiVault.Get().GetTextEditor().TextArea));
MenuItemGoToLine.Command = new RelayCommand(() => new GoToLine().ShowDialog(ApiVault.Get().GetMainWindow()));

MenuItemRefreshSyntax.Command = new RelayCommand(async () => await SyntaxLoader.RefreshSyntaxAsync());

Expand Down
5 changes: 5 additions & 0 deletions SkEditor/Languages/English.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<system:String x:Key="MenuHeaderDuplicate">Duplicate</system:String>
<system:String x:Key="MenuHeaderComment">Comment</system:String>
<system:String x:Key="MenuHeaderDelete">Delete</system:String>
<system:String x:Key="MenuHeaderGoToLine">Go to line</system:String>

<!-- Tools Menu -->
<system:String x:Key="MenuHeaderDocumentation">Documentation</system:String>
Expand Down Expand Up @@ -365,5 +366,9 @@
<system:String x:Key="MarketplaceButtonDisable">Disable</system:String>
<system:String x:Key="MarketplaceButtonEnable">Enable</system:String>

<!-- Go to line -->
<system:String x:Key="GoToLine">Go to line</system:String>
<system:String x:Key="GoToLineButton">Go</system:String>


</ResourceDictionary>
5 changes: 5 additions & 0 deletions SkEditor/Languages/Polish.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<system:String x:Key="MenuHeaderDuplicate">Duplikuj</system:String>
<system:String x:Key="MenuHeaderComment">Zakomentuj</system:String>
<system:String x:Key="MenuHeaderDelete">Usuń</system:String>
<system:String x:Key="MenuHeaderGoToLine">Przejdź do linii</system:String>

<!-- Tools Menu -->
<system:String x:Key="MenuHeaderDocumentation">Dokumentacja</system:String>
Expand Down Expand Up @@ -293,5 +294,9 @@
<system:String x:Key="MarketplaceButtonDisable">Wyłącz</system:String>
<system:String x:Key="MarketplaceButtonEnable">Włącz</system:String>

<!-- Go to line -->
<system:String x:Key="GoToLine">Przejdź do linii</system:String>
<system:String x:Key="GoToLineButton">Idź</system:String>


</ResourceDictionary>
14 changes: 14 additions & 0 deletions SkEditor/Utilities/Editor/GoToLine.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="using:FluentAvalonia.UI.Controls"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SkEditor.Utilities.Editor.GoToLine" Icon="/Assets/SkEditor.ico"
Title="{DynamicResource GoToLine}" Height="80" Width="160" CanResize="False" WindowStartupLocation="CenterOwner" Theme="{StaticResource SmallWindowTheme}">

<Grid>
<TextBox Name="GoToLineInput" HorizontalAlignment="Left" Margin="20"/>
<Button Name="GoToLineButton" Content="{DynamicResource GoToLineButton}" HorizontalAlignment="Right" Margin="0, 0, 10, 0"/>
</Grid>
</Window>
45 changes: 45 additions & 0 deletions SkEditor/Utilities/Editor/GoToLine.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using AvaloniaEdit;
using AvaloniaEdit.Document;
using CommunityToolkit.Mvvm.Input;
using FluentAvalonia.UI.Windowing;
using SkEditor.API;

namespace SkEditor.Utilities.Editor;
public partial class GoToLine : AppWindow
{

public GoToLine()
{
InitializeComponent();
GoToLineInput.Loaded += (sender, e) => GoToLineInput.Focus();
GoToLineInput.TextChanged += (_, _) => UpdateInput();
GoToLineButton.Command = new RelayCommand(Execute);

}

private void Execute()
{
if (string.IsNullOrWhiteSpace(GoToLineInput.Text)) return;

TextEditor editor = ApiVault.Get().GetTextEditor();
if (!int.TryParse(GoToLineInput.Text, out int lineNumber)) return;
DocumentLine line = editor.Document.GetLineByNumber(lineNumber);
editor.ScrollTo(line.LineNumber, 0);
editor.Focus();
editor.CaretOffset = line.Offset;
Close();
}

private void UpdateInput()
{
TextEditor editor = ApiVault.Get().GetTextEditor();
int documentLines = editor.Document.LineCount;
if (!int.TryParse(GoToLineInput.Text, out int line)) {
GoToLineInput.Text = "";
return;
};
line = Math.Clamp(line, 1, documentLines);
GoToLineInput.Text = line.ToString();
}
}