摺疊PHP的Scintilla代碼與其餘部分稍有不同,因爲它是由HTML詞法分析器處理的。下面的代碼將啓用PHP中的代碼摺疊。摺疊將看起來像Visual Studio(內部有一個加號的盒子)
wxStyledTextCtrl *ctrl = // from somewhere ....
wxColour backgroundColor = // the background color
wxColour color = // the foreground color
ctrl->SetProperty(wxT("fold"), wxT("1"));
ctrl->SetProperty(wxT("fold.comment"), wxT("1"));
ctrl->SetProperty(wxT("fold.html"), wxT("1"));
ctrl->SetFoldFlags(wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED | wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED);
int marginNum = 1; // can be 0-5 I believe
ctrl->SetMarginType(marginNum, wxSTC_MARGIN_SYMBOL);
ctrl->SetMarginWidth(marginNum, 16);
ctrl->SetMarginSensitive(marginNum, true);
ctrl->SetMarginMask(1, wxSTC_MASK_FOLDERS);
ctrl->SetFoldMarginColour(true, backgroundColor);
ctrl->SetFoldMarginHiColour(true, backgroundColor);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUS, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUS, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_BOXPLUSCONNECTED, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_BOXMINUSCONNECTED, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, backgroundColor, color);
它工作完美!我沒有啓用'fold.html'屬性,那就是問題所在。到現在爲止,我無法完成工作。非常感謝你! – 2011-07-08 16:11:59