forked from qt-creator/qt-creator
Terminal: Add icons to tabs
Change-Id: Id219366de16944daf83c3eb154d6b087c79b7fd9 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
9a7f45cc46
commit
2f6f9d2d33
@@ -16,11 +16,13 @@ using namespace Utils;
|
||||
|
||||
struct ShellItemBuilder
|
||||
{
|
||||
explicit ShellItemBuilder(const CommandLine &value)
|
||||
explicit ShellItemBuilder(const QFileIconProvider &iconProvider, const CommandLine &value) :
|
||||
iconProvider(iconProvider)
|
||||
{
|
||||
m_item.openParameters.shellCommand = value;
|
||||
}
|
||||
explicit ShellItemBuilder(const FilePath &value)
|
||||
explicit ShellItemBuilder(const QFileIconProvider &iconProvider, const FilePath &value) :
|
||||
iconProvider(iconProvider)
|
||||
{
|
||||
m_item.openParameters.shellCommand = CommandLine(value);
|
||||
}
|
||||
@@ -31,8 +33,7 @@ struct ShellItemBuilder
|
||||
}
|
||||
ShellItemBuilder &icon(const FilePath &value)
|
||||
{
|
||||
static QFileIconProvider iconProvider;
|
||||
m_item.icon = iconProvider.icon(value.toFileInfo());
|
||||
m_item.openParameters.icon = iconProvider.icon(value.toFileInfo());
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -41,13 +42,14 @@ struct ShellItemBuilder
|
||||
{
|
||||
if (m_item.name.isEmpty())
|
||||
m_item.name = m_item.openParameters.shellCommand->executable().toUserOutput();
|
||||
if (m_item.icon.isNull())
|
||||
if (m_item.openParameters.icon.isNull())
|
||||
icon(m_item.openParameters.shellCommand->executable());
|
||||
return m_item;
|
||||
}
|
||||
|
||||
private:
|
||||
ShellModelItem m_item;
|
||||
const QFileIconProvider &iconProvider;
|
||||
};
|
||||
|
||||
static QSet<FilePath> msysPaths()
|
||||
@@ -74,31 +76,32 @@ struct ShellModelPrivate
|
||||
|
||||
ShellModelPrivate::ShellModelPrivate()
|
||||
{
|
||||
QFileIconProvider iconProvider;
|
||||
if (Utils::HostOsInfo::isWindowsHost()) {
|
||||
const FilePath comspec = FilePath::fromUserInput(qtcEnvironmentVariable("COMSPEC"));
|
||||
localShells << ShellItemBuilder(comspec);
|
||||
localShells << ShellItemBuilder(iconProvider, comspec);
|
||||
|
||||
if (comspec.fileName() != "cmd.exe") {
|
||||
FilePath cmd = FilePath::fromUserInput(QStandardPaths::findExecutable("cmd.exe"));
|
||||
localShells << ShellItemBuilder(cmd);
|
||||
localShells << ShellItemBuilder(iconProvider, cmd);
|
||||
}
|
||||
|
||||
const FilePath powershell = FilePath::fromUserInput(
|
||||
QStandardPaths::findExecutable("powershell.exe"));
|
||||
|
||||
if (powershell.exists())
|
||||
localShells << ShellItemBuilder(powershell);
|
||||
localShells << ShellItemBuilder(iconProvider, powershell);
|
||||
|
||||
const FilePath sys_bash =
|
||||
FilePath::fromUserInput(QStandardPaths::findExecutable("bash.exe"));
|
||||
if (sys_bash.exists())
|
||||
localShells << ShellItemBuilder({sys_bash, {"--login"}});
|
||||
localShells << ShellItemBuilder(iconProvider, {sys_bash, {"--login"}});
|
||||
|
||||
const FilePath git_exe = FilePath::fromUserInput(QStandardPaths::findExecutable("git.exe"));
|
||||
if (git_exe.exists()) {
|
||||
FilePath git_bash = git_exe.parentDir().parentDir().pathAppended("bin/bash.exe");
|
||||
if (git_bash.exists()) {
|
||||
localShells << ShellItemBuilder({git_bash, {"--login"}})
|
||||
localShells << ShellItemBuilder(iconProvider, {git_bash, {"--login"}})
|
||||
.icon(git_bash.parentDir().parentDir().pathAppended("git-bash.exe"));
|
||||
}
|
||||
}
|
||||
@@ -111,7 +114,7 @@ ShellModelPrivate::ShellModelPrivate()
|
||||
QDirIterator it(type.path().replace(".ico", "/bin"), QDir::Files);
|
||||
if (!it.hasNext())
|
||||
continue;
|
||||
localShells << ShellItemBuilder(
|
||||
localShells << ShellItemBuilder(iconProvider,
|
||||
{msys2_cmd, msys2_args + QStringList{"-" + type.baseName()}})
|
||||
.icon(type)
|
||||
.name(type.toUserOutput().replace(".ico", ".exe"));
|
||||
@@ -137,8 +140,8 @@ ShellModelPrivate::ShellModelPrivate()
|
||||
// ... and filter out non-existing shells.
|
||||
localShells = Utils::transform(
|
||||
Utils::filtered(shells, [](const FilePath &shell) {return shell.exists(); }),
|
||||
[](const FilePath &shell) {
|
||||
return ShellItemBuilder(shell).item();
|
||||
[&iconProvider](const FilePath &shell) {
|
||||
return ShellItemBuilder(iconProvider, shell).item();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -162,7 +165,7 @@ QList<ShellModelItem> ShellModel::remote() const
|
||||
|
||||
const QList<ShellModelItem> deviceItems = Utils::transform(
|
||||
deviceCmds, [](const Utils::Terminal::NameAndCommandLine &item) -> ShellModelItem {
|
||||
return ShellModelItem{item.name, {}, {item.commandLine}};
|
||||
return ShellModelItem{item.name, {item.commandLine}};
|
||||
});
|
||||
|
||||
return deviceItems;
|
||||
|
||||
Reference in New Issue
Block a user