From d55d77a42649d58269aae4b160c9cf7bf6cc6f33 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 23 Sep 2019 14:37:02 +0200 Subject: [PATCH] finish profile filtering (1/?) --- .../ClassProfileFilter.vb | 87 +++++++++---------- app/DD_Clipboard_Searcher/frmStart.vb | 12 +++ 2 files changed, 52 insertions(+), 47 deletions(-) diff --git a/app/DD_Clipboard_Searcher/ClassProfileFilter.vb b/app/DD_Clipboard_Searcher/ClassProfileFilter.vb index a1cdf09..8af92f6 100644 --- a/app/DD_Clipboard_Searcher/ClassProfileFilter.vb +++ b/app/DD_Clipboard_Searcher/ClassProfileFilter.vb @@ -101,16 +101,6 @@ Public Class ClassProfileFilter Return _Profiles End Function - Private Function FindNode(ByVal Node As TreeNode, SearchTerm As String) - Dim oNode As TreeNode - For Each oNode In Node.Nodes - If oNode.Text = SearchTerm Then - Return oNode - End If - Next - Return Node - End Function - Private Function GetLowestNode(ByVal Node As TreeNode) As TreeNode If Node.GetNodeCount(False) = 1 Then Return GetLowestNode(Node.Nodes.Item(0)) @@ -119,11 +109,36 @@ Public Class ClassProfileFilter End If End Function + Private Function Node_Get_Lowest_Node(NodeTag As String) As TreeNode + Dim oExit = False + Dim oParentNode As TreeNode + For Each oTreeNode As TreeNode In CurrMatchTreeView.Nodes + For Each oNodes As TreeNode In oTreeNode.Nodes + If oExit = True Then Exit For + If oNodes.Tag = NodeTag Then + oParentNode = oNodes + oExit = True + Exit For + End If + Next + Next + Dim olowestNode As TreeNode = GetLowestNode(oParentNode) + + Return olowestNode + End Function + Public Function FilterProfilesByClipboardRegex(Profiles As List(Of ProfileData), ClipboardContents As String) As List(Of ProfileData) Dim oFilteredProfiles As New List(Of ProfileData) For Each oProfile In Profiles Logger.Debug("Current Profile: {0}", oProfile.Name) + Dim oNode As New TreeNode() With { + .Text = $"Profile: {oProfile.Name}", + .ImageIndex = 0, + .Tag = oProfile.Name & "-PROFILE" + } + CurrMatchTreeView.Nodes.Add(oNode) + Try Dim oRegex As New Regex(oProfile.Regex) Dim oMatch = oRegex.Match(ClipboardContents) @@ -132,11 +147,7 @@ Public Class ClassProfileFilter 'TODO: Add Debug Data oFilteredProfiles.Add(oProfile) oProfile.IsMatched = True - Dim oNode As New TreeNode($"Profile: {oProfile.Name}") - oNode.ImageIndex = 0 - Dim f = New Font("Tahoma", 9, FontStyle.Bold) - oNode.NodeFont = f - CurrMatchTreeView.Nodes.Add(oNode) + Dim oSubnode As New TreeNode($"MATCH on Global Clipboard Regex: {oProfile.Regex}") oSubnode.ImageIndex = 1 oSubnode.Tag = oProfile.Name & "-REGEX" @@ -337,8 +348,6 @@ Public Class ClassProfileFilter If oTreeNode.Tag = oProfile.Name & "-REGEX" Then oResult = oTreeNode End If - - Next If Not IsNothing(oResult) Then Dim oNode As New TreeNode($"MATCH on WINDOW Clipboard Regex: [{w.Regex}]") @@ -507,23 +516,7 @@ Public Class ClassProfileFilter Return oFilteredProfiles End Function - Private Function Node_Get_Lowest_Node(NodeTag As String) As TreeNode - Dim oExit = False - Dim oParentNode As TreeNode - For Each oTreeNode As TreeNode In CurrMatchTreeView.Nodes - For Each oNodes As TreeNode In oTreeNode.Nodes - If oExit = True Then Exit For - If oNodes.Tag = NodeTag Then - oParentNode = oNodes - oExit = True - Exit For - End If - Next - Next - Dim olowestNode As TreeNode = GetLowestNode(oParentNode) - Return olowestNode - End Function Public Function ClearNotMatchedProfiles(Profiles As List(Of ProfileData)) As List(Of ProfileData) Dim oFilteredProfiles As New List(Of ProfileData) For Each oProfile In Profiles @@ -552,7 +545,6 @@ Public Class ClassProfileFilter oList.Add(New ProfileData() With { .Guid = oRow.Item("GUID"), - .Regex = NotNull(oRow.Item("REGEX_EXPRESSION"), String.Empty), .Name = NotNull(oRow.Item("NAME"), String.Empty), .Comment = NotNull(oRow.Item("COMMENT"), String.Empty), .ProfileType = NotNull(oRow.Item("PROFILE_TYPE"), String.Empty), @@ -573,7 +565,6 @@ Public Class ClassProfileFilter oControlList.Add(New ControlData() With { .Guid = oRow.Item("GUID"), .Description = NotNull(oRow.Item("DESCRIPTION"), String.Empty), - .Regex = NotNull(oRow.Item("REGEX"), String.Empty), .WindowId = oRow.Item("WINDOW_ID"), .TopLeft = New ControlBounds() With { .Left = oRow.Item("TOPLEFT_LEFT"), @@ -609,12 +600,13 @@ Public Class ClassProfileFilter Dim oProcessList As New List(Of ProcessData) For Each oRow As DataRow In ProcessDatatable.Rows - oProcessList.Add(New ProcessData() With { - .Guid = oRow.Item("GUID"), - .PROFILE_ID = oRow.Item("PROFILE_ID"), - .ProcessName = NotNull(oRow.Item("PROC_NAME"), String.Empty) - }) - + If oRow.Item("PROFILE_ID") = ProfileId Then + oProcessList.Add(New ProcessData() With { + .Guid = oRow.Item("GUID"), + .PROFILE_ID = oRow.Item("PROFILE_ID"), + .ProcessName = NotNull(oRow.Item("PROC_NAME"), String.Empty) + }) + End If Next Return oProcessList @@ -623,14 +615,15 @@ Public Class ClassProfileFilter Dim oWindowList As New List(Of WindowData) For Each oRow As DataRow In WindowDatatable.Rows - oWindowList.Add(New WindowData() With { + If oRow.Item("PROFILE_ID") = ProfileId Then + oWindowList.Add(New WindowData() With { .Guid = oRow.Item("GUID"), - .WindowProcessID = oRow.Item("PROCESS_ID"), - .Title = NotNull(oRow.Item("DESCRIPTION"), String.Empty), - .Regex = NotNull(oRow.Item("REGEX"), String.Empty), - .Sequence = NotNull(oRow.Item("SEQUENCE"), 0) + .WindowProcessID = oRow.Item("PROCESS_ID"), + .Title = NotNull(oRow.Item("DESCRIPTION"), String.Empty), + .Regex = NotNull(oRow.Item("REGEX"), String.Empty), + .Sequence = NotNull(oRow.Item("SEQUENCE"), 0) }) - + End If Next Return oWindowList diff --git a/app/DD_Clipboard_Searcher/frmStart.vb b/app/DD_Clipboard_Searcher/frmStart.vb index 3f6fb06..ec514fd 100644 --- a/app/DD_Clipboard_Searcher/frmStart.vb +++ b/app/DD_Clipboard_Searcher/frmStart.vb @@ -105,6 +105,18 @@ Public Class frmStart Exit Sub End If + If DTPROFILE_REL_PROCESS Is Nothing OrElse DTPROFILE_REL_PROCESS.Rows.Count = 0 Then + Exit Sub + End If + + If DTPROFILE_REL_WINDOW Is Nothing OrElse DTPROFILE_REL_WINDOW.Rows.Count = 0 Then + Exit Sub + End If + + If DTPROFILE_REL_CONTROL Is Nothing OrElse DTPROFILE_REL_CONTROL.Rows.Count = 0 Then + Exit Sub + End If + Dim oWindowInfo = GetWindowInfo() Dim ClipboardContents As String = Clipboard.GetText() Dim oProfileFilter As ClassProfileFilter