TextEditor: Some fileName -> filePath renaming

Change-Id: Id0751f936666fa658226d62a1906b82e3bac1660
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2023-02-07 18:14:53 +01:00
parent a7bf65c288
commit 3f8240a7de
11 changed files with 46 additions and 48 deletions

View File

@@ -66,10 +66,10 @@ void Bookmark::updateBlock(const QTextBlock &block)
} }
} }
void Bookmark::updateFileName(const FilePath &filePath) void Bookmark::updateFilePath(const FilePath &filePath)
{ {
const FilePath oldFilePath = this->fileName(); const FilePath oldFilePath = this->filePath();
TextMark::updateFileName(filePath); TextMark::updateFilePath(filePath);
m_manager->updateBookmarkFileName(this, oldFilePath); m_manager->updateBookmarkFileName(this, oldFilePath);
} }

View File

@@ -17,7 +17,7 @@ public:
void updateLineNumber(int lineNumber) override; void updateLineNumber(int lineNumber) override;
void move(int line) override; void move(int line) override;
void updateBlock(const QTextBlock &block) override; void updateBlock(const QTextBlock &block) override;
void updateFileName(const Utils::FilePath &filePath) override; void updateFilePath(const Utils::FilePath &filePath) override;
void removedFromEditor() override; void removedFromEditor() override;
bool isDraggable() const override; bool isDraggable() const override;

View File

