Thread: SVN Commit by dpage: r4709 - in trunk/pgadmin3: . src/ctl src/frm src/include src/include/ctl

Author: dpage
Date: 2005-11-09 11:15:41 +0000 (Wed, 09 Nov 2005)
New Revision: 4709

Modified:
   trunk/pgadmin3/CHANGELOG.txt
   trunk/pgadmin3/src/ctl/ctlSQLBox.cpp
   trunk/pgadmin3/src/frm/frmQuery.cpp
   trunk/pgadmin3/src/include/ctl/ctlSQLBox.h
   trunk/pgadmin3/src/include/frmQuery.h
   trunk/pgadmin3/src/include/menu.h
Log:
Add search/replace to the query editor

Modified: trunk/pgadmin3/CHANGELOG.txt
===================================================================
--- trunk/pgadmin3/CHANGELOG.txt    2005-11-09 10:41:31 UTC (rev 4708)
+++ trunk/pgadmin3/CHANGELOG.txt    2005-11-09 11:15:41 UTC (rev 4709)
@@ -17,6 +17,7 @@
 </ul>
 <br>
 <ul>
+    <li>2005-11-09 DP  1.4    Add search/replace to the query editor
     <li>2005-11-09 AP  1.4.1  Fix param name quoting for procedures (r: Alex Tyagloff)
     <li>2005-11-04 AP  1.4.0  Fix SET role (r:Florian Pflug), fix role help
     <li>2005-11-04 DP  1.4.0  Fix role inheritance option when creating roles, per Mike Allen

Modified: trunk/pgadmin3/src/ctl/ctlSQLBox.cpp
===================================================================
--- trunk/pgadmin3/src/ctl/ctlSQLBox.cpp    2005-11-09 10:41:31 UTC (rev 4708)
+++ trunk/pgadmin3/src/ctl/ctlSQLBox.cpp    2005-11-09 11:15:41 UTC (rev 4709)
@@ -380,6 +380,19 @@
 }


+void ctlSQLBox::OnReplace(wxCommandEvent& ev)
+{
+    if (!m_dlgFind)
+    {
+        m_dlgFind = new wxFindReplaceDialog(this, &m_findData, _("Find text"), wxFR_REPLACEDIALOG);
+
+        m_dlgFind->Show(true);
+    }
+    else
+        m_dlgFind->SetFocus();
+}
+
+
 void ctlSQLBox::OnFindDialog(wxFindDialogEvent& event)
 {
     wxEventType type = event.GetEventType();
@@ -420,11 +433,58 @@
                         wxICON_EXCLAMATION | wxOK, this);
         }
     }
-    else if (type == wxEVT_COMMAND_FIND_REPLACE || type == wxEVT_COMMAND_FIND_REPLACE_ALL)
+    else if (type == wxEVT_COMMAND_FIND_REPLACE)
     {
-        wxMessageBox(_("Not implemented"), _("Find text"),
-                     wxICON_EXCLAMATION | wxOK, this);
+        int flags = 0;
+        if (event.GetFlags() & wxFR_MATCHCASE)
+            flags |= wxSTC_FIND_MATCHCASE;
+
+        if (event.GetFlags() & wxFR_WHOLEWORD)
+            flags |= wxSTC_FIND_WHOLEWORD;
+
+        int startPos = GetSelectionStart();
+        int endPos = GetTextLength();
+
+        int pos = FindText(startPos, endPos, event.GetFindString().c_str(), flags);
+
+        if (pos >= 0)
+        {
+            SetSelectionStart(pos);
+            SetSelectionEnd(pos + event.GetFindString().Length());
+            ReplaceSelection(event.GetReplaceString().c_str());
+            EnsureCaretVisible();
+        }
+        else
+        {
+            wxMessageBox(_("Reached end of the document"), _("Replace text"),
+                        wxICON_EXCLAMATION | wxOK, this);
+        }
     }
+    else if (type == wxEVT_COMMAND_FIND_REPLACE_ALL)
+    {
+        int flags = 0;
+        if (event.GetFlags() & wxFR_MATCHCASE)
+            flags |= wxSTC_FIND_MATCHCASE;
+
+        if (event.GetFlags() & wxFR_WHOLEWORD)
+            flags |= wxSTC_FIND_WHOLEWORD;
+
+        int initialPos = GetCurrentPos();
+        int startPos = 0;
+        int endPos = GetTextLength();
+
+        int pos = FindText(startPos, endPos, event.GetFindString().c_str(), flags);
+
+        while (pos >= 0)
+        {
+            SetSelectionStart(pos);
+            SetSelectionEnd(pos + event.GetFindString().Length());
+            ReplaceSelection(event.GetReplaceString().c_str());
+            pos = FindText(pos, endPos, event.GetFindString().c_str(), flags);
+        }
+
+        GotoPos(initialPos);
+    }
     else if (type == wxEVT_COMMAND_FIND_CLOSE)
     {
         wxFindReplaceDialog *dlg = event.GetDialog();

Modified: trunk/pgadmin3/src/frm/frmQuery.cpp
===================================================================
--- trunk/pgadmin3/src/frm/frmQuery.cpp    2005-11-09 10:41:31 UTC (rev 4708)
+++ trunk/pgadmin3/src/frm/frmQuery.cpp    2005-11-09 11:15:41 UTC (rev 4709)
@@ -62,6 +62,7 @@
     EVT_MENU(MNU_PASTE,             frmQuery::OnPaste)
     EVT_MENU(MNU_CLEAR,             frmQuery::OnClear)
     EVT_MENU(MNU_FIND,              frmQuery::OnFind)
+    EVT_MENU(MNU_REPLACE,           frmQuery::OnReplace)
     EVT_MENU(MNU_UNDO,              frmQuery::OnUndo)
     EVT_MENU(MNU_REDO,              frmQuery::OnRedo)
     EVT_MENU(MNU_EXECUTE,           frmQuery::OnExecute)
@@ -125,6 +126,7 @@
     editMenu->Append(MNU_CLEAR, _("C&lear window"), _("Clear edit window"), wxITEM_NORMAL);
     editMenu->AppendSeparator();
     editMenu->Append(MNU_FIND, _("&Find\tCtrl-F"), _("Find text"), wxITEM_NORMAL);
+    editMenu->Append(MNU_REPLACE, _("&Replace\tCtrl-R"), _("Find and Replace text"), wxITEM_NORMAL);
     menuBar->Append(editMenu, _("&Edit"));

     queryMenu = new wxMenu();
@@ -156,16 +158,17 @@

     UpdateRecentFiles();

-    wxAcceleratorEntry entries[8];
+    wxAcceleratorEntry entries[9];

     entries[0].Set(wxACCEL_CTRL,                (int)'E',      MNU_EXECUTE);
     entries[1].Set(wxACCEL_CTRL,                (int)'O',      MNU_OPEN);
     entries[2].Set(wxACCEL_CTRL,                (int)'S',      MNU_SAVE);
     entries[3].Set(wxACCEL_CTRL,                (int)'F',      MNU_FIND);
-    entries[4].Set(wxACCEL_NORMAL,              WXK_F5,        MNU_EXECUTE);
-    entries[5].Set(wxACCEL_NORMAL,              WXK_F7,        MNU_EXPLAIN);
-    entries[6].Set(wxACCEL_ALT,                 WXK_PAUSE,     MNU_CANCEL);
-    entries[7].Set(wxACCEL_NORMAL,              WXK_F1,        MNU_HELP);
+    entries[4].Set(wxACCEL_CTRL,                (int)'R',      MNU_REPLACE);
+    entries[5].Set(wxACCEL_NORMAL,              WXK_F5,        MNU_EXECUTE);
+    entries[6].Set(wxACCEL_NORMAL,              WXK_F7,        MNU_EXPLAIN);
+    entries[7].Set(wxACCEL_ALT,                 WXK_PAUSE,     MNU_CANCEL);
+    entries[8].Set(wxACCEL_NORMAL,              WXK_F1,        MNU_HELP);

     wxAcceleratorTable accel(8, entries);
     SetAcceleratorTable(accel);
@@ -632,6 +635,12 @@
       sqlQuery->OnFind(ev);
 }

+void frmQuery::OnReplace(wxCommandEvent& ev)
+{
+      sqlQuery->OnReplace(ev);
+}
+
+
 void frmQuery::OnUndo(wxCommandEvent& ev)
 {
     sqlQuery->Undo();

Modified: trunk/pgadmin3/src/include/ctl/ctlSQLBox.h
===================================================================
--- trunk/pgadmin3/src/include/ctl/ctlSQLBox.h    2005-11-09 10:41:31 UTC (rev 4708)
+++ trunk/pgadmin3/src/include/ctl/ctlSQLBox.h    2005-11-09 11:15:41 UTC (rev 4709)
@@ -34,6 +34,7 @@

     void OnKeyDown(wxKeyEvent& event);
     void OnFind(wxCommandEvent& event);
+    void OnReplace(wxCommandEvent& event);
     void OnFindDialog(wxFindDialogEvent& event);

     DECLARE_DYNAMIC_CLASS(ctlSQLBox)

Modified: trunk/pgadmin3/src/include/frmQuery.h
===================================================================
--- trunk/pgadmin3/src/include/frmQuery.h    2005-11-09 10:41:31 UTC (rev 4708)
+++ trunk/pgadmin3/src/include/frmQuery.h    2005-11-09 11:15:41 UTC (rev 4709)
@@ -57,6 +57,7 @@
     void OnPaste(wxCommandEvent& event);
     void OnClear(wxCommandEvent& event);
     void OnFind(wxCommandEvent& event);
+    void OnReplace(wxCommandEvent& event);
     void OnUndo(wxCommandEvent& event);
     void OnRedo(wxCommandEvent& event);
     void OnSaveHistory(wxCommandEvent& event);

Modified: trunk/pgadmin3/src/include/menu.h
===================================================================
--- trunk/pgadmin3/src/include/menu.h    2005-11-09 10:41:31 UTC (rev 4708)
+++ trunk/pgadmin3/src/include/menu.h    2005-11-09 11:15:41 UTC (rev 4709)
@@ -42,6 +42,7 @@
     MNU_PASTE,
     MNU_CLEAR,
     MNU_FIND,
+    MNU_REPLACE,
     MNU_UNDO,
     MNU_REDO,
     MNU_CANCEL,