Patch #2833 2009-09-30 19:29

tpetrov

regex testbed refinemenst
Download
2833-regex_testbed.patch (8.1 KB)
Category
Plugin::Refinement
Status
Accepted
Close date
2009-12-31 16:21
Assigned to
mortenmacfly
Index: src/plugins/contrib/regex_testbed/regexdlg.cpp
===================================================================
--- src/plugins/contrib/regex_testbed/regexdlg.cpp    (revision 5755)
+++ src/plugins/contrib/regex_testbed/regexdlg.cpp    (working copy)
@@ -19,13 +19,6 @@
 #endif
 
 //(*InternalHeaders(regex_dialog)
-#include <wx/bitmap.h>
-#include <wx/font.h>
-#include <wx/fontenum.h>
-#include <wx/fontmap.h>
-#include <wx/image.h>
-#include <wx/intl.h>
-#include <wx/settings.h>
 #include <wx/xrc/xmlres.h>
 //*)
 
@@ -37,6 +30,8 @@
     EVT_UPDATE_UI(-1, RegExDlg::OnUpdateUI)
 END_EVENT_TABLE()
 
+RegExDlg::VisibleDialogs RegExDlg::m_visible_dialogs;
+
 RegExDlg::RegExDlg(wxWindow* parent,wxWindowID id)
 {
     //(*Initialize(regex_dialog)
@@ -48,6 +43,8 @@
     m_newlines = (wxCheckBox*)FindWindow(XRCID("ID_NEWLINES"));
     m_text = (wxTextCtrl*)FindWindow(XRCID("ID_TEXT"));
     m_output = (wxHtmlWindow*)FindWindow(XRCID("ID_OUT"));
+
+    Connect(wxID_ANY,wxEVT_CLOSE_WINDOW,(wxObjectEventFunction)&RegExDlg::OnClose);
     //*)
 
     assert(m_regex);
@@ -58,15 +55,48 @@
     assert(m_text);
     assert(m_output);
 
+    m_text->MoveAfterInTabOrder(m_quoted);
+
     m_library->SetSelection(0);
     m_output->SetBorders(0);
     m_quoted->SetEditable(false);
+
+    m_visible_dialogs.insert(this);
 }
 
 RegExDlg::~RegExDlg()
 {
 }
 
+void RegExDlg::OnClose(wxCloseEvent& event)
+{
+    VisibleDialogs::iterator it = m_visible_dialogs.find(this);
+    if(it != m_visible_dialogs.end())
+    {
+        delete *it;
+        m_visible_dialogs.erase(it);
+    }
+}
+
+
+void RegExDlg::ReleaseAll()
+{
+    for(VisibleDialogs::iterator it = m_visible_dialogs.begin(); it != m_visible_dialogs.end(); ++it)
+        delete *it;
+    m_visible_dialogs.clear();
+}
+
+/**
+    @brief Makes the input string to be valid html string (replaces <,>,&," with &lt;,&gt;,&amp;,&quot; respectively)
+    @param [inout] s - string that will be escaped
+*/
+void cbEscapeHtml(wxString &s)
+{
+    s.Replace(wxT("&"), wxT("&amp;"));
+    s.Replace(wxT("<"), wxT("&lt;"));
+    s.Replace(wxT(">"), wxT("&gt;"));
+    s.Replace(wxT("\""), wxT("&quot;"));
+}
 
 void RegExDlg::OnUpdateUI(wxUpdateUIEvent& event)
 {
@@ -118,6 +148,10 @@
 
     for(size_t i = 0; i < as.GetCount(); ++i)
     {
+        Manager::Get()->GetLogManager()->Log(wxT("unescaped:") + as[i]);
+        cbEscapeHtml(as[i]);
+        Manager::Get()->GetLogManager()->Log(wxT("escaped:") + as[i]);
+
         tmp.Printf(_T("<tr><td width=35><b>%d</b></td><td>%s</td></tr>"), i, as[i].c_str());
         s.append(tmp);
     }
@@ -182,6 +216,3 @@
 
     return ret;
 }
-
-
-
Index: src/plugins/contrib/regex_testbed/wxsmith/RegExDlg.wxs
===================================================================
--- src/plugins/contrib/regex_testbed/wxsmith/RegExDlg.wxs    (revision 5755)
+++ src/plugins/contrib/regex_testbed/wxsmith/RegExDlg.wxs    (working copy)
@@ -1,7 +1,9 @@
 <?xml version="1.0" encoding="utf-8" ?>
 <wxsmith>
     <resource_extra>
-        <object root="1" />
+        <object root="1">
+            <handler function="OnClose" entry="EVT_CLOSE" />
+        </object>
         <object name="ID_3" class="wxStaticText" variable="StaticText1" member="no" />
         <object name="ID_REGEX" class="wxTextCtrl" variable="m_regex" member="yes" />
         <object name="ID_QUOTED" class="wxTextCtrl" variable="m_quoted" member="yes" />
Index: src/plugins/contrib/regex_testbed/RegExTestbed.cpp
===================================================================
--- src/plugins/contrib/regex_testbed/RegExTestbed.cpp    (revision 5755)
+++ src/plugins/contrib/regex_testbed/RegExTestbed.cpp    (working copy)
@@ -38,6 +38,7 @@
 // destructor
 RegExTestbed::~RegExTestbed()
 {
+    RegExDlg::ReleaseAll();
 }
 
 void RegExTestbed::OnAttach()
@@ -57,15 +58,16 @@
     // which means you must not use any of the SDK Managers
     // NOTE: after this function, the inherited member variable
     // m_IsAttached will be FALSE...
+    RegExDlg::ReleaseAll();
 }
 
 int RegExTestbed::Execute()
 {
     try
     {
-        RegExDlg dlg(0, -1);
-        PlaceWindow(&dlg);
-        dlg.ShowModal();
+        RegExDlg *dlg = new RegExDlg(0, -1);
+        PlaceWindow(dlg);
+        dlg->Show();
     }
     catch (...)
     {
Index: src/plugins/contrib/regex_testbed/regexdlg.h
===================================================================
--- src/plugins/contrib/regex_testbed/regexdlg.h    (revision 5755)
+++ src/plugins/contrib/regex_testbed/regexdlg.h    (working copy)
@@ -7,14 +7,14 @@
     #pragma hdrstop
 #endif
 
+#include <set>
+
 //(*Headers(regex_dialog)
 #include <wx/checkbox.h>
-#include <wx/choice.h>
 #include <wx/dialog.h>
-#include <wx/html/htmlwin.h>
-#include <wx/sizer.h>
-#include <wx/stattext.h>
 #include <wx/textctrl.h>
+#include <wx/choice.h>
+#include <wx/html/htmlwin.h>
 //*)
 
 #include <wx/html/htmlwin.h>
@@ -38,6 +38,8 @@
 
         void EndModal(int retCode);
 
+        sta
download for full patch...
mortenmacfly 2009-10-25 19:17

A bit more description, please. What exactly does this patch do?

tpetrov 2009-10-26 00:37

1. Does some html escaping on the result of the regexp, so std::vector<int> can be displayed correctly

2. Makes the dialog modeless, so you can copy and paste from the source in you project

2.1. Allow many instances of the dialog

2.2. Puts the dialog on top, as TOPMOST, maybe that is wrong, but I don't know how to make it stay on top of the main window on linux