Example #1
0
void Copyright::OnBatchInsertCopyrights(wxCommandEvent& e)
{
    // pop up the projects selection dialog
    if(m_mgr->IsWorkspaceOpen() == false) {
        wxMessageBox(_("Batch insert requires a workspace to be opened"), _("CodeLite"), wxICON_WARNING | wxOK);
        return;
    }

    if(!m_mgr->SaveAll()) return;

    // read configuration
    CopyrightsConfigData data;
    m_mgr->GetConfigTool()->ReadObject(wxT("CopyrightsConfig"), &data);

    wxString content;
    if(!Validate(content)) {
        return;
    }

    CopyrightsProjectSelDlg dlg(m_mgr->GetTheApp()->GetTopWindow(), m_mgr->GetWorkspace());
    if(dlg.ShowModal() == wxID_OK) {
        wxArrayString projects;
        dlg.GetProjects(projects);

        // expand constants
        wxString err_msg;
        std::vector<wxFileName> files;
        std::vector<wxFileName> filtered_files;
        // loop over the project and collect list of files to work with
        for(size_t i = 0; i < projects.size(); i++) {
            ProjectPtr p = m_mgr->GetWorkspace()->FindProjectByName(projects.Item(i), err_msg);
            if(p) {
                p->GetFiles(files, true);
            }
        }

        wxString mask(data.GetFileMasking());
        mask.Replace(wxT("*."), wxEmptyString);
        mask = mask.Trim().Trim(false);

        wxArrayString exts = wxStringTokenize(mask, wxT(";"));

        // filter out non-matching files (according to masking)
        for(size_t i = 0; i < files.size(); i++) {
            if(exts.Index(files.at(i).GetExt(), false) != wxNOT_FOUND) {
                // valid file
                filtered_files.push_back(files.at(i));
            }
        }

        if(filtered_files.empty() == false) {
            MassUpdate(filtered_files, content);
        }
    }
}
Example #2
0
void Copyright::OnProjectInsertCopyrights(wxCommandEvent& e)
{
    // pop up the projects selection dialog
    if(m_mgr->IsWorkspaceOpen() == false) {
        wxMessageBox(_("Batch insert requires a workspace to be opened"), _("CodeLite"), wxICON_WARNING | wxOK);
        return;
    }

    if(!m_mgr->SaveAll()) return;

    // read configuration
    CopyrightsConfigData data;
    m_mgr->GetConfigTool()->ReadObject(wxT("CopyrightsConfig"), &data);

    wxString content;
    if(!Validate(content)) {
        return;
    }

    // get the project to work on
    TreeItemInfo info = m_mgr->GetSelectedTreeItemInfo(TreeFileView);
    wxString project_name = info.m_text;

    wxString err_msg;
    std::vector<wxFileName> files;
    std::vector<wxFileName> filtered_files;
    // loop over the project and collect list of files to work with
    ProjectPtr p = m_mgr->GetWorkspace()->FindProjectByName(project_name, err_msg);
    if(!p) {
        return;
    }

    p->GetFiles(files, true);

    // filter non matched files
    wxString mask(data.GetFileMasking());
    mask.Replace(wxT("*."), wxEmptyString);
    mask = mask.Trim().Trim(false);

    wxArrayString exts = wxStringTokenize(mask, wxT(";"));

    // filter out non-matching files (according to masking)
    for(size_t i = 0; i < files.size(); i++) {
        if(exts.Index(files.at(i).GetExt(), false) != wxNOT_FOUND) {
            // valid file
            filtered_files.push_back(files.at(i));
        }
    }

    // update files
    if(filtered_files.empty() == false) {
        MassUpdate(filtered_files, content);
    }
}