source insight plugin:
project & sanp images in:
svn://svn.code.sf.net/p/zyjcodeblocks/svnit need some change in SDK and codecompletion.
-------------------changes in SDK:------------------------------------
1.editorbase.cpp
EditorBase::EditorBase(wxWindow* parent, const wxString& filename)
: wxPanel(parent, -1),
m_IsBuiltinEditor(false),
m_Shortname(_T("")),
m_Filename(_T("")),
m_WinTitle(filename)
{
m_pData = new EditorBaseInternalData(this);
//add by nwork, if Open in output need not to add
if( Manager::Get()->GetEditorManager()->GetInoutput()==false )
Manager::Get()->GetEditorManager()->AddCustomEditor(this);
InitFilename(filename);
SetTitle(m_Shortname);
}
---------------------- changes in CodeCompletion ------------------------
codecompletion.cpp
void CodeCompletion::OnValueTooltip(CodeBlocksEvent& event)
{
//add by nwork, other plugins( SourceInsight,BrowseTracker) need this event
if( event.GetExtraLong() != 0 )
return;
event.Skip();
if (IsAttached() && m_InitDone)
{
if (!Manager::Get()->GetConfigManager(_T("code_completion"))->ReadBool(_T("eval_tooltip"), true))
return;
EditorBase* base = event.GetEditor();
cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : 0;
if (!ed || ed->IsContextMenuOpened())
return;
if (ed->GetControl()->CallTipActive())
ed->GetControl()->CallTipCancel();
// Manager::Get()->GetLogManager()->DebugLog(F(_T("CodeCompletion::OnValueTooltip: %p"), ed));
/* NOTE: The following 2 lines of codes can fix [Bug #11785].
* The solution may not the best one and it requires the editor
* to have the focus (even if C::B has the focus) in order to pop-up the tooltip. */
if (wxWindow::FindFocus() != static_cast<wxWindow*>(ed->GetControl()))
return;
// ignore comments, strings, preprocesor, etc
int style = event.GetInt();
if ( (style != wxSCI_C_DEFAULT)
&& (style != wxSCI_C_OPERATOR)
&& (style != wxSCI_C_IDENTIFIER) )
return;
int pos = ed->GetControl()->PositionFromPointClose(event.GetX(), event.GetY());
if (pos < 0 || pos >= ed->GetControl()->GetLength())
return;
int endOfWord = ed->GetControl()->WordEndPosition(pos, true);
Token* poutput_token = NULL;
Parser* parser = m_NativeParser.GetParserPtr();
if (parser)
{
TokenIdxSet result;
// int endOfWord = ed->GetControl()->WordEndPosition(pos, true);
if (m_NativeParser.MarkItemsByAI(result, true, true, true, endOfWord))
{
wxString msg;
int count = 0;
bool flag = false;
for (TokenIdxSet::iterator it = result.begin(); it != result.end(); ++it)
{
Token* token = parser->GetTokens()->at(*it);
if (token)
{
msg << token->DisplayName() << _T("\n");
++count;
if (count > 32) // allow max 32 matches (else something is definitely wrong)
{
msg.Clear();
break;
}
if( poutput_token==NULL || token->m_ImplFileIdx )
poutput_token = token;
}
}
if (!msg.IsEmpty())
{
if( msg.Find( '\r' ) >=0 )
msg.Replace( "\r", " " );
if( msg.Last() == '\n' )
msg.RemoveLast();
if( msg.First('\t') >=0 )
msg.Replace( "\t", " " );
ed->GetControl()->CallTipShow(pos, msg);
// Manager::Get()->GetLogManager()->DebugLog(F(msg));
}
}
}
//add by nwork for sourceinsight
if( poutput_token )
{
int line;
wxString filename = poutput_token->GetImplFilename();
wxString dispname = poutput_token->DisplayName();
line = poutput_token->m_ImplLine;
if( filename.IsEmpty() )
{
filename = poutput_token->GetFilename();
line = poutput_token->m_Line;
}
//dispname|filename
dispname += "|";
dispname += filename;
CodeBlocksEvent event(cbEVT_EDITOR_TOOLTIP);
event.SetEditor(ed);
event.SetInt(line);
event.SetString(dispname);
event.SetExtraLong(-1); //for source insight
Manager::Get()->GetPluginManager()->NotifyPlugins(event);
} }
}