ClassWizardDlg::ClassWizardDlg(wxWindow* parent)
{
    wxXmlResource::Get()->LoadObject(this, parent, _T("dlgNewClass"),_T("wxScrollingDialog"));

    ProjectManager* prjMan = Manager::Get()->GetProjectManager();
    cbProject* prj = prjMan->GetActiveProject();
    if (prj)
    {
        XRCCTRL(*this, "txtIncludeDir", wxTextCtrl)->SetValue(prj->GetCommonTopLevelPath() + _T("include"));
        XRCCTRL(*this, "txtImplDir", wxTextCtrl)->SetValue(prj->GetCommonTopLevelPath() + _T("src"));
        XRCCTRL(*this, "txtCommonDir", wxTextCtrl)->SetValue(prj->GetCommonTopLevelPath());
    }
    else
    {
        XRCCTRL(*this, "txtIncludeDir", wxTextCtrl)->SetValue(::wxGetCwd());
        XRCCTRL(*this, "txtImplDir", wxTextCtrl)->SetValue(::wxGetCwd());
        XRCCTRL(*this, "txtCommonDir", wxTextCtrl)->SetValue(::wxGetCwd());
    }
    XRCCTRL(*this, "txtInheritanceFilename", wxTextCtrl)->SetValue(_T("<>"));
    XRCCTRL(*this, "cmbInheritanceScope", wxComboBox)->SetSelection(0);
    XRCCTRL(*this, "cmbMemberScope", wxComboBox)->SetSelection(2);
    XRCCTRL(*this, "txtHeaderInclude", wxTextCtrl)->SetValue(_T("\"\""));

    ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("classwizard"));
    if (cfg)
    {
        XRCCTRL(*this, "chkDocumentation", wxCheckBox)->SetValue(cfg->ReadBool(_T("documentation")));
        XRCCTRL(*this, "chkCommonDir",     wxCheckBox)->SetValue(cfg->ReadBool(_T("common_dir")));
        XRCCTRL(*this, "chkLowerCase",     wxCheckBox)->SetValue(cfg->ReadBool(_T("lower_case")));
    }
    XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
}
Exemplo n.º 2
0
void ClassWizard::OnLaunch(cb_unused wxCommandEvent& event)
{
    ProjectManager* prjMan = Manager::Get()->GetProjectManager();
    cbProject* prj = prjMan->GetActiveProject();

    ClassWizardDlg dlg(Manager::Get()->GetAppWindow());
    PlaceWindow(&dlg);
    if (dlg.ShowModal() == wxID_OK)
    {
        if (!prj)
        {
            cbMessageBox(   _("The new class has been created."),
                            _("Information"),
                            wxOK | wxICON_INFORMATION,
                            Manager::Get()->GetAppWindow());
        }
        else if( cbMessageBox( _("The new class has been created.\n"
                                 "Do you want to add it to the current project?"),
                               _("Add to project?"),
                               wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION,
                               Manager::Get()->GetAppWindow()) == wxID_YES)
        {
            wxArrayInt targets;
            prjMan->AddFileToProject(dlg.GetHeaderFilename(), prj, targets);
            if ( (targets.GetCount() != 0) && (dlg.IsValidImplementationFilename()) )
                prjMan->AddFileToProject(dlg.GetImplementationFilename(), prj, targets);
            if (dlg.AddPathToProject())
            {
                // Add the include Path to the Build targets....
                for (size_t i = 0; i < targets.GetCount(); ++i)
                {
                    ProjectBuildTarget* buildTarget = prj->GetBuildTarget(targets[i]);  // Get the top level build Target
                    if (buildTarget)
                    {
                        wxString include_dir = dlg.GetIncludeDir();
                        if (!include_dir.IsEmpty())
                            buildTarget->AddIncludeDir(include_dir);
                    }
                    else
                    {
                        wxString information;
                        information.Printf(_("Could not find build target ID = %i.\nThe include directory won't be added to this target. Please do it manually"), targets[i]);
                        cbMessageBox(information, _("Information"),
                                     wxOK | wxICON_INFORMATION,
                                     Manager::Get()->GetAppWindow());
                    }
                }
            }
            prjMan->GetUI().RebuildTree();
        }
    }
}
Exemplo n.º 3
0
void DebuggerToolbarHandler::OnUpdateUI(wxUpdateUIEvent& event)
{
    cbDebuggerPlugin *plugin = Manager::Get()->GetDebuggerManager()->GetActiveDebugger();
    ProjectManager *manager = Manager::Get()->GetProjectManager();

    bool en = false;
    bool stopped = false, isRunning = false;

    if (plugin)
    {
        cbProject* prj = manager->GetActiveProject();
        en = (prj && !prj->GetCurrentlyCompilingTarget()) || plugin->IsAttachedToProcess();
        stopped = plugin->IsStopped();
        isRunning = plugin->IsRunning();
    }

    if (m_Toolbar)
    {
        cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();

        cbPlugin *runningPlugin = manager->GetIsRunning();
        if (runningPlugin != NULL && runningPlugin != plugin)
            en = false;

        m_Toolbar->EnableTool(idMenuDebug, (!isRunning || stopped) && en);
        m_Toolbar->EnableTool(idMenuRunToCursor, en && ed && stopped);
        m_Toolbar->EnableTool(idMenuNext, isRunning && en && stopped);
        m_Toolbar->EnableTool(idMenuNextInstr, isRunning && en && stopped);
        m_Toolbar->EnableTool(idMenuStepIntoInstr, isRunning && en && stopped);
        m_Toolbar->EnableTool(idMenuStep, en && stopped);
        m_Toolbar->EnableTool(idMenuStepOut, isRunning && en && stopped);
        m_Toolbar->EnableTool(idToolbarStop, isRunning && en);
        m_Toolbar->EnableTool(idMenuBreak, isRunning && !stopped && en);
        m_Toolbar->EnableTool(idDebuggerToolInfo, plugin && plugin->ToolMenuEnabled());
    }

    // allow other UpdateUI handlers to process this event
    // *very* important! don't forget it...
    event.Skip();
}
Exemplo n.º 4
0
void Autosave::OnTimer(wxTimerEvent& e)
{
    if(e.GetId() == 10000)
    {
        int method = Manager::Get()->GetConfigManager(_T("autosave"))->ReadInt(_T("method"));
        bool allProjects = Manager::Get()->GetConfigManager(_T("autosave"))->ReadBool(_T("all_projects"), true);
        bool doWorkspace = Manager::Get()->GetConfigManager(_T("autosave"))->ReadBool(_T("do_workspace"), true);
        ProjectManager *pm = Manager::Get()->GetProjectManager();
        if(pm)// && pm->GetActiveProject())
        {
            if (allProjects)
            {
                ProjectsArray *projects = pm->GetProjects();
                for (size_t ii = 0; ii < projects->GetCount(); ++ii)
                    SaveProject((*projects)[ii], method);
            }
            else if(cbProject *p = pm->GetActiveProject())
                SaveProject(p, method);

            cbWorkspace *workspace = pm->GetWorkspace();
            if (doWorkspace && workspace && workspace->GetModified())
            {
                switch(method)
                {
                    case 0:
                        if(::wxRenameFile(workspace->GetFilename(), workspace->GetFilename() + _T(".bak")))
                            workspace->Save();
                        break;
                    case 1:
                        workspace->Save();
                        break;
                    case 2:
                    case 3:
                    {
                        WorkspaceLoader loader;
                        loader.Save(workspace->GetTitle(), workspace->GetFilename() + wxT(".save"));
                        workspace->SetModified(true);
                        break;
                    }
                    default:
                        break;
                }
            }
        }
    }
    else if(e.GetId() == 20000)
    {
        int method = Manager::Get()->GetConfigManager(_T("autosave"))->ReadInt(_T("method"));
        EditorManager* em = Manager::Get()->GetEditorManager();

        if(em)
        {
            for(int i = 0; i < em->GetEditorsCount(); ++i)
            {
                cbEditor* ed = em->GetBuiltinEditor(em->GetEditor(i));
                if(ed && ed->GetModified())
                {
                    wxFileName fn(ed->GetFilename());
                    switch(method)
                    {
                        case 0:
                        {
                            if(::wxRenameFile(fn.GetFullPath(), fn.GetFullPath() + _T(".bak")))
                                cbSaveToFile(fn.GetFullPath(), ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom());
                            break;
                        }
                        case 1:
                        {
                            ed->Save();
                            break;
                        }
                        case 2:
                        {
                            cbSaveToFile(fn.GetFullPath() + _T(".save"), ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom());
                            ed->SetModified(); // the "real" file has not been saved!
                            break;
                        }
                        case 3:
                        {
                            wxString tmp1;
                            wxString tmp2;

                            for(unsigned int revisions = 8; revisions; --revisions)
                            {
                                tmp1.Printf(_T("%s/%s.%u.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), revisions,   fn.GetExt().c_str());
                                tmp2.Printf(_T("%s/%s.%u.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), revisions+1, fn.GetExt().c_str());

                                if(::wxFileExists(tmp2))
                                    ::wxRemoveFile(tmp2);
                                if(::wxFileExists(tmp1))
                                    ::wxRenameFile(tmp1, tmp2);
                            }

                            tmp1.Printf(_T("%s/%s.1.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), fn.GetExt().c_str());

                            cbSaveToFile(tmp1, ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom());
                            ed->SetModified(); // the "real" file has not been saved!
                            break;
                        }
                        default:
                            break;
                    }
                }

            }
        }
    }

}
Exemplo n.º 5
0
void DebuggerManager::FindTargetsDebugger()
{
    if (Manager::Get()->GetProjectManager()->IsLoadingOrClosing())
        return;

    m_activeDebugger = nullptr;
    m_menuHandler->SetActiveDebugger(nullptr);

    if (m_registered.empty())
    {
        m_menuHandler->MarkActiveTargetAsValid(false);
        return;
    }

    ProjectManager* projectMgr = Manager::Get()->GetProjectManager();
    LogManager* log = Manager::Get()->GetLogManager();
    cbProject* project = projectMgr->GetActiveProject();
    ProjectBuildTarget *target = nullptr;
    if (project)
    {
        const wxString &targetName = project->GetActiveBuildTarget();
        if (project->BuildTargetValid(targetName))
            target = project->GetBuildTarget(targetName);
    }


    Compiler *compiler = nullptr;
    if (!target)
    {
        if (project)
            compiler = CompilerFactory::GetCompiler(project->GetCompilerID());
        if (!compiler)
            compiler = CompilerFactory::GetDefaultCompiler();
        if (!compiler)
        {
            log->LogError(_("Can't get the compiler for the active target, nor the project, nor the default one!"));
            m_menuHandler->MarkActiveTargetAsValid(false);
            return;
        }
    }
    else
    {
        compiler = CompilerFactory::GetCompiler(target->GetCompilerID());
        if (!compiler)
        {
            log->LogError(wxString::Format(_("Current target '%s' doesn't have valid compiler!"),
                                           target->GetTitle().c_str()));
            m_menuHandler->MarkActiveTargetAsValid(false);
            return;
        }
    }
    wxString dbgString = compiler->GetPrograms().DBGconfig;
    wxString::size_type pos = dbgString.find(wxT(':'));

    wxString name, config;
    if (pos != wxString::npos)
    {
        name = dbgString.substr(0, pos);
        config = dbgString.substr(pos + 1, dbgString.length() - pos - 1);
    }

    if (name.empty() || config.empty())
    {
        log->LogError(wxString::Format(_("Current compiler '%s' doesn't have correctly defined debugger!"),
                                       compiler->GetName().c_str()));
        m_menuHandler->MarkActiveTargetAsValid(false);
        return;
    }

    for (RegisteredPlugins::iterator it = m_registered.begin(); it != m_registered.end(); ++it)
    {
        PluginData &data = it->second;
        if (it->first->GetSettingsName() == name)
        {
            ConfigurationVector &configs = data.GetConfigurations();
            int index = 0;
            for (ConfigurationVector::iterator itConf = configs.begin(); itConf != configs.end(); ++itConf, ++index)
            {
                if ((*itConf)->GetName() == config)
                {
                    m_activeDebugger = it->first;
                    m_activeDebugger->SetActiveConfig(index);
                    m_useTargetsDefault = true;

                    WriteActiveDebuggerConfig(wxEmptyString, -1);
                    RefreshUI();
                    m_menuHandler->MarkActiveTargetAsValid(true);
                    return;
                }
            }
        }
    }

    wxString targetTitle(target ? target->GetTitle() : wxT("<nullptr>"));
    log->LogError(wxString::Format(_("Can't find the debugger config: '%s:%s' for the current target '%s'!"),
                                   name.c_str(), config.c_str(),
                                   targetTitle.c_str()));
    m_menuHandler->MarkActiveTargetAsValid(false);
}
Exemplo n.º 6
0
/*!
    \brief Write OpenOCD config file.

    Writes common information to the config file, then calls OnWriteConfigFile so
    the plugins can write their information to the file.

    \return 0 on success, -1 on failure.
*/
int OpenOCDDriver::WriteConfigFile(void)
{
    char buf[256];

    // Write GDB target config file
    wxFile of;

    // Target file output dir
    ProjectManager* prjMan = Manager::Get()->GetProjectManager();
    cbProject* project = prjMan->GetActiveProject();

    wxString bt = project->GetBasePath();
    wxString cf = bt + m_ConfigFile;

    // Open target file
    bool ret = of.Open(cf, wxFile::write);
    if (ret == false)
        return -1;  // Cannot open file for writing

    // Write header
    of.Write(_T("# OpenOCD config file, auto generated by CodeBlocks"));

    // Write settings. Daemon config
    of.Write(_T("\n\n#daemon configuration\ntelnet_port "));
    sprintf(buf, "%d", m_TelnetPort);   // Get from config
    of.Write(buf, strlen(buf));

    // GDB port
    of.Write(_T("\ngdb_port "));
    sprintf(buf, "%d", m_GDBPort);
    of.Write(buf, strlen(buf));

    // TCL port
    of.Write(_T("\ntcl_port "));
    sprintf(buf, "%d", m_TCLPort);
    of.Write(buf, strlen(buf));

    //of.Write(_T("\ngdb_detach reset"));
    //of.Write(_T("gdb_memory_map enable\n"));
    //of.Write(_T("gdb_flash_program enable\n\n"));

    // Interface settings
    of.Write(_T("\n\n#interface\ninterface "));
    wxString str;

    // Write interface.
    of.Write(m_Interface);

    // Now find option index in array.
    int item;

    OpenOCDDevs devs;

    item = devs.FindItem(m_Interface);
    if (item == -1) {
        // The item was not found in the list.
        cbMessageBox(_T("The currently selected interface does not exist."), _("cbmcu plugin error"), wxICON_STOP);
        return -1;
    }

    OpenOCDIntDev *pDev = devs.GetInterfaceDevice(item);
    if (!(pDev == NULL)) {
        wxString str;

        item = pDev->FindItem(m_Option);
        if (item == -1) {
            cbMessageBox(_T("The currently selected device does not exist."), _("cbmcu plugin error"), wxICON_STOP);
        } else {
            pDev->BuildDeviceString(item, str);
            of.Write(str);
        }
    }

    of.Write(_T("\n\n"));

    // The plugin can write the rest
    int nRet = OnWriteConfigFile(of);
    if (nRet == 0) {
        // Plugin config failed.
        cbMessageBox(_T("Plugin has failed to write configuration"), _("cbmcu plugin error"), wxICON_STOP);
        nRet = -1;
    }
    of.Close();

    return nRet;
}
Exemplo n.º 7
0
void Autosave::OnTimer(wxTimerEvent& e)
{
    if(e.GetId() == 10000)
    {
        PluginManager *plm = Manager::Get()->GetPluginManager();
        int method = Manager::Get()->GetConfigManager(_T("autosave"))->ReadInt(_T("method"));
        ProjectManager *pm = Manager::Get()->GetProjectManager();
        if(pm && pm->GetActiveProject())
        {
            if(cbProject * p = pm->GetActiveProject())
            {
                switch(method)
                {
                    case 0:
                    {
                        if(p->GetModified())
                        {
                            if(::wxRenameFile(p->GetFilename(), p->GetFilename() + _T(".bak")))
                                if(p->Save())
                                {
                                    CodeBlocksEvent e(cbEVT_PROJECT_SAVE, 0, p);
                                    plm->NotifyPlugins(e);
                                }
                        }
                        wxFileName file = p->GetFilename();
                        file.SetExt(_T("layout"));
                        wxString filename = file.GetFullPath();
                        if(::wxRenameFile(filename, filename + _T(".bak")))
                            p->SaveLayout();
                        break;
                    }
                    case 1:
                    {
                        if(p->GetModified() && p->Save())
                        {
                            CodeBlocksEvent e(cbEVT_PROJECT_SAVE, 0, p);
                            plm->NotifyPlugins(e);
                        }
                        p->SaveLayout();
                        break;
                    }
                    case 2:
                    case 3: // doesn't really make sense to keep so many versions of a project file
                    {
                        if (p->IsLoaded() == false)
                            return;
                        if(p->GetModified())
                        {
                            ProjectLoader loader(p);
                            if(loader.Save(p->GetFilename() + _T(".save")))
                            {
                                CodeBlocksEvent e(cbEVT_PROJECT_SAVE, 0, p);
                                plm->NotifyPlugins(e);
                            }
                            p->SetModified(); // the actual project file is still not updated!
                        }
                        wxFileName file = wxFileName(p->GetFilename());
                        file.SetExt(_T("layout"));
                        wxString filename = file.GetFullPath();
                        wxString temp = filename + _T(".temp");
                        wxString save = filename + _T(".save");
                        if(::wxFileExists(filename) && ::wxCopyFile(filename, temp))
                        {
                            p->SaveLayout();
                            ::wxRenameFile(filename, save);
                            ::wxRenameFile(temp, filename);
                        }
                        break;
                    }
                }
            }
        }
    }
    else if(e.GetId() == 20000)
    {
        int method = Manager::Get()->GetConfigManager(_T("autosave"))->ReadInt(_T("method"));
        EditorManager* em = Manager::Get()->GetEditorManager();

        if(em)
        {
            for(int i = 0; i < em->GetEditorsCount(); ++i)
            {
                cbEditor* ed = em->GetBuiltinEditor(em->GetEditor(i));
                if(ed && ed->GetModified())
                {
                    wxFileName fn(ed->GetFilename());
                    switch(method)
                    {
                        case 0:
                        {
                            if(::wxRenameFile(fn.GetFullPath(), fn.GetFullPath() + _T(".bak")))
                                cbSaveToFile(fn.GetFullPath(), ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom());
                            break;
                        }
                        case 1:
                        {
                            ed->Save();
                            break;
                        }
                        case 2:
                        {
                            cbSaveToFile(fn.GetFullPath() + _T(".save"), ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom());
                            ed->SetModified(); // the "real" file has not been saved!
                            break;
                        }
                        case 3:
                        {
                            wxString tmp1;
                            wxString tmp2;

                            for(unsigned int i = 8; i; --i)
                            {
                                tmp1.Printf(_T("%s/%s.%u.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), i,   fn.GetExt().c_str());
                                tmp2.Printf(_T("%s/%s.%u.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), i+1, fn.GetExt().c_str());

                                if(::wxFileExists(tmp2))
                                    ::wxRemoveFile(tmp2);
                                if(::wxFileExists(tmp1))
                                    ::wxRenameFile(tmp1, tmp2);
                            }

                            tmp1.Printf(_T("%s/%s.1.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), fn.GetExt().c_str());

                            cbSaveToFile(tmp1, ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom());
                            ed->SetModified(); // the "real" file has not been saved!
                            break;
                        }
                    }
                }

            }
        }
    }

}