mirror of
https://github.com/fadden/6502bench.git
synced 2024-11-19 21:31:30 +00:00
3a67c14247
The Find box now has forward/backward radio buttons. Find Next searches forward, and Find Previous searches backward, regardless of the direction of the initial search. The standard key sequence for "find previous" is Shift+F3. The WPF ListView has some weird logic that does something like: if you hit a key, and the selection changes, and the shift key was held down, then you must have meant to select a range. So Shift+F3 often (but not always) selects a range. I think this might be fixable if I can figure out how ListView keeps track of the current keyboard navigation position (which is not the same as the selection). For now I'm working around the problem by using Ctrl+F3 to search. Yay WPF.
100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
/*
|
|
* Copyright 2019 faddenSoft
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
|
|
namespace SourceGen.WpfGui {
|
|
/// <summary>
|
|
/// Find text dialog.
|
|
/// </summary>
|
|
public partial class FindBox : Window, INotifyPropertyChanged {
|
|
static bool sLastSearchBackward = false;
|
|
|
|
/// <summary>
|
|
/// Text to find. On success, holds the string searched for. This is bound to the
|
|
/// text field.
|
|
/// </summary>
|
|
public string TextToFind {
|
|
get { return mTextToFind; }
|
|
set { mTextToFind = value; OnPropertyChanged(); }
|
|
}
|
|
private string mTextToFind;
|
|
|
|
private bool mIsForward;
|
|
public bool IsForward {
|
|
get { return mIsForward; }
|
|
set { mIsForward = value; OnPropertyChanged(); }
|
|
}
|
|
private bool mIsBackward;
|
|
public bool IsBackward {
|
|
get { return mIsBackward; }
|
|
set { mIsBackward = value; OnPropertyChanged(); }
|
|
}
|
|
|
|
// INotifyPropertyChanged implementation
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Constructor. Pass in the last string searched for, to use as the initial value.
|
|
/// </summary>
|
|
public FindBox(Window owner, string findStr) {
|
|
InitializeComponent();
|
|
Owner = owner;
|
|
DataContext = this;
|
|
|
|
Debug.Assert(findStr != null);
|
|
TextToFind = findStr;
|
|
|
|
if (sLastSearchBackward) {
|
|
IsBackward = true;
|
|
} else {
|
|
IsForward = true;
|
|
}
|
|
}
|
|
|
|
private void Window_ContentRendered(object sender, EventArgs e) {
|
|
findTextBox.Focus();
|
|
findTextBox.SelectAll();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles key events, looking for the escape key.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Required because we don't have a "cancel" button. Thanks:
|
|
/// https://stackoverflow.com/a/419615/294248
|
|
/// </remarks>
|
|
private void Window_KeyEventHandler(object sender, KeyEventArgs e) {
|
|
if (e.Key == Key.Escape) {
|
|
DialogResult = false;
|
|
}
|
|
}
|
|
|
|
private void OkButton_Click(object sender, RoutedEventArgs e) {
|
|
DialogResult = true;
|
|
sLastSearchBackward = IsBackward;
|
|
}
|
|
}
|
|
}
|