2025-06-22 19:41:52 +00:00
|
|
|
using System.IO;
|
2025-06-22 02:13:07 +00:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
2025-06-22 20:45:42 +00:00
|
|
|
using System.Windows.Controls;
|
2025-06-22 02:13:07 +00:00
|
|
|
using System.Windows.Input;
|
2025-06-24 01:57:41 +00:00
|
|
|
using System.Windows.Threading;
|
2025-06-22 02:13:07 +00:00
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2025-06-22 19:41:52 +00:00
|
|
|
using Flow.Launcher.Plugin.Explorer.Helper;
|
2025-06-20 19:40:20 +00:00
|
|
|
|
|
|
|
|
|
2025-06-22 02:13:07 +00:00
|
|
|
namespace Flow.Launcher.Plugin.Explorer.Views
|
2025-06-20 19:40:20 +00:00
|
|
|
{
|
2025-06-23 22:23:57 +00:00
|
|
|
|
2025-06-22 02:13:07 +00:00
|
|
|
[INotifyPropertyChanged]
|
2025-06-23 22:23:57 +00:00
|
|
|
public partial class RenameFile : Window
|
2025-06-22 02:13:07 +00:00
|
|
|
{
|
2025-06-23 22:23:57 +00:00
|
|
|
|
2025-06-22 02:13:07 +00:00
|
|
|
|
|
|
|
|
public string NewFileName
|
|
|
|
|
{
|
2025-06-22 19:41:52 +00:00
|
|
|
get => _newFileName;
|
2025-06-22 02:13:07 +00:00
|
|
|
set
|
|
|
|
|
{
|
2025-06-22 19:41:52 +00:00
|
|
|
_ = SetProperty(ref _newFileName, value);
|
2025-06-22 02:13:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-06-22 19:41:52 +00:00
|
|
|
private string _newFileName;
|
2025-06-23 22:23:57 +00:00
|
|
|
|
2025-06-22 02:13:07 +00:00
|
|
|
private readonly IPublicAPI _api;
|
2025-06-22 19:41:52 +00:00
|
|
|
private readonly string _oldFilePath;
|
2025-06-22 02:13:07 +00:00
|
|
|
|
2025-06-22 19:41:52 +00:00
|
|
|
private readonly FileSystemInfo _info;
|
2025-06-22 02:13:07 +00:00
|
|
|
|
2025-06-22 19:41:52 +00:00
|
|
|
public RenameFile(IPublicAPI api, FileSystemInfo info)
|
2025-06-22 02:13:07 +00:00
|
|
|
{
|
|
|
|
|
_api = api;
|
2025-06-24 01:57:41 +00:00
|
|
|
_info = info;
|
|
|
|
|
_oldFilePath = _info.FullName;
|
|
|
|
|
NewFileName = _info.Name;
|
2025-06-22 02:13:07 +00:00
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2025-06-24 01:57:41 +00:00
|
|
|
|
2025-06-22 20:45:42 +00:00
|
|
|
|
2025-06-22 02:13:07 +00:00
|
|
|
ShowInTaskbar = false;
|
2025-06-22 19:41:52 +00:00
|
|
|
|
2025-06-24 01:57:41 +00:00
|
|
|
|
2025-06-22 20:45:42 +00:00
|
|
|
|
2025-06-24 01:57:41 +00:00
|
|
|
RenameTb.Focus();
|
|
|
|
|
|
2025-06-23 22:23:57 +00:00
|
|
|
|
|
|
|
|
|
2025-06-22 02:13:07 +00:00
|
|
|
}
|
2025-06-24 01:57:41 +00:00
|
|
|
/// <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 );
|
2025-06-22 02:13:07 +00:00
|
|
|
|
2025-06-24 01:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2025-06-22 02:13:07 +00:00
|
|
|
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2025-06-24 00:59:33 +00:00
|
|
|
RenameThing.Rename(NewFileName, _info, _api);
|
2025-06-22 19:41:52 +00:00
|
|
|
Close();
|
2025-06-23 22:23:57 +00:00
|
|
|
|
2025-06-22 02:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BtnCancel(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2025-06-23 22:23:57 +00:00
|
|
|
|
2025-06-22 19:41:52 +00:00
|
|
|
private void RenameTb_OnKeyDown(object sender, KeyEventArgs e)
|
2025-06-22 02:13:07 +00:00
|
|
|
{
|
|
|
|
|
if (e.Key == Key.Enter)
|
|
|
|
|
{
|
|
|
|
|
btnDone.Focus();
|
|
|
|
|
OnDoneButtonClick(sender, e);
|
|
|
|
|
e.Handled = true;
|
2025-06-23 22:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-06-22 02:13:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
2025-06-20 19:40:20 +00:00
|
|
|
}
|