← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3012: add a regex filter to the dev plugin

 

------------------------------------------------------------
revno: 3012
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2012-07-20 16:43:48 +0200
message:
  add a regex filter to the dev plugin
modified:
  plugins/Dev/Dialog.cpp
  plugins/Dev/SConscript
  plugins/Dev/resource.h
  plugins/Dev/resource.rc


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'plugins/Dev/Dialog.cpp'
--- plugins/Dev/Dialog.cpp	2012-07-20 13:49:53 +0000
+++ plugins/Dev/Dialog.cpp	2012-07-20 14:43:48 +0000
@@ -24,6 +24,8 @@
 #include <unordered_set>
 #include <vector>
 
+#include <boost/regex.hpp>
+
 #include <CriticalSection.h>
 
 #include <commctrl.h>
@@ -51,6 +53,7 @@
 bool userMessages = true;
 unordered_set<tstring> filter;
 tstring filterSel;
+boost::regex regex;
 
 struct Item {
 	tstring index;
@@ -127,6 +130,17 @@
 			continue;
 		}
 
+		if(!regex.empty()) {
+			try {
+				if(!boost::regex_search(message.message, regex)) {
+					continue;
+				}
+			} catch(const std::runtime_error&) {
+				// most likely a stack overflow, ignore...
+				continue;
+			}
+		}
+
 		auto item = new Item;
 		item->index = Util::toT(Util::toString(counter));
 		item->dir = message.sending ? _T("Out") : _T("In");
@@ -229,6 +243,24 @@
 	}
 }
 
+void applyRegex(HWND hwnd) {
+	regex = "";
+
+	auto control = GetDlgItem(hwnd, IDC_REGEX);
+
+	auto n = SendMessage(control, WM_GETTEXTLENGTH, 0, 0);
+	if(!n) { return; }
+	tstring str(n + 1, 0);
+	str.resize(SendMessage(control, WM_GETTEXT, static_cast<WPARAM>(n + 1), reinterpret_cast<LPARAM>(&str[0])));
+
+	try {
+		regex.assign(Util::fromT(str));
+	} catch(const std::runtime_error&) {
+		MessageBox(hwnd, _T("Invalid regular expression"), _T("Dev plugin"), MB_OK);
+		return;
+	}
+}
+
 void clear(HWND hwnd) {
 	auto control = GetDlgItem(hwnd, IDC_MESSAGES);
 
@@ -290,6 +322,12 @@
 			break;
 		}
 
+	case IDC_REGEX_APPLY:
+		{
+			applyRegex(hwnd);
+			break;
+		}
+
 	case IDC_CLEAR:
 		{
 			clear(hwnd);

=== modified file 'plugins/Dev/SConscript'
--- plugins/Dev/SConscript	2012-07-19 22:00:20 +0000
+++ plugins/Dev/SConscript	2012-07-20 14:43:48 +0000
@@ -15,5 +15,5 @@
 elif 'link' in env['LINK']:
 	sources.append('Plugin.def')
 
-ret = dev.build_lib(env, target, [sources, res], shared = True)
+ret = dev.build_lib(env, target, [sources, res, dev.boost], shared = True)
 Return('ret')

=== modified file 'plugins/Dev/resource.h'
--- plugins/Dev/resource.h	2012-07-20 13:49:53 +0000
+++ plugins/Dev/resource.h	2012-07-20 14:43:48 +0000
@@ -11,6 +11,8 @@
 #define IDC_HUB_MESSAGES                1005
 #define IDC_USER_MESSAGES               1006
 #define IDC_FILTER                      1007
+#define IDC_REGEX                       1008
+#define IDC_REGEX_APPLY                 1009
 
 // Next default values for new objects
 // 
@@ -18,7 +20,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        102
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1008
+#define _APS_NEXT_CONTROL_VALUE         1010
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif

=== modified file 'plugins/Dev/resource.rc'
--- plugins/Dev/resource.rc	2012-07-20 13:49:53 +0000
+++ plugins/Dev/resource.rc	2012-07-20 14:43:48 +0000
@@ -96,13 +96,15 @@
 BEGIN
     DEFPUSHBUTTON   "Close",IDOK,666,458,50,14
     PUSHBUTTON      "Cancel",IDCANCEL,615,458,50,14,NOT WS_VISIBLE | WS_DISABLED
-    CONTROL         "",IDC_MESSAGES,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP,7,7,709,441
+    CONTROL         "",IDC_MESSAGES,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP,7,7,709,418
     PUSHBUTTON      "Copy selected messages",IDC_COPY,7,458,129,14
-    PUSHBUTTON      "Clear the list",IDC_CLEAR,563,458,88,14
-    CONTROL         "Auto-scroll",IDC_SCROLL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,150,462,50,10
-    CONTROL         "Add hub messages",IDC_HUB_MESSAGES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,213,462,76,10
-    CONTROL         "Add user messages",IDC_USER_MESSAGES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,305,462,78,10
-    COMBOBOX        IDC_FILTER,404,460,140,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+    PUSHBUTTON      "Clear the list",IDC_CLEAR,260,458,88,14
+    CONTROL         "Auto-scroll",IDC_SCROLL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,168,462,50,10
+    CONTROL         "Add hub messages",IDC_HUB_MESSAGES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,439,76,10
+    CONTROL         "Add user messages",IDC_USER_MESSAGES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,95,439,78,10
+    COMBOBOX        IDC_FILTER,187,437,140,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+    EDITTEXT        IDC_REGEX,351,435,206,14,ES_AUTOHSCROLL
+    PUSHBUTTON      "Apply the regex",IDC_REGEX_APPLY,565,435,81,14
 END
 
 
@@ -120,6 +122,8 @@
         RIGHTMARGIN, 716
         TOPMARGIN, 7
         BOTTOMMARGIN, 472
+        HORZGUIDE, 435
+        HORZGUIDE, 449
         HORZGUIDE, 458
     END
 END