void ClangPlugin::OnEditorClose(CodeBlocksEvent& event) { event.Skip(); #ifdef CLANGPLUGIN_TRACE_FUNCTIONS fprintf(stdout,"%s\n", __PRETTY_FUNCTION__); #endif int translId = m_TranslUnitId; EditorManager* edm = Manager::Get()->GetEditorManager(); if (!edm) { event.Skip(); return; } cbEditor* ed = edm->GetBuiltinEditor(event.GetEditor()); if (ed) { if (ed != m_pLastEditor) { translId = m_Proxy.GetTranslationUnitId(m_TranslUnitId, event.GetEditor()->GetFilename()); } } ClangProxy::RemoveTranslationUnitJob job( cbEVT_CLANG_ASYNCTASK_FINISHED, idClangRemoveTU, translId); m_Proxy.AppendPendingJob(job); if (translId == m_TranslUnitId) { m_TranslUnitId = wxNOT_FOUND; m_ReparseNeeded = 0; } }
// Code::Blocks events void ClangDiagnostics::OnEditorActivate(CodeBlocksEvent& event) { event.Skip(); if (!IsAttached()) return; cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(event.GetEditor()); if (ed) { wxString fn = ed->GetFilename(); ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("ClangLib")); m_bShowInline = cfg->ReadBool(wxT("/diagnostics_show_inline"), true); m_bShowWarning = cfg->ReadBool(wxT("/diagnostics_show_warnings"), true); m_bShowError = cfg->ReadBool(wxT("/diagnostics_show_errors"), true); m_TranslUnitId = m_pClangPlugin->GetTranslationUnitId(fn); cbStyledTextCtrl* stc = ed->GetControl(); stc->StyleSetBackground(51, Manager::Get()->GetColourManager()->GetColour(wxT("diagnostics_popup_warnbg"))); stc->StyleSetForeground(51, Manager::Get()->GetColourManager()->GetColour(wxT("diagnostics_popup_warntext"))); stc->StyleSetBackground(52, Manager::Get()->GetColourManager()->GetColour(wxT("diagnostics_popup_errbg"))); stc->StyleSetForeground(52, Manager::Get()->GetColourManager()->GetColour(wxT("diagnostics_popup_errtext"))); } m_Diagnostics.clear(); }
//TODO: Tooltips for error messages void CodeChecker::OnTooltip(CodeBlocksEvent& e) { EditorBase *edb=e.GetEditor(); if(!edb->IsBuiltinEditor()) return; cbEditor *ed=(cbEditor *)edb; int lexer=ed->GetControl()->GetLexer(); if(m_commands.find(lexer)==m_commands.end()) return; /* 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; int pos = ed->GetControl()->PositionFromPointClose(e.GetX(), e.GetY()); if(pos==wxSCI_INVALID_POSITION) return; int line = ed->GetControl()->LineFromPosition(pos); if(m_issues.find(ed->GetFilename())==m_issues.end()) return; CodeIssues &ci=m_issues[ed->GetFilename()]; for(CodeIssues::iterator it=ci.begin();it!=ci.end();++it) if(line==it->line) { if (ed->GetControl()->CallTipActive()) ed->GetControl()->CallTipCancel(); // LogMessage(wxString::Format(_("Tooltip dear: X - %i, Y - %i, pos - %i"),e.GetX(),e.GetY(),pos)); wxString msg=it->msg;//_T("Goodnight Dear"); ed->GetControl()->CallTipShow(pos, msg); } }
void ClangPlugin::OnEditorOpen(CodeBlocksEvent& event) { cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(event.GetEditor()); if (ed) m_EdOpenTimer.Start(ED_OPEN_DELAY, wxTIMER_ONE_SHOT); event.Skip(); }
void ClangPlugin::OnEditorSave(CodeBlocksEvent& event) { event.Skip(); #ifdef CLANGPLUGIN_TRACE_FUNCTIONS fprintf(stdout,"%s\n", __PRETTY_FUNCTION__); #endif EditorManager* edMgr = Manager::Get()->GetEditorManager(); cbEditor* ed = edMgr->GetBuiltinEditor(event.GetEditor()); if (!ed) { return; } if ( m_TranslUnitId == -1 ) return; std::map<wxString, wxString> unsavedFiles; // Our saved file is not yet known to all translation units since it's no longer in the unsaved files. We update them here unsavedFiles.insert(std::make_pair(ed->GetFilename(), ed->GetControl()->GetText())); for (int i = 0; i < edMgr->GetEditorsCount(); ++i) { cbEditor* editor = edMgr->GetBuiltinEditor(i); if (editor && editor->GetModified()) unsavedFiles.insert(std::make_pair(editor->GetFilename(), editor->GetControl()->GetText())); } ClangProxy::ReparseJob job( cbEVT_CLANG_ASYNCTASK_FINISHED, idClangReparse, m_TranslUnitId, m_CompileCommand, ed->GetFilename(), unsavedFiles, true); m_Proxy.AppendPendingJob(job); }
void ClangPlugin::OnEditorActivate(CodeBlocksEvent& event) { cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(event.GetEditor()); if (ed && !m_EdOpenTimer.IsRunning()) m_EdOpenTimer.Start(ED_ACTIVATE_DELAY, wxTIMER_ONE_SHOT); event.Skip(); }
void cbDebuggerPlugin::OnEditorOpened(CodeBlocksEvent& event) { // when an editor opens, look if we have breakpoints for it // and notify it... EditorBase* ed = event.GetEditor(); if (ed) { ed->RefreshBreakpointMarkers(); if (IsRunning()) { wxString filename; int line; GetCurrentPosition(filename, line); wxFileName edFileName(ed->GetFilename()); edFileName.Normalize(); wxFileName dbgFileName(filename); dbgFileName.Normalize(); if (dbgFileName.GetFullPath().IsSameAs(edFileName.GetFullPath()) && line != -1) { ed->SetDebugLine(line - 1); } } } event.Skip(); // must do }
void cbSmartIndentPlugin::OnCCDoneEvent(CodeBlocksEvent& event) { EditorBase* eb = event.GetEditor(); if (eb && eb->IsBuiltinEditor()) { cbEditor* ed = static_cast<cbEditor *>(eb); OnCCDone(ed); } }
// cbEVT_EDITOR_OPEN void CCManager::OnEditorOpen(CodeBlocksEvent& event) { cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(event.GetEditor()); if (ed) { ed->GetControl()->Connect(wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler(CCManager::OnAutocompleteSelect), nullptr, this); } }
void OpenFilesListPlugin::OnEditorOpened(CodeBlocksEvent& event) { EditorBase* eb = event.GetEditor(); if (Manager::Get()->GetProjectManager()->IsBusy() && eb && (m_EditorArray.Index(eb) == wxNOT_FOUND)) { m_EditorArray.Add(eb); } else { RefreshOpenFilesTree(eb); } }
void PythonDebugger::OnValueTooltip(CodeBlocksEvent& event) { event.Skip(); if (!m_DebuggerActive) return; if (!IsStopped()) return; EditorBase* base = event.GetEditor(); cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : 0; if (!ed) return; if(ed->IsContextMenuOpened()) { return; } // get rid of other calltips (if any) [for example the code completion one, at this time we // want the debugger value call/tool-tip to win and be shown] if(ed->GetControl()->CallTipActive()) { ed->GetControl()->CallTipCancel(); } const int style = event.GetInt(); if (style != wxSCI_P_DEFAULT && style != wxSCI_P_OPERATOR && style != wxSCI_P_IDENTIFIER && style != wxSCI_P_CLASSNAME) return; wxPoint pt; pt.x = event.GetX(); pt.y = event.GetY(); int pos = ed->GetControl()->PositionFromPoint(pt); int start = ed->GetControl()->WordStartPosition(pos, true); int end = ed->GetControl()->WordEndPosition(pos, true); while(ed->GetControl()->GetCharAt(start-1)==_T('.')) start=ed->GetControl()->WordStartPosition(start-2, true); wxString token; if (start >= ed->GetControl()->GetSelectionStart() && end <= ed->GetControl()->GetSelectionEnd()) { token = ed->GetControl()->GetSelectedText(); } else token = ed->GetControl()->GetTextRange(start,end); if (token.IsEmpty()) return; wxString cmd; cmd+=_T("pw ")+token+_T("\n"); DispatchCommands(cmd,DBGCMDTYPE_WATCHTOOLTIP,true); m_watch_tooltip_pos=pos; }
// cbEVT_EDITOR_DEACTIVATED void CCManager::OnDeactivateEd(CodeBlocksEvent& event) { DoHidePopup(); cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(event.GetEditor()); if (ed) { cbStyledTextCtrl* stc = ed->GetControl(); if (stc->CallTipActive()) stc->CallTipCancel(); m_CallTipActive = wxSCI_INVALID_POSITION; } event.Skip(); }
// cbEVT_EDITOR_CLOSE void CCManager::OnEditorClose(CodeBlocksEvent& event) { DoHidePopup(); cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(event.GetEditor()); if (ed == m_pLastEditor) m_pLastEditor = nullptr; if (ed && ed->GetControl()) { // TODO: is this ever called? ed->GetControl()->Disconnect(wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler(CCManager::OnAutocompleteSelect), nullptr, this); } }
void ClangPlugin::OnProjectOptionsChanged(CodeBlocksEvent& event) { event.Skip(); cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(event.GetEditor()); if (ed) { int compileCommandChanged = UpdateCompileCommand(ed); if (compileCommandChanged) { std::cout<<"OnProjectOptionsChanged: Calling reparse (compile command changed)"<<std::endl; RequestReparse(); } } }
void ClangCodeCompletion::OnEditorActivate(CodeBlocksEvent& event) { event.Skip(); cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(event.GetEditor()); if (ed) { wxString fn = ed->GetFilename(); ClTranslUnitId id = m_pClangPlugin->GetTranslationUnitId(fn); if (m_TranslUnitId != id ) { } m_TranslUnitId = id; } }
void TidyCmt::OnSave(CodeBlocksEvent& event) { cbEditor* ed = (cbEditor*) event.GetEditor(); cbStyledTextCtrl* ctrl = ed->GetControl(); unsigned int n = ctrl->GetLineCount(); int pos = ctrl->GetCurrentPos(); ctrl->SendMsg(SCI_SETUNDOCOLLECTION, 0, 0); for(unsigned int i = 0; i < n; ++i) { int a = ctrl->GetLineIndentPosition(i); int b = ctrl->GetLineEndPosition(i); wxString s = ctrl->GetTextRange(a,b); if(s.StartsWith(_T("//--"))) { unsigned int from = s.find_first_not_of(_T("/- \t\r\n")); unsigned int to = s.find_last_not_of(_T("/- \t\r\n")) + 1; s = s.Mid(from, to - from); unsigned int pad = len - s.length() - 8 - ctrl->GetLineIndentation(i); s = _T("//---- ") + s + _T(' ') + wxString(_T('-'), pad); ctrl->SetTargetStart(a); ctrl->SetTargetEnd(b); ctrl->ReplaceTarget(s); } if(s.StartsWith(_T("/*--")) && s.EndsWith(_T("*/"))) { s.RemoveLast().RemoveLast(); unsigned int from = s.find_first_not_of(_T("/*- \t\r\n")); unsigned int to = s.find_last_not_of(_T("/*- \t\r\n")) + 1; s = s.Mid(from, to - from); unsigned int pad = len - s.length() - 10 - ctrl->GetLineIndentation(i); s = _T("/*---- ") + s + _T(' ') + wxString(_T('-'), pad) + _T("*/"); ctrl->SetTargetStart(a); ctrl->SetTargetEnd(b); ctrl->ReplaceTarget(s); } } ctrl->SendMsg(SCI_SETUNDOCOLLECTION, 1, 0); ctrl->SetCurrentPos(pos); }
void SpellCheckerPlugin::OnEditorSaved(CodeBlocksEvent& event) { EditorBase *eb = event.GetEditor(); if ( !eb ) return; // the personal dictionary (with the current language) gets saved -> // reload its content into SpellChecker if ( eb->GetFilename() == m_sccfg->GetPersonalDictionaryFilename() ) { ConfigurePersonalDictionary(); // redo on line checks: m_pOnlineChecker->EnableOnlineChecks(m_sccfg->GetEnableOnlineChecker()); } }
// ---------------------------------------------------------------------------- void JumpTracker::OnEditorActivated(CodeBlocksEvent& event) // ---------------------------------------------------------------------------- { // Record this activation event and place activation in history event.Skip(); if (m_bShuttingDown) return; if (not IsAttached()) return; // Don't record closing editor activations if (m_bProjectClosing) return; EditorBase* eb = event.GetEditor(); wxString edFilename = eb->GetFilename(); cbEditor* cbed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(eb); if (not cbed) { // Since wxAuiNotebook added, there's no cbEditor associated during // an initial cbEVT_EDITOR_ACTIVATED event. So we ignore the inital // call and get OnEditorOpened() to re-issue OnEditorActivated() when // it does have a cbEditor, but no cbProject associated; #if defined(LOGGING) LOGIT( _T("JT [OnEditorActivated ignored:no cbEditor[%s]"), edFilename.c_str()); #endif return; } #if defined(LOGGING) LOGIT( _T("JT Editor Activated[%s]"), eb->GetShortName().c_str() ); #endif cbStyledTextCtrl* edstc = cbed->GetControl(); if(edstc->GetCurrentLine() == wxSCI_INVALID_POSITION) return; long edPosn = edstc->GetCurrentPos(); //if ( m_Cursor not_eq JumpDataContains(edFilename, edPosn) ) JumpDataAdd(edFilename, edPosn); return; }//OnEditorActivated
void ReopenEditor::OnEditorClosed(CodeBlocksEvent& event) { EditorBase* eb = event.GetEditor(); if(eb && eb->IsBuiltinEditor()) { cbProject* prj = nullptr; bool isPrjClosing = false; ProjectFile* prjf = ((cbEditor*)eb)->GetProjectFile(); if(prjf) prj = prjf->GetParentProject(); wxString name = wxEmptyString; if(prj) { isPrjClosing = (m_ClosedProjects.Index(prj) != wxNOT_FOUND); name = prj->GetTitle(); } if(!prj || (prj && !isPrjClosing)) { wxArrayString list; list.Add(eb->GetFilename()); if(prj) { list.Add(prj->GetTitle()); list.Add(prj->GetFilename()); } else { list.Add(_("<none>")); list.Add(_("<none>")); } m_pListLog->Prepend(list); m_pListLog->SetProject(0, prj); } } wxMenuBar* menuBar = Manager::Get()->GetAppFrame()->GetMenuBar(); menuBar->Enable(idReopenEditor, (m_pListLog->GetItemsCount() > 0)); event.Skip(); }
void cbDebuggerPlugin::ProcessValueTooltip(CodeBlocksEvent& event) { event.Skip(); if (cbDebuggerCommonConfig::GetFlag(cbDebuggerCommonConfig::RequireCtrlForTooltips)) { if (!wxGetKeyState(WXK_CONTROL)) return; } if (Manager::Get()->GetDebuggerManager()->GetInterfaceFactory()->IsValueTooltipShown()) return; if (!ShowValueTooltip(event.GetInt())) return; EditorBase* base = event.GetEditor(); cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : nullptr; if (!ed) return; if (ed->IsContextMenuOpened()) return; // get rid of other calltips (if any) [for example the code completion one, at this time we // want the debugger value call/tool-tip to win and be shown] if (ed->GetControl()->CallTipActive()) ed->GetControl()->CallTipCancel(); wxPoint pt; pt.x = event.GetX(); pt.y = event.GetY(); const wxString &token = GetEditorWordAtCaret(&pt); if (!token.empty()) { pt = ed->GetControl()->ClientToScreen(pt); OnValueTooltip(token, wxRect(pt.x - 5, pt.y, 10, 10)); } }
void CodeChecker::OnAnalyze(CodeBlocksEvent &e) { EditorBase *edb=e.GetEditor(); if(!edb->IsBuiltinEditor()) return; cbEditor *ed=(cbEditor *)edb; int lexer=ed->GetControl()->GetLexer(); if(m_commands.find(lexer)==m_commands.end()) return; ProcessQueueItems p; p.lang=lexer; p.file=ed->GetFilename(); ProcessQueue::iterator it=m_processqueue.begin(); for(;it!=m_processqueue.end();++it) if(it->file==p.file) break; if(it==m_processqueue.begin() || it==m_processqueue.end()) { m_processqueue.push_back(p); if(m_processqueue.size()==1) m_queuetimer.Start(1000,true); } }
void ReopenEditor::OnEditorOpened(CodeBlocksEvent& event) { if(m_pListLog->GetItemsCount() > 0) { EditorBase* eb = event.GetEditor(); if(eb && eb->IsBuiltinEditor()) { wxString fname = eb->GetFilename(); for(size_t i = m_pListLog->GetItemsCount(); i > 0; --i) { if(fname == m_pListLog->GetFilename(i-1)) { m_pListLog->RemoveAt(i-1); break; } } } } wxMenuBar* menuBar = Manager::Get()->GetAppFrame()->GetMenuBar(); menuBar->Enable(idReopenEditor, (m_pListLog->GetItemsCount() > 0)); event.Skip(); }
void ClangPlugin::OnEditorActivate(CodeBlocksEvent& event) { #ifdef CLANGPLUGIN_TRACE_FUNCTIONS fprintf(stdout,"%s\n", __PRETTY_FUNCTION__); #endif event.Skip(); cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(event.GetEditor()); if (ed) { if (ed != m_pLastEditor) { m_pLastEditor = ed; m_TranslUnitId = wxNOT_FOUND; m_ReparseNeeded = 0; } int reparseNeeded = UpdateCompileCommand(ed); if ((m_TranslUnitId == wxNOT_FOUND)||(reparseNeeded)) { wxCommandEvent evt(cbEVT_COMMAND_CREATETU, idClangCreateTU); evt.SetString(ed->GetFilename()); AddPendingEvent(evt); } } }
void RndGen::OnSave(CodeBlocksEvent& event) { ini_random(); cbEditor* ed = (cbEditor*) event.GetEditor(); cbStyledTextCtrl* ctrl = ed->GetControl(); wxString quicktest = ctrl->GetText(); if(quicktest.Contains(_T("RANDGEN:")) == false) return; int pos = ctrl->GetCurrentPos(); ctrl->SendMsg(SCI_SETUNDOCOLLECTION, 0, 0); wxRegEx int_re(_T("([0-9]+)\\ *;?\\ */\\*(\\ *RANDGEN:INT\\((.*))\\*/")); // wxRegEx alnum_re(_T("\\\"([^\"]+)\\\"\\ *;?\\ */\\*(\\ *RANDGEN:ALNUM\\((.*))\\*/")); wxRegEx alnum_re(_T("\\\"([^\\\"]+)\\\"\\ *;?\\ */\\*(\\ *RANDGEN:(ALNUM|DIGITS|CHARS|UPPERCHARS|LOWERCHARS)\\((.*))\\*/")); wxString c(_T("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")); assert(alnum_re.IsValid() && int_re.IsValid()); unsigned int n = ctrl->GetLineCount(); for(unsigned int i = 0; i < n; ++i) { int a = ctrl->GetLineIndentPosition(i); int b = ctrl->GetLineEndPosition(i); wxString s = ctrl->GetTextRange(a,b); // This is rather crude and will only match a single hit per line. // However, that should be good enough for any sensible use, as you will not want more than that anyway. // Still, if more correct matching is needed, feel free to do this as homework :-) if(int_re.Matches(s)) { wxString search = int_re.GetMatch(s, 1); long arg; int_re.GetMatch(s, 3).ToLong(&arg); wxString replace; int rnd = random() % (arg+1); replace.Printf(_T("%u"), rnd); s.Replace(search, replace, false); ctrl->SetTargetStart(a); ctrl->SetTargetEnd(b); ctrl->ReplaceTarget(s); } else if(alnum_re.Matches(s)) { wxString search = alnum_re.GetMatch(s, 1); long arg; wxString what = alnum_re.GetMatch(s, 3); alnum_re.GetMatch(s, 4).ToLong(&arg); wxString replace; if(what == _T("ALNUM")) { for(int i = 0; i<arg; ++i) replace += c[random() % c.length()]; } if(what == _T("DIGITS")) { for(int i = 0; i<arg; ++i) replace += c[random() % 10]; } if(what == _T("CHARS")) { for(int i = 0; i<arg; ++i) replace += c[10+ random() % (c.length() - 10)]; } if(what == _T("UPPERCHARS")) { for(int i = 0; i<arg; ++i) replace += c[36 + random() % 26]; } if(what == _T("LOWERCHARS")) { for(int i = 0; i<arg; ++i) replace += c[10 + random() % 26]; } s.Replace(search, replace, false); ctrl->SetTargetStart(a); ctrl->SetTargetEnd(b); ctrl->ReplaceTarget(s); } } ctrl->SendMsg(SCI_SETUNDOCOLLECTION, 1, 0); ctrl->SetCurrentPos(pos); }
void SpellCheckerPlugin::OnEditorTooltip(CodeBlocksEvent& event) { if ( !IsAttached() || wxGetKeyState(WXK_CONTROL) || !(m_sccfg->GetEnableSpellTooltips() || m_sccfg->GetEnableThesaurusTooltips())) { event.Skip(); return; } EditorBase* base = event.GetEditor(); cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : 0; if ( !ed || ed->IsContextMenuOpened() || wxWindow::FindFocus() != static_cast<wxWindow*>(ed->GetControl()) ) { event.Skip(); return; } cbStyledTextCtrl* stc = ed->GetControl(); if (!stc) return; int pos = stc->PositionFromPointClose(event.GetX(), event.GetY()); if (pos < 0 || pos >= stc->GetLength()) { event.Skip(); return; } wxString tip; int wordstart = pos, wordend = pos; while (wordstart) { if ( m_pSpellHelper->IsWhiteSpace( stc->GetCharAt(wordstart - 1) ) ) break; --wordstart; } while ( wordend < stc->GetLength() ) { if ( m_pSpellHelper->IsWhiteSpace( stc->GetCharAt(++wordend) ) ) break; } int tipWidth = 0; if ( m_sccfg->GetEnableSpellTooltips() && m_pSpellChecker->IsInitialized() && stc->IndicatorValueAt(m_pOnlineChecker->GetIndicator(), pos)) { // indicator is on -> check if we can find a suggestion wxString misspelledWord = stc->GetTextRange(wordstart, wordend); m_suggestions = m_pSpellChecker->GetSuggestions(misspelledWord); if (!m_suggestions.IsEmpty()) { // allow maximum 12 entries in 3 rows int lineWidth = 0; for (size_t i = 0; i < 12 && i < m_suggestions.size(); ++i) { tip << m_suggestions[i]; lineWidth += m_suggestions[i].Length(); if (i % 4 == 3) { tip << wxT(",\n"); if (lineWidth > tipWidth) tipWidth = lineWidth; lineWidth = 0; } else { tip << wxT(", "); lineWidth += 2; } } tip.RemoveLast(2); lineWidth -= 2; if (lineWidth > tipWidth) // in case the last line was not full, and thereby not checked tipWidth = lineWidth; } } else if ( m_sccfg->GetEnableThesaurusTooltips() && m_pThesaurus->IsOk() && m_pSpellHelper->HasStyleToBeChecked(ed->GetColourSet()->GetLanguageName(ed->GetLanguage()), event.GetInt())) { wxString word = stc->GetTextRange(wordstart, wordend); synonyms syn = m_pThesaurus->GetSynonyms(word); if (!syn.size()) // if not found, try lower case syn = m_pThesaurus->GetSynonyms(word.Lower()); if (syn.size()) { wxArrayString usedSyns; // avoid duplicate synonyms // allow maximum 12 entries in 4 rows synonyms::iterator it = syn.begin(); for (size_t i = 0; i < 4 && it != syn.end(); ++i, ++it) { wxString tipLine(it->first + wxT(": ")); std::vector< wxString > syns = syn[it->first]; size_t j = 0; for (size_t k = 0; k < 3 && j < syns.size(); ++j, ++k) { if (usedSyns.Index(syns[j]) == wxNOT_FOUND) { tipLine << syns[j] << wxT(", "); usedSyns.Add(syns[j]); } else --k; // synonym already listed, look for another word } tipLine.RemoveLast(2); if (tipLine.Length() > static_cast<size_t>(tipWidth)) tipWidth = tipLine.Length(); tip << tipLine << wxT("\n"); } tip.RemoveLast(); } } if (tip.IsEmpty()) { event.Skip(); return; } if (stc->CallTipActive()) stc->CallTipCancel(); // calculation from CC const int lnStart = stc->PositionFromLine(stc->LineFromPosition(pos)); // pos - lnStart == distance from start of line // + tipWidth + 1 == projected virtual position of tip end (with a 1 character buffer) from start of line // - (width_of_editor_in_pixels / width_of_character) == distance tip extends past window edge // horizontal scrolling is accounted for by PointFromPosition().x const int offset = tipWidth + pos + 1 - lnStart - (stc->GetSize().x - stc->PointFromPosition(lnStart).x) / stc->TextWidth(wxSCI_STYLE_LINENUMBER, _T("W")); if (offset > 0) pos -= offset; if (pos < lnStart) // do not go to previous line if tip is wider than editor pos = lnStart; stc->CallTipShow(pos, tip); event.SetExtraLong(1); // notify CC not to cancel this tooltip event.Skip(); }
// cbEVT_EDITOR_TOOLTIP void CCManager::OnEditorTooltip(CodeBlocksEvent& event) { event.Skip(); if (wxGetKeyState(WXK_CONTROL)) return; EditorBase* base = event.GetEditor(); cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : nullptr; if (!ed || ed->IsContextMenuOpened()) return; cbStyledTextCtrl* stc = ed->GetControl(); cbCodeCompletionPlugin* ccPlugin = GetProviderFor(ed); int pos = stc->PositionFromPointClose(event.GetX(), event.GetY()); if (!ccPlugin || pos < 0 || pos >= stc->GetLength()) { if (stc->CallTipActive() && event.GetExtraLong() == 0 && m_CallTipActive == wxSCI_INVALID_POSITION) static_cast<wxScintilla*>(stc)->CallTipCancel(); return; } int hlStart, hlEnd, argsPos; hlStart = hlEnd = argsPos = wxSCI_INVALID_POSITION; bool allowCallTip = true; const std::vector<cbCodeCompletionPlugin::CCToken>& tokens = ccPlugin->GetTokenAt(pos, ed, allowCallTip); std::set<wxString> uniqueTips; for (size_t i = 0; i < tokens.size(); ++i) uniqueTips.insert(tokens[i].displayName); wxStringVec tips(uniqueTips.begin(), uniqueTips.end()); const int style = event.GetInt(); if (!tips.empty()) { const int tknStart = stc->WordStartPosition(pos, true); const int tknEnd = stc->WordEndPosition(pos, true); if (tknEnd - tknStart > 2) { for (size_t i = 0; i < tips[0].Length(); ++i) { size_t hlLoc = tips[0].find(stc->GetTextRange(tknStart, tknEnd), i); if (hlLoc == wxString::npos) break; hlStart = hlLoc; hlEnd = hlStart + tknEnd - tknStart; if ( (hlStart > 0 && (tips[0][hlStart - 1] == wxT('_') || wxIsalpha(tips[0][hlStart - 1]))) || (hlEnd < static_cast<int>(tips[0].Length()) - 1 && (tips[0][hlEnd] == wxT('_') || wxIsalpha(tips[0][hlEnd]))) ) { i = hlEnd; hlStart = hlEnd = wxSCI_INVALID_POSITION; } else break; } } } else if ( allowCallTip && !( stc->IsString(style) || stc->IsComment(style) || stc->IsCharacter(style) || stc->IsPreprocessor(style) ) ) { const int line = stc->LineFromPosition(pos); if (pos + 4 > stc->PositionFromLine(line) + (int)ed->GetLineIndentString(line).Length()) { const CallTipVec& cTips = ccPlugin->GetCallTips(pos, style, ed, argsPos); for (size_t i = 0; i < cTips.size(); ++i) tips.push_back(cTips[i].tip); if (!tips.empty()) { hlStart = cTips[0].hlStart; hlEnd = cTips[0].hlEnd; } } } if (tips.empty()) { if (stc->CallTipActive() && event.GetExtraLong() == 0 && m_CallTipActive == wxSCI_INVALID_POSITION) static_cast<wxScintilla*>(stc)->CallTipCancel(); } else { DoShowTips(tips, stc, pos, argsPos, hlStart, hlEnd); event.SetExtraLong(1); } m_CallTipActive = wxSCI_INVALID_POSITION; }
void OpenFilesListPlugin::OnEditorSaved(CodeBlocksEvent& event) { // Manager::Get()->GetLogManager()->Log(_T("OnEditorSaved: ") + event.GetEditor()->GetFilename()); RefreshOpenFilesTree(event.GetEditor()); }