⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compileroptionsdlg.cpp

📁 非常好用的可移植的多平台C/C++源代码编辑器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void CompilerOptionsDlg::DoSaveOptions(int compilerIdx, ScopeTreeData* data)
{
    // only if "Commands" page exists
	if (XRCCTRL(*this, "txtCmdBefore", wxTextCtrl))
	{
        m_AlwaysUsePre = XRCCTRL(*this, "chkAlwaysRunPre", wxCheckBox)->GetValue();
        m_AlwaysUsePost = XRCCTRL(*this, "chkAlwaysRunPost", wxCheckBox)->GetValue();
        DoGetCompileOptions(m_CommandsBeforeBuild, XRCCTRL(*this, "txtCmdBefore", wxTextCtrl));
        DoGetCompileOptions(m_CommandsAfterBuild, XRCCTRL(*this, "txtCmdAfter", wxTextCtrl));
	}
	DoGetCompileDirs(m_IncludeDirs, XRCCTRL(*this, "lstIncludeDirs", wxListBox));
	DoGetCompileDirs(m_LibDirs, XRCCTRL(*this, "lstLibDirs", wxListBox));
	DoGetCompileDirs(m_ResDirs, XRCCTRL(*this, "lstResDirs", wxListBox));
	DoGetCompileOptions(m_CompilerOptions, XRCCTRL(*this, "txtCompilerOptions", wxTextCtrl));
	DoGetCompileOptions(m_LinkerOptions, XRCCTRL(*this, "txtLinkerOptions", wxTextCtrl));
    OptionsToText();

	if (!data)
	{
		// global options
        Compiler* compiler = CompilerFactory::Compilers[compilerIdx];

		compiler->SetIncludeDirs(m_IncludeDirs);
		compiler->SetLibDirs(m_LibDirs);
		compiler->SetResourceIncludeDirs(m_ResDirs);
		compiler->SetCompilerOptions(m_CompilerOptions);
		compiler->SetLinkerOptions(m_LinkerOptions);
		compiler->SetLinkLibs(m_LinkLibs);
		compiler->SetCommandsBeforeBuild(m_CommandsBeforeBuild);
		compiler->SetCommandsAfterBuild(m_CommandsAfterBuild);
		compiler->SetAlwaysRunPreBuildSteps(m_AlwaysUsePre);
		compiler->SetAlwaysRunPostBuildSteps(m_AlwaysUsePost);

        wxComboBox* cmb = XRCCTRL(*this, "cmbLogging", wxComboBox);
        if (cmb)
        {
            CompilerSwitches switches = compiler->GetSwitches();
            switches.logging = (CompilerLoggingType)cmb->GetSelection();
            compiler->SetSwitches(switches);
        }
        cmb = XRCCTRL(*this, "cmbBuildMethod", wxComboBox);
        if (cmb)
        {
            CompilerSwitches switches = compiler->GetSwitches();
            switches.buildMethod = (CompilerBuildMethod)cmb->GetSelection();
            compiler->SetSwitches(switches);
        }
	}
	else
	{
		if (!data->GetTarget())
		{
			// project options
			cbProject* project = data->GetProject();
			project->SetIncludeDirs(m_IncludeDirs);
			project->SetResourceIncludeDirs(m_ResDirs);
			project->SetLibDirs(m_LibDirs);
			project->SetCompilerOptions(m_CompilerOptions);
			project->SetLinkerOptions(m_LinkerOptions);
			project->SetLinkLibs(m_LinkLibs);
			project->SetCommandsBeforeBuild(m_CommandsBeforeBuild);
			project->SetCommandsAfterBuild(m_CommandsAfterBuild);
            project->SetAlwaysRunPreBuildSteps(m_AlwaysUsePre);
            project->SetAlwaysRunPostBuildSteps(m_AlwaysUsePost);
		}
		else
		{
			// target options
			ProjectBuildTarget* target = data->GetTarget();
			target->SetIncludeDirs(m_IncludeDirs);
			target->SetResourceIncludeDirs(m_ResDirs);
			target->SetLibDirs(m_LibDirs);
			target->SetCompilerOptions(m_CompilerOptions);
			target->SetLinkerOptions(m_LinkerOptions);
			target->SetLinkLibs(m_LinkLibs);
            target->SetOptionRelation(ortCompilerOptions, OptionsRelation(XRCCTRL(*this, "cmbCompilerPolicy", wxComboBox)->GetSelection()));
            target->SetOptionRelation(ortLinkerOptions, OptionsRelation(XRCCTRL(*this, "cmbLinkerPolicy", wxComboBox)->GetSelection()));
            target->SetOptionRelation(ortIncludeDirs, OptionsRelation(XRCCTRL(*this, "cmbIncludesPolicy", wxComboBox)->GetSelection()));
            target->SetOptionRelation(ortLibDirs, OptionsRelation(XRCCTRL(*this, "cmbLibDirsPolicy", wxComboBox)->GetSelection()));
            target->SetOptionRelation(ortResDirs, OptionsRelation(XRCCTRL(*this, "cmbResDirsPolicy", wxComboBox)->GetSelection()));
			target->SetCommandsBeforeBuild(m_CommandsBeforeBuild);
			target->SetCommandsAfterBuild(m_CommandsAfterBuild);
            target->SetAlwaysRunPreBuildSteps(m_AlwaysUsePre);
            target->SetAlwaysRunPostBuildSteps(m_AlwaysUsePost);
		}
	}
}

