/** Count the lines on all project's files and display the results.
 *  @param languages Languages definitions
 *  @param nb_languages Number of languages defined in the 'languages' array
 */
int CodeStatExecDlg::Execute(LanguageDef languages[NB_FILETYPES_MAX], int numLanguages)
{
    m_choice->Clear();
    m_choice->Append(_T("Entire workspace"));

    ProjectsArray* projects = Manager::Get()->GetProjectManager()->GetProjects();
    for (size_t i = 0, length = projects->GetCount(); i < length; ++i)
    {
        m_choice->Append(projects->Item(i)->GetTitle());
    }
    m_cache.clear();
    m_cache.resize(projects->GetCount() + 1);

    m_languages = languages;
    m_numLanguages = numLanguages;

    // Check if all files have been saved
    bool all_saved = true;
    for (size_t i = 0, nb_projects = projects->GetCount(); i < nb_projects; ++i)
    {
        cbProject* project = projects->Item(i);
        for (int j = 0, nb_files = project->GetFilesCount(); j < nb_files; ++j)
        {
            ProjectFile* pf = project->GetFile(j);
            if (pf->GetFileState() == fvsModified)
            {
                all_saved = false;
                break;
            }
        }
    }

    // If not, ask user if we can save them
    if (!all_saved)
    {
        if (cbMessageBox(_T("Some files are not saved.\nDo you want to save them before running the plugin?"),
                         _("Warning"),
                         wxICON_EXCLAMATION | wxYES_NO,
                         Manager::Get()->GetAppWindow()) == wxID_YES)
        {
            for (size_t i = 0, nb_projects = projects->GetCount(); i < nb_projects; ++i)
                (*projects)[i]->SaveAllFiles();
        }
    }

    cbProject* project = Manager::Get()->GetProjectManager()->GetActiveProject();
    int index = m_choice->FindString(project->GetTitle(), true);
    m_choice->SetSelection(index);
    DoParseProject(index);

    ShowResults(index);

    ShowModal();

    return 0;
}
Exemple #2
0
cbProject* wxcHelper::GetProject(const wxString& name)
{
    cbProject *selectedProject ( NULL );
    ProjectsArray* projects = Manager::Get()->GetProjectManager()->GetProjects();
    for ( size_t i=0; i<projects->GetCount(); ++i ) {
        if ( projects->Item(i)->GetTitle() == name ) {
            selectedProject = projects->Item(i);
            break;
        }
    }
    return selectedProject;
}
void ProjectDepsDlg::FillList()
{
    wxChoice* cmb = XRCCTRL(*this, "cmbProject", wxChoice);
    wxCheckListBox* lst = XRCCTRL(*this, "lstDeps", wxCheckListBox);

    int idx = cmb->GetSelection();
    if (m_LastSel != idx && m_LastSel != -1)
    {
        // save old list
        SaveList();
    }
    m_LastSel = idx;
    if (idx == -1)
        return;

    cbProject* thisprj = static_cast<cbProject*>(cmb->GetClientData(idx));
    if (!thisprj)
        return;
    const ProjectsArray* arr = Manager::Get()->GetProjectManager()->GetDependenciesForProject(thisprj);

    lst->Clear();
    ProjectsArray* mainarr = Manager::Get()->GetProjectManager()->GetProjects();
    for (size_t i = 0; i < mainarr->GetCount(); ++i)
    {
        cbProject* prj = mainarr->Item(i);
        if (prj == thisprj)
            continue;
        lst->Append(prj->GetTitle());

        // check dependency
        lst->Check(lst->GetCount() - 1, arr && arr->Index(prj) != wxNOT_FOUND);
    }
}
bool ProjectDepsDlg::SaveList()
{
    wxChoice* cmb = XRCCTRL(*this, "cmbProject", wxChoice);
    wxCheckListBox* lst = XRCCTRL(*this, "lstDeps", wxCheckListBox);

    if (m_LastSel == -1)
        return true;

    cbProject* thisprj = static_cast<cbProject*>(cmb->GetClientData(m_LastSel));
    if (!thisprj)
        return true;

    // first clear all deps for this project
    Manager::Get()->GetProjectManager()->ClearProjectDependencies(thisprj);

    // now set the the new deps
    for (size_t i = 0; i < lst->GetCount(); ++i)
    {
        if (!lst->IsChecked(i))
            continue;

        cbProject* prj = nullptr;

        ProjectsArray* mainarr = Manager::Get()->GetProjectManager()->GetProjects();
        for (size_t x = 0; x < mainarr->GetCount(); ++x)
        {
            if (mainarr->Item(x)->GetTitle() == lst->GetString(i))
            {
                prj = mainarr->Item(x);
                break;
            }
        }
        if (!prj)
            continue;

        if (!Manager::Get()->GetProjectManager()->AddProjectDependency(thisprj, prj))
        {
            cbMessageBox(wxString::Format(_("Cannot add project '%s' as a dependency to '%s' because this "
                                            "would cause a circular dependency error..."),
                                            thisprj->GetTitle().c_str(), prj->GetTitle().c_str()),
                        _("Error"), wxICON_ERROR, this);
            return false;
        }
    }
    return true;
}
bool ProjectOptionsManipulator::OperateProject(size_t prj_idx, wxArrayString& result)
{
  ProjectsArray* pa = Manager::Get()->GetProjectManager()->GetProjects();
  bool success = true;
  if (pa)
    success &= OperateProject( pa->Item(prj_idx), result );

  return success;
}
bool ProjectOptionsManipulator::OperateWorkspace(wxArrayString& result)
{
  ProjectsArray* pa = Manager::Get()->GetProjectManager()->GetProjects();
  bool success = true;
  if (pa)
  {
    for (size_t i=0; i<pa->GetCount(); ++i)
      success &= OperateProject( pa->Item(i), result );
  }

  return success;
}
Exemple #7
0
void wxcHelper::GetAllFiles(FilesList& files, const wxString& filterExt)
{
    wxString filterExtLowerCase = filterExt;
    filterExtLowerCase.MakeLower();

    ProjectsArray* projects = Manager::Get()->GetProjectManager()->GetProjects();
    for ( size_t i=0; i<projects->GetCount(); ++i ) {
        cbProject* pProj = projects->Item(i);
        const FilesList& fileList = pProj->GetFilesList();
        FilesList::const_iterator iter = fileList.begin();
        for( ; iter != fileList.end(); ++iter ) {
            if( filterExtLowerCase.IsEmpty() || filterExtLowerCase == (*iter)->file.GetExt().MakeLower() ) {
                files.insert( (*iter) );
            }
        }
    }
}
bool WorkspaceLoader::Save(const wxString& title, const wxString& filename)
{
    const char* ROOT_TAG = "CodeBlocks_workspace_file";

    TiXmlDocument doc;
    doc.SetCondenseWhiteSpace(false);
    doc.InsertEndChild(TiXmlDeclaration("1.0", "UTF-8", "yes"));
    TiXmlElement* rootnode = static_cast<TiXmlElement*>(doc.InsertEndChild(TiXmlElement(ROOT_TAG)));
    if (!rootnode)
        return false;

    TiXmlElement* wksp = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("Workspace")));
    wksp->SetAttribute("title", cbU2C(title));

    ProjectsArray* arr = Manager::Get()->GetProjectManager()->GetProjects();
    for (unsigned int i = 0; i < arr->GetCount(); ++i)
    {
        cbProject* prj = arr->Item(i);

        wxFileName wfname(filename);
        wxFileName fname(prj->GetFilename());
        fname.MakeRelativeTo(wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));

        TiXmlElement* node = static_cast<TiXmlElement*>(wksp->InsertEndChild(TiXmlElement("Project")));
        node->SetAttribute("filename", cbU2C( ExportFilename(fname) ) );
        if (prj == Manager::Get()->GetProjectManager()->GetActiveProject())
            node->SetAttribute("active", 1);

        const ProjectsArray* deps = Manager::Get()->GetProjectManager()->GetDependenciesForProject(prj);
        if (deps && deps->GetCount())
        {
            for (size_t i = 0; i < deps->GetCount(); ++i)
            {
                prj = deps->Item(i);
                fname.Assign(prj->GetFilename());
                fname.MakeRelativeTo(wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
                TiXmlElement* dnode = static_cast<TiXmlElement*>(node->InsertEndChild(TiXmlElement("Depends")));
                dnode->SetAttribute("filename", cbU2C( ExportFilename(fname) ) );
            }
        }
    }
    return cbSaveTinyXMLDocument(&doc, filename);
}
void ProjectOptionsManipulatorDlg::OnScanSelect(wxCommandEvent& event)
{
  m_ChoScanProjects->Clear();
  if ( event.GetInt()==1 ) // project
  {
    ProjectsArray* pa = Manager::Get()->GetProjectManager()->GetProjects();
    if (pa)
    {
      for (size_t i=0; i<pa->GetCount(); ++i)
      {
        cbProject* prj = pa->Item(i);
        if (prj)
          m_ChoScanProjects->Append( prj->GetTitle() );
      }

      if ( pa->GetCount() )
        m_ChoScanProjects->SetSelection(0);
    }
    m_ChoScanProjects->Enable();
  }
  else
    m_ChoScanProjects->Disable();
}
ProjectDepsDlg::ProjectDepsDlg(wxWindow* parent, cbProject* sel)
    : m_LastSel(-1)
{
    //ctor
    wxXmlResource::Get()->LoadObject(this, parent, _T("dlgConfigureProjectDeps"),_T("wxScrollingDialog"));

    wxChoice* cmb = XRCCTRL(*this, "cmbProject", wxChoice);

    int idx = 0;
    ProjectsArray* mainarr = Manager::Get()->GetProjectManager()->GetProjects();
    for (size_t i = 0; i < mainarr->GetCount(); ++i)
    {
        cbProject* prj = mainarr->Item(i);
        cmb->Append(prj->GetTitle(), prj);
        if (prj == sel)
            idx = i;
    }
    cmb->SetSelection(idx);
    m_LastSel = idx;
    FillList();

    Fit();
}
void CodeStatExecDlg::DoParseWorkspace()
{
    ProjectCodeStats& statWS = m_cache[0];
    if (statWS.isParsed)
        return;

    m_progress = new wxProgressDialog(_("Code Statistics plugin"),_("Parsing workspace files. Please wait..."));

    m_currentFile = 0;
    m_numFiles = 0;

    ProjectsArray* projects = Manager::Get()->GetProjectManager()->GetProjects();
    for (size_t i = 0, count = projects->GetCount(); i < count; ++i)
        m_numFiles += projects->Item(i)->GetFilesCount();

    ParsedFileNamesSet parsedFileNames;

    for (size_t i = 1, count = projects->GetCount(); i < count + 1; ++i)
    {
        ProjectCodeStats statProject = ParseProject(i, &parsedFileNames);

        statWS.numFiles           += statProject.numFiles;
        statWS.numFilesNotFound   += statProject.numFilesNotFound;
        statWS.numSkippedFiles    += statProject.numSkippedFiles;
        statWS.codeLines          += statProject.codeLines;
        statWS.emptyLines         += statProject.emptyLines;
        statWS.commentLines       += statProject.commentLines;
        statWS.codeAndCommentLines += statProject.codeAndCommentLines;
        statWS.totalLines         += statProject.totalLines ;
    }

    statWS.isParsed = true;

    m_progress->Update(100);
    delete m_progress;
    m_progress = nullptr;
}
size_t WorkspaceBrowserF::FindMatchTokens(wxString search, TokensArrayF& result)
{
    size_t count=0;
    switch (m_BrowserOptions.displayFilter)
    {
        case bdfFile:
        {
            count = m_pParser->FindMatchTokens(m_ActiveFilename, search, result);
            break;
        }
        case bdfProject:
        {
            for (FilesList::iterator it = m_pActiveProject->GetFilesList().begin(); it != m_pActiveProject->GetFilesList().end(); ++it)
            {
                ProjectFile* pf = *it;
                count = m_pParser->FindMatchTokens(pf->file.GetFullPath(), search, result);
            }
            break;
        }
        case bdfWorkspace:
        {
            ProjectsArray* projects = Manager::Get()->GetProjectManager()->GetProjects();
            for (size_t i=0; i < projects->GetCount(); ++i)
            {
                cbProject* project = projects->Item(i);
                for (FilesList::iterator it = project->GetFilesList().begin(); it != project->GetFilesList().end(); ++it)
                {
                    ProjectFile* pf = *it;
                    count = m_pParser->FindMatchTokens(pf->file.GetFullPath(), search, result);
                }
            }
            break;
        }
    }
    return count;
}
void *ThreadSearchThread::Entry()
{
    // Tests if we have a working searcher object.
    // Cancel search if it is not the case
    if ( m_pTextFileSearcher == NULL )
        return 0;

    size_t i = 0;

    // For now, we look for all paths for the different search scopes
    // and store them in a sorted array to avoid pasing several times
    // the same file.
    // This will be changed to avoid consuming a lot of memory (parsing
    // form C:\ and storing all paths...). Aim is to avoid the use of the
    // array for storing items.

    // Search in directory files ?
    if ( m_FindData.MustSearchInDirectory() == true )
    {
        int flags = wxDIR_FILES | wxDIR_DIRS | wxDIR_DOTDOT;
        flags    |= m_FindData.GetHiddenSearch() ? wxDIR_HIDDEN : 0;

        const wxString &path = m_FindData.GetSearchPath(true);
        if (!wxDir::Exists(path))
        {
            ThreadSearchEvent event(wxEVT_THREAD_SEARCH_ERROR, -1);
            event.SetString(_("Cannot open folder ") + path);

            // Using wxPostEvent, we avoid multi-threaded memory violation.
            wxPostEvent(m_pThreadSearchView,event);
            return 0;
        }
        else
        {
            wxDir Dir(path);
            Dir.Traverse(*(static_cast<wxDirTraverser*>(this)), wxEmptyString, flags);
        }

        // Tests thread stop (cancel search, app shutdown)
        if ( TestDestroy() == true ) return 0;
    }

    // Search in workspace files ?
    if ( m_FindData.MustSearchInWorkspace() == true )
    {
        ProjectsArray* pProjectsArray = Manager::Get()->GetProjectManager()->GetProjects();
        for ( size_t j=0; j < pProjectsArray->GetCount(); ++j )
        {
            AddProjectFiles(m_FilePaths, *pProjectsArray->Item(j));
            if ( TestDestroy() == true ) return 0;
        }
    }
    else if ( m_FindData.MustSearchInProject() == true )
    {
        // Search in project files ?
        // Necessary only if not already parsed in worspace part
        cbProject* pProject = Manager::Get()->GetProjectManager()->GetActiveProject();
        if ( pProject != NULL )
        {
            AddProjectFiles(m_FilePaths, *pProject);
            if ( TestDestroy() == true ) return 0;
        }
    }
    else if ( m_FindData.MustSearchInTarget() == true )
    {
        // Search in target files ?
        // Necessary only if not already parsed in project part
        cbProject* pProject = Manager::Get()->GetProjectManager()->GetActiveProject();
        if ( pProject != NULL )
        {
            ProjectBuildTarget *pTarget = pProject->GetBuildTarget(pProject->GetActiveBuildTarget());
            if ( pTarget != 0 )
            {
                AddTargetFiles(m_FilePaths, *pTarget);
                if ( TestDestroy() == true ) return 0;
            }
        }
    }

    // Tests thread stop (cancel search, app shutdown)
    if ( TestDestroy() == true ) return 0;

    // Open files
    if ( m_FindData.MustSearchInOpenFiles() == true )
    {
        EditorManager* pEdManager = Manager::Get()->GetEditorManager();
        for (i = 0; i < (size_t)pEdManager->GetNotebook()->GetPageCount(); ++i)
        {
            cbEditor* pEditor = pEdManager->GetBuiltinEditor(i);
            if ( pEditor != NULL )
            {
                AddNewItem(m_FilePaths, pEditor->GetFilename(), m_Masks);
            }
        }
    }

    // Tests thread stop (cancel search, app shutdown)
    if ( TestDestroy() == true ) return 0;

    // if the list is empty, leave
    if (m_FilePaths.GetCount() == 0)
    {
        //-cbMessageBox(wxT("No files to search in!"), wxT("Error"), wxICON_WARNING);
        ////(pecan 2008/4/26)
        // DO NOT issue graphics calls from this thread !!!!!!
        ThreadSearchEvent event(wxEVT_THREAD_SEARCH_ERROR, -1);
        event.SetString(_("No files to search.\nCheck options "));
        // Using wxPostEvent, we avoid multi-threaded memory violation.
        wxPostEvent(m_pThreadSearchView,event);
        return 0;
    }

    for ( i = 0; i < m_FilePaths.GetCount(); ++i )
    {
        FindInFile(m_FilePaths[i]);

        // Tests thread stop (cancel search, app shutdown)
        if ( TestDestroy() == true ) return 0;
    }

    return 0;
}