polished ui

This commit is contained in:
Koisu 2025-06-23 18:57:41 -07:00
parent f36ee61de4
commit e12c2be419
2 changed files with 39 additions and 16 deletions

View file

@ -74,18 +74,20 @@
Orientation="Horizontal">
<TextBlock
MinWidth="150"
Margin="0 10 15 10"
Margin="0 10 5 10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource plugin_explorer_new_file_name}"/>
<TextBox
Name="RenameTb"
Width="135"
Width="Auto"
HorizontalAlignment="Left"
VerticalAlignment="Center"
PreviewKeyDown="RenameTb_OnKeyDown"
Text="{Binding NewFileName}"/>
Text="{Binding NewFileName}"
GotFocus="SelectAll_OnTextBoxGotFocus"
/>
</StackPanel>
</StackPanel>
</StackPanel>
@ -100,14 +102,14 @@
x:Name="btnCancel"
Width="145"
Height="30"
Margin="0 0 5 0"
Margin="5 0 5 0"
Click="BtnCancel"
Content="{DynamicResource cancel}"/>
<Button
Name="btnDone"
Width="145"
Height="30"
Margin="5 0 0 0"
Margin="5 0 5 0"
Click="OnDoneButtonClick"
Style="{StaticResource AccentButtonStyle}">
<TextBlock x:Name="lblAdd"

View file

@ -4,6 +4,7 @@ using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using Flow.Launcher.Plugin.Explorer.Helper;
using Microsoft.VisualBasic.Logging;
@ -37,24 +38,44 @@ namespace Flow.Launcher.Plugin.Explorer.Views
public RenameFile(IPublicAPI api, FileSystemInfo info)
{
_api = api;
InitializeComponent();
RenameTb.Focus();
ShowInTaskbar = false;
RenameTb.SelectAll();
_info = info;
_oldFilePath = _info.FullName;
NewFileName = _info.Name;
InitializeComponent();
ShowInTaskbar = false;
RenameTb.Focus();
}
/// <summary>
/// https://stackoverflow.com/a/59560352/24045055
/// </summary>
private async void SelectAll_OnTextBoxGotFocus(object sender, RoutedEventArgs e)
{
var textBox = sender as TextBox;
if (_info is DirectoryInfo)
{
await Application.Current.Dispatcher.InvokeAsync(textBox.SelectAll, DispatcherPriority.Background);
}
// select everything but the extension
else if (_info is FileInfo info)
{
string properName = Path.GetFileNameWithoutExtension(info.Name);
Application.Current.Dispatcher.Invoke(textBox.Select, DispatcherPriority.Background, textBox.Text.IndexOf(properName), properName.Length );
}
}
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
{
RenameThing.Rename(NewFileName, _info, _api);