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

📄 compileroptionsdlg.cpp

📁 非常好用的可移植的多平台C/C++源代码编辑器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        return;
    }
    extraPaths[control->GetSelection()] = path;
    compiler->SetExtraPaths(extraPaths);
    control->SetString(control->GetSelection(), path);
}

void CompilerOptionsDlg::OnRemoveExtraPathClick(wxCommandEvent& event)
{
    wxListBox* control = XRCCTRL(*this, "lstExtraPaths", wxListBox);
    if (!control || control->GetSelection() < 0)
        return;

    int compilerIdx = XRCCTRL(*this, "cmbCompiler", wxComboBox)->GetSelection();
    Compiler* compiler = CompilerFactory::Compilers[compilerIdx];
    wxArrayString extraPaths = CompilerFactory::Compilers[compilerIdx]->GetExtraPaths();
    extraPaths.RemoveAt(control->GetSelection());
    compiler->SetExtraPaths(extraPaths);
    control->Delete(control->GetSelection());
}

void CompilerOptionsDlg::OnMoveLibUpClick(wxSpinEvent& event)
{
    wxListBox* lstLibs = XRCCTRL(*this, "lstLibs", wxListBox);
    if (lstLibs->GetSelection() <= 0)
        return;
    int sel = lstLibs->GetSelection();
    wxString lib = lstLibs->GetStringSelection();
    lstLibs->Delete(sel);
    lstLibs->InsertItems(1, &lib, sel - 1);
    lstLibs->SetSelection(sel - 1);
    if (m_pProject)
        m_pProject->SetModified(true);
}

void CompilerOptionsDlg::OnMoveLibDownClick(wxSpinEvent& event)
{
    wxListBox* lstLibs = XRCCTRL(*this, "lstLibs", wxListBox);
    if (lstLibs->GetSelection() == lstLibs->GetCount() - 1)
        return;
    int sel = lstLibs->GetSelection();
    wxString lib = lstLibs->GetStringSelection();
    lstLibs->Delete(sel);
    lstLibs->InsertItems(1, &lib, sel + 1);
    lstLibs->SetSelection(sel + 1);
    if (m_pProject)
        m_pProject->SetModified(true);
}

void CompilerOptionsDlg::OnMoveDirUpClick(wxSpinEvent& event)
{
    wxListBox* lst = GetDirsListBox();
    if (!lst || lst->GetSelection() <= 0)
        return;
    int sel = lst->GetSelection();
    wxString lib = lst->GetStringSelection();
    lst->Delete(sel);
    lst->InsertItems(1, &lib, sel - 1);
    lst->SetSelection(sel - 1);
    if (m_pProject)
        m_pProject->SetModified(true);
}

void CompilerOptionsDlg::OnMoveDirDownClick(wxSpinEvent& event)
{
    wxListBox* lst = GetDirsListBox();
    if (!lst || lst->GetSelection() == lst->GetCount() - 1)
        return;
    int sel = lst->GetSelection();
    wxString lib = lst->GetStringSelection();
    lst->Delete(sel);
    lst->InsertItems(1, &lib, sel + 1);
    lst->SetSelection(sel + 1);
    if (m_pProject)
        m_pProject->SetModified(true);
}

void CompilerOptionsDlg::OnMasterPathClick(wxCommandEvent& event)
{
    wxString path = ChooseDirectory(this,
                                    _("Select directory"),
                                    XRCCTRL(*this, "txtMasterPath", wxTextCtrl)->GetValue());
    if (path.IsEmpty())
        return;
    if (!path.IsEmpty())
    {
        XRCCTRL(*this, "txtMasterPath", wxTextCtrl)->SetValue(path);
        int compilerIdx = XRCCTRL(*this, "cmbCompiler", wxComboBox)->GetSelection();
        DoSaveCompilerPrograms(compilerIdx);
    }
}

void CompilerOptionsDlg::OnAutoDetectClick(wxCommandEvent& event)
{
    AutoDetectCompiler();
}

void CompilerOptionsDlg::OnSelectProgramClick(wxCommandEvent& event)
{
    // see who called us
    wxTextCtrl* obj = 0L;
    if (event.GetId() == XRCID("btnCcompiler"))
        obj = XRCCTRL(*this, "txtCcompiler", wxTextCtrl);
    else if (event.GetId() == XRCID("btnCPPcompiler"))
        obj = XRCCTRL(*this, "txtCPPcompiler", wxTextCtrl);
    else if (event.GetId() == XRCID("btnLinker"))
        obj = XRCCTRL(*this, "txtLinker", wxTextCtrl);
    else if (event.GetId() == XRCID("btnLibLinker"))
        obj = XRCCTRL(*this, "txtLibLinker", wxTextCtrl);
    else if (event.GetId() == XRCID("btnDebugger"))
        obj = XRCCTRL(*this, "txtDebugger", wxTextCtrl);
    else if (event.GetId() == XRCID("btnResComp"))
        obj = XRCCTRL(*this, "txtResComp", wxTextCtrl);
    else if (event.GetId() == XRCID("btnMake"))
        obj = XRCCTRL(*this, "txtMake", wxTextCtrl);

    if (!obj)
        return; // called from invalid caller

    // common part follows
    wxFileDialog* dlg = new wxFileDialog(this,
                            _("Select file"),
                            XRCCTRL(*this, "txtMasterPath", wxTextCtrl)->GetValue() + _T("/bin"),
                            obj->GetValue(),
                            _("Executable files (*.exe)|*.exe"),
                            wxOPEN | wxFILE_MUST_EXIST);
    dlg->SetFilterIndex(0);

    if (dlg->ShowModal() != wxID_OK)
        return;
    wxFileName fname(dlg->GetPath());
    obj->SetValue(fname.GetFullName());
    int compilerIdx = XRCCTRL(*this, "cmbCompiler", wxComboBox)->GetSelection();
    DoSaveCompilerPrograms(compilerIdx);
}

void CompilerOptionsDlg::OnAdvancedClick(wxCommandEvent& event)
{
	if (wxMessageBox(_("The compiler's advanced settings, need command-line "
                        "compiler knowledge to be tweaked.\nIf you don't know "
                        "*exactly* what you 're doing, it is suggested to "
                        "NOT tamper with the advanced settings...\n\n"
                        "Are you sure you want to edit the advanced settings?"),
					_("Warning"),
					wxOK | wxCANCEL | wxICON_WARNING) == wxOK)
    {
        wxComboBox* cmb = XRCCTRL(*this, "cmbCompiler", wxComboBox);
        int compilerIdx = cmb->GetSelection();
        AdvancedCompilerOptionsDlg dlg(this, compilerIdx);
        dlg.ShowModal();
    }
}

void CompilerOptionsDlg::OnUpdateUI(wxUpdateUIEvent& event)
{
    wxListBox* control = GetDirsListBox();
    if (control)
    {
        // add/edit/delete dir
        bool en = control->GetSelection() >= 0;
        XRCCTRL(*this, "btnEditDir", wxButton)->Enable(en);
        XRCCTRL(*this, "btnDelDir", wxButton)->Enable(en);

        // moveup/movedown dir
        XRCCTRL(*this, "spnDirs", wxSpinButton)->Enable(en);
    }

    // add/edit/delete/moveup/movedown lib
    bool en = XRCCTRL(*this, "lstLibs", wxListBox)->GetSelection() >= 0;
    XRCCTRL(*this, "btnEditLib", wxButton)->Enable(en);
    XRCCTRL(*this, "btnDelLib", wxButton)->Enable(en);
    XRCCTRL(*this, "spnLibs", wxSpinButton)->Enable(en);

    // add/edit/delete vars
    if (XRCCTRL(*this, "lstVars", wxListBox))
    {
        en = XRCCTRL(*this, "lstVars", wxListBox)->GetSelection() >= 0;
        XRCCTRL(*this, "btnEditVar", wxButton)->Enable(en);
        XRCCTRL(*this, "btnDeleteVar", wxButton)->Enable(en);
    }

    // policies
	wxTreeCtrl* tc = XRCCTRL(*this, "tcScope", wxTreeCtrl);
	ScopeTreeData* data = (ScopeTreeData*)tc->GetItemData(tc->GetSelection());
	en = (data && data->GetTarget());
    XRCCTRL(*this, "cmbCompilerPolicy", wxComboBox)->Enable(en);
    XRCCTRL(*this, "cmbLinkerPolicy", wxComboBox)->Enable(en);
    XRCCTRL(*this, "cmbIncludesPolicy", wxComboBox)->Enable(en);
    XRCCTRL(*this, "cmbLibDirsPolicy", wxComboBox)->Enable(en);
    XRCCTRL(*this, "cmbResDirsPolicy", wxComboBox)->Enable(en);

    // compiler set buttons
    if (XRCCTRL(*this, "btnAddCompiler", wxButton)) // only if exist
    {
        en = !data; // global options selected
        int idx = XRCCTRL(*this, "cmbCompiler", wxComboBox)->GetSelection();
        int count = XRCCTRL(*this, "cmbCompiler", wxComboBox)->GetCount(); // compilers count
        XRCCTRL(*this, "btnSetDefaultCompiler", wxButton)->Enable(CompilerFactory::GetDefaultCompilerIndex() != idx);
        XRCCTRL(*this, "btnAddCompiler", wxButton)->Enable(en);
        XRCCTRL(*this, "btnRenameCompiler", wxButton)->Enable(en && count);
        XRCCTRL(*this, "btnDelCompiler", wxButton)->Enable(en &&
                                                        CompilerFactory::CompilerIndexOK(idx) &&
                                                        CompilerFactory::Compilers[idx]->GetParentID() != -1);
        XRCCTRL(*this, "btnResetCompiler", wxButton)->Enable(en &&
                                                        CompilerFactory::CompilerIndexOK(idx) &&
                                                        CompilerFactory::Compilers[idx]->GetParentID() == -1);
    }

    // compiler programs
    if (XRCCTRL(*this, "txtMasterPath", wxTextCtrl)) // "Programs" page exists?
    {
        en = !data; // global options selected
        int extraSel = XRCCTRL(*this, "lstExtraPaths", wxListBox)->GetSelection();
        XRCCTRL(*this, "txtMasterPath", wxTextCtrl)->Enable(en);
        XRCCTRL(*this, "btnMasterPath", wxButton)->Enable(en);
        XRCCTRL(*this, "btnExtraAdd", wxButton)->Enable(en);
        XRCCTRL(*this, "btnExtraEdit", wxButton)->Enable(en && extraSel != -1);
        XRCCTRL(*this, "btnExtraDelete", wxButton)->Enable(en && extraSel != -1);
        XRCCTRL(*this, "txtCcompiler", wxTextCtrl)->Enable(en);
        XRCCTRL(*this, "btnCcompiler", wxButton)->Enable(en);
        XRCCTRL(*this, "txtCPPcompiler", wxTextCtrl)->Enable(en);
        XRCCTRL(*this, "btnCPPcompiler", wxButton)->Enable(en);
        XRCCTRL(*this, "txtLinker", wxTextCtrl)->Enable(en);
        XRCCTRL(*this, "btnLinker", wxButton)->Enable(en);
        XRCCTRL(*this, "txtLibLinker", wxTextCtrl)->Enable(en);
        XRCCTRL(*this, "btnLibLinker", wxButton)->Enable(en);
        XRCCTRL(*this, "txtDebugger", wxTextCtrl)->Enable(en);
        XRCCTRL(*this, "btnDebugger", wxButton)->Enable(en);
        XRCCTRL(*this, "txtResComp", wxTextCtrl)->Enable(en);
        XRCCTRL(*this, "btnResComp", wxButton)->Enable(en);
        XRCCTRL(*this, "txtMake", wxTextCtrl)->Enable(en);
        XRCCTRL(*this, "btnMake", wxButton)->Enable(en);
        XRCCTRL(*this, "cmbCompiler", wxComboBox)->Enable(en);
    }
}