void CompilerOptionsDlg::DoMakeRelative(wxFileName& path)
{
    // NOTE: this function is not currently used

	wxTreeCtrl* tc = XRCCTRL(*this, "tcScope", wxTreeCtrl);
	ScopeTreeData* data = (ScopeTreeData*)tc->GetItemData(tc->GetSelection());
	if (data && data->GetProject())
	{
        path.MakeRelativeTo(data->GetProject()->GetBasePath());
    }
}

void CompilerOptionsDlg::DoSaveCompilerPrograms(int compilerIdx)
{
    if (m_pProject || // no "Programs" page
        !CompilerFactory::CompilerIndexOK(compilerIdx))
    {
        return;
    }
    CompilerPrograms progs;
    wxString masterPath = XRCCTRL(*this, "txtMasterPath", wxTextCtrl)->GetValue();
    progs.C = XRCCTRL(*this, "txtCcompiler", wxTextCtrl)->GetValue();
    progs.CPP = XRCCTRL(*this, "txtCPPcompiler", wxTextCtrl)->GetValue();
    progs.LD = XRCCTRL(*this, "txtLinker", wxTextCtrl)->GetValue();
    progs.LIB = XRCCTRL(*this, "txtLibLinker", wxTextCtrl)->GetValue();
    progs.WINDRES = XRCCTRL(*this, "txtResComp", wxTextCtrl)->GetValue();
    progs.MAKE = XRCCTRL(*this, "txtMake", wxTextCtrl)->GetValue();
    progs.DBG = XRCCTRL(*this, "txtDebugger", wxTextCtrl)->GetValue();
    CompilerFactory::Compilers[compilerIdx]->SetPrograms(progs);
    CompilerFactory::Compilers[compilerIdx]->SetMasterPath(masterPath);
    CompilerFactory::Compilers[compilerIdx]->SetOptions(m_Options);
}

// events

void CompilerOptionsDlg::OnTreeSelectionChange(wxTreeEvent& event)
{
	if (m_BuildingTree)
		return;
	wxTreeCtrl* tc = XRCCTRL(*this, "tcScope", wxTreeCtrl);
	ScopeTreeData* data = (ScopeTreeData*)tc->GetItemData(event.GetItem());
	if (!data)
        return;
    int compilerIdx = data->GetTarget() ? data->GetTarget()->GetCompilerIndex() :
                        (data->GetProject() ? data->GetProject()->GetCompilerIndex() :
                        XRCCTRL(*this, "cmbCompiler", wxComboBox)->GetSelection());
    XRCCTRL(*this, "cmbCompiler", wxComboBox)->SetSelection(compilerIdx);
    CompilerChanged(data);
    m_pTarget = data->GetTarget();
//	DoLoadOptions(compilerIdx, data);
}

void CompilerOptionsDlg::OnTreeSelectionChanging(wxTreeEvent& event)
{
	if (m_BuildingTree)
		return;
	wxTreeCtrl* tc = XRCCTRL(*this, "tcScope", wxTreeCtrl);
	ScopeTreeData* data = (ScopeTreeData*)tc->GetItemData(event.GetOldItem());
	if (!data)
        return;
    int compilerIdx = XRCCTRL(*this, "cmbCompiler", wxComboBox)->GetSelection();
	DoSaveOptions(compilerIdx, data);
}

void CompilerOptionsDlg::OnCompilerChanged(wxCommandEvent& event)
{
	wxTreeCtrl* tc = XRCCTRL(*this, "tcScope", wxTreeCtrl);
	ScopeTreeData* data = tc ? (ScopeTreeData*)tc->GetItemData(tc->GetSelection()) : 0;
	DoSaveCompilerPrograms(m_LastCompilerIdx);
	DoSaveOptions(m_LastCompilerIdx, data);
    CompilerChanged(data);
}

void CompilerOptionsDlg::CompilerChanged(ScopeTreeData* data)
{
    int compilerIdx = XRCCTRL(*this, "cmbCompiler", wxComboBox)->GetSelection();

    if (data)
    {
        if (data->GetTarget())
             data->GetTarget()->SetCompilerIndex(compilerIdx);
        else if (data->GetProject())
            data->GetProject()->SetCompilerIndex(compilerIdx);
    }
    else if (m_pProject)
        m_pProject->SetCompilerIndex(compilerIdx);

    m_Options = CompilerFactory::Compilers[compilerIdx]->GetOptions();
    DoFillCompilerPrograms();
    DoFillCategories();
    DoFillOptions();

	if (m_BuildingTree)
		return;
	DoLoadOptions(compilerIdx, data);
	m_LastCompilerIdx = compilerIdx;

	// this relies on GetCustomVars(), which relies on m_LastCompilerIdx
	DoFillVars();
}

void CompilerOptionsDlg::UpdateCompilerForTargets(int compilerIdx)
{
    int ret = wxMessageBox(_("You have changed the compiler used for the project.\n"
                            "Do you want to use the same compiler for all the project's build targets too?"),
                            _("Question"),
                            wxICON_QUESTION | wxYES_NO);
    if (ret == wxYES)
    {
        for (int i = 0; i < m_pProject->GetBuildTargetsCount(); ++i)
        {
            ProjectBuildTarget* target = m_pProject->GetBuildTarget(i);
            target->SetCompilerIndex(compilerIdx);
        }
    }
}