@@ -57,7 +57,7 @@ void BookmarkFilter::prepareSearch(const QString &entry)
for (const QModelIndex &idx : matches) { for (const QModelIndex &idx : matches) {
const Bookmark *bookmark = m_manager->bookmarkForIndex(idx); const Bookmark *bookmark = m_manager->bookmarkForIndex(idx);
const QString filename = bookmark->fileName().fileName(); const QString filename = bookmark->filePath().fileName();
LocatorFilterEntry filterEntry(this, LocatorFilterEntry filterEntry(this,
QString("%1:%2").arg(filename).arg(bookmark->lineNumber()), QString("%1:%2").arg(filename).arg(bookmark->lineNumber()),
QVariant::fromValue(idx)); QVariant::fromValue(idx));
@@ -66,7 +66,7 @@ void BookmarkFilter::prepareSearch(const QString &entry)
else if (!bookmark->lineText().isEmpty()) else if (!bookmark->lineText().isEmpty())
filterEntry.extraInfo = bookmark->lineText(); filterEntry.extraInfo = bookmark->lineText();
else else
filterEntry.extraInfo = bookmark->fileName().toString(); filterEntry.extraInfo = bookmark->filePath().toString();
int highlightIndex = filterEntry.displayName.indexOf(entry, 0, Qt::CaseInsensitive); int highlightIndex = filterEntry.displayName.indexOf(entry, 0, Qt::CaseInsensitive);
if (highlightIndex >= 0) { if (highlightIndex >= 0) {
filterEntry.highlightInfo = {highlightIndex, int(entry.length())}; filterEntry.highlightInfo = {highlightIndex, int(entry.length())};

View File

@@ -343,17 +343,17 @@ QVariant BookmarkManager::data(const QModelIndex &index, int role) const
Bookmark *bookMark = m_bookmarksList.at(index.row()); Bookmark *bookMark = m_bookmarksList.at(index.row());
if (role == BookmarkManager::Filename) if (role == BookmarkManager::Filename)
return bookMark->fileName().fileName(); return bookMark->filePath().fileName();
if (role == BookmarkManager::LineNumber) if (role == BookmarkManager::LineNumber)
return bookMark->lineNumber(); return bookMark->lineNumber();
if (role == BookmarkManager::Directory) if (role == BookmarkManager::Directory)
return bookMark->fileName().toFileInfo().path(); return bookMark->filePath().toFileInfo().path();
if (role == BookmarkManager::LineText) if (role == BookmarkManager::LineText)
return bookMark->lineText(); return bookMark->lineText();
if (role == BookmarkManager::Note) if (role == BookmarkManager::Note)
return bookMark->note(); return bookMark->note();
if (role == Qt::ToolTipRole) if (role == Qt::ToolTipRole)
return bookMark->fileName().toUserOutput(); return bookMark->filePath().toUserOutput();
return QVariant(); return QVariant();
} }
@@ -381,7 +381,7 @@ QMimeData *BookmarkManager::mimeData(const QModelIndexList &indexes) const
if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= m_bookmarksList.count()) if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= m_bookmarksList.count())
continue; continue;
Bookmark *bookMark = m_bookmarksList.at(index.row()); Bookmark *bookMark = m_bookmarksList.at(index.row());
data->addFile(bookMark->fileName(), bookMark->lineNumber()); data->addFile(bookMark->filePath(), bookMark->lineNumber());
} }
return data; return data;
} }
@@ -400,7 +400,7 @@ void BookmarkManager::toggleBookmark(const FilePath &fileName, int lineNumber)
// Add a new bookmark if no bookmark existed on this line // Add a new bookmark if no bookmark existed on this line
auto mark = new Bookmark(lineNumber, this); auto mark = new Bookmark(lineNumber, this);
mark->updateFileName(fileName); mark->updateFilePath(fileName);
const QModelIndex currentIndex = selectionModel()->currentIndex(); const QModelIndex currentIndex = selectionModel()->currentIndex();
const int insertionIndex = currentIndex.isValid() ? currentIndex.row() + 1 const int insertionIndex = currentIndex.isValid() ? currentIndex.row() + 1
: m_bookmarksList.size(); : m_bookmarksList.size();
@@ -419,11 +419,11 @@ void BookmarkManager::updateBookmark(Bookmark *bookmark)
void BookmarkManager::updateBookmarkFileName(Bookmark *bookmark, const FilePath &oldFilePath) void BookmarkManager::updateBookmarkFileName(Bookmark *bookmark, const FilePath &oldFilePath)
{ {
if (oldFilePath == bookmark->fileName()) if (oldFilePath == bookmark->filePath())
return; return;
m_bookmarksMap[oldFilePath].removeAll(bookmark); m_bookmarksMap[oldFilePath].removeAll(bookmark);
m_bookmarksMap[bookmark->fileName()].append(bookmark); m_bookmarksMap[bookmark->filePath()].append(bookmark);
updateBookmark(bookmark); updateBookmark(bookmark);
} }
@@ -444,7 +444,7 @@ void BookmarkManager::deleteBookmark(Bookmark *bookmark)
int idx = m_bookmarksList.indexOf(bookmark); int idx = m_bookmarksList.indexOf(bookmark);
beginRemoveRows(QModelIndex(), idx, idx); beginRemoveRows(QModelIndex(), idx, idx);
m_bookmarksMap[bookmark->fileName()].removeAll(bookmark); m_bookmarksMap[bookmark->filePath()].removeAll(bookmark);
delete bookmark; delete bookmark;
m_bookmarksList.removeAt(idx); m_bookmarksList.removeAt(idx);
@@ -467,7 +467,7 @@ Bookmark *BookmarkManager::bookmarkForIndex(const QModelIndex &index) const
bool BookmarkManager::gotoBookmark(const Bookmark *bookmark) const bool BookmarkManager::gotoBookmark(const Bookmark *bookmark) const
{ {
if (IEditor *editor = EditorManager::openEditorAt( if (IEditor *editor = EditorManager::openEditorAt(
Utils::Link(bookmark->fileName(), bookmark->lineNumber()))) { Utils::Link(bookmark->filePath(), bookmark->lineNumber()))) {
return editor->currentLine() == bookmark->lineNumber(); return editor->currentLine() == bookmark->lineNumber();
} }
return false; return false;
@@ -687,7 +687,7 @@ void BookmarkManager::insertBookmark(int idx, Bookmark *bookmark, bool userset)
idx = qBound(0, idx, m_bookmarksList.size()); idx = qBound(0, idx, m_bookmarksList.size());
beginInsertRows(QModelIndex(), idx, idx); beginInsertRows(QModelIndex(), idx, idx);
m_bookmarksMap[bookmark->fileName()].append(bookmark); m_bookmarksMap[bookmark->filePath()].append(bookmark);
m_bookmarksList.insert(idx, bookmark); m_bookmarksList.insert(idx, bookmark);
endInsertRows(); endInsertRows();
@@ -724,7 +724,7 @@ void BookmarkManager::addBookmark(const QString &s)
const int lineNumber = s.mid(index2 + 1, index3 - index2 - 1).toInt(); const int lineNumber = s.mid(index2 + 1, index3 - index2 - 1).toInt();
if (!filePath.isEmpty() && !findBookmark(FilePath::fromString(filePath), lineNumber)) { if (!filePath.isEmpty() && !findBookmark(FilePath::fromString(filePath), lineNumber)) {
auto b = new Bookmark(lineNumber, this); auto b = new Bookmark(lineNumber, this);
b->updateFileName(FilePath::fromString(filePath)); b->updateFilePath(FilePath::fromString(filePath));
b->setNote(note); b->setNote(note);
addBookmark(b, false); addBookmark(b, false);
} }
@@ -739,7 +739,7 @@ QString BookmarkManager::bookmarkToString(const Bookmark *b)
const QLatin1Char colon(':'); const QLatin1Char colon(':');
// Using \t as delimiter because any another symbol can be a part of note. // Using \t as delimiter because any another symbol can be a part of note.
const QLatin1Char noteDelimiter('\t'); const QLatin1Char noteDelimiter('\t');
return colon + b->fileName().toString() + return colon + b->filePath().toString() +
colon + QString::number(b->lineNumber()) + colon + QString::number(b->lineNumber()) +
noteDelimiter + b->note(); noteDelimiter + b->note();
} }
@@ -772,7 +772,7 @@ bool BookmarkManager::isAtCurrentBookmark() const
return true; return true;
IEditor *currentEditor = EditorManager::currentEditor(); IEditor *currentEditor = EditorManager::currentEditor();
return currentEditor return currentEditor
&& currentEditor->document()->filePath() == bk->fileName() && currentEditor->document()->filePath() == bk->filePath()
&& currentEditor->currentLine() == bk->lineNumber(); && currentEditor->currentLine() == bk->lineNumber();
} }

View File

@@ -323,7 +323,7 @@ ClangdTextMark::ClangdTextMark(const FilePath &filePath,
bool ClangdTextMark::addToolTipContent(QLayout *target) const bool ClangdTextMark::addToolTipContent(QLayout *target) const
{ {
const auto canApplyFixIt = [c = m_client, diag = m_lspDiagnostic, fp = fileName()] { const auto canApplyFixIt = [c = m_client, diag = m_lspDiagnostic, fp = filePath()] {
return QTC_GUARD(c) && c->reachable() && c->hasDiagnostic(fp, diag); return QTC_GUARD(c) && c->reachable() && c->hasDiagnostic(fp, diag);
}; };
const QString clientName = QTC_GUARD(m_client) ? m_client->name() : "clangd [unknown]"; const QString clientName = QTC_GUARD(m_client) ? m_client->name() : "clangd [unknown]";

View File

@@ -89,9 +89,9 @@ public:
gbp->m_params.lineNumber = lineNumber; gbp->m_params.lineNumber = lineNumber;
} }
void updateFileName(const FilePath &fileName) final void updateFilePath(const FilePath &fileName) final
{ {
TextMark::updateFileName(fileName); TextMark::updateFilePath(fileName);
QTC_ASSERT(m_bp, return); QTC_ASSERT(m_bp, return);
m_bp->setFileName(fileName); m_bp->setFileName(fileName);
if (GlobalBreakpoint gbp = m_bp->globalBreakpoint()) if (GlobalBreakpoint gbp = m_bp->globalBreakpoint())
@@ -158,9 +158,9 @@ public:
m_gbp->updateLineNumber(lineNumber); m_gbp->updateLineNumber(lineNumber);
} }
void updateFileName(const FilePath &fileName) final void updateFilePath(const FilePath &fileName) final
{ {
TextMark::updateFileName(fileName); TextMark::updateFilePath(fileName);
QTC_ASSERT(m_gbp, return); QTC_ASSERT(m_gbp, return);
m_gbp->updateFileName(fileName); m_gbp->updateFileName(fileName);
} }
@@ -1883,7 +1883,7 @@ void BreakpointItem::updateMarker()
{ {
const FilePath &file = markerFileName(); const FilePath &file = markerFileName();
int line = markerLineNumber(); int line = markerLineNumber();
if (m_marker && (file != m_marker->fileName() || line != m_marker->lineNumber())) if (m_marker && (file != m_marker->filePath() || line != m_marker->lineNumber()))
destroyMarker(); destroyMarker();
if (!m_marker && !file.isEmpty() && line > 0) if (!m_marker && !file.isEmpty() && line > 0)
@@ -2308,8 +2308,8 @@ void GlobalBreakpointItem::updateMarker()
const int line = m_params.lineNumber; const int line = m_params.lineNumber;
if (m_marker) { if (m_marker) {
if (m_params.fileName != m_marker->fileName()) if (m_params.fileName != m_marker->filePath())
m_marker->updateFileName(m_params.fileName); m_marker->updateFilePath(m_params.fileName);
if (line != m_marker->lineNumber()) if (line != m_marker->lineNumber())
m_marker->move(line); m_marker->move(line);
} else if (!m_params.fileName.isEmpty() && line > 0) { } else if (!m_params.fileName.isEmpty() && line > 0) {

View File

@@ -65,7 +65,7 @@ public:
bool isClickable() const override; bool isClickable() const override;
void clicked() override; void clicked() override;
void updateFileName(const FilePath &fileName) override; void updateFilePath(const FilePath &fileName) override;
void updateLineNumber(int lineNumber) override; void updateLineNumber(int lineNumber) override;
void removedFromEditor() override; void removedFromEditor() override;
private: private:
@@ -78,10 +78,10 @@ void TaskMark::updateLineNumber(int lineNumber)
TextMark::updateLineNumber(lineNumber); TextMark::updateLineNumber(lineNumber);
} }
void TaskMark::updateFileName(const FilePath &fileName) void TaskMark::updateFilePath(const FilePath &fileName)
{ {
TaskHub::updateTaskFileName(m_task, fileName.toString()); TaskHub::updateTaskFileName(m_task, fileName.toString());
TextMark::updateFileName(FilePath::fromString(fileName.toString())); TextMark::updateFilePath(FilePath::fromString(fileName.toString()));
} }
void TaskMark::removedFromEditor() void TaskMark::removedFromEditor()

View File

@@ -995,7 +995,7 @@ void SquishTools::updateLocationMarker(const Utils::FilePath &file, int line)
if (QTC_GUARD(!m_locationMarker)) { if (QTC_GUARD(!m_locationMarker)) {
m_locationMarker = new SquishLocationMark(file, line); m_locationMarker = new SquishLocationMark(file, line);
} else { } else {
m_locationMarker->updateFileName(file); m_locationMarker->updateFilePath(file);
m_locationMarker->move(line); m_locationMarker->move(line);
} }
} }

View File

@@ -63,8 +63,8 @@ private:
TextMarkRegistry *m_instance = nullptr; TextMarkRegistry *m_instance = nullptr;
TextMark::TextMark(const FilePath &fileName, int lineNumber, TextMarkCategory category) TextMark::TextMark(const FilePath &filePath, int lineNumber, TextMarkCategory category)
: m_fileName(fileName) : m_fileName(filePath)
, m_lineNumber(lineNumber) , m_lineNumber(lineNumber)
, m_visible(true) , m_visible(true)
, m_category(category) , m_category(category)
@@ -82,18 +82,18 @@ TextMark::~TextMark()
m_baseTextDocument = nullptr; m_baseTextDocument = nullptr;
} }
FilePath TextMark::fileName() const FilePath TextMark::filePath() const
{ {
return m_fileName; return m_fileName;
} }
void TextMark::updateFileName(const FilePath &fileName) void TextMark::updateFilePath(const FilePath &filePath)
{ {
if (fileName == m_fileName) if (filePath == m_fileName)
return; return;
if (!m_fileName.isEmpty()) if (!m_fileName.isEmpty())
TextMarkRegistry::remove(this); TextMarkRegistry::remove(this);
m_fileName = fileName; m_fileName = filePath;
if (!m_fileName.isEmpty()) if (!m_fileName.isEmpty())
TextMarkRegistry::add(this); TextMarkRegistry::add(this);
} }
@@ -451,14 +451,14 @@ TextMarkRegistry::TextMarkRegistry(QObject *parent)
void TextMarkRegistry::add(TextMark *mark) void TextMarkRegistry::add(TextMark *mark)
{ {
instance()->m_marks[mark->fileName()].insert(mark); instance()->m_marks[mark->filePath()].insert(mark);
if (TextDocument *document = TextDocument::textDocumentForFilePath(mark->fileName())) if (TextDocument *document = TextDocument::textDocumentForFilePath(mark->filePath()))
document->addMark(mark); document->addMark(mark);
} }
bool TextMarkRegistry::remove(TextMark *mark) bool TextMarkRegistry::remove(TextMark *mark)
{ {
return instance()->m_marks[mark->fileName()].remove(mark); return instance()->m_marks[mark->filePath()].remove(mark);
} }
TextMarkRegistry *TextMarkRegistry::instance() TextMarkRegistry *TextMarkRegistry::instance()
@@ -500,7 +500,7 @@ void TextMarkRegistry::documentRenamed(IDocument *document,
m_marks[newPath].unite(toBeMoved); m_marks[newPath].unite(toBeMoved);
for (TextMark *mark : std::as_const(toBeMoved)) for (TextMark *mark : std::as_const(toBeMoved))
mark->updateFileName(newPath); mark->updateFilePath(newPath);
} }
void TextMarkRegistry::allDocumentsRenamed(const FilePath &oldPath, const FilePath &newPath) void TextMarkRegistry::allDocumentsRenamed(const FilePath &oldPath, const FilePath &newPath)
@@ -514,7 +514,7 @@ void TextMarkRegistry::allDocumentsRenamed(const FilePath &oldPath, const FilePa
m_marks[oldPath].clear(); m_marks[oldPath].clear();
for (TextMark *mark : oldFileNameMarks) for (TextMark *mark : oldFileNameMarks)
mark->updateFileName(newPath); mark->updateFilePath(newPath);
} }
QHash<AnnotationColors::SourceColors, AnnotationColors> AnnotationColors::m_colorCache; QHash<AnnotationColors::SourceColors, AnnotationColors> AnnotationColors::m_colorCache;

View File

@@ -38,10 +38,8 @@ public:
class TEXTEDITOR_EXPORT TextMark class TEXTEDITOR_EXPORT TextMark
{ {
public: public:
TextMark(const Utils::FilePath &fileName,
int lineNumber,
TextMarkCategory category);
TextMark() = delete; TextMark() = delete;
TextMark(const Utils::FilePath &filePath, int lineNumber, TextMarkCategory category);
virtual ~TextMark(); virtual ~TextMark();
// determine order on markers on the same line. // determine order on markers on the same line.
@@ -52,7 +50,7 @@ public:
HighPriority // shown on top. HighPriority // shown on top.
}; };
Utils::FilePath fileName() const; Utils::FilePath filePath() const;
int lineNumber() const; int lineNumber() const;
virtual void paintIcon(QPainter *painter, const QRect &rect) const; virtual void paintIcon(QPainter *painter, const QRect &rect) const;
@@ -74,7 +72,7 @@ public:
AnnotationRects annotationRects(const QRectF &boundingRect, const QFontMetrics &fm, AnnotationRects annotationRects(const QRectF &boundingRect, const QFontMetrics &fm,
const qreal fadeInOffset, const qreal fadeOutOffset) const; const qreal fadeInOffset, const qreal fadeOutOffset) const;
/// called if the filename of the document changed /// called if the filename of the document changed
virtual void updateFileName(const Utils::FilePath &fileName); virtual void updateFilePath(const Utils::FilePath &filePath);
virtual void updateLineNumber(int lineNumber); virtual void updateLineNumber(int lineNumber);
virtual void updateBlock(const QTextBlock &block); virtual void updateBlock(const QTextBlock &block);
virtual void move(int line); virtual void move(int line);

View File

@@ -833,7 +833,7 @@ void CallgrindToolPrivate::requestContextMenu(TextEditorWidget *widget, int line
{ {
// Find callgrind text mark that corresponds to this editor's file and line number // Find callgrind text mark that corresponds to this editor's file and line number
for (CallgrindTextMark *textMark : std::as_const(m_textMarks)) { for (CallgrindTextMark *textMark : std::as_const(m_textMarks)) {
if (textMark->fileName() == widget->textDocument()->filePath() && textMark->lineNumber() == line) { if (textMark->filePath() == widget->textDocument()->filePath() && textMark->lineNumber() == line) {
const Function *func = textMark->function(); const Function *func = textMark->function();
QAction *action = menu->addAction(Tr::tr("Select This Function in the Analyzer Output")); QAction *action = menu->addAction(Tr::tr("Select This Function in the Analyzer Output"));
connect(action, &QAction::triggered, this, [this, func] { selectFunction(func); }); connect(action, &QAction::triggered, this, [this, func] { selectFunction(func); });