-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_spacebar.py
More file actions
100 lines (87 loc) · 5.06 KB
/
Copy pathpatch_spacebar.py
File metadata and controls
100 lines (87 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import sys
def replace_in_file(filepath, search_str, replace_str):
with open(filepath, 'r') as f:
content = f.read()
if search_str in content:
content = content.replace(search_str, replace_str)
with open(filepath, 'w') as f:
f.write(content)
print(f"Patched {filepath}")
else:
print(f"Could not find search string in {filepath}")
cs_search = """ if (e.Key == Key.Space)
{
var focusedElement = System.Windows.Input.Keyboard.FocusedElement as ListViewItem;
if (focusedElement == null)
{
// Fallback to selected item if focus is lost but something is selected
if (FilesListView.SelectedItem != null)
{
focusedElement = FilesListView.ItemContainerGenerator.ContainerFromItem(FilesListView.SelectedItem) as ListViewItem;
}
}
if (focusedElement != null)
{
// Toggle selection without clearing the rest
focusedElement.IsSelected = !focusedElement.IsSelected;
int currentIndex = FilesListView.ItemContainerGenerator.IndexFromContainer(focusedElement);
int nextIndex = currentIndex + 1;
if (nextIndex < FilesListView.Items.Count)
{
var nextItem = FilesListView.Items[nextIndex];
FilesListView.ScrollIntoView(nextItem);
// Delay focus slightly to ensure the container is generated
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var nextContainer = FilesListView.ItemContainerGenerator.ContainerFromIndex(nextIndex) as ListViewItem;
if (nextContainer != null)
{
nextContainer.Focus();
}
}), System.Windows.Threading.DispatcherPriority.Background);
}
}
e.Handled = true;
return;
}"""
cs_replace = """ if (e.Key == Key.Space)
{
var focusedElement = System.Windows.Input.Keyboard.FocusedElement as ListViewItem;
if (focusedElement == null)
{
// Fallback to selected item if focus is lost but something is selected
if (FilesListView.SelectedItem != null)
{
focusedElement = FilesListView.ItemContainerGenerator.ContainerFromItem(FilesListView.SelectedItem) as ListViewItem;
}
}
if (focusedElement != null)
{
var itemData = FilesListView.ItemContainerGenerator.ItemFromContainer(focusedElement) as QuickViewFile.Models.ItemList;
if (itemData != null)
{
itemData.IsChecked = !itemData.IsChecked;
int currentIndex = FilesListView.ItemContainerGenerator.IndexFromContainer(focusedElement);
int nextIndex = currentIndex + 1;
if (nextIndex < FilesListView.Items.Count)
{
// Move selection to the next item
FilesListView.SelectedIndex = nextIndex;
FilesListView.ScrollIntoView(FilesListView.SelectedItem);
// Make sure it also gets focus so next spacebar works
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var nextContainer = FilesListView.ItemContainerGenerator.ContainerFromIndex(nextIndex) as ListViewItem;
if (nextContainer != null)
{
nextContainer.Focus();
}
}), System.Windows.Threading.DispatcherPriority.Background);
}
}
}
e.Handled = true;
return;
}"""
replace_in_file("QuickViewFile/MainWindow.xaml.cs", cs_search, cs_replace)
replace_in_file("QuickViewFile/MainWindowNoBorder.xaml.cs", cs_search, cs_replace)