77 const wxChar* eol_from = eol_lf;
78 const wxChar* eol_to = eol_lf;
122 titles.
Add(
_(
"File"));
123 titles.
Add(
_(
"Line"));
124 titles.
Add(
_(
"Text"));
150 lineTextL = lineText;
154 lineTextL.
Trim(
false);
155 lineTextL.
Trim(
true);
156 if (lineTextL.
Length() > 300)
161 values.
Add(lineTextL);
169 bool hasSelection =
false;
187 hasSelection =
false;
190 phraseAtCursor = wordAtCursor;
195 if ( selstartline != selendline )
201 !replace, !ed, explicitly_find_in_files);
305 if (!control || !data)
313 data->
end = std::min(slen, clen);
329 if ((data->
scope == 0) && data->
NewSearch && (ssta != cpos || send != cpos))
364 if (data->
scope == 1 &&
368 if (data->
scope == 1)
374 data->
start = std::max(ssta, send);
375 data->
end = std::min(ssta, send);
379 data->
start = std::min(ssta, send);
380 data->
end = std::max(ssta, send);
388 if (cpos < ssta || cpos > send)
411 if (!control || !data)
416 cbMessageBox(
_(
"This file is read-only.\nReplacing in a read-only file is not possible."),
421 bool advRegex =
false;
423 int replacecount = 0;
455 if (
Manager::Get()->GetConfigManager(
_T(
"editor"))->ReadBool(
_T(
"/use_posix_style_regexes"),
false))
457 #ifdef wxHAS_REGEX_ADVANCED 463 #ifdef wxHAS_REGEX_ADVANCED 474 bool replace =
false;
478 bool HaveLastDlgPosition =
false;
479 bool wrapAround =
false;
480 int data_start_initial = data->
start;
481 bool wrapAroundNotification =
false;
498 pos=start+data->
start;
500 if ((start==0) && (len==0))
506 pos = start+data->
start + 1;
518 if (pos != -1 && data->
start!=data->
end)
526 else if (!wrapAround)
528 if ( (data->
scope == 0) &&
534 msg =
_(
"Text not found.\nSearch from the start of the document?");
536 msg =
_(
"Text not found.\nSearch from the end of the document?");
539 if (auto_wrap_around)
540 wrapAroundNotification =
true;
543 data->
end = data_start_initial;
557 if (wrapAroundNotification)
561 wrapAroundNotification =
false;
579 if ( HaveLastDlgPosition )
580 dlg.Move(LastDlgPosition);
585 LastDlgPosition = dlg.GetPosition();
586 HaveLastDlgPosition =
true;
623 lengthReplace=text.
Len();
639 data->
start += lengthReplace;
642 int diff = lengthReplace - lengthFound;
647 if (data->
end < diff)
656 data->
start += lengthFound;
658 data->
start -= lengthFound;
662 if (control->IsFrozen())
667 msg =
_T(
"No matches found for \"") + data->
findText +
_T(
"\"");
668 else if (replacecount == 0 && foundcount == 1)
669 msg =
_T(
"One match found but not replaced");
671 msg.
Printf(
_(
"Replaced %i of %i matches"), replacecount, foundcount);
690 if (data->
scope == 0)
700 else if (data->
scope == 1)
721 if (filesList.
Index(fullpath) >= 0)
724 filesList.
Add(fullpath);
728 else if (data->
scope == 2)
734 int count = pProjects->GetCount();
735 for (
int idxProject = 0; idxProject < count; ++idxProject)
737 cbProject* pProject = pProjects->Item(idxProject);
748 if (filesList.
Index(fullpath) == -1)
751 filesList.
Add(fullpath);
759 else if (data->
scope == 3)
768 unsigned int count = masks.
GetCount();
770 for (
unsigned int i = 0; i < count; ++i)
777 int filesCount = filesList.
GetCount();
796 if (
Manager::Get()->GetConfigManager(
_T(
"editor"))->ReadBool(
_T(
"/use_posix_style_regexes"),
false))
798 #ifdef wxHAS_REGEX_ADVANCED 804 #ifdef wxHAS_REGEX_ADVANCED 815 bool replace =
false;
818 bool wholeFile =
false;
823 bool HaveLastDlgPosition =
false;
833 int read_only_files_skipped = 0;
834 for (
int i = 0; i<filesCount && !stop; ++i)
838 bool fileWasNotOpen =
false;
856 fileWasNotOpen =
false;
865 wxFile file(filesList[i]);
886 fileWasNotOpen =
true;
888 ed = editorMgr->
Open(filesList[i]);
897 read_only_files_skipped++;
905 bool replacementsWereMade =
false;
916 if (IsMultiLine && data->
fixEOLs)
931 if (!all) confirm =
true;
934 while (!stop || wholeFile)
949 pos = start + data->
start;
951 if ((start==0) && (len==0))
957 pos = start + data->
start + 1;
969 if ((pos == -1) || (data->
start == data->
end))
994 if ( HaveLastDlgPosition )
995 dlg.Move(LastDlgPosition);
1000 LastDlgPosition = dlg.GetPosition();
1001 HaveLastDlgPosition =
true;
1026 _(
"Please wait while replacing in files..."),
1046 replacementsWereMade =
true;
1057 lengthReplace=text.
Len();
1070 data->
start += lengthReplace;
1074 int diff = lengthReplace - lengthFound;
1083 data->
start += lengthFound;
1085 data->
start -= lengthFound;
1093 if (!replacementsWereMade && fileWasNotOpen)
1094 editorMgr->
Close(ed,
true);
1097 if (read_only_files_skipped)
1100 msg.
Printf(
_(
"Skipped %d read-only file(s)."), read_only_files_skipped);
1110 _(
"Replace in files has finished all operations."),
1119 if (!control || !data)
1122 bool advRegex =
false;
1123 bool advRegexNewLinePolicy =! data->
IsMultiLine();
1137 if (
Manager::Get()->GetConfigManager(
_T(
"editor"))->ReadBool(
_T(
"/use_posix_style_regexes"),
false))
1139 #ifdef wxHAS_REGEX_ADVANCED 1145 #ifdef wxHAS_REGEX_ADVANCED 1157 bool wrapAround =
false;
1160 if (data->
scope == 1)
1165 bool wrapAroundNotification =
false;
1168 int lengthFound = 0;
1181 pos = start + data->
start;
1183 if ((start==0) && (len==0))
1189 pos = start + data->
start + 1;
1199 if (pos != -1 && data->
start!=data->
end)
1203 int l1 = line - onScreen;
1204 int l2 = line + onScreen;
1205 for (
int l=l1; l<=l2; l+=2)
1221 if (data->
scope == 1)
1224 msg =
_(
"Text not found.\nSearch from the start of the selection?");
1226 msg =
_(
"Text not found.\nSearch from the end of the selection?");
1231 msg =
_(
"Text not found.\nSearch from the start of the document?");
1233 msg =
_(
"Text not found.\nSearch from the end of the document?");
1237 if (auto_wrap_around)
1238 wrapAroundNotification =
true;
1243 if (data->
scope == 1)
1279 wrapAroundNotification =
false;
1283 else if (wrapAround)
1288 wrapAroundNotification =
false;
1295 if (wrapAroundNotification)
1321 if (data->
scope == 0)
1331 else if (data->
scope == 1)
1352 if (filesList.
Index(fullpath) >= 0)
1355 filesList.
Add(fullpath);
1359 else if (data->
scope == 2)
1365 count = pProjects->GetCount();
1371 for (
int idxProject = 0; idxProject < count; ++idxProject)
1373 cbProject* pProject = pProjects->Item(idxProject);
1383 if (filesList.
Index(fullpath) == -1)
1386 filesList.
Add(fullpath);
1393 else if (data->
scope == 3)
1402 unsigned int count = masks.
GetCount();
1404 for (
unsigned int i = 0; i < count; ++i)
1410 else if (data->
scope == 4)
1432 control->Show(
false);
1436 _(
"Please wait while searching inside the files..."),
1454 for (
size_t i = 0; i < filesList.
GetCount(); ++i)
1457 if (!progress->
Update(i))
1470 if (!detector.
IsOK())
1478 if (
Find(control, data) == -1)
1501 while (
FindNext(
true, control, data,
false) != -1 )
1507 if (line == lastline)
1521 if (
Manager::Get()->GetConfigManager(
_T(
"message_manager"))->ReadBool(
_T(
"/auto_show_search"),
true))
1544 msg.
Printf(
_(
"not found in %lu files"), static_cast<unsigned long>(filesList.
GetCount()));
1600 data->
regEx =
false;
1624 if (!phraseAtCursor.
IsEmpty())
1633 return Find(control, data);
1652 return FindNext(goingDown,
nullptr,
nullptr,
true);
static wxFontEncoding GetEncodingFromName(const wxString &encoding)
DLLIMPORT wxArrayString GetArrayFromString(const wxString &text, const wxString &separator=DEFAULT_ARRAY_SEP, bool trimSpaces=true)
cbEditor * IsBuiltinOpen(const wxString &filename)
static void Display(const wxString &title, const wxString &message, unsigned int delay=5000, unsigned int hysteresis=1)
virtual bool GetAutoWrapSearch() const =0
#define wxSCI_FIND_REGEXP
int Replace(cbStyledTextCtrl *control, cbFindReplaceData *data)
void Append(const wxString &msg, Logger::level lv=info) override
void ReplaceSelection(const wxString &text)
Replace the selected text with the argument text.
virtual bool Update(int value, const wxString &newmsg=wxEmptyString, bool *skip=NULL)
void SetSelectionVoid(int startPos, int endPos)
Select a range of text.
int WordEndPosition(int pos, bool onlyWordCharacters)
Get position of end of word.
void EnsureVisible(int line)
Ensure a particular line is visible by expanding any header line hiding it.
ConfigManager * GetConfigManager(const wxString &name_space) const
virtual bool IsFindInFiles() const =0
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
int ReplaceInFiles(cbFindReplaceData *data)
bool fixEOLs
for multi-line S&R. Fixes EOLs in all the files searched.
DLLIMPORT wxBitmap cbLoadBitmap(const wxString &filename, wxBitmapType bitmapType=wxBITMAP_TYPE_PNG)
This function loads a bitmap from disk.
virtual FilesList & GetFilesList()
Provides an easy way to iterate all the files belonging in this target.
bool wxFileExists(const wxString &filename)
wxFileName file
The full filename of this file.
virtual int GetDirection() const =0
virtual bool GetFixEOLs() const =0
virtual bool GetHidden() const =0
#define wxSCI_FIND_WHOLEWORD
int ShowFindDialog(bool replace, bool explicitly_find_in_files=false)
virtual int GetOrigin() const =0
bool ReadBool(const wxString &name, bool defaultVal=false)
int Index(const wxString &sz, bool bCase=true, bool bFromEnd=false) const
bool multiLine
for multi-line S&R.
virtual bool GetFindUsesSelectedText() const =0
virtual int GetScope() const =0
Event used to request from the main app to add a log.
bool findUsesSelectedText
void SetText(const wxString &text)
Replace the contents of the document with the argument text.
wxString GetLine(int line) const
Retrieve the contents of a line.
bool Matches(const wxString &text, int flags=0) const
void SetActiveEditor(EditorBase *ed)
int GetSelectionStart() const
Returns the position at the start of the selection.
virtual wxString GetSearchMask() const =0
bool Close(const wxString &filename, bool dontsave=false)
virtual size_t GetItemsCount() const
#define wxICON_INFORMATION
virtual bool GetSortSearchResult() const =0
static size_t GetAllFiles(const wxString &dirname, wxArrayString *files, const wxString &filespec=wxEmptyString, int flags=wxDIR_DEFAULT)
cbSearchResultsLog * m_pSearchLog
Represents a file in a Code::Blocks project.
void SetBasePath(const wxString base)
wxWindow * GetAppWindow() const
#define wxICON_EXCLAMATION
int WordStartPosition(int pos, bool onlyWordCharacters)
Get position of start of word.
EditorManager * GetEditorManager() const
void SetSelectionEnd(int caret)
Sets the position that ends the selection - this becomes the caret.
virtual int GetTarget() const =0
Try to detect the encoding of a file on disk.
wxUSE_UNICODE_dependent wxChar
virtual wxString GetReplaceString() const =0
wxString GetSelectedText()
Retrieve the selected text.
ProjectManager * GetProjectManager() const
Functions returning pointers to the respective sub-manager instances.
bool MakeRelativeTo(const wxString &pathBase=wxEmptyString, wxPathFormat format=wxPATH_NATIVE)
DLLIMPORT wxString cbReadFileContents(wxFile &file, wxFontEncoding encoding=wxFONTENCODING_SYSTEM)
Reads a wxString from a non-unicode file. File must be open. File is closed automatically.
int Replace(wxString *text, const wxString &replacement, size_t maxMatches=0) const
virtual const wxString & GetFilename() const
Get the editor's filename (if applicable).
Represents a Code::Blocks project.
int GetEOLMode() const
Retrieve the current end of line mode - one of wxSCI_EOL_CRLF, wxSCI_EOL_CR, or wxSCI_EOL_LF.
EditorBase * GetActiveEditor()
#define wxSCI_FIND_MATCHCASE
EVTIMPORT const wxEventType cbEVT_ADD_LOG_WINDOW
cbStyledTextCtrl * GetControl() const
Returns a pointer to the underlying cbStyledTextCtrl object (which itself is the wxWindows implementa...
void FocusEntry(size_t index)
virtual const wxString & GetTitle() const
Read the target's title.
static wxString GetSystemEncodingName()
size_t Replace(const wxString &strOld, const wxString &strNew, bool replaceAll=true)
cbEditor * GetBuiltinActiveEditor()
const wxPoint wxDefaultPosition
void SetChangeCollection(bool collectChange)
Choose between collecting actions into the changes history and discarding them.
bool IsSameAs(const wxString &s, bool caseSensitive=true) const
static bool IsBatchBuild()
bool GetMatch(size_t *start, size_t *len, size_t index=0) const
int FindText(int minPos, int maxPos, const wxString &text, int flags=0, int *findEnd=NULL)
Find some text in the document.
Base class that all "editors" should inherit from.
void ConvertEOLs(int newmode)
int GetCurrentPos() const
Returns the position of the caret.
EVTIMPORT const wxEventType cbEVT_SWITCH_TO_LOG_WINDOW
wxString & Truncate(size_t len)
wxString Read(const wxString &key, const wxString &defaultVal=wxEmptyString)
int SearchInSelectionEnd
keep track of the end of a 'search' selection
int GetLength() const
Returns the number of bytes in the document.
void CalculateFindReplaceStartEnd(cbStyledTextCtrl *control, cbFindReplaceData *data, bool replace=false)
wxString GetWxStr() const
int Find(cbStyledTextCtrl *control, cbFindReplaceData *data)
int SearchInSelectionStart
keep track of the start of a 'search' selection
void CalcPosition(cbStyledTextCtrl *ed)
virtual bool GetStartWord() const =0
virtual bool GetDeleteOldSearches() const =0
bool startFile
To be implemented.
virtual bool GetMatchCase() const =0
cbEditor * Open(const wxString &filename, int pos=0, ProjectFile *data=nullptr)
const wxString & _(const wxString &string)
wxString & Trim(bool fromRight=true)
int GetSelectionEnd() const
Returns the position at the end of the selection.
cbEditor * GetBuiltinEditor(EditorBase *eb)
virtual bool GetRecursive() const =0
wxArray< int > wxArrayInt
static wxString GetDataFolder(bool global=true)
ProjectBuildTarget * GetBuildTarget(int index)
Access a build target.
virtual bool GetRegEx() const =0
bool GetReadOnly() const
In read-only mode?
virtual bool GetMultiLine() const =0
DLLIMPORT void PlaceWindow(wxTopLevelWindow *w, cbPlaceDialogMode mode=pdlBest, bool enforce=false)
void EndUndoAction()
End a sequence of actions that is undone and redone as a unit.
cbAuiNotebook * GetNotebook()
void GotoPos(int caret)
Set caret to a position and ensure it is visible.
bool NewSearch
only true when a new search has been started
bool ProcessEvent(CodeBlocksEvent &event)
void SetSearchResultLogger(cbSearchResultsLog *log)
Sets the pointer to the search result logger, users must not call this method.
void SetSCIFocus(bool focus)
Change internal focus flag.
size_t Add(const wxString &str, size_t copies=1)
int FindNext(bool goingDown, cbStyledTextCtrl *control, cbFindReplaceData *data, bool selected)
void SetTargetStart(int start)
Sets the position that starts the target which is used for updating the document without affecting th...
bool StartsWith(const wxString &prefix, wxString *rest=NULL) const
int LineFromPosition(int pos) const
Retrieve the line containing a position.
void Sort(bool reverseOrder=false)
bool Compile(const wxString &pattern, int flags=wxRE_DEFAULT)
wxString GetText() const
Retrieve all the text in the document.
int LinesOnScreen() const
Retrieves the number of lines completely visible.
int Find(wxUniChar ch, bool fromEnd=false) const
void SetTargetEnd(int end)
Sets the position that ends the target which is used for updating the document without affecting the ...
ProjectsArray * GetProjects()
Retrieve an array of all the opened projects.
int ReplaceTargetRE(const wxString &text)
Replace the target text with the argument text after \d processing.
virtual wxString GetFindString() const =0
int FindInFiles(cbFindReplaceData *data)
virtual bool GetMatchWord() const =0
virtual wxString GetSearchPath() const =0
void BeginUndoAction()
Start a sequence of actions that is undone and redone as a unit.
int Printf(const wxString &pszFormat,...)
void LogSearch(const wxString &file, int line, const wxString &lineText)
EditorBase * IsOpen(const wxString &filename)
wxString GetFullPath(wxPathFormat format=wxPATH_NATIVE) const
wxArtID wxART_INFORMATION
wxString Mid(size_t first, size_t nCount=wxString::npos) const
virtual int GetProject() const =0
void GotoLine(int line)
Set caret to start of a line and ensure it is visible.
Dialog that contains a "Don't annoy me" checkbox.
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.
void SetSelectionStart(int anchor)
Sets the position that starts the selection - this becomes the anchor.
int eolMode
for multi-line S&R
void ConvertEOLs(int eolMode)
Convert all line endings in the document to one mode.
EVTIMPORT const wxEventType cbEVT_SHOW_LOG_MANAGER
wxArrayString buildTargets
An array of strings, containing the names of all the build targets this file belongs to...
virtual bool GetStartFile() const =0
int FindSelectedText(bool goingDown)
#define wxSCI_FIND_WORDSTART
cbFindReplaceData * m_LastFindReplaceData