bool ThreadSearchView::UpdatePreview(const wxString& file, long line) { bool success(true); if ( line > 0 ) { // Line display begins at 1 but line index at 0 line--; } // Disable read only m_pSearchPreview->Enable(false); m_pSearchPreview->SetReadOnly(false); // Loads file if different from current loaded wxFileName filename(file); if ( (m_PreviewFilePath != file) || (m_PreviewFileDate != filename.GetModificationTime()) ) { ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor")); // Remember current file path and modification time m_PreviewFilePath = file; m_PreviewFileDate = filename.GetModificationTime(); EncodingDetector enc(m_PreviewFilePath, false); success = enc.IsOK(); m_pSearchPreview->SetText(enc.GetWxStr()); // Colorize cbEditor::ApplyStyles(m_pSearchPreview); EditorColourSet EdColSet; EdColSet.Apply(EdColSet.GetLanguageForFilename(m_PreviewFilePath), m_pSearchPreview, false, true); SetFoldingIndicator(mgr->ReadInt(_T("/folding/indicator"), 2)); UnderlineFoldedLines(mgr->ReadBool(_T("/folding/underline_folded_line"), true)); } if ( success == true ) { // Display the selected line int onScreen = m_pSearchPreview->LinesOnScreen() >> 1; m_pSearchPreview->GotoLine(line - onScreen); m_pSearchPreview->GotoLine(line + onScreen); m_pSearchPreview->GotoLine(line); m_pSearchPreview->EnsureVisible(line); int startPos = m_pSearchPreview->PositionFromLine(line); int endPos = m_pSearchPreview->GetLineEndPosition(line); m_pSearchPreview->SetSelectionVoid(endPos, startPos); }
void MiniDocPanel::ChangeMiniStcDoc(cbEditor *ed) { if(ed) { miniStc_->SetDocPointer(ed->GetControl()->GetDocPointer()); EditorColourSet *ecs = Manager::Get()->GetEditorManager()->GetColourSet(); ecs->Apply(ed->GetLanguage(), miniStc_); // for (unsigned int style = 0 ; style <= wxSCI_STYLE_MAX ; ++style) // miniStc_->StyleSetSize(style, 3); miniStc_->UpdateMiniature(ed->GetControl(),true); } else { miniStc_->SetDocPointer(NULL); } }
void AbbreviationsConfigPanel::ApplyColours() { EditorColourSet* theme = Manager::Get()->GetEditorManager()->GetColourSet(); if (theme) { wxString FontString = Manager::Get()->GetConfigManager(_T("editor"))->Read(_T("/font"), wxEmptyString); wxFont tmpFont(10, wxMODERN, wxNORMAL, wxNORMAL); if (!FontString.IsEmpty()) { wxNativeFontInfo nfi; nfi.FromString(FontString); tmpFont.SetNativeFontInfo(nfi); } if (m_AutoCompTextControl) { m_AutoCompTextControl->StyleSetFont(wxSCI_STYLE_DEFAULT, tmpFont); theme->Apply(theme->GetHighlightLanguage(_T("C/C++")), m_AutoCompTextControl); } } }
FInfoWindow::FInfoWindow() :wxPanel(Manager::Get()->GetAppWindow()) { //ctor m_pView = new cbStyledTextCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(1,1)); wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(m_pView, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0); SetSizer(sizer); sizer->Fit(this); sizer->SetSizeHints(this); m_pView->SetReadOnly(true); // Colorize cbEditor::ApplyStyles(m_pView); EditorColourSet edColSet; edColSet.Apply(edColSet.GetLanguageForFilename(_T("name.f90")), m_pView); SetFoldingIndicator(); CodeBlocksLogEvent evtAdd(cbEVT_ADD_LOG_WINDOW, this, _("Fortran info")); Manager::Get()->ProcessEvent(evtAdd); }
size_t CodeRefactoring::VerifyResult(const TokenIdxSet& targetResult, const wxString& targetText, bool isLocalVariable) { EditorManager* edMan = Manager::Get()->GetEditorManager(); cbEditor* editor = edMan->GetBuiltinActiveEditor(); if (!editor) return 0; const Token* parentOfLocalVariable = nullptr; if (isLocalVariable) { TokenTree* tree = m_NativeParser.GetParser().GetTokenTree(); CC_LOCKER_TRACK_TT_MTX_LOCK(s_TokenTreeMutex) const Token* token = tree->at(*targetResult.begin()); parentOfLocalVariable = tree->at(token->m_ParentIndex); CC_LOCKER_TRACK_TT_MTX_UNLOCK(s_TokenTreeMutex) } // now that list is filled, we'll search cbStyledTextCtrl* control = new cbStyledTextCtrl(editor->GetParent(), wxID_ANY, wxDefaultPosition, wxSize(0, 0)); control->Show(false); // styled the text to support control->GetStyleAt() cbEditor::ApplyStyles(control); EditorColourSet edColSet; size_t totalCount = 0; for (SearchDataMap::const_iterator it = m_SearchDataMap.begin(); it != m_SearchDataMap.end(); ++it) totalCount += it->second.size(); // let's create a progress dialog because it might take some time depending on the files count wxProgressDialog* progress = new wxProgressDialog(_("Code Refactoring"), _("Please wait while verifying result..."), totalCount, Manager::Get()->GetAppWindow(), wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT); PlaceWindow(progress); size_t task = totalCount; TokenIdxSet result; bool userBreak = false; for (SearchDataMap::iterator it = m_SearchDataMap.begin(); it != m_SearchDataMap.end();) { // check if the file is already opened in built-in editor and do search in it cbEditor* ed = edMan->IsBuiltinOpen(it->first); if (ed) control->SetText(ed->GetControl()->GetText()); else // else load the file in the control { EncodingDetector detector(it->first); if (!detector.IsOK()) { task -= it->second.size(); m_SearchDataMap.erase(it++); continue; // failed } control->SetText(detector.GetWxStr()); } // apply the corlor setting edColSet.Apply(editor->GetLanguage(), control); ccSearchData searchData = { control, it->first }; for (SearchDataList::iterator itList = it->second.begin(); itList != it->second.end();) { // update the progress bar if (!progress->Update(totalCount - (--task))) { userBreak = true; break; // user pressed "Cancel" } // skip string or comment const int style = control->GetStyleAt(itList->pos); if (control->IsString(style) || control->IsComment(style)) { it->second.erase(itList++); continue; } // do cc search const int endOfWord = itList->pos + targetText.Len(); control->GotoPos(endOfWord); m_NativeParser.MarkItemsByAI(&searchData, result, true, false, true, endOfWord); if (result.empty()) { it->second.erase(itList++); continue; } // verify result TokenIdxSet::const_iterator findIter = targetResult.begin(); for (; findIter != targetResult.end(); ++findIter) { if (result.find(*findIter) != result.end()) break; } if (findIter == targetResult.end()) // not found it->second.erase(itList++); else { // handle for local variable if (isLocalVariable) { bool do_continue = false; TokenTree* tree = m_NativeParser.GetParser().GetTokenTree(); CC_LOCKER_TRACK_TT_MTX_LOCK(s_TokenTreeMutex) const Token* token = tree->at(*findIter); if (token) { const Token* parent = tree->at(token->m_ParentIndex); if (parent != parentOfLocalVariable) { it->second.erase(itList++); do_continue = true; } } CC_LOCKER_TRACK_TT_MTX_UNLOCK(s_TokenTreeMutex) if (do_continue) continue; } ++itList; } } if (it->second.empty()) m_SearchDataMap.erase(it++); else ++it; if (userBreak) break; } delete control; // done with it delete progress; // done here too return m_SearchDataMap.size(); }