void CompilerOptionsDlg::EndModal(int retCode)
{
	wxTreeCtrl* tc = XRCCTRL(*this, "tcScope", wxTreeCtrl);
	ScopeTreeData* data = (ScopeTreeData*)tc->GetItemData(tc->GetSelection());
    int compilerIdx = XRCCTRL(*this, "cmbCompiler", wxComboBox)->GetSelection();
	DoSaveOptions(compilerIdx, data);
	CompilerFactory::SaveSettings();

    // compiler set
    int idx = XRCCTRL(*this, "cmbCompiler", wxComboBox)->GetSelection();
    if (m_pProject && !data->GetTarget() && idx != m_InitialCompilerIdx)
    {
        m_pProject->SetCompilerIndex(idx);
        UpdateCompilerForTargets(idx);
        wxMessageBox(_("You changed the compiler used for this project.\n"
                        "It is recommended that you fully rebuild your project, "
                        "otherwise linking errors might occur..."),
                        _("Notice"),
                        wxICON_EXCLAMATION);
    }

    if (!m_pProject)
    {
        // only do it for global compiler options
        // why does it crash for project compiler options???
        DoSaveCompilerPrograms(idx);
    }

	//others
    wxTextCtrl* txt = XRCCTRL(*this, "txtConsoleShell", wxTextCtrl);
    if (txt)
        ConfigManager::Get()->Write(_T("/compiler_gcc/console_shell"), txt->GetValue());
    wxSpinCtrl* spn = XRCCTRL(*this, "spnMaxErrors", wxSpinCtrl);
    if (spn)
        ConfigManager::Get()->Write(_T("/compiler_gcc/max_reported_errors"), spn->GetValue());

	wxDialog::EndModal(retCode);
}

void CompilerOptionsDlg::OnMyCharHook(wxKeyEvent& event)
{
    wxWindow* focused = wxWindow::FindFocus();
    if(!focused)
        { event.Skip();return; }
    int keycode = event.GetKeyCode();
    int id = focused->GetId();

    int myid = 0;
    unsigned int myidx = 0;

    const wxChar* str_libs[3] = { _T("btnEditLib"),_T("btnAddLib"),_T("btnDelLib") };
    const wxChar* str_dirs[3] = { _T("btnEditDir"),_T("btnAddDir"),_T("btnDelDir") };
    const wxChar* str_vars[3] = { _T("btnEditVar"),_T("btnAddVar"),_T("btnDeleteVar") };
    const wxChar* str_xtra[3] = { _T("btnExtraEdit"),_T("btnExtraAdd"),_T("btnExtraDelete") };

    if(keycode == WXK_RETURN || keycode == WXK_NUMPAD_ENTER)
        { myidx = 0; } // Edit
    else if(keycode == WXK_INSERT || keycode == WXK_NUMPAD_INSERT)
        { myidx = 1; } // Add
    else if(keycode == WXK_DELETE || keycode == WXK_NUMPAD_DELETE)
        { myidx = 2; } // Delete
    else
        { event.Skip();return; }

    if(     id == XRCID("lstLibs")) // Link libraries
        { myid =  wxXmlResource::GetXRCID(str_libs[myidx]); }
    else if(id == XRCID("lstIncludeDirs") || id == XRCID("lstLibDirs") || id == XRCID("lstResDirs")) // Directories
        { myid =  wxXmlResource::GetXRCID(str_dirs[myidx]); }
    else if(id == XRCID("lstVars")) // Custom Vars
        { myid =  wxXmlResource::GetXRCID(str_vars[myidx]); }
    else if(id == XRCID("lstExtraPaths")) // Extra Paths
        { myid =  wxXmlResource::GetXRCID(str_xtra[myidx]); }
    else
        myid = 0;

    // Generate the event
    if(myid == 0)
        event.Skip();
    else
    {
        wxCommandEvent newevent(wxEVT_COMMAND_BUTTON_CLICKED,myid);
        this->ProcessEvent(newevent);
    }
}

⌨️ 快捷键说明

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