forked from qt-creator/qt-creator
Core: filepathify FileIconProvider
Change-Id: Id6fcc05317f3f5144c662fb4826438407f8d9d21 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -58,7 +58,7 @@ QVariant FilePathItem::data(int column, int role) const
|
|||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return m_filePath.toUserOutput();
|
return m_filePath.toUserOutput();
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return Core::FileIconProvider::icon(m_filePath.toFileInfo());
|
return Core::FileIconProvider::icon(m_filePath);
|
||||||
case Debugger::DetailedErrorView::FullTextRole:
|
case Debugger::DetailedErrorView::FullTextRole:
|
||||||
return m_filePath.toUserOutput();
|
return m_filePath.toUserOutput();
|
||||||
default:
|
default:
|
||||||
|
@@ -414,21 +414,20 @@ void ReadOnlyFilesDialogPrivate::initDialog(const FilePaths &filePaths)
|
|||||||
QString vcsMakeWritableTextForAll;
|
QString vcsMakeWritableTextForAll;
|
||||||
bool useMakeWritable = false;
|
bool useMakeWritable = false;
|
||||||
for (const FilePath &filePath : filePaths) {
|
for (const FilePath &filePath : filePaths) {
|
||||||
const QFileInfo info = filePath.toFileInfo();
|
const QString visibleName = filePath.fileName();
|
||||||
const QString visibleName = info.fileName();
|
const FilePath directory = filePath.absolutePath();
|
||||||
const QString directory = info.absolutePath();
|
|
||||||
|
|
||||||
// Setup a default entry with filename folder and make writable radio button.
|
// Setup a default entry with filename folder and make writable radio button.
|
||||||
auto item = new QTreeWidgetItem(ui.treeWidget);
|
auto item = new QTreeWidgetItem(ui.treeWidget);
|
||||||
item->setText(FileName, visibleName);
|
item->setText(FileName, visibleName);
|
||||||
item->setIcon(FileName, FileIconProvider::icon(info));
|
item->setIcon(FileName, FileIconProvider::icon(filePath));
|
||||||
item->setText(Folder, Utils::FilePath::fromString(directory).shortNativePath());
|
item->setText(Folder, directory.shortNativePath());
|
||||||
auto radioButtonGroup = new QButtonGroup;
|
auto radioButtonGroup = new QButtonGroup;
|
||||||
|
|
||||||
// Add a button for opening the file with a version control system
|
// Add a button for opening the file with a version control system
|
||||||
// if the file is managed by an version control system which allows opening files.
|
// if the file is managed by an version control system which allows opening files.
|
||||||
IVersionControl *versionControlForFile =
|
IVersionControl *versionControlForFile =
|
||||||
VcsManager::findVersionControlForDirectory(directory);
|
VcsManager::findVersionControlForDirectory(directory.toString());
|
||||||
const bool fileManagedByVCS = versionControlForFile
|
const bool fileManagedByVCS = versionControlForFile
|
||||||
&& versionControlForFile->openSupportMode(filePath.toString()) != IVersionControl::NoOpen;
|
&& versionControlForFile->openSupportMode(filePath.toString()) != IVersionControl::NoOpen;
|
||||||
if (fileManagedByVCS) {
|
if (fileManagedByVCS) {
|
||||||
|
@@ -68,18 +68,17 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent,
|
|||||||
foreach (IDocument *document, items) {
|
foreach (IDocument *document, items) {
|
||||||
QString visibleName;
|
QString visibleName;
|
||||||
QString directory;
|
QString directory;
|
||||||
QString fileName = document->filePath().toString();
|
Utils::FilePath filePath = document->filePath();
|
||||||
if (fileName.isEmpty()) {
|
if (filePath.isEmpty()) {
|
||||||
visibleName = document->fallbackSaveAsFileName();
|
visibleName = document->fallbackSaveAsFileName();
|
||||||
} else {
|
} else {
|
||||||
QFileInfo info = QFileInfo(fileName);
|
directory = filePath.absolutePath().toUserOutput();
|
||||||
directory = info.absolutePath();
|
visibleName = filePath.fileName();
|
||||||
visibleName = info.fileName();
|
|
||||||
}
|
}
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList()
|
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList()
|
||||||
<< visibleName << QDir::toNativeSeparators(directory));
|
<< visibleName << QDir::toNativeSeparators(directory));
|
||||||
if (!fileName.isEmpty())
|
if (!filePath.isEmpty())
|
||||||
item->setIcon(0, FileIconProvider::icon(QFileInfo(fileName)));
|
item->setIcon(0, FileIconProvider::icon(filePath));
|
||||||
item->setData(0, Qt::UserRole, QVariant::fromValue(document));
|
item->setData(0, Qt::UserRole, QVariant::fromValue(document));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -417,7 +417,7 @@ void EditorToolBar::updateDocumentStatus(IDocument *document)
|
|||||||
if (document->filePath().isEmpty())
|
if (document->filePath().isEmpty())
|
||||||
d->m_dragHandle->setIcon(QIcon());
|
d->m_dragHandle->setIcon(QIcon());
|
||||||
else
|
else
|
||||||
d->m_dragHandle->setIcon(FileIconProvider::icon(document->filePath().toFileInfo()));
|
d->m_dragHandle->setIcon(FileIconProvider::icon(document->filePath()));
|
||||||
|
|
||||||
d->m_editorList->setToolTip(document->filePath().isEmpty()
|
d->m_editorList->setToolTip(document->filePath().isEmpty()
|
||||||
? document->displayName()
|
? document->displayName()
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "fileiconprovider.h"
|
#include "fileiconprovider.h"
|
||||||
|
|
||||||
|
#include <utils/fileutils.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/mimetypes/mimedatabase.h>
|
#include <utils/mimetypes/mimedatabase.h>
|
||||||
#include <utils/optional.h>
|
#include <utils/optional.h>
|
||||||
@@ -90,7 +91,7 @@ public:
|
|||||||
FileIconProviderImplementation()
|
FileIconProviderImplementation()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QIcon icon(const QFileInfo &info) const override;
|
QIcon icon(const FilePath &filePath) const;
|
||||||
using QFileIconProvider::icon;
|
using QFileIconProvider::icon;
|
||||||
|
|
||||||
void registerIconOverlayForFilename(const QString &iconFilePath, const QString &filename)
|
void registerIconOverlayForFilename(const QString &iconFilePath, const QString &filename)
|
||||||
@@ -139,19 +140,19 @@ QFileIconProvider *iconProvider()
|
|||||||
return instance();
|
return instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon FileIconProviderImplementation::icon(const QFileInfo &fileInfo) const
|
QIcon FileIconProviderImplementation::icon(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << "FileIconProvider::icon" << fileInfo.absoluteFilePath();
|
qDebug() << "FileIconProvider::icon" << filePath.absoluteFilePath();
|
||||||
// Check for cached overlay icons by file suffix.
|
// Check for cached overlay icons by file suffix.
|
||||||
bool isDir = fileInfo.isDir();
|
bool isDir = filePath.isDir();
|
||||||
const QString filename = !isDir ? fileInfo.fileName() : QString();
|
const QString filename = !isDir ? filePath.fileName() : QString();
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
const Utils::optional<QIcon> icon = getIcon(m_filenameCache, filename);
|
const Utils::optional<QIcon> icon = getIcon(m_filenameCache, filename);
|
||||||
if (icon)
|
if (icon)
|
||||||
return *icon;
|
return *icon;
|
||||||
}
|
}
|
||||||
const QString suffix = !isDir ? fileInfo.suffix() : QString();
|
const QString suffix = !isDir ? filePath.suffix() : QString();
|
||||||
if (!suffix.isEmpty()) {
|
if (!suffix.isEmpty()) {
|
||||||
const Utils::optional<QIcon> icon = getIcon(m_suffixCache, suffix);
|
const Utils::optional<QIcon> icon = getIcon(m_suffixCache, suffix);
|
||||||
if (icon)
|
if (icon)
|
||||||
@@ -161,10 +162,10 @@ QIcon FileIconProviderImplementation::icon(const QFileInfo &fileInfo) const
|
|||||||
// Get icon from OS (and cache it based on suffix!)
|
// Get icon from OS (and cache it based on suffix!)
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
if (HostOsInfo::isWindowsHost() || HostOsInfo::isMacHost()) {
|
if (HostOsInfo::isWindowsHost() || HostOsInfo::isMacHost()) {
|
||||||
icon = QFileIconProvider::icon(fileInfo);
|
icon = QFileIconProvider::icon(filePath.toFileInfo());
|
||||||
} else { // File icons are unknown on linux systems.
|
} else { // File icons are unknown on linux systems.
|
||||||
static const QIcon unknownFileIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon));
|
static const QIcon unknownFileIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon));
|
||||||
icon = isDir ? QFileIconProvider::icon(fileInfo) : unknownFileIcon;
|
icon = isDir ? QFileIconProvider::icon(filePath.toFileInfo()) : unknownFileIcon;
|
||||||
}
|
}
|
||||||
if (!isDir && !suffix.isEmpty())
|
if (!isDir && !suffix.isEmpty())
|
||||||
m_suffixCache.insert(suffix, icon);
|
m_suffixCache.insert(suffix, icon);
|
||||||
@@ -176,9 +177,9 @@ QIcon FileIconProviderImplementation::icon(const QFileInfo &fileInfo) const
|
|||||||
the default icon of the operating system is returned.
|
the default icon of the operating system is returned.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QIcon icon(const QFileInfo &info)
|
QIcon icon(const FilePath &filePath)
|
||||||
{
|
{
|
||||||
return instance()->icon(info);
|
return instance()->icon(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@@ -30,6 +30,8 @@
|
|||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QFileIconProvider>
|
#include <QFileIconProvider>
|
||||||
|
|
||||||
|
namespace Utils { class FilePath; }
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
namespace FileIconProvider {
|
namespace FileIconProvider {
|
||||||
@@ -38,7 +40,7 @@ namespace FileIconProvider {
|
|||||||
CORE_EXPORT QFileIconProvider *iconProvider();
|
CORE_EXPORT QFileIconProvider *iconProvider();
|
||||||
|
|
||||||
// Access to individual items
|
// Access to individual items
|
||||||
CORE_EXPORT QIcon icon(const QFileInfo &info);
|
CORE_EXPORT QIcon icon(const Utils::FilePath &filePath);
|
||||||
CORE_EXPORT QIcon icon(QFileIconProvider::IconType type);
|
CORE_EXPORT QIcon icon(QFileIconProvider::IconType type);
|
||||||
|
|
||||||
// Register additional overlay icons
|
// Register additional overlay icons
|
||||||
|
@@ -210,7 +210,7 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const
|
|||||||
if (index.column() == DisplayNameColumn) {
|
if (index.column() == DisplayNameColumn) {
|
||||||
LocatorFilterEntry &entry = mEntries[index.row()];
|
LocatorFilterEntry &entry = mEntries[index.row()];
|
||||||
if (!entry.displayIcon && !entry.filePath.isEmpty())
|
if (!entry.displayIcon && !entry.filePath.isEmpty())
|
||||||
entry.displayIcon = FileIconProvider::icon(entry.filePath.toFileInfo());
|
entry.displayIcon = FileIconProvider::icon(entry.filePath);
|
||||||
return entry.displayIcon ? entry.displayIcon.value() : QIcon();
|
return entry.displayIcon ? entry.displayIcon.value() : QIcon();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@@ -345,10 +345,8 @@ FilePaths VcsManager::promptToDelete(const FilePaths &filePaths)
|
|||||||
// Categorize files by their parent directory, so we won't call
|
// Categorize files by their parent directory, so we won't call
|
||||||
// findVersionControlForDirectory() more often than necessary.
|
// findVersionControlForDirectory() more often than necessary.
|
||||||
QMap<FilePath, FilePaths> filesByParentDir;
|
QMap<FilePath, FilePaths> filesByParentDir;
|
||||||
for (const FilePath &fp : filePaths) {
|
for (const FilePath &fp : filePaths)
|
||||||
filesByParentDir[FilePath::fromString(QDir::cleanPath(fp.toFileInfo().absolutePath()))]
|
filesByParentDir[fp.absolutePath()].append(fp);
|
||||||
.append(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Categorize by version control system.
|
// Categorize by version control system.
|
||||||
QHash<IVersionControl *, FilePaths> filesByVersionControl;
|
QHash<IVersionControl *, FilePaths> filesByVersionControl;
|
||||||
|
@@ -47,7 +47,7 @@ QVariant FilePathItem::data(int column, int role) const
|
|||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return m_filePath;
|
return m_filePath;
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return Core::FileIconProvider::icon(QFileInfo(m_filePath));
|
return Core::FileIconProvider::icon(Utils::FilePath::fromString(m_filePath));
|
||||||
case Debugger::DetailedErrorView::FullTextRole:
|
case Debugger::DetailedErrorView::FullTextRole:
|
||||||
return m_filePath;
|
return m_filePath;
|
||||||
default:
|
default:
|
||||||
|
@@ -197,9 +197,9 @@ QVariant CppIncludeHierarchyItem::data(int column, int role) const
|
|||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
return m_filePath;
|
return m_filePath;
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return FileIconProvider::icon(QFileInfo(m_filePath));
|
return FileIconProvider::icon(FilePath::fromString(m_filePath));
|
||||||
case LinkRole:
|
case LinkRole:
|
||||||
return QVariant::fromValue(Utils::Link(Utils::FilePath::fromString(m_filePath), m_line));
|
return QVariant::fromValue(Link(FilePath::fromString(m_filePath), m_line));
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@@ -99,7 +99,7 @@ QVariant DependenciesModel::data(const QModelIndex &index, int role) const
|
|||||||
case Qt::CheckStateRole:
|
case Qt::CheckStateRole:
|
||||||
return SessionManager::hasDependency(m_project, p) ? Qt::Checked : Qt::Unchecked;
|
return SessionManager::hasDependency(m_project, p) ? Qt::Checked : Qt::Unchecked;
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return Core::FileIconProvider::icon(p->projectFilePath().toFileInfo());
|
return Core::FileIconProvider::icon(p->projectFilePath());
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@@ -142,7 +142,7 @@ QVariant FlatModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
case Qt::DecorationRole: {
|
case Qt::DecorationRole: {
|
||||||
if (!folderNode)
|
if (!folderNode)
|
||||||
return Core::FileIconProvider::icon(node->filePath().toFileInfo());
|
return Core::FileIconProvider::icon(node->filePath());
|
||||||
if (!project)
|
if (!project)
|
||||||
return folderNode->icon();
|
return folderNode->icon();
|
||||||
static QIcon warnIcon = Utils::Icons::WARNING.icon();
|
static QIcon warnIcon = Utils::Icons::WARNING.icon();
|
||||||
|
@@ -231,7 +231,7 @@ QVariant SelectableFilesModel::data(const QModelIndex &index, int role) const
|
|||||||
return t->checked;
|
return t->checked;
|
||||||
if (role == Qt::DecorationRole) {
|
if (role == Qt::DecorationRole) {
|
||||||
if (t->icon.isNull())
|
if (t->icon.isNull())
|
||||||
t->icon = Core::FileIconProvider::icon(t->fullPath.toFileInfo());
|
t->icon = Core::FileIconProvider::icon(t->fullPath);
|
||||||
return t->icon;
|
return t->icon;
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@@ -798,7 +798,7 @@ QVariant ResourceModel::data(const QModelIndex &index, int role) const
|
|||||||
if (iconFileExtension(path))
|
if (iconFileExtension(path))
|
||||||
file->icon = QIcon(path);
|
file->icon = QIcon(path);
|
||||||
else
|
else
|
||||||
file->icon = Core::FileIconProvider::icon(QFileInfo(path));
|
file->icon = Core::FileIconProvider::icon(Utils::FilePath::fromString(path));
|
||||||
}
|
}
|
||||||
if (!file->icon.isNull())
|
if (!file->icon.isNull())
|
||||||
result = file->icon;
|
result = file->icon;
|
||||||
|
@@ -243,7 +243,7 @@ ResourceTopLevelNode::ResourceTopLevelNode(const FilePath &filePath,
|
|||||||
const QString &contents)
|
const QString &contents)
|
||||||
: FolderNode(filePath)
|
: FolderNode(filePath)
|
||||||
{
|
{
|
||||||
setIcon([filePath] { return FileIconProvider::icon(filePath.toFileInfo()); });
|
setIcon([filePath] { return FileIconProvider::icon(filePath); });
|
||||||
setPriority(Node::DefaultFilePriority);
|
setPriority(Node::DefaultFilePriority);
|
||||||
setListInProject(true);
|
setListInProject(true);
|
||||||
setAddFileFilter("*.png; *.jpg; *.gif; *.svg; *.ico; *.qml; *.qml.ui");
|
setAddFileFilter("*.png; *.jpg; *.gif; *.svg; *.ico; *.qml; *.qml.ui");
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "submitfilemodel.h"
|
#include "submitfilemodel.h"
|
||||||
|
|
||||||
#include <coreplugin/fileiconprovider.h>
|
#include <coreplugin/fileiconprovider.h>
|
||||||
|
#include <utils/fileutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
|
||||||
@@ -88,8 +89,8 @@ static QList<QStandardItem *> createFileRow(const QString &repositoryRoot,
|
|||||||
// For some reason, Windows (at least) requires a valid (existing) file path to the icon, so
|
// For some reason, Windows (at least) requires a valid (existing) file path to the icon, so
|
||||||
// the repository root is needed here.
|
// the repository root is needed here.
|
||||||
// Note: for "overlaid" icons in Core::FileIconProvider a valid file path is not required
|
// Note: for "overlaid" icons in Core::FileIconProvider a valid file path is not required
|
||||||
const QFileInfo fi(repositoryRoot + QLatin1Char('/') + fileName);
|
fileItem->setIcon(Core::FileIconProvider::icon(
|
||||||
fileItem->setIcon(Core::FileIconProvider::icon(fi));
|
Utils::FilePath::fromString(repositoryRoot).pathAppended(fileName)));
|
||||||
const QList<QStandardItem *> row{statusItem, fileItem};
|
const QList<QStandardItem *> row{statusItem, fileItem};
|
||||||
if (statusHint != SubmitFileModel::FileStatusUnknown) {
|
if (statusHint != SubmitFileModel::FileStatusUnknown) {
|
||||||
const QBrush textForeground = fileStatusTextForeground(statusHint);
|
const QBrush textForeground = fileStatusTextForeground(statusHint);
|
||||||
|
Reference in New Issue
Block a user