void CompilerOptionsDlg::AutoDetectCompiler()
{
    wxComboBox* cmb = XRCCTRL(*this, "cmbCompiler", wxComboBox);
    int compilerIdx = cmb->GetSelection();
    Compiler* compiler = CompilerFactory::Compilers[compilerIdx];
    wxString backup = XRCCTRL(*this, "txtMasterPath", wxTextCtrl)->GetValue();

    wxArrayString empty;
    compiler->SetExtraPaths(empty);

    switch (compiler->AutoDetectInstallationDir())
    {
        case adrDetected:
        {
            wxString msg;
            msg.Printf(_("Auto-detected installation path of \"%s\"\nin \"%s\""), compiler->GetName().c_str(), compiler->GetMasterPath().c_str());
            wxMessageBox(msg);
        }
        break;

        case adrGuessed:
        {
            wxString msg;
            msg.Printf(_("Could not auto-detect installation path of \"%s\"...\n"
                        "Do you want to use this compiler's default installation directory?"),
                        compiler->GetName().c_str());
            if (wxMessageBox(msg, _("Confirmation"), wxICON_QUESTION | wxYES_NO) == wxNO)
                compiler->SetMasterPath(backup);
        }
        break;
    }
    XRCCTRL(*this, "txtMasterPath", wxTextCtrl)->SetValue(compiler->GetMasterPath());
    XRCCTRL(*this, "lstExtraPaths", wxListBox)->Clear();
    const wxArrayString& extraPaths = CompilerFactory::Compilers[compilerIdx]->GetExtraPaths();
    for (unsigned int i = 0; i < extraPaths.GetCount(); ++i)
    {
        XRCCTRL(*this, "lstExtraPaths", wxListBox)->Append(extraPaths[i]);
    }
}

wxListBox* CompilerOptionsDlg::GetDirsListBox()
{
    wxNotebook* nb = XRCCTRL(*this, "nbDirs", wxNotebook);
    if (!nb)
        return 0;
    switch (nb->GetSelection())
    {
        case 0: // compiler dirs
            return XRCCTRL(*this, "lstIncludeDirs", wxListBox);
        case 1: // linker dirs
            return XRCCTRL(*this, "lstLibDirs", wxListBox);
        case 2: // resource compiler dirs
            return XRCCTRL(*this, "lstResDirs", wxListBox);
        default: break;
    }
    return 0;
}

CustomVars* CompilerOptionsDlg::GetCustomVars()
{
	wxTreeCtrl* tc = XRCCTRL(*this, "tcScope", wxTreeCtrl);
    ScopeTreeData* data = tc ? (ScopeTreeData*)tc->GetItemData(tc->GetSelection()) : 0;
    CustomVars* vars = 0;
    if (!data)
        vars = GetCustomVars(0);
    else
    {
        if (data->GetTarget())
            vars = &data->GetTarget()->GetCustomVars();
        else
            vars = &m_pProject->GetCustomVars();
    }
    return vars;
}

CustomVars* CompilerOptionsDlg::GetCustomVars(CompileOptionsBase* base)
{
	if (base)
        return &base->GetCustomVars();
    Compiler* compiler = CompilerFactory::Compilers[m_LastCompilerIdx];
    return compiler ? &compiler->GetCustomVars() : 0;
}

void CompilerOptionsDlg::OnCategoryChanged(wxCommandEvent& event)
{
	DoFillOptions();
}

void CompilerOptionsDlg::OnOptionToggled(wxCommandEvent& event)
{
	wxCheckListBox* list = XRCCTRL(*this, "lstCompilerOptions", wxCheckListBox);
	int sel = event.GetInt();
	CompOption* copt = m_Options.GetOptionByName(list->GetString(sel));
	if (copt)
	{
		copt->enabled = list->IsChecked(sel);
//        Manager::Get()->GetMessageManager()->DebugLog("option %s (0x%8.8x) %s", copt->option.c_str(), copt, copt->enabled ? "enabled" : "disabled");
    }
}

void CompilerOptionsDlg::OnAddDirClick(wxCommandEvent& event)
{
    /*wxString path = ChooseDirectory(this,
                                    _("Select directory"),
                                    m_pProject ? m_pProject->GetBasePath() : "",
                                    m_pProject ? m_pProject->GetBasePath() : "",
                                    true,
                                    true);*/

    EditPathDlg dlg(this,
            m_pProject ? m_pProject->GetBasePath() : _T(""),
            m_pProject ? m_pProject->GetBasePath() : _T(""),
            _("Add directory"));

    if (dlg.ShowModal() == wxID_OK)
    {
        wxString path = dlg.GetPath();

        wxListBox* control = GetDirsListBox();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -