Flow.Launcher/Plugins/Flow.Launcher.Plugin.Explorer/Views/RenameFile.xaml.cs

84 lines
1.6 KiB
C#
Raw Normal View History

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