Patch #2039 2007-06-06 14:00

dmoore

Replace in Files for search path/mask
Download
2039-Replace_in_Fil.patch (11.9 KB)
Category
 
Status
Open
Close date
 
Assigned to
dmoore
Index: src/sdk/replacedlg.cpp
===================================================================
--- src/sdk/replacedlg.cpp    (revision 4064)
+++ src/sdk/replacedlg.cpp    (working copy)
@@ -46,6 +46,8 @@
 BEGIN_EVENT_TABLE(ReplaceDlg, wxDialog)
     EVT_NOTEBOOK_PAGE_CHANGED(XRCID("nbReplace"), ReplaceDlg::OnFindChange)
     EVT_CHECKBOX(XRCID("chkRegEx1"),     ReplaceDlg::OnRegEx)
+    EVT_BUTTON(XRCID("btnBrowsePath"),  ReplaceDlg::OnBrowsePath)
+    EVT_RADIOBOX(XRCID("rbScope2"),     ReplaceDlg::OnRadioBox)
     EVT_ACTIVATE(                       ReplaceDlg::OnActivate)
 END_EVENT_TABLE()

@@ -256,6 +258,37 @@
         return XRCCTRL(*this, "rbScope1", wxRadioBox)->GetSelection();
 }

+bool ReplaceDlg::GetRecursive() const
+{
+    return XRCCTRL(*this, "chkSearchRecursively", wxCheckBox)->IsChecked();
+}
+
+bool ReplaceDlg::GetHidden() const
+{
+    return XRCCTRL(*this, "chkSearchHidden", wxCheckBox)->IsChecked();
+}
+
+wxString ReplaceDlg::GetSearchPath() const
+{
+    return XRCCTRL(*this, "txtSearchPath", wxTextCtrl)->GetValue();
+}
+
+wxString ReplaceDlg::GetSearchMask() const
+{
+    return XRCCTRL(*this, "txtSearchMask", wxTextCtrl)->GetValue();
+}
+
+void ReplaceDlg::UpdateUI()
+{
+    bool on = XRCCTRL(*this, "rbScope2", wxRadioBox)->GetSelection() == 2; // find in search path
+    XRCCTRL(*this, "txtSearchPath", wxTextCtrl)->Enable(on);
+    XRCCTRL(*this, "txtSearchMask", wxTextCtrl)->Enable(on);
+    XRCCTRL(*this, "btnBrowsePath", wxButton)->Enable(on);
+    XRCCTRL(*this, "chkSearchRecursively", wxCheckBox)->Enable(on);
+    XRCCTRL(*this, "chkSearchHidden", wxCheckBox)->Enable(on);
+} // end of UpdateUI
+
+
 // events

 void ReplaceDlg::OnFindChange(wxNotebookEvent& event)
@@ -285,6 +318,20 @@
         XRCCTRL(*this, "rbDirection", wxRadioBox)->Enable(!XRCCTRL(*this, "chkRegEx1", wxCheckBox)->GetValue());
 }

+void ReplaceDlg::OnBrowsePath(wxCommandEvent& event)
+{
+    wxString txtSearchPath = XRCCTRL(*this, "txtSearchPath", wxTextCtrl)->GetValue();
+    wxString dir = ChooseDirectory(0, _("Select search path"), txtSearchPath);
+    if (!dir.IsEmpty())
+        XRCCTRL(*this, "txtSearchPath", wxTextCtrl)->SetValue(dir);
+}
+
+void ReplaceDlg::OnRadioBox(wxCommandEvent& event)
+{
+    UpdateUI();
+    event.Skip();
+}
+
 void ReplaceDlg::OnActivate(wxActivateEvent& event)
 {
     wxComboBox* cbp = 0;
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp    (revision 4064)
+++ src/sdk/editormanager.cpp    (working copy)
@@ -1672,8 +1672,25 @@
                 filesList.Add(ed->GetFilename());
         }
     }
-    else if (data->scope == 2) // find in workspace
+    else if (data->scope == 2) // find in custom search path and mask
     {
+        // fill the search list with the files found under the search path
+        int flags = wxDIR_FILES |
+                    (data->recursiveSearch ? wxDIR_DIRS : 0) |
+                    (data->hiddenSearch ? wxDIR_HIDDEN : 0);
+        wxArrayString masks = GetArrayFromString(data->searchMask);
+        if (!masks.GetCount())
+            masks.Add(_T("*"));
+        unsigned int count = masks.GetCount();
+        wxLogNull ln; // no logging
+        for (unsigned int i = 0; i < count; ++i)
+        {
+            // wxDir::GetAllFiles() does *not* clear the array, so it suits us just fine ;)
+            wxDir::GetAllFiles(data->searchPath, &filesList, masks[i], flags);
+        }
+    }
+    else if (data->scope == 3) // find in workspace
+    {
         // loop over all the projects in the workspace (they are contained in the ProjectManager)
         const ProjectsArray* pProjects = Manager::Get()->GetProjectManager()->GetProjects();
         if(pProjects)
Index: src/sdk/resources/replace_dialog.xrc
===================================================================
--- src/sdk/resources/replace_dialog.xrc    (revision 4064)
+++ src/sdk/resources/replace_dialog.xrc    (working copy)
@@ -232,12 +232,113 @@
                         <content>
                           <item>&amp;Project files</item>
                           <item>&amp;Open files</item>
+                          <item>Search path (below)</item>
                           <item>Workspace files</item>
                         </content>
                       </object>
                     </object>
                   </object>
                 </object>
+                    <object class="sizeritem">
+                        <flag>wxGROW|wxLEFT|wxRIGHT|wxBOTTOM</flag>
+                        <border>8</border>
+                        <option>1</option>
+                        <object class="wxStaticBoxSizer" name="wxID_ANY">
+                            <orient>wxVERTICAL</orient>
+                            <label>Search path</label>
+                            <object class="sizeritem">
+                                <flag>wxGROW|wxALL</flag>
+                                <border>4</bo
download for full patch...
dmoore 2007-06-06 14:02

I realise this patch is potentially dangerous because it could open thousands of files with a careless replace operation, but it sure is handy. (the user does have the option to cancel so long as they don't hit replace all, maybe we could start saving & closing files once more than a threshold number of files is open).

* an alternative might be to define a replace operation on previous list of search results.

* more generally it is probably a good idea to keep a log of all replacements akin the the find in files results list.