mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use DataObject handler method
This commit is contained in:
parent
e9dba45f82
commit
b77c9aad13
2 changed files with 11 additions and 7 deletions
|
|
@ -221,7 +221,6 @@
|
|||
Visibility="Visible">
|
||||
<TextBox.CommandBindings>
|
||||
<CommandBinding Command="ApplicationCommands.Copy" Executed="OnCopy" />
|
||||
<CommandBinding Command="ApplicationCommands.Paste" Executed="OnPaste" />
|
||||
</TextBox.CommandBindings>
|
||||
<TextBox.ContextMenu>
|
||||
<ContextMenu MinWidth="160">
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ using ModernWpf.Controls;
|
|||
using Key = System.Windows.Input.Key;
|
||||
using System.Media;
|
||||
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
|
||||
using DataObject = System.Windows.DataObject;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
|
|
@ -50,7 +51,8 @@ namespace Flow.Launcher
|
|||
_settings = settings;
|
||||
|
||||
InitializeComponent();
|
||||
InitializePosition();
|
||||
InitializePosition();
|
||||
DataObject.AddPastingHandler(QueryTextBox, OnPaste);
|
||||
}
|
||||
|
||||
public MainWindow()
|
||||
|
|
@ -72,13 +74,16 @@ namespace Flow.Launcher
|
|||
}
|
||||
}
|
||||
|
||||
private void OnPaste(object sender, ExecutedRoutedEventArgs e)
|
||||
private void OnPaste(object sender, DataObjectPastingEventArgs e)
|
||||
{
|
||||
if (System.Windows.Clipboard.ContainsText())
|
||||
var isText = e.SourceDataObject.GetDataPresent(System.Windows.DataFormats.UnicodeText, true);
|
||||
if (isText)
|
||||
{
|
||||
var clipboardText = System.Windows.Clipboard.GetText().Replace("\r\n", " ");
|
||||
_viewModel.ChangeQueryText(QueryTextBox.Text.Insert(QueryTextBox.CaretIndex, clipboardText));
|
||||
e.Handled = true;
|
||||
var text = e.SourceDataObject.GetData(System.Windows.DataFormats.UnicodeText) as string;
|
||||
text = text.Replace(Environment.NewLine, " ");
|
||||
DataObject data = new DataObject();
|
||||
data.SetData(System.Windows.DataFormats.UnicodeText, text);
|
||||
e.DataObject = data;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue