Example #1
0
void FindInFilesDialog::OnAddPath(wxCommandEvent& event)
{
    // Show a popup menu
    wxMenu menu;
    int firstItem = 8994;
    menu.Append(firstItem + 5, "Add Folder...");
    menu.AppendSeparator();
    menu.Append(firstItem + 0, SEARCH_IN_WORKSPACE);
    menu.Append(firstItem + 1, SEARCH_IN_PROJECT);
    menu.Append(firstItem + 2, SEARCH_IN_CURR_FILE_PROJECT);
    menu.Append(firstItem + 3, SEARCH_IN_CURRENT_FILE);
    menu.Append(firstItem + 4, SEARCH_IN_OPEN_FILES);

    std::map<int, wxString> options;
    options.insert(std::make_pair(firstItem, SEARCH_IN_WORKSPACE));
    options.insert(std::make_pair(firstItem + 1, SEARCH_IN_PROJECT));
    options.insert(std::make_pair(firstItem + 2, SEARCH_IN_CURR_FILE_PROJECT));
    options.insert(std::make_pair(firstItem + 3, SEARCH_IN_CURRENT_FILE));
    options.insert(std::make_pair(firstItem + 4, SEARCH_IN_OPEN_FILES));

    wxPoint pt = m_btnAddPath->GetRect().GetBottomLeft();
    pt.x += 1;
    pt.y += 1;

    int selection = GetPopupMenuSelectionFromUser(menu, pt);
    if(selection == wxID_NONE) return;
    if(selection == (firstItem + 5)) {
        wxString folder = ::wxDirSelector();
        if(folder.IsEmpty()) return;
        DoAddSearchPath(folder);

    } else if(options.count(selection)) {
        DoAddSearchPath(options.find(selection)->second);
    }
}
void FindInFilesDialog::OnAddPath(wxCommandEvent& event)
{
#ifdef __WXOSX__
    // There is a bug in OSX that prevents popup menu from being displayed from dialogs
    // so we use an alternative way
    FindInFilesLocationsDlg dlg(this, m_listPaths->GetStrings());
    if(dlg.ShowModal() == wxID_OK) {
        m_listPaths->Clear();
        m_listPaths->Append(dlg.GetLocations());
    }
#else
    // Show a popup menu
    wxMenu menu;
    int firstItem = 8994;
    menu.Append(firstItem + 5, "Add Folder...");
    menu.AppendSeparator();
    menu.Append(firstItem + 0, SEARCH_IN_WORKSPACE);
    menu.Append(firstItem + 1, SEARCH_IN_PROJECT);
    menu.Append(firstItem + 2, SEARCH_IN_CURR_FILE_PROJECT);
    menu.Append(firstItem + 3, SEARCH_IN_CURRENT_FILE);
    menu.Append(firstItem + 4, SEARCH_IN_OPEN_FILES);

    std::map<int, wxString> options;
    options.insert(std::make_pair(firstItem, SEARCH_IN_WORKSPACE));
    options.insert(std::make_pair(firstItem + 1, SEARCH_IN_PROJECT));
    options.insert(std::make_pair(firstItem + 2, SEARCH_IN_CURR_FILE_PROJECT));
    options.insert(std::make_pair(firstItem + 3, SEARCH_IN_CURRENT_FILE));
    options.insert(std::make_pair(firstItem + 4, SEARCH_IN_OPEN_FILES));

    // Menu will be shown in client coordinates
    wxRect size = m_btnAddPath->GetSize();
    wxPoint menuPos(0, size.GetHeight());
    int selection = m_btnAddPath->GetPopupMenuSelectionFromUser(menu, menuPos);

    if(selection == wxID_NONE) return;
    if(selection == (firstItem + 5)) {
        wxString folder = ::wxDirSelector();
        if(folder.IsEmpty()) return;
        DoAddSearchPath(folder);

    } else if(options.count(selection)) {
        DoAddSearchPath(options.find(selection)->second);
    }
#endif
}
void FindInFilesDialog::DoAddSearchPaths(const wxArrayString& paths)
{
    for(size_t i = 0; i < paths.size(); ++i) {
        DoAddSearchPath(paths.Item(i));
    }
}