Patch #2839 2009-10-15 20:50

tpetrov

Select file from all projects in the workspace
Download
2839-Select_file_fr.patch (8.2 KB)
Category
Application::Refinement
Status
Accepted
Close date
2010-08-19 04:57
Assigned to
mortenmacfly
Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp    (revision 6490)
+++ src/plugins/codecompletion/codecompletion.cpp    (working copy)
@@ -1723,7 +1723,9 @@
             tmpsearch.AddItem(token->DisplayName(), token);
         }
     }
-    IncrementalSelectListDlg dlg(Manager::Get()->GetAppWindow(), tokens, _("Select function..."), _("Please select function to go to:"));
+    IncrementalSelectIteratorStringArray iterator(tokens);
+    IncrementalSelectListDlg dlg(Manager::Get()->GetAppWindow(), iterator,
+                                 _("Select function..."), _("Please select function to go to:"));
     PlaceWindow(&dlg);
     if (dlg.ShowModal() == wxID_OK)
     {
Index: src/sdk/projectmanager.cpp
===================================================================
--- src/sdk/projectmanager.cpp    (revision 6490)
+++ src/sdk/projectmanager.cpp    (working copy)
@@ -2322,6 +2322,29 @@
     }
 }
 
+struct ProjectFileRelativePathCmp
+{
+    bool operator()(ProjectFile* f1, ProjectFile* f2)
+    {
+        return f1->relativeFilename.Cmp(f2->relativeFilename) < 0;
+    }
+};
+struct ProjectFileAbsolutePathCmp
+{
+    bool operator()(ProjectFile* f1, ProjectFile* f2)
+    {
+        return f1->file.GetFullPath().Cmp(f2->file.GetFullPath()) < 0;
+    }
+};
+
+struct ProjectFileAbsolutePathEqual
+{
+    bool operator()(ProjectFile* f1, ProjectFile* f2)
+    {
+        return f1->file.GetFullPath() == f2->file.GetFullPath();
+    }
+};
+
 void ProjectManager::OnGotoFile(wxCommandEvent& /*event*/)
 {
     if (!m_pActiveProject)
@@ -2330,19 +2353,58 @@
         return;
     }
 
-    wxArrayString files;
-    for (int i = 0; i < m_pActiveProject->GetFilesCount(); ++i)
-        files.Add(m_pActiveProject->GetFile(i)->relativeFilename);
+//    wxArrayString files;
+    typedef std::vector<ProjectFile*> ProjectFiles;
+    ProjectFiles files;
+    for (size_t proj_index = 0; proj_index < m_pProjects->GetCount(); ++proj_index)
+    {
+        cbProject *project = (*m_pProjects)[proj_index];
+        for (int i = 0; i < project->GetFilesCount(); ++i)
+            files.push_back(project->GetFile(i));
+    }
 
-    IncrementalSelectListDlg dlg(Manager::Get()->GetAppWindow(), files, _("Select file..."), _("Please select file to open:"));
-    PlaceWindow(&dlg);
-    if (dlg.ShowModal() == wxID_OK)
+    if(!files.empty())
+    {
+        std::sort(files.begin(), files.end(), ProjectFileAbsolutePathCmp());
+        ProjectFiles::iterator last = std::unique(files.begin(), files.end(), ProjectFileAbsolutePathEqual());
+
+        if(last != files.end())
+        {
+            files.erase(last, files.end());
+        }
+
+        std::sort(files.begin(), files.end(), ProjectFileRelativePathCmp());
+    }
+
+    class Iterator : public IncrementalSelectIterator
+    {
+        public:
+            Iterator(ProjectFiles &files) : m_files(files)
+            {
+            }
+
+            virtual long GetCount() const
     {
-        ProjectFile* pf = m_pActiveProject->GetFileByFilename(dlg.GetStringSelection(), true);
-        if (pf)
+                return m_files.size();
+            }
+            virtual wxString GetItem(long index) const
         {
-            DoOpenFile(pf, pf->file.GetFullPath());
+                return m_files[index]->relativeFilename;
         }
+        private:
+            ProjectFiles &m_files;
+
+    };
+
+    Iterator iterator(files);
+    IncrementalSelectListDlg dlg(Manager::Get()->GetAppWindow(), iterator,
+                                 _("Select file..."), _("Please select file to open:"));
+    PlaceWindow(&dlg);
+    if (dlg.ShowModal() == wxID_OK)
+    {
+        long selection = dlg.GetSelection();
+        if(selection != -1)
+            DoOpenFile(files[selection], files[selection]->file.GetFullPath());
     }
 }
 
Index: src/sdk/incrementalselectlistdlg.cpp
===================================================================
--- src/sdk/incrementalselectlistdlg.cpp    (revision 6490)
+++ src/sdk/incrementalselectlistdlg.cpp    (working copy)
@@ -77,11 +77,12 @@
     EVT_LISTBOX_DCLICK(XRCID("lstItems"), IncrementalSelectListDlg::OnSelect)
 END_EVENT_TABLE()
 
-IncrementalSelectListDlg::IncrementalSelectListDlg(wxWindow* parent, const wxArrayString& items, const wxString& caption, const wxString& message)
+IncrementalSelectListDlg::IncrementalSelectListDlg(wxWindow* parent, const IncrementalSelectIterator& iterator,
+                                                   const wxString& caption, const wxString& message)
     : m_pMyEvtHandler(0L),
     m_List(0L),
     m_Text(0L),
-    m_Items(items)
+    m_Iterator(iterator)
 {
     wxXmlResource::Get()->LoadObject(this, parent, _T("dlgIncrementalSelectList"),_T("wxScrollingDialog"));
     if (!caption.IsEmpty())
@@ -112,9 +113,13 @@
     return m_List->GetStringSelection();
 }
 
-int IncrementalSelectListDlg::G
download for full patch...
tpetrov 2009-12-11 22:06

Fixed a crash, when the there were no matching files

mortenmacfly 2010-01-01 07:47

This doesn't look good to me:

int IncrementalSelectListDlg::GetSelection()

{

[...]

return reinterpret_cast<long>(m_List->GetClientData(selection));

}

You return a long type value in an integer (int) type method...?! Is it possible to have an int there (not just "casted away")?

tpetrov 2010-01-02 08:48

The m_List->GetClientData(selection) returns/stores void* pointers and casting it to int fails on 64bit linux.

tpetrov 2010-01-19 18:39

Any suggestions?

mortenmacfly 2010-08-04 18:12

My suggestions was to change the signature of the method from:

int IncrementalSelectListDlg::GetSelection()

to:

long IncrementalSelectListDlg::GetSelection()

...with all the stuff to be modified around?!

mortenmacfly 2010-08-18 04:38

...any progress/comment on this?!

I'd like to apply this patch to trunk...

tpetrov 2010-08-18 21:40

Here is the updated patch