void ZoomNavigator::OnPreviewClicked(wxMouseEvent& e) { IEditor* curEditor = m_mgr->GetActiveEditor(); // user clicked on the preview CHECK_CONDITION(m_startupCompleted); CHECK_CONDITION(curEditor); CHECK_CONDITION(m_enabled); // the first line is taken from the preview int pos = m_text->PositionFromPoint(e.GetPosition()); if(pos == wxSTC_INVALID_POSITION) { return; } int first = m_text->LineFromPosition(pos); int nLinesOnScreen = curEditor->GetCtrl()->LinesOnScreen(); first -= (nLinesOnScreen / 2); if(first < 0) first = 0; // however, the last line is set according to the actual editor int last = nLinesOnScreen + first; PatchUpHighlights(first, last); curEditor->GetCtrl()->SetFirstVisibleLine(first); curEditor->SetCaretAt(curEditor->PosFromLine(first + (nLinesOnScreen / 2))); // reset the from/last members to avoid unwanted movements in the 'OnTimer' function m_markerFirstLine = curEditor->GetCtrl()->GetFirstVisibleLine(); m_markerLastLine = m_markerFirstLine + curEditor->GetCtrl()->LinesOnScreen(); }
void CMakeHelpTab::CreateHelpPage(const wxString& content, const wxString& subject) { wxString text = content; text.Replace("<br />", "\n"); text.Replace("<" , "<"); text.Replace(">" , ">"); text.Replace("\r", ""); text.Replace("\n\n", "\n"); text.Replace("::\n", "\n\n"); IManager* manager = ::clGetManager(); // Write the content of the help into a temporary file wxFileName fnTemp = wxFileName::CreateTempFileName("cmake"); wxFileName fnCMakeHelpFile = fnTemp; fnCMakeHelpFile.SetFullName("CMakeHelp.cmake"); if(!FileUtils::WriteFileContent(fnCMakeHelpFile, text)) return; if(manager->OpenFile(fnCMakeHelpFile.GetFullPath())) { IEditor* activeEditor = manager->GetActiveEditor(); if(activeEditor && activeEditor->GetFileName().GetFullPath() == fnCMakeHelpFile.GetFullPath()) { activeEditor->GetCtrl()->SetEditable(true); activeEditor->ReloadFile(); activeEditor->GetCtrl()->SetFirstVisibleLine(0); activeEditor->GetCtrl()->SetEditable(false); } } }
void PHPEditorContextMenu::OnInsertDoxyComment(wxCommandEvent& e) { IEditor* editor = m_manager->GetActiveEditor(); if(editor) { PHPEntityBase::Ptr_t entry = PHPCodeCompletion::Instance()->GetPHPEntityAtPos(editor, editor->GetCurrentPosition()); if(entry) { wxStyledTextCtrl* ctrl = editor->GetCtrl(); ctrl->BeginUndoAction(); wxString comment = entry->FormatPhpDoc(); // Create the whitespace buffer int lineStartPos = ctrl->PositionFromLine(ctrl->GetCurrentLine()); int lineEndPos = lineStartPos + ctrl->LineLength(ctrl->GetCurrentLine()); // Collect all whitespace from the begining of the line until the first non whitespace // character we find wxString whitespace; for(int i = lineStartPos; lineStartPos < lineEndPos; ++i) { if(ctrl->GetCharAt(i) == ' ' || ctrl->GetCharAt(i) == '\t') { whitespace << (wxChar)ctrl->GetCharAt(i); } else { break; } } // Prepare the comment block wxArrayString lines = ::wxStringTokenize(comment, "\n", wxTOKEN_STRTOK); for(size_t i = 0; i < lines.size(); ++i) { lines.Item(i).Prepend(whitespace); } // Glue the lines back together wxString doxyBlock = ::wxJoin(lines, '\n'); doxyBlock << "\n"; // Insert the text ctrl->InsertText(lineStartPos, doxyBlock); // Try to place the caret after the @brief wxRegEx reBrief("[@\\]brief[ \t]*"); if(reBrief.IsValid() && reBrief.Matches(doxyBlock)) { wxString match = reBrief.GetMatch(doxyBlock); // Get the index int where = doxyBlock.Find(match); if(where != wxNOT_FOUND) { where += match.length(); int caretPos = lineStartPos + where; editor->SetCaretAt(caretPos); // Remove the @brief as its non standard in the PHP world editor->GetCtrl()->DeleteRange(caretPos - match.length(), match.length()); } } editor->GetCtrl()->EndUndoAction(); } } }
// ------------------------------------------------------------ void SpellCheck::OnContextMenu(wxCommandEvent& e) { IEditor* editor = GetEditor(); if(!editor) { e.Skip(); return; } wxPoint pt = wxGetMousePosition(); pt = editor->GetCtrl()->ScreenToClient(pt); int pos = editor->GetCtrl()->PositionFromPoint(pt); if(editor->GetCtrl()->IndicatorValueAt(3, pos) == 1) { wxMenu popUp; m_timer.Stop(); int start = editor->WordStartPos(pos, true); editor->SelectText(start, editor->WordEndPos(pos, true) - start); wxString sel = editor->GetSelection(); wxArrayString sugg = m_pEngine->GetSuggestions(sel); for(wxUint32 i = 0; i < sugg.GetCount(); i++) { popUp.Append(SPC_BASEID + i, sugg[i], ""); } if(sugg.GetCount() == 0) popUp.SetTitle(_("No suggestions")); else popUp.AppendSeparator(); popUp.Append(SPC_BASEID - 1, _("Ignore"), ""); popUp.Append(SPC_BASEID - 2, _("Add"), ""); int index = editor->GetCtrl()->GetPopupMenuSelectionFromUser(popUp); if(index != wxID_NONE) { if(index >= SPC_BASEID) { index -= SPC_BASEID; editor->ReplaceSelection(sugg[index]); } else { if(index == SPC_BASEID - 1) m_pEngine->AddWordToIgnoreList(sel); else if(index == SPC_BASEID - 2) m_pEngine->AddWordToUserDict(sel); } } m_timer.Start(PARSE_TIME); } else e.Skip(); }
void wxCodeCompletionBoxManager::InsertSelectionTemplateFunction(const wxString& selection) { IManager* manager = ::clGetManager(); IEditor* editor = manager->GetActiveEditor(); if(editor) { wxStyledTextCtrl* ctrl = editor->GetCtrl(); // Default behviour: remove the partial text from teh editor and replace it // with the selection int start = ctrl->WordStartPosition(ctrl->GetCurrentPos(), true); int end = ctrl->GetCurrentPos(); ctrl->SetSelection(start, end); wxString entryText = selection; if(entryText.Find("(") != wxNOT_FOUND) { // a function like wxString textToInsert = entryText.BeforeFirst('('); textToInsert << "<>()"; ctrl->ReplaceSelection(textToInsert); // Place the caret between the angle brackets int caretPos = start + textToInsert.Len() - 3; ctrl->SetCurrentPos(caretPos); ctrl->SetSelection(caretPos, caretPos); } else { ctrl->ReplaceSelection(entryText); } } }
void MainBook::DoUpdateNotebookTheme() { size_t initialStyle = m_book->GetStyle(); size_t style = m_book->GetStyle(); if(EditorConfigST::Get()->GetOptions()->IsTabColourMatchesTheme()) { // Update theme IEditor* editor = GetActiveEditor(); if(editor) { wxColour bgColour = editor->GetCtrl()->StyleGetBackground(0); if(DrawingUtils::IsDark(bgColour) && !(m_book->GetStyle() & kNotebook_DarkTabs)) { style &= ~kNotebook_LightTabs; style |= kNotebook_DarkTabs; } else if(!DrawingUtils::IsDark(bgColour) && !(m_book->GetStyle() & kNotebook_LightTabs)) { style &= ~kNotebook_DarkTabs; style |= kNotebook_LightTabs; } } else { style &= ~kNotebook_DarkTabs; style |= kNotebook_LightTabs; } } else { style &= ~kNotebook_DarkTabs; style |= kNotebook_LightTabs; } if(!EditorConfigST::Get()->GetOptions()->IsTabHasXButton()) { style &= ~(kNotebook_CloseButtonOnActiveTab | kNotebook_CloseButtonOnActiveTabFireEvent); } else { style |= (kNotebook_CloseButtonOnActiveTab | kNotebook_CloseButtonOnActiveTabFireEvent); } if(initialStyle != style) { m_book->SetStyle(style); } }
void ZoomNavigator::DoUpdate() { // sanity tests CHECK_CONDITION(m_enabled); CHECK_CONDITION(!m_mgr->IsShutdownInProgress()); IEditor* curEditor = m_mgr->GetActiveEditor(); if(!curEditor && !m_text->IsEmpty()) { DoCleanup(); } CHECK_CONDITION(curEditor); wxStyledTextCtrl* stc = curEditor->GetCtrl(); CHECK_CONDITION(stc); if(curEditor->GetFileName().GetFullPath() != m_curfile) { SetEditorText(curEditor); } int first = stc->GetFirstVisibleLine(); int last = stc->LinesOnScreen() + first; if(m_markerFirstLine != first || m_markerLastLine != last) { PatchUpHighlights(first, last); SetZoomTextScrollPosToMiddle(stc); } }
void LLDBPlugin::OnToggleBreakpoint(clDebugEvent& event) { // Call Skip() here since we want codelite to manage the breakpoint as well ( in term of serialization in the // session file ) CHECK_IS_LLDB_SESSION(); // check to see if we are removing a breakpoint or adding one LLDBBreakpoint::Ptr_t bp(new LLDBBreakpoint(event.GetFileName(), event.GetInt())); IEditor* editor = m_mgr->GetActiveEditor(); if(editor) { // get the marker type set on the line int markerType = editor->GetCtrl()->MarkerGet(bp->GetLineNumber() - 1); for(size_t type = smt_FIRST_BP_TYPE; type <= smt_LAST_BP_TYPE; ++type) { int markerMask = (1 << type); if(markerType & markerMask) { // removing a breakpoint. "DeleteBreakpoint" will handle the interactive/non-interactive mode // of the debugger m_connector.MarkBreakpointForDeletion(bp); m_connector.DeleteBreakpoints(); return; } } // if we got here, its a new breakpoint, add it // Add the breakpoint to the list of breakpoints m_connector.AddBreakpoint(bp->GetFilename(), bp->GetLineNumber()); // apply it. In case the debugger can not interact with, it will be interrupted and the interrupt reason // will be set to ApplyBreakpoints m_connector.ApplyBreakpoints(); } }
void WebTools::OnCodeComplete(clCodeCompletionEvent& event) { event.Skip(); IEditor* editor = m_mgr->GetActiveEditor(); if(editor && m_jsCodeComplete && IsJavaScriptFile(editor)) { event.Skip(false); if(InsideJSComment(editor) || InsideJSString(editor)) { // User the word completion plugin instead m_jsCodeComplete->TriggerWordCompletion(); } else { m_jsCodeComplete->CodeComplete(editor); } } else if(editor && m_xmlCodeComplete && editor->GetCtrl()->GetLexer() == wxSTC_LEX_XML) { // an XML file event.Skip(false); m_xmlCodeComplete->XmlCodeComplete(editor); } else if(editor && m_xmlCodeComplete && IsHTMLFile(editor)) { // Html code completion event.Skip(false); m_xmlCodeComplete->HtmlCodeComplete(editor); } else if(editor && m_cssCodeComplete && IsCSSFile(editor)) { // CSS code completion event.Skip(false); m_cssCodeComplete->CssCodeComplete(editor); } }
wxStyledTextCtrl* PHPEditorContextMenu::DoGetActiveScintila() { IEditor* editor = m_manager->GetActiveEditor(); if(editor) { return editor->GetCtrl(); } return NULL; }
void WebTools::ColourJavaScript(const JavaScriptSyntaxColourThread::Reply& reply) { IEditor* editor = m_mgr->FindEditor(reply.filename); if(editor) { wxStyledTextCtrl* ctrl = editor->GetCtrl(); ctrl->SetKeyWords(1, reply.properties); ctrl->SetKeyWords(3, reply.functions); m_lastColourUpdate = time(NULL); } }
void PHPCodeCompletion::DoOpenEditorForEntry(PHPEntityBase::Ptr_t entry) { // Open the file (make sure we use the 'OpenFile' so we will get a browsing record) IEditor* editor = m_manager->OpenFile(entry->GetFilename().GetFullPath(), wxEmptyString, entry->GetLine()); if(editor) { // Select the word in the editor (its a new one) int selectFromPos = editor->GetCtrl()->PositionFromLine(entry->GetLine()); DoSelectInEditor(editor, entry->GetShortName(), selectFromPos); } }
void MemCheckOutputView::JumpToLocation(const wxDataViewItem& item) { // CL_DEBUG1(PLUGIN_PREFIX("MemCheckOutputView::JumpToLocation()")); MemCheckErrorLocationReferrer* locationRef = dynamic_cast<MemCheckErrorLocationReferrer*>(m_dataViewCtrlErrorsModel->GetClientObject(item)); if(!locationRef) return; int line = locationRef->Get().line - 1; wxString fileName = locationRef->Get().getFile(); if(line < 0 || fileName.IsEmpty()) return; if(m_mgr->OpenFile(fileName, wxEmptyString, line)) { IEditor* editor = m_mgr->GetActiveEditor(); if(editor) { int posStart = editor->GetCtrl()->PositionFromLine(line); int lineLen = editor->GetCtrl()->LineLength(line); editor->SelectText(posStart, lineLen - 1); } } }
void NodeJSBptManager::OnEditorChanged(wxCommandEvent& e) { e.Skip(); // Apply breakpoints for this editor if(clGetManager()) { IEditor* editor = clGetManager()->GetActiveEditor(); if(editor) { NodeJSBreakpoint::List_t bps; if(GetBreakpointsForFile(editor->GetFileName().GetFullPath(), bps)) { NodeJSBreakpoint::List_t::iterator iter = bps.begin(); for(; iter != bps.end(); ++iter) { int markerMask = editor->GetCtrl()->MarkerGet(iter->GetLine() - 1); if(!(markerMask & mmt_breakpoint)) { // No marker on this line yet // add one editor->GetCtrl()->MarkerAdd(iter->GetLine() - 1, smt_breakpoint); } } } } } }
void XMLCodeCompletion::OnCodeComplete(clCodeCompletionEvent& event) { event.Skip(); IEditor* editor = dynamic_cast<IEditor*>(event.GetEditor()); if(editor && editor->GetCtrl()->GetLexer() == wxSTC_LEX_XML) { // an XML file event.Skip(false); XmlCodeComplete(editor); } else if(editor && m_plugin->IsHTMLFile(editor)) { // Html code completion event.Skip(false); HtmlCodeComplete(editor); } }
bool PHPEditorContextMenu::IsIncludeOrRequireStatement(wxString& includeWhat) { // Do a basic check to see whether this line is include statement or not. // Don't bother in full parsing the file since it can be a quite an expensive operation // (include|require_once|require|include_once)[ \t\\(]*(.*?)[\\) \t)]*; static wxRegEx reInclude(wxT("(include|require_once|require|include_once)[ \t\\(]*(.*?)[\\) \t]*;"), wxRE_ADVANCED); IEditor* editor = m_manager->GetActiveEditor(); if(!editor) return false; wxString line = editor->GetCtrl()->GetLine(editor->GetCurrentLine()); if(reInclude.IsValid() && reInclude.Matches(line)) { includeWhat = reInclude.GetMatch(line, 2); return true; } return false; }
void PHPCodeCompletion::GotoDefinition(IEditor* editor, int pos) { CHECK_PTR_RET(editor); wxStyledTextCtrl* sci = editor->GetCtrl(); CHECK_PTR_RET(sci); PHPLocation::Ptr_t definitionLocation = FindDefinition(editor, pos); CHECK_PTR_RET(definitionLocation); // Open the file (make sure we use the 'OpenFile' so we will get a browsing record) IEditor* activeEditor = m_manager->OpenFile(definitionLocation->filename, wxEmptyString, definitionLocation->linenumber); if(activeEditor) { int selectFromPos = activeEditor->GetCtrl()->PositionFromLine(definitionLocation->linenumber); DoSelectInEditor(activeEditor, definitionLocation->what, selectFromPos); } }
void PHPEditorContextMenu::OnGenerateSettersGetters(wxCommandEvent& e) { // CHeck the current context IEditor* editor = m_manager->GetActiveEditor(); if(editor) { // determine the scope name at the current position // Parse until the current position wxString text = editor->GetTextRange(0, editor->GetCurrentPosition()); PHPSourceFile sourceFile(text); sourceFile.SetParseFunctionBody(true); sourceFile.SetFilename(editor->GetFileName()); sourceFile.Parse(); const PHPEntityClass* scopeAtPoint = sourceFile.Class()->Cast<PHPEntityClass>(); if(!scopeAtPoint) { // Could not determine the scope at the give location return; } // get the class name wxString className = scopeAtPoint->GetShortName(); // generate the code to generate wxString textToAdd; PHPSettersGettersDialog dlg(EventNotifier::Get()->TopFrame(), editor, m_manager); if(dlg.ShowModal() == wxID_OK) { PHPSetterGetterEntry::Vec_t members = dlg.GetMembers(); for(size_t i = 0; i < members.size(); ++i) { textToAdd << members.at(i).GetSetter(dlg.GetScope(), dlg.GetFlags()) << "\n"; textToAdd << members.at(i).GetGetter(dlg.GetFlags()) << "\n"; } if(!textToAdd.IsEmpty()) { int line = PHPCodeCompletion::Instance()->GetLocationForSettersGetters( editor->GetTextRange(0, editor->GetLength()), className); if(!textToAdd.IsEmpty() && line != wxNOT_FOUND) { editor->GetCtrl()->InsertText(editor->PosFromLine(line), textToAdd); } } } } }
void AbbreviationPlugin::OnAbbreviations(wxCommandEvent& e) { IEditor* editor = m_mgr->GetActiveEditor(); if(!editor) { return; } AbbreviationJSONEntry jsonData; if(!m_config.ReadItem(&jsonData)) { // merge the data from the old configuration AbbreviationEntry data; m_mgr->GetConfigTool()->ReadObject(wxT("AbbreviationsData"), &data); jsonData.SetAutoInsert(data.GetAutoInsert()); jsonData.SetEntries(data.GetEntries()); m_config.WriteItem(&jsonData); } wxString wordAtCaret = editor->GetWordAtCaret(); bool autoInsert = (jsonData.IsAutoInsert() && wordAtCaret.IsEmpty() == false); if(autoInsert) { autoInsert = InsertExpansion(wordAtCaret); } if(!autoInsert) { static wxBitmap bmp = LoadBitmapFile(wxT("abbrev.png")); if(bmp.IsOk()) { wxCodeCompletionBoxEntry::Vec_t ccEntries; wxCodeCompletionBox::BmpVec_t bitmaps; bitmaps.push_back(bmp); // search for the old item const JSONElement::wxStringMap_t& entries = jsonData.GetEntries(); JSONElement::wxStringMap_t::const_iterator iter = entries.begin(); for(; iter != entries.end(); ++iter) { ccEntries.push_back(wxCodeCompletionBoxEntry::New(iter->first, 0)); } wxCodeCompletionBoxManager::Get().ShowCompletionBox( editor->GetCtrl(), ccEntries, bitmaps, wxCodeCompletionBox::kNone, wxNOT_FOUND, this); } } }
void clAuiMainNotebookTabArt::DoSetColours() { // Set the colours // based on the selected book theme if(!m_bgColour.IsOk()) { DoInitializeColoursFromTheme(); } // If we have an active editor, update the colours, if not - keep the old ones IEditor* editor = m_manager->GetActiveEditor(); SetLightColours(); // We use the colour theme based on the active editor if(editor) { // Change lightness ranges between 0-200 // 0 would be completely black, 200 completely white an ialpha of 100 returns the same colour. m_activeTabBgColour = editor->GetCtrl()->StyleGetBackground(0); if(DrawingUtils::IsDark(m_activeTabBgColour)) { SetDarkColours(); } } }
wxCodeCompletionBox::wxCodeCompletionBox(wxWindow* parent, wxEvtHandler* eventObject, size_t flags) : wxCodeCompletionBoxBase(parent) , m_index(0) , m_stc(NULL) , m_startPos(wxNOT_FOUND) , m_useLightColours(false) , m_eventObject(eventObject) , m_tipWindow(NULL) , m_flags(flags) { SetBackgroundStyle(wxBG_STYLE_PAINT); m_ccFont = DrawingUtils::GetDefaultFixedFont(); SetCursor(wxCURSOR_HAND); // Calculate the size of the box int singleLineHeight = GetSingleLineHeight(); int boxHeight = singleLineHeight * LINES_PER_PAGE; int boxWidth = BOX_WIDTH; // 100 pixels wxSize boxSize = wxSize(boxWidth, boxHeight); wxRect rect(boxSize); // Set the default bitmap list BitmapLoader* bmpLoader = clGetManager()->GetStdIcons(); m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/class")); // 0 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/struct")); // 1 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/namespace")); // 2 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/member_public")); // 3 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/typedef")); // 4 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/member_private")); // 5 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/member_public")); // 6 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/member_protected")); // 7 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/function_private")); // 8 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/function_public")); // 9 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/function_protected")); // 10 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/typedef")); // 11 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/enum")); // 12 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/enumerator")); // 13 m_bitmaps.push_back(bmpLoader->LoadBitmap("mime/16/cpp")); // 14 m_bitmaps.push_back(bmpLoader->LoadBitmap("mime/16/h")); // 15 m_bitmaps.push_back(bmpLoader->LoadBitmap("mime/16/text")); // 16 m_bitmaps.push_back(bmpLoader->LoadBitmap("cc/16/cpp_keyword")); // 17 InitializeDefaultBitmaps(); // Increase the size by 2 pixel for each dimension rect.Inflate(2, 2); SetSize(rect); m_canvas->SetBackgroundStyle(wxBG_STYLE_PAINT); m_canvas->Bind(wxEVT_LEFT_DOWN, &wxCodeCompletionBox::OnLeftDClick, this); m_canvas->Bind(wxEVT_LEFT_DCLICK, &wxCodeCompletionBox::OnLeftDClick, this); // Default colorus (dark theme) clColourPalette palette = DrawingUtils::GetColourPalette(); m_lightBorder = wxColour("rgb(77, 77, 77)"); m_darkBorder = wxColour("rgb(54, 54, 54)"); m_penColour = palette.penColour; m_bgColour = palette.bgColour; m_textColour = palette.textColour; m_selectedTextColour = palette.selecteTextColour; m_selection = palette.selectionBgColour; m_scrollBgColour = wxColour("rgb(50, 50, 50)"); IManager* manager = ::clGetManager(); if(manager) { IEditor* editor = manager->GetActiveEditor(); if(editor) { wxColour bgColour = editor->GetCtrl()->StyleGetBackground(0); if(!DrawingUtils::IsDark(bgColour)) { m_useLightColours = true; // Need bright colours m_lightBorder = *wxWHITE; m_darkBorder = wxColour("rgb(207, 207, 207)"); m_scrollBgColour = wxColour("rgb(198, 198, 198)"); } } } m_bmpDown = wxXmlResource::Get()->LoadBitmap("cc-box-down"); m_bmpDownEnabled = m_bmpDown.ConvertToDisabled(); m_bmpUp = wxXmlResource::Get()->LoadBitmap("cc-box-up"); m_bmpUpEnabled = m_bmpUp.ConvertToDisabled(); if(m_useLightColours) { // swap between the disabled and enabeld bitmaps { wxBitmap tmpBitmap; tmpBitmap = m_bmpDown; m_bmpDown = m_bmpDownEnabled; m_bmpDownEnabled = tmpBitmap; } { wxBitmap tmpBitmap; tmpBitmap = m_bmpUp; m_bmpUp = m_bmpUpEnabled; m_bmpUpEnabled = tmpBitmap; } } }
void LLDBPlugin::OnLLDBStopped(LLDBEvent& event) { event.Skip(); CL_DEBUGS(wxString() << "CODELITE>> LLDB stopped at " << event.GetFileName() << ":" << event.GetLinenumber()); m_connector.SetCanInteract(true); if(event.GetInterruptReason() == kInterruptReasonNone) { if(m_raisOnBpHit) { EventNotifier::Get()->TopFrame()->Raise(); } // Mark the debugger line / file IEditor* editor = m_mgr->FindEditor(event.GetFileName()); if(!editor && wxFileName::Exists(event.GetFileName())) { // Try to open the editor editor = m_mgr->OpenFile(event.GetFileName(), "", event.GetLinenumber() - 1); } if(editor) { // select it first if(editor != m_mgr->GetActiveEditor()) { m_mgr->SelectPage(editor->GetCtrl()); } else { // just make sure that the page has the focus editor->SetActive(); } // clear the markers ClearDebuggerMarker(); SetDebuggerMarker(editor->GetCtrl(), event.GetLinenumber() - 1); } else { ClearDebuggerMarker(); } // request for local variables m_connector.RequestLocals(); wxString message; if(!m_stopReasonPrompted && event.ShouldPromptStopReason(message)) { m_stopReasonPrompted = true; // show this message only once per debug session wxString msg; msg << "Program stopped\nStop reason: " << message; ::wxMessageBox(msg, "CodeLite", wxICON_ERROR | wxOK | wxCENTER); } } else if(event.GetInterruptReason() == kInterruptReasonApplyBreakpoints) { CL_DEBUG("Applying breakpoints and continue..."); m_connector.ApplyBreakpoints(); m_connector.Continue(); } else if(event.GetInterruptReason() == kInterruptReasonDeleteAllBreakpoints) { CL_DEBUG("Deleting all breakpoints"); m_connector.DeleteAllBreakpoints(); m_connector.Continue(); } else if(event.GetInterruptReason() == kInterruptReasonDeleteBreakpoint) { CL_DEBUG("Deleting all pending deletion breakpoints"); m_connector.DeleteBreakpoints(); m_connector.Continue(); } else if(event.GetInterruptReason() == kInterruptReasonDetaching) { CL_DEBUG("Detaching from process"); m_connector.Detach(); } }
void clAuiMainNotebookTabArt::DoSetColours() { // Set the colours // based on the selected book theme if(!m_bgColour.IsOk()) { DoInitializeColoursFromTheme(); } // If we have an active editor, update the colours, if not - keep the old ones IEditor* editor = m_manager->GetActiveEditor(); // Default buttons m_bmpClose = wxXmlResource::Get()->LoadBitmap("tab_x_close"); m_bmpCloseHover = wxXmlResource::Get()->LoadBitmap("tab_x_close_hover"); m_bmpClosePressed = wxXmlResource::Get()->LoadBitmap("tab_x_close_pressed"); // We use the colour theme based on the active editor if(editor) { // Change lightness ranges between 0-200 // 0 would be completely black, 200 completely white an ialpha of 100 returns the same colour. m_activeTabBgColour = editor->GetCtrl()->StyleGetBackground(0); if(DrawingUtils::IsDark(m_activeTabBgColour)) { // Adjust the button colours m_bmpClose = wxXmlResource::Get()->LoadBitmap("tab_x_close_dark"); m_bmpCloseHover = wxXmlResource::Get()->LoadBitmap("tab_x_close_dark_hover"); m_bmpClosePressed = wxXmlResource::Get()->LoadBitmap("tab_x_close_dark_pressed"); // adjust some colours m_activeTabTextColour = *wxWHITE; m_tabTextColour = m_activeTabTextColour.ChangeLightness(70); m_activeTabPenColour = m_activeTabBgColour.ChangeLightness(80); m_tabBgColour = m_activeTabBgColour.ChangeLightness(110); #ifdef __WXMAC__ m_bgColour = m_activeTabBgColour.ChangeLightness(150); #else m_bgColour = m_activeTabBgColour.ChangeLightness(130); #endif m_penColour = m_activeTabPenColour.ChangeLightness(110); m_innerPenColour = m_penColour.ChangeLightness(115); } else { wxColour tmp = m_activeTabBgColour; DoInitializeColoursFromTheme(); m_activeTabBgColour = tmp; m_activeTabTextColour = *wxBLACK; m_tabTextColour = m_activeTabTextColour.ChangeLightness(130); #ifdef __WXOSX__ // use a bit darker colour on OSX m_tabBgColour = m_tabBgColour.ChangeLightness(90); m_innerPenColour = m_tabBgColour.ChangeLightness(110); m_penColour = m_innerPenColour.ChangeLightness(90); #else m_tabBgColour = m_tabBgColour.ChangeLightness(120); m_penColour = m_innerPenColour.ChangeLightness(90); #endif } } else { m_activeTabBgColour = DrawingUtils::GetPanelBgColour(); m_activeTabTextColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); } }
void WordCompletionPlugin::OnWordComplete(wxCommandEvent& event) { event.Skip(); IEditor* activeEditor = m_mgr->GetActiveEditor(); CHECK_PTR_RET(activeEditor); WordCompletionSettings settings; settings.Load(); // Enabled? if(!settings.IsEnabled()) return; // Build the suggetsion list wxString suggestString; wxCodeCompletionBoxEntry::Vec_t entries; wxCodeCompletionBox::BmpVec_t bitmaps; bitmaps.push_back(m_images.Bitmap("m_bmpWord")); // Filter (what the user has typed so far) wxStyledTextCtrl* stc = activeEditor->GetCtrl(); int curPos = stc->GetCurrentPos(); int start = stc->WordStartPosition(stc->GetCurrentPos(), true); if(curPos < start) return; wxString filter = stc->GetTextRange(start, curPos); wxString lcFilter = filter.Lower(); wxStringSet_t words = m_dictionary->GetWords(); // Parse the current bufer (if modified), to include non saved words if(activeEditor->IsModified()) { wxStringSet_t unsavedBufferWords; WordCompletionThread::ParseBuffer(stc->GetText(), unsavedBufferWords); // Merge the results words.insert(unsavedBufferWords.begin(), unsavedBufferWords.end()); } // Get the editor keywords and add them LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexerForFile(activeEditor->GetFileName().GetFullName()); if(lexer) { wxString keywords; for(size_t i = 0; i < wxSTC_KEYWORDSET_MAX; ++i) { keywords << lexer->GetKeyWords(i) << " "; } wxArrayString langWords = ::wxStringTokenize(keywords, "\n\t \r", wxTOKEN_STRTOK); words.insert(langWords.begin(), langWords.end()); } wxStringSet_t filterdSet; if(lcFilter.IsEmpty()) { filterdSet.swap(words); } else { for(wxStringSet_t::iterator iter = words.begin(); iter != words.end(); ++iter) { wxString word = *iter; wxString lcWord = word.Lower(); if(settings.GetComparisonMethod() == WordCompletionSettings::kComparisonStartsWith) { if(lcWord.StartsWith(lcFilter) && filter != word) { filterdSet.insert(word); } } else { if(lcWord.Contains(lcFilter) && filter != word) { filterdSet.insert(word); } } } } for(wxStringSet_t::iterator iter = filterdSet.begin(); iter != filterdSet.end(); ++iter) { entries.push_back(wxCodeCompletionBoxEntry::New(*iter, 0)); } wxCodeCompletionBoxManager::Get().ShowCompletionBox(activeEditor->GetCtrl(), entries, bitmaps, event.GetId() == XRCID("text_word_complete") ? wxCodeCompletionBox::kInsertSingleMatch : wxCodeCompletionBox::kNone, wxNOT_FOUND); }
void MemCheckOutputView::SuppressErrors(unsigned int mode, wxDataViewItem* dvItem) { if(m_mgr->OpenFile(m_choiceSuppFile->GetStringSelection())) { IEditor* editor = m_mgr->GetActiveEditor(); if(editor) { editor->GetCtrl()->DocumentEnd(); editor->GetCtrl()->Home(); int posStart = editor->GetCtrl()->GetCurrentPos(); editor->AppendText(wxString::Format("\n# Added %s", wxDateTime::Now().Format("%F %T"))); switch(mode) { case SUPPRESS_CLICKED: { MemCheckErrorReferrer* errorRef = dynamic_cast<MemCheckErrorReferrer*>(m_dataViewCtrlErrorsModel->GetClientObject(*dvItem)); // TODO ? print error message? if(!errorRef) break; editor->AppendText(wxString::Format("\n%s", errorRef->Get().getSuppression())); errorRef->Get().suppressed = true; } break; case SUPPRESS_CHECKED: { wxVariant variant; wxDataViewItemArray items; m_dataViewCtrlErrorsModel->GetChildren(wxDataViewItem(0), items); int supColumn = GetColumnByName(_("Suppress")); if(supColumn == wxNOT_FOUND) { return; } MemCheckErrorReferrer* errorRef; for(wxDataViewItemArray::iterator it = items.begin(); it != items.end(); ++it) { m_dataViewCtrlErrorsModel->GetValue(variant, *it, supColumn); if(variant.GetBool()) { errorRef = dynamic_cast<MemCheckErrorReferrer*>(m_dataViewCtrlErrorsModel->GetClientObject(*it)); editor->AppendText(wxString::Format("\n%s", errorRef->Get().getSuppression())); errorRef->Get().suppressed = true; } } } break; case SUPPRESS_ALL: for(size_t item = 0; item < m_filterResults.size(); ++item) { editor->AppendText(wxString::Format("\n%s", m_filterResults[item]->getSuppression())); m_filterResults[item]->suppressed = true; } break; case SUPPRESS_SELECTED: long item = -1; for(;;) { item = m_listCtrlErrors->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if(item == -1) break; editor->AppendText(wxString::Format("\n%s", m_filterResults[item]->getSuppression())); m_filterResults[item]->suppressed = true; } break; } editor->AppendText(wxT("\n")); editor->GetCtrl()->DocumentEnd(); int textLen = editor->GetCtrl()->GetCurrentPos() - posStart; editor->SelectText(posStart, textLen); wxCommandEvent saveEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("save_file")); m_mgr->GetTheApp()->GetTopWindow()->GetEventHandler()->ProcessEvent(saveEvent); // reload pages after suppression if(m_plugin->GetSettings()->GetOmitSuppressed()) { switch(mode) { case SUPPRESS_CLICKED: case SUPPRESS_CHECKED: ResetItemsView(); ShowPageView(m_currentPage); itemsInvalidSupp = true; break; case SUPPRESS_ALL: case SUPPRESS_SELECTED: ResetItemsSupp(); ApplyFilterSupp(FILTER_STRING); itemsInvalidView = true; break; } } } } }
void WordCompletionPlugin::OnWordComplete(clCodeCompletionEvent& event) { event.Skip(); // Always skip this IEditor* activeEditor = dynamic_cast<IEditor*>(event.GetEditor()); CHECK_PTR_RET(activeEditor); WordCompletionSettings settings; settings.Load(); // Enabled? if(!settings.IsEnabled()) { return; } // Build the suggetsion list static wxBitmap sBmp = wxNullBitmap; if(!sBmp.IsOk()) { sBmp = m_mgr->GetStdIcons()->LoadBitmap("word"); } // Filter (what the user has typed so far) // wxStyledTextCtrl* stc = activeEditor->GetCtrl(); // int curPos = stc->GetCurrentPos(); // int start = stc->WordStartPosition(stc->GetCurrentPos(), true); // if(curPos < start) return; wxString filter = event.GetWord().Lower(); // stc->GetTextRange(start, curPos); wxStringSet_t words = m_dictionary->GetWords(); // Parse the current bufer (if modified), to include non saved words if(activeEditor->IsModified()) { // For performance (this parsing is done in the main thread) // only parse the visible area of the document wxStringSet_t unsavedBufferWords; wxStyledTextCtrl* stc = activeEditor->GetCtrl(); int startPos = stc->PositionFromLine(stc->GetFirstVisibleLine()); int endPos = stc->GetCurrentPos(); wxString buffer = stc->GetTextRange(startPos, endPos); WordCompletionThread::ParseBuffer(buffer, unsavedBufferWords); // Merge the results words.insert(unsavedBufferWords.begin(), unsavedBufferWords.end()); } // Get the editor keywords and add them LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexerForFile(activeEditor->GetFileName().GetFullName()); if(lexer) { wxString keywords; for(size_t i = 0; i < wxSTC_KEYWORDSET_MAX; ++i) { keywords << lexer->GetKeyWords(i) << " "; } wxArrayString langWords = ::wxStringTokenize(keywords, "\n\t \r", wxTOKEN_STRTOK); words.insert(langWords.begin(), langWords.end()); } wxStringSet_t filterdSet; if(filter.IsEmpty()) { filterdSet.swap(words); } else { for(wxStringSet_t::iterator iter = words.begin(); iter != words.end(); ++iter) { wxString word = *iter; wxString lcWord = word.Lower(); if(settings.GetComparisonMethod() == WordCompletionSettings::kComparisonStartsWith) { if(lcWord.StartsWith(filter) && filter != word) { filterdSet.insert(word); } } else { if(lcWord.Contains(filter) && filter != word) { filterdSet.insert(word); } } } } wxCodeCompletionBoxEntry::Vec_t entries; for(wxStringSet_t::iterator iter = filterdSet.begin(); iter != filterdSet.end(); ++iter) { entries.push_back(wxCodeCompletionBoxEntry::New(*iter, sBmp)); } event.GetEntries().insert(event.GetEntries().end(), entries.begin(), entries.end()); }
void wxCodeCompletionBoxManager::InsertSelection(const wxString& selection) { IManager* manager = ::clGetManager(); IEditor* editor = manager->GetActiveEditor(); if(editor) { wxStyledTextCtrl* ctrl = editor->GetCtrl(); bool addParens(false); int start = wxNOT_FOUND, end = wxNOT_FOUND; std::vector<std::pair<int, int> > ranges; if(ctrl->GetSelections() > 1) { for(int i = 0; i < ctrl->GetSelections(); ++i) { int nStart = ctrl->WordStartPosition(ctrl->GetSelectionNCaret(i), true); int nEnd = ctrl->GetSelectionNCaret(i); ranges.push_back(std::make_pair(nStart, nEnd)); } std::sort(ranges.begin(), ranges.end(), [&](const std::pair<int, int>& e1, const std::pair<int, int>& e2) { return e1.first < e2.first; }); } else { // Default behviour: remove the partial text from teh editor and replace it // with the selection start = ctrl->WordStartPosition(ctrl->GetCurrentPos(), true); end = ctrl->GetCurrentPos(); ctrl->SetSelection(start, end); if(ctrl->GetCharAt(end) != '(') { addParens = true; } } wxString entryText = selection; if(entryText.Find("(") != wxNOT_FOUND) { // a function like wxString textToInsert = entryText.BeforeFirst('('); // Build the function signature wxString funcSig = entryText.AfterFirst('('); funcSig = funcSig.BeforeLast(')'); funcSig.Trim().Trim(false); CL_DEBUG("Inserting selection: %s", textToInsert); CL_DEBUG("Signature is: %s", funcSig); // Check if already have an open paren, don't add another if(addParens) { textToInsert << "()"; } if(!ranges.empty()) { // Multiple carets int offset = 0; for(size_t i = 0; i < ranges.size(); ++i) { int from = ranges.at(i).first; int to = ranges.at(i).second; from += offset; to += offset; // Once we enter that text into the editor, it will change the original // offsets (in most cases the entered text is larger than that typed text) offset += textToInsert.length() - (to - from); ctrl->Replace(from, to, textToInsert); ctrl->SetSelectionNStart(i, from + textToInsert.length()); ctrl->SetSelectionNEnd(i, from + textToInsert.length()); } } else { ctrl->ReplaceSelection(textToInsert); if(!funcSig.IsEmpty()) { // Place the caret between the parenthesis int caretPos(wxNOT_FOUND); if(addParens) { caretPos = start + textToInsert.length() - 1; } else { // Move the caret one char to the right caretPos = start + textToInsert.length() + 1; } ctrl->SetCurrentPos(caretPos); ctrl->SetSelection(caretPos, caretPos); // trigger a code complete for function calltip. // We do this by simply mimicing the user action of going to the menubar: // Edit->Display Function Calltip wxCommandEvent event(wxEVT_MENU, XRCID("function_call_tip")); wxTheApp->GetTopWindow()->GetEventHandler()->AddPendingEvent(event); } } } else { if(!ranges.empty()) { // Multiple carets int offset = 0; for(size_t i = 0; i < ranges.size(); ++i) { int from = ranges.at(i).first; int to = ranges.at(i).second; from += offset; to += offset; // Once we enter that text into the editor, it will change the original // offsets (in most cases the entered text is larger than that typed text) offset += entryText.length() - (to - from); ctrl->Replace(from, to, entryText); ctrl->SetSelectionNStart(i, from + entryText.length()); ctrl->SetSelectionNEnd(i, from + entryText.length()); } } else { // Default ctrl->ReplaceSelection(entryText); } } } }