Browse Source

Add ability to open/copy selected files from Search-results

Add ability to open/copy selected files from Search-results, not always ALL files.

Fix #15741, close #15763
pull/15810/head
Alan Kilborn 2 weeks ago committed by Don Ho
parent
commit
b8224808bd
  1. 4
      PowerEditor/installer/nativeLang/english.xml
  2. 4
      PowerEditor/installer/nativeLang/english_customizable.xml
  3. 2
      PowerEditor/src/Notepad_plus.cpp
  4. 55
      PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
  5. 2
      PowerEditor/src/ScintillaComponent/FindReplaceDlg.h
  6. 4
      PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
  7. 4
      PowerEditor/src/ScintillaComponent/ScintillaEditView.h

4
PowerEditor/installer/nativeLang/english.xml

@ -1719,9 +1719,9 @@ Find in all files but exclude all folders log or logs recursively:
<finder-collapse-all value="Fold all"/>
<finder-uncollapse-all value="Unfold all"/>
<finder-copy value="Copy Selected Line(s)"/>
<finder-copy-paths value="Copy Pathname(s)"/>
<finder-copy-paths value="Copy Selected Pathname(s)"/>
<finder-clear-all value="Clear all"/>
<finder-open-all value="Open all"/>
<finder-open-all value="Open Selected Pathname(s)"/>
<finder-purge-for-every-search value="Purge for every search"/>
<finder-wrap-long-lines value="Word wrap long lines"/>
<common-ok value="OK"/>

4
PowerEditor/installer/nativeLang/english_customizable.xml

@ -1717,9 +1717,9 @@ Find in all files but exclude all folders log or logs recursively:
<finder-collapse-all value="Fold all"/>
<finder-uncollapse-all value="Unfold all"/>
<finder-copy value="Copy Selected Line(s)"/>
<finder-copy-paths value="Copy Pathname(s)"/>
<finder-copy-paths value="Copy Selected Pathname(s)"/>
<finder-clear-all value="Clear all"/>
<finder-open-all value="Open all"/>
<finder-open-all value="Open Selected Pathname(s)"/>
<finder-purge-for-every-search value="Purge for every search"/>
<finder-wrap-long-lines value="Word wrap long lines"/>
<common-ok value="OK"/>

2
PowerEditor/src/Notepad_plus.cpp

@ -2055,7 +2055,7 @@ bool Notepad_plus::findInFinderFiles(FindersInfo *findInFolderInfo)
_pEditView = &_invisibleEditView;
Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER);
vector<wstring> fileNames = findInFolderInfo->_pSourceFinder->getResultFilePaths();
vector<wstring> fileNames = findInFolderInfo->_pSourceFinder->getResultFilePaths(false);
findInFolderInfo->_pDestFinder->beginNewFilesSearch();
findInFolderInfo->_pDestFinder->addSearchLine(findInFolderInfo->_findOption._str2Search.c_str());

55
PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp

@ -682,24 +682,45 @@ void Finder::deleteResult()
assert(size_t(_scintView.execute(SCI_GETLINECOUNT)) == _pMainFoundInfos->size() + 1);
}
vector<wstring> Finder::getResultFilePaths() const
vector<wstring> Finder::getResultFilePaths(bool onlyInSelectedText) const
{
vector<wstring> paths;
size_t len = _pMainFoundInfos->size();
for (size_t i = 0; i < len; ++i)
std::vector<wstring> paths;
size_t fromLine = 0, toLine = 0;
if (onlyInSelectedText)
{
// make sure that path is not already in
wstring & path2add = (*_pMainFoundInfos)[i]._fullPath;
bool found = path2add.empty();
for (size_t j = 0; j < paths.size() && !found; ++j)
{
if (paths[j] == path2add)
found = true;
const pair<size_t, size_t> lineRange = _scintView.getSelectionLinesRange();
fromLine = lineRange.first;
toLine = lineRange.second;
}
else
{
toLine = _scintView.execute(SCI_GETLINECOUNT) - 1;
}
for (size_t line = fromLine; line <= toLine; ++line)
{
const int lineFoldLevel = _scintView.execute(SCI_GETFOLDLEVEL, line) & SC_FOLDLEVELNUMBERMASK;
if (lineFoldLevel == fileHeaderLevel)
{
wstring lineStr = _scintView.getLine(line);
// fileHeaderLevel line format examples:
// spacespaceD:\folder\file.ext (2 hits)
// spacespacenew 1 (1 hit)
const size_t startIndex = 2; // for number of leading spaces
auto endIndex = lineStr.find_last_of(L'(');
--endIndex; // adjust for space in front of (
wstring path = lineStr.substr(startIndex, endIndex - startIndex);
// make sure that path is not already in before adding
if (std::find(paths.begin(), paths.end(), path) == paths.end())
{
paths.push_back(path);
}
}
if (!found)
paths.push_back(path2add);
}
return paths;
}
@ -5350,7 +5371,7 @@ void Finder::removeAll()
void Finder::openAll()
{
for (auto&& path : getResultFilePaths())
for (auto&& path : getResultFilePaths(true))
{
::SendMessage(_hParent, WM_DOOPEN, 0, reinterpret_cast<LPARAM>(path.c_str()));
}
@ -5359,7 +5380,7 @@ void Finder::openAll()
void Finder::copyPathnames()
{
wstring toClipboard;
for (auto&& path : getResultFilePaths())
for (auto&& path : getResultFilePaths(true))
{
toClipboard += path + L"\r\n";
}
@ -5710,12 +5731,12 @@ intptr_t CALLBACK Finder::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam
wstring copyLines = pNativeSpeaker->getLocalizedStrFromID("finder-copy", L"Copy Selected Line(s)");
wstring copyVerbatim = pNativeSpeaker->getNativeLangMenuString(IDM_EDIT_COPY, L"Copy", true);
copyVerbatim += L"\tCtrl+C";
wstring copyPaths = pNativeSpeaker->getLocalizedStrFromID("finder-copy-paths", L"Copy Pathname(s)");
wstring copyPaths = pNativeSpeaker->getLocalizedStrFromID("finder-copy-paths", L"Copy Selected Pathname(s)");
wstring selectAll = pNativeSpeaker->getNativeLangMenuString(IDM_EDIT_SELECTALL, L"Select all", true);
selectAll += L"\tCtrl+A";
wstring clearAll = pNativeSpeaker->getLocalizedStrFromID("finder-clear-all", L"Clear all");
wstring purgeForEverySearch = pNativeSpeaker->getLocalizedStrFromID("finder-purge-for-every-search", L"Purge for every search");
wstring openAll = pNativeSpeaker->getLocalizedStrFromID("finder-open-all", L"Open all");
wstring openAll = pNativeSpeaker->getLocalizedStrFromID("finder-open-all", L"Open Selected Pathname(s)");
wstring wrapLongLines = pNativeSpeaker->getLocalizedStrFromID("finder-wrap-long-lines", L"Word wrap long lines");
tmp.push_back(MenuItemUnit(NPPM_INTERNAL_FINDINFINDERDLG, findInFinder));

2
PowerEditor/src/ScintillaComponent/FindReplaceDlg.h

@ -143,7 +143,7 @@ public:
void gotoNextFoundResult(int direction);
std::pair<intptr_t, intptr_t> gotoFoundLine(size_t nOccurrence = 0); // value 0 means this argument is not used
void deleteResult();
std::vector<std::wstring> getResultFilePaths() const;
std::vector<std::wstring> getResultFilePaths(bool onlyInSelectedText) const;
bool canFind(const wchar_t *fileName, size_t lineNumber, size_t* indexToStartFrom) const;
void setVolatiled(bool val) { _canBeVolatiled = val; };
std::wstring getHitsString(int count) const;

4
PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp

@ -2801,7 +2801,7 @@ void ScintillaEditView::showCallTip(size_t startPos, const wchar_t * def)
execute(SCI_CALLTIPSHOW, startPos, reinterpret_cast<LPARAM>(defA));
}
wstring ScintillaEditView::getLine(size_t lineNumber)
wstring ScintillaEditView::getLine(size_t lineNumber) const
{
size_t lineLen = execute(SCI_LINELENGTH, lineNumber);
const size_t bufSize = lineLen + 1;
@ -2810,7 +2810,7 @@ wstring ScintillaEditView::getLine(size_t lineNumber)
return buf.get();
}
void ScintillaEditView::getLine(size_t lineNumber, wchar_t * line, size_t lineBufferLen)
void ScintillaEditView::getLine(size_t lineNumber, wchar_t * line, size_t lineBufferLen) const
{
// make sure the buffer length is enough to get the whole line
size_t lineLen = execute(SCI_LINELENGTH, lineNumber);

4
PowerEditor/src/ScintillaComponent/ScintillaEditView.h

@ -476,8 +476,8 @@ public:
intptr_t replaceTargetRegExMode(const wchar_t * re, intptr_t fromTargetPos = -1, intptr_t toTargetPos = -1) const;
void showAutoComletion(size_t lenEntered, const wchar_t * list);
void showCallTip(size_t startPos, const wchar_t * def);
std::wstring getLine(size_t lineNumber);
void getLine(size_t lineNumber, wchar_t * line, size_t lineBufferLen);
std::wstring getLine(size_t lineNumber) const;
void getLine(size_t lineNumber, wchar_t * line, size_t lineBufferLen) const;
void addText(size_t length, const char *buf);
void insertNewLineAboveCurrentLine();

Loading…
Cancel
Save