2011-05-30 121 views
1

我需要使用WxStyledTextCtrl顯示PHP代碼。除了代碼摺疊,所有工作都很好。WxStyledTextCtrl PHP摺疊代碼

我遵循wxWidgets頁面http://wiki.wxwidgets.org/WxStyledTextCtrl中的示例,它們使用wxSTC_LEX_CPP詞法分析器,它可以工作。我適應他們的代碼,但是當我改變這樣的:

text->SetLexer(wxSTC_LEX_CPP); 

此:

text->SetLexer(wxSTC_LEX_HTML); 

代碼摺疊停止工作,我嘗試了一切,但我不能使它發揮作用。 我正在使用VS2010編譯的wxWidgets的最新版本。 任何幫助將不勝感激。

回答

2

摺疊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); 
+0

它工作完美!我沒有啓用'fold.html'屬性,那就是問題所在。到現在爲止,我無法完成工作。非常感謝你! – 2011-07-08 16:11:59