From 299488d6263ba9cb46232d236b93849de542ae65 Mon Sep 17 00:00:00 2001 From: Uffe Jakobsen Date: Mon, 30 Dec 2024 12:30:40 +0100 Subject: [PATCH] --- CodeLite/CMakeLists.txt | 2 ++ CodeLite/clFilesCollector.cpp | 23 ++++++++++++----------- LiteEditor/mainbook.cpp | 23 ++++++++++++++++------- Plugin/globals.cpp | 12 +++++++++--- Plugin/globals.h | 2 +- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/CodeLite/CMakeLists.txt b/CodeLite/CMakeLists.txt index 537fea7fc7..5761b62bd5 100644 --- a/CodeLite/CMakeLists.txt +++ b/CodeLite/CMakeLists.txt @@ -34,6 +34,8 @@ target_include_directories(libcodelite "${CL_SRC_ROOT}/CodeLite" "${CL_SRC_ROOT}/CodeLite/ssh" "${CL_SRC_ROOT}/PCH" + "${CL_SRC_ROOT}/Interfaces" + "${CL_SRC_ROOT}/Plugin" PRIVATE "${CL_SRC_ROOT}/submodules/asio/asio/include" "${CL_SRC_ROOT}/submodules/websocketpp" diff --git a/CodeLite/clFilesCollector.cpp b/CodeLite/clFilesCollector.cpp index 9ac9685450..bdaa006f44 100644 --- a/CodeLite/clFilesCollector.cpp +++ b/CodeLite/clFilesCollector.cpp @@ -2,6 +2,7 @@ #include "file_logger.h" #include "fileutils.h" +#include "globals.h" #include #include @@ -110,19 +111,19 @@ size_t clFilesScanner::Scan(const wxString& rootFolder, std::vector& f filename.MakeLower(); #endif bool isDirectory = wxFileName::DirExists(fullpath); - // Use FileUtils::RealPath() here to cope with symlinks on Linux + // Use CLRealPath() here to cope with symlinks on Linux bool isExcludeDir = isDirectory && ( #if defined(__FreeBSD__) - ((FileUtils::IsSymlink(fullpath) && excludeFolders.count(FileUtils::RealPath(fullpath))) + ((FileUtils::IsSymlink(fullpath) && excludeFolders.count(CLRealPath(fullpath))) #else - (excludeFolders.count(FileUtils::RealPath(fullpath)) + (excludeFolders.count(CLRealPath(fullpath)) #endif || IsRelPathContainedInSpec(rootFolder, fullpath, excludeFolders))); if (isDirectory && !isExcludeDir) { // Traverse into this folder - wxString realPath = FileUtils::RealPath(fullpath); + wxString realPath = CLRealPath(fullpath); if (Visited.insert(realPath).second) { Q.push(fullpath); } @@ -153,8 +154,8 @@ size_t clFilesScanner::Scan(const wxString& rootFolder, const wxString& filespec std::queue Q; std::unordered_set Visited; - Q.push(FileUtils::RealPath(rootFolder)); - Visited.insert(FileUtils::RealPath(rootFolder)); + Q.push(CLRealPath(rootFolder)); + Visited.insert(CLRealPath(rootFolder)); size_t nCount = 0; while (!Q.empty()) { @@ -174,11 +175,11 @@ size_t clFilesScanner::Scan(const wxString& rootFolder, const wxString& filespec fullpath << dir.GetNameWithSep() << filename; bool isDirectory = wxFileName::DirExists(fullpath); bool isFile = !isDirectory; - // Use FileUtils::RealPath() here to cope with symlinks on Linux + // Use CLRealPath() here to cope with symlinks on Linux if (isDirectory /* a folder */ && !FileUtils::WildMatch(excludeFoldersSpecArr, filename) /* does not match the exclude folder spec */) { // Traverse into this folder - wxString real_path = FileUtils::RealPath(fullpath); + wxString real_path = CLRealPath(fullpath); if (Visited.count(real_path) == 0) { Visited.insert(real_path); Q.push(fullpath); @@ -259,8 +260,8 @@ void clFilesScanner::ScanWithCallbacks(const wxString& rootFolder, std::function std::vector Q; std::unordered_set Visited; - Q.push_back(FileUtils::RealPath(rootFolder)); - Visited.insert(FileUtils::RealPath(rootFolder)); + Q.push_back(CLRealPath(rootFolder)); + Visited.insert(CLRealPath(rootFolder)); while (!Q.empty()) { wxString dirpath = Q.front(); @@ -299,7 +300,7 @@ void clFilesScanner::ScanWithCallbacks(const wxString& rootFolder, std::function if (on_folder_cb && on_folder_cb(fullpath)) { // Traverse into this folder - wxString real_path = FileUtils::RealPath(fullpath); + wxString real_path = CLRealPath(fullpath); if (Visited.insert(real_path).second) { Q.push_back(fullpath); } diff --git a/LiteEditor/mainbook.cpp b/LiteEditor/mainbook.cpp index 844c970ac0..a00c2b4526 100644 --- a/LiteEditor/mainbook.cpp +++ b/LiteEditor/mainbook.cpp @@ -455,7 +455,7 @@ int MainBook::FindEditorIndexByFullPath(const wxString& fullpath) { #ifdef __WXGTK__ // On gtk either fileName or the editor filepath (or both) may be (or their paths contain) symlinks - wxString fileNameDest = CLRealPath(fullpath); + wxString fileNameDest = CLRealPath(fullpath, true); #endif for (size_t i = 0; i < m_book->GetPageCount(); ++i) { @@ -489,7 +489,7 @@ int MainBook::FindEditorIndexByFullPath(const wxString& fullpath) #if defined(__WXGTK__) // Try again, dereferencing the editor fpath - wxString editorDest = CLRealPath(unixStyleFile); + wxString editorDest = CLRealPath(unixStyleFile, true); if (editorDest.Cmp(fullpath) == 0 || editorDest.Cmp(fileNameDest) == 0) { return i; } @@ -517,8 +517,9 @@ wxWindow* MainBook::FindPage(const wxString& text) return editor; } - if (m_book->GetPageText(i) == text) + if (m_book->GetPageText(i) == text) { return m_book->GetPage(i); + } } return NULL; } @@ -625,6 +626,13 @@ clEditor* MainBook::OpenFile(const wxString& file_name, const wxString& tooltip /* wxEmptyString */) { wxFileName fileName(CLRealPath(file_name)); + + if (fileName.IsRelative()) { + if (clWorkspaceManager::Get().IsWorkspaceOpened()) { + wxFileName wsPath = clWorkspaceManager::Get().GetWorkspace()->GetDir(); + fileName.MakeAbsolute(wsPath.GetFullPath()); + } + } fileName.MakeAbsolute(); #ifdef __WXMSW__ @@ -1741,7 +1749,7 @@ WelcomePage* MainBook::GetWelcomePage(bool createIfMissing) clEditor* MainBook::OpenFileAsync(const wxString& file_name, std::function&& callback) { - wxString real_path = CLRealPath(file_name); + wxString real_path = CLRealPath(file_name, true); auto editor = FindEditor(real_path); if (editor) { push_callback(std::move(callback), real_path); @@ -1752,7 +1760,7 @@ clEditor* MainBook::OpenFileAsync(const wxString& file_name, std::functionSetSelection(index); } } else { - editor = OpenFile(real_path); + editor = OpenFile(file_name); if (editor) { push_callback(std::move(callback), real_path); } @@ -1817,11 +1825,12 @@ void MainBook::OnIdle(wxIdleEvent& event) auto editor = GetActiveEditor(); CHECK_PTR_RET(editor); - execute_callbacks_for_file(CLRealPath(editor->GetFileName().GetFullPath())); + execute_callbacks_for_file(CLRealPath(editor->GetFileName().GetFullPath(), true)); } void MainBook::OnEditorModified(clCommandEvent& event) { event.Skip(); } void MainBook::OnEditorSaved(clCommandEvent& event) { event.Skip(); } -void MainBook::OnSessionLoaded(clCommandEvent& event) { event.Skip(); } \ No newline at end of file +void MainBook::OnSessionLoaded(clCommandEvent& event) { event.Skip(); } + diff --git a/Plugin/globals.cpp b/Plugin/globals.cpp index 100970911d..6e336cb946 100644 --- a/Plugin/globals.cpp +++ b/Plugin/globals.cpp @@ -104,6 +104,8 @@ #include "SFTPBrowserDlg.h" #endif +static const char* pEnv_CL_RealPath = getenv("CL_REALPATH"); + const wxEventType wxEVT_COMMAND_CL_INTERNAL_0_ARGS = ::wxNewEventType(); const wxEventType wxEVT_COMMAND_CL_INTERNAL_1_ARGS = ::wxNewEventType(); @@ -928,7 +930,7 @@ wxFileName wxReadLink(const wxFileName& filename) if (wxIsFileSymlink(filename)) { #if defined(__WXGTK__) // Use 'realpath' on Linux, otherwise this breaks on relative symlinks, and (untested) on symlinks-to-symlinks - return wxFileName(CLRealPath(filename.GetFullPath())); + return wxFileName(CLRealPath(filename.GetFullPath(), true)); #else // OSX wxFileName realFileName; @@ -948,10 +950,14 @@ wxFileName wxReadLink(const wxFileName& filename) #endif } -wxString CLRealPath(const wxString& filepath) // This is readlink on steroids: it also makes-absolute, and dereferences +wxString CLRealPath(const wxString& filepath, bool force) // This is readlink on steroids: it also makes-absolute, and dereferences // any symlinked dirs in the path { - return FileUtils::RealPath(filepath); + if (force || pEnv_CL_RealPath) { + return FileUtils::RealPath(filepath); + } else { + return filepath; + } } int wxStringToInt(const wxString& str, int defval, int minval, int maxval) diff --git a/Plugin/globals.h b/Plugin/globals.h index 3748406c98..19383391da 100644 --- a/Plugin/globals.h +++ b/Plugin/globals.h @@ -336,7 +336,7 @@ WXDLLIMPEXP_SDK wxFileName wxReadLink(const wxFileName& filename); /** * @brief makes-absolute filepath, and dereferences it and any symlinked dirs in the path */ -WXDLLIMPEXP_SDK wxString CLRealPath(const wxString& filepath); +WXDLLIMPEXP_SDK wxString CLRealPath(const wxString& filepath, bool force=false); /** * @brief convert string to integer using range validation and default value