-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
190 lines (161 loc) · 6.57 KB
/
MainWindow.xaml.cs
File metadata and controls
190 lines (161 loc) · 6.57 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Configuration;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Data;
using MouseKeyboardLibrary;
using Purple.DataHandlers;
using System.Windows.Forms;
using Purple.ViewControllers;
using PurpleLib;
using Control = System.Windows.Forms.Control;
using MouseEventArgs = System.Windows.Forms.MouseEventArgs;
namespace Purple
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
InitMouseEventHandlers();
}
//Initialize View Controllers
private MainScreen_VC mainScreenVc = new MainScreen_VC();
public List<UIA_ElementInfo> Elements;
#region MouseHandlers Code to handle mouse driven events on the MainScreen
//For some reason i couldn't pass around MouseEventArgs properly. Bah! --Had to include it in the main form class.
private MouseHook mouseHook = new MouseHook();
private int _mouseXLoc;
private int _mouseYLoc;
private void InitMouseEventHandlers()
{
mouseHook.MouseMove += mouseHook_MouseMove;
mouseHook.MouseDown += mouseHook_MouseDown;
mouseHook.MouseUp += mouseHook_MouseUp;
}
private void mouseHook_MouseUp(object sender, MouseEventArgs e)
{
//Stub for mouse up action if needed.
}
public void mouseHook_MouseDown(object sender, MouseEventArgs e)
{
mouseHook.Stop();
GatherElementDetail();
}
private void mouseHook_MouseMove(object sender, MouseEventArgs e)
{
Xcord.Text = e.X.ToString();
YCord.Text = e.Y.ToString();
}
private void GatherElementDetail()
{
//This function is called from the mouseHook_MouseDown() function
if (!mouseHook.IsStarted)
{
mainScreenVc.AddPoint(new Point(double.Parse(Xcord.Text), double.Parse(YCord.Text)));
mainScreenVc.GetElementInfo(ref purplepathtextbox);
mainScreenVc.SetElementDetail(ref purplepathtextbox, ref AvailableInfo_textbox, ref IsEnabled_Checkbox, ref IsKeyboardFocusable_checkbox, ref IsOffscreen_checkbox,
ref ProcessID_textbox);
}
}
#endregion
#region FormLoad and Exit events
private void Purple_MainWindow_Loaded(object sender, RoutedEventArgs e)
{
//This function fires when the window is first loaded
Elements = mainScreenVc.BuildApplicationTree();
ApplicationTree.ItemsSource = Elements;
ApplicationTextBox.Text = mainScreenVc.getConfigAppName();
//ApplicationTree.AddHandler(TreeViewItem.ExpandedEvent, new RoutedEventHandler(mainScreenVc.BuildChildTree));
}
private void Purple_MainWindow_Unloaded(object sender, RoutedEventArgs e)
{
mainScreenVc.SaveSettings_OnExit();
}
#endregion
#region Options Code to handle options expander
#endregion
#region MotherFuckingTreeView Event handlers for the goddamn treeview
private void ApplicationTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
UIA_ElementInfo thing = (UIA_ElementInfo) ApplicationTree.SelectedItem;
var what = ApplicationTree.Items.CurrentPosition;
ApplicationTree_OnExpanded(sender, e);
}
private void ApplicationTree_OnExpanded(object sender, RoutedEventArgs e)
{
mainScreenVc.BuildChildTree((UIA_ElementInfo)ApplicationTree.SelectedValue, sender, e);
}
private void TreeItem_GetInfo(object sender, RoutedEventArgs e)
{
UIA_ElementInfo thing = (UIA_ElementInfo)ApplicationTree.SelectedItem;
if (thing != null)
{
mainScreenVc.FoundElement = thing;
mainScreenVc.SetElementDetail(ref purplepathtextbox, ref AvailableInfo_textbox, ref IsEnabled_Checkbox, ref IsKeyboardFocusable_checkbox, ref IsOffscreen_checkbox,
ref ProcessID_textbox);
}
}
#endregion
#region Buttons on Main Form
private void Cursor_Button_Click(object sender, RoutedEventArgs e)
{
purplepathtextbox.Text = "PurplePath";
mouseHook.Start();
}
private void Add_Element_Selected_Click(object sender, RoutedEventArgs e)
{
if (!mouseHook.IsStarted)
{
mainScreenVc.SelectedElements_AddRow(ref CachedElementsGrid);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
mainScreenVc.TestPurplePath(purplepathtextbox.Text);
}
private void CopyButton_Click(object sender, RoutedEventArgs e)
{
System.Windows.Clipboard.SetText(purplepathtextbox.Text);
}
private void ClearCache_button_Click(object sender, RoutedEventArgs e)
{
mainScreenVc.ClearCachedElements(ref CachedElementsGrid);
}
private void ShowElement_Click(object sender, RoutedEventArgs e)
{
mainScreenVc.drawRectangle();
}
private void RefreshButton_Click(object sender, RoutedEventArgs e)
{
if (ApplicationTextBox.Text.Contains(ConfigurationManager.AppSettings["DefaultStartScreen"]))
{
Elements = mainScreenVc.RefreshTreeView(ConfigurationManager.AppSettings["DefaultStartScreen"]);
ApplicationTextBox.Text = ConfigurationManager.AppSettings["DefaultStartScreen"];
}
else
{
Elements = mainScreenVc.RefreshTreeView(ApplicationTextBox.Text);
}
ApplicationTree.Items.Refresh();
}
private void BuildCache_button_Click(object sender, RoutedEventArgs e)
{
//stub for build cache button
//This needs to use a function on the MainScreen_VC to pass the List of UIA_ELementInfo to the gridfilewriter
bool locatorsOnly = (bool) ckbx_Locators_Only.IsChecked;
mainScreenVc.BuildCacheFile(locatorsOnly);
}
#endregion
}
}