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
@@ -8,6 +8,8 @@
|
|||||||
#include "filepath.h"
|
#include "filepath.h"
|
||||||
#include "id.h"
|
#include "id.h"
|
||||||
|
|
||||||
|
#include <QIcon>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -58,6 +60,7 @@ struct OpenTerminalParameters
|
|||||||
std::optional<CommandLine> shellCommand;
|
std::optional<CommandLine> shellCommand;
|
||||||
std::optional<FilePath> workingDirectory;
|
std::optional<FilePath> workingDirectory;
|
||||||
std::optional<Environment> environment;
|
std::optional<Environment> environment;
|
||||||
|
QIcon icon;
|
||||||
ExitBehavior m_exitBehavior{ExitBehavior::Close};
|
ExitBehavior m_exitBehavior{ExitBehavior::Close};
|
||||||
std::optional<Id> identifier{std::nullopt};
|
std::optional<Id> identifier{std::nullopt};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,11 +16,13 @@ using namespace Utils;
|
|||||||
|
|
||||||
struct ShellItemBuilder
|
struct ShellItemBuilder
|
||||||
{
|
{
|
||||||
explicit ShellItemBuilder(const CommandLine &value)
|
explicit ShellItemBuilder(const QFileIconProvider &iconProvider, const CommandLine &value) :
|
||||||
|
iconProvider(iconProvider)
|
||||||
{
|
{
|
||||||
m_item.openParameters.shellCommand = value;
|
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);
|
m_item.openParameters.shellCommand = CommandLine(value);
|
||||||
}
|
}
|
||||||
@@ -31,8 +33,7 @@ struct ShellItemBuilder
|
|||||||
}
|
}
|
||||||
ShellItemBuilder &icon(const FilePath &value)
|
ShellItemBuilder &icon(const FilePath &value)
|
||||||
{
|
{
|
||||||
static QFileIconProvider iconProvider;
|
m_item.openParameters.icon = iconProvider.icon(value.toFileInfo());
|
||||||
m_item.icon = iconProvider.icon(value.toFileInfo());
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,13 +42,14 @@ struct ShellItemBuilder
|
|||||||
{
|
{
|
||||||
if (m_item.name.isEmpty())
|
if (m_item.name.isEmpty())
|
||||||
m_item.name = m_item.openParameters.shellCommand->executable().toUserOutput();
|
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());
|
icon(m_item.openParameters.shellCommand->executable());
|
||||||
return m_item;
|
return m_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ShellModelItem m_item;
|
ShellModelItem m_item;
|
||||||
|
const QFileIconProvider &iconProvider;
|
||||||
};
|
};
|
||||||
|
|
||||||
static QSet<FilePath> msysPaths()
|
static QSet<FilePath> msysPaths()
|
||||||
@@ -74,31 +76,32 @@ struct ShellModelPrivate
|
|||||||
|
|
||||||
ShellModelPrivate::ShellModelPrivate()
|
ShellModelPrivate::ShellModelPrivate()
|
||||||
{
|
{
|
||||||
|
QFileIconProvider iconProvider;
|
||||||
if (Utils::HostOsInfo::isWindowsHost()) {
|
if (Utils::HostOsInfo::isWindowsHost()) {
|
||||||
const FilePath comspec = FilePath::fromUserInput(qtcEnvironmentVariable("COMSPEC"));
|
const FilePath comspec = FilePath::fromUserInput(qtcEnvironmentVariable("COMSPEC"));
|
||||||
localShells << ShellItemBuilder(comspec);
|
localShells << ShellItemBuilder(iconProvider, comspec);
|
||||||
|
|
||||||
if (comspec.fileName() != "cmd.exe") {
|
if (comspec.fileName() != "cmd.exe") {
|
||||||
FilePath cmd = FilePath::fromUserInput(QStandardPaths::findExecutable("cmd.exe"));
|
FilePath cmd = FilePath::fromUserInput(QStandardPaths::findExecutable("cmd.exe"));
|
||||||
localShells << ShellItemBuilder(cmd);
|
localShells << ShellItemBuilder(iconProvider, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
const FilePath powershell = FilePath::fromUserInput(
|
const FilePath powershell = FilePath::fromUserInput(
|
||||||
QStandardPaths::findExecutable("powershell.exe"));
|
QStandardPaths::findExecutable("powershell.exe"));
|
||||||
|
|
||||||
if (powershell.exists())
|
if (powershell.exists())
|
||||||
localShells << ShellItemBuilder(powershell);
|
localShells << ShellItemBuilder(iconProvider, powershell);
|
||||||
|
|
||||||
const FilePath sys_bash =
|
const FilePath sys_bash =
|
||||||
FilePath::fromUserInput(QStandardPaths::findExecutable("bash.exe"));
|
FilePath::fromUserInput(QStandardPaths::findExecutable("bash.exe"));
|
||||||
if (sys_bash.exists())
|
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"));
|
const FilePath git_exe = FilePath::fromUserInput(QStandardPaths::findExecutable("git.exe"));
|
||||||
if (git_exe.exists()) {
|
if (git_exe.exists()) {
|
||||||
FilePath git_bash = git_exe.parentDir().parentDir().pathAppended("bin/bash.exe");
|
FilePath git_bash = git_exe.parentDir().parentDir().pathAppended("bin/bash.exe");
|
||||||
if (git_bash.exists()) {
|
if (git_bash.exists()) {
|
||||||
localShells << ShellItemBuilder({git_bash, {"--login"}})
|
localShells << ShellItemBuilder(iconProvider, {git_bash, {"--login"}})
|
||||||
.icon(git_bash.parentDir().parentDir().pathAppended("git-bash.exe"));
|
.icon(git_bash.parentDir().parentDir().pathAppended("git-bash.exe"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,7 +114,7 @@ ShellModelPrivate::ShellModelPrivate()
|
|||||||
QDirIterator it(type.path().replace(".ico", "/bin"), QDir::Files);
|
QDirIterator it(type.path().replace(".ico", "/bin"), QDir::Files);
|
||||||
if (!it.hasNext())
|
if (!it.hasNext())
|
||||||
continue;
|
continue;
|
||||||
localShells << ShellItemBuilder(
|
localShells << ShellItemBuilder(iconProvider,
|
||||||
{msys2_cmd, msys2_args + QStringList{"-" + type.baseName()}})
|
{msys2_cmd, msys2_args + QStringList{"-" + type.baseName()}})
|
||||||
.icon(type)
|
.icon(type)
|
||||||
.name(type.toUserOutput().replace(".ico", ".exe"));
|
.name(type.toUserOutput().replace(".ico", ".exe"));
|
||||||
@@ -137,8 +140,8 @@ ShellModelPrivate::ShellModelPrivate()
|
|||||||
// ... and filter out non-existing shells.
|
// ... and filter out non-existing shells.
|
||||||
localShells = Utils::transform(
|
localShells = Utils::transform(
|
||||||
Utils::filtered(shells, [](const FilePath &shell) {return shell.exists(); }),
|
Utils::filtered(shells, [](const FilePath &shell) {return shell.exists(); }),
|
||||||
[](const FilePath &shell) {
|
[&iconProvider](const FilePath &shell) {
|
||||||
return ShellItemBuilder(shell).item();
|
return ShellItemBuilder(iconProvider, shell).item();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,7 +165,7 @@ QList<ShellModelItem> ShellModel::remote() const
|
|||||||
|
|
||||||
const QList<ShellModelItem> deviceItems = Utils::transform(
|
const QList<ShellModelItem> deviceItems = Utils::transform(
|
||||||
deviceCmds, [](const Utils::Terminal::NameAndCommandLine &item) -> ShellModelItem {
|
deviceCmds, [](const Utils::Terminal::NameAndCommandLine &item) -> ShellModelItem {
|
||||||
return ShellModelItem{item.name, {}, {item.commandLine}};
|
return ShellModelItem{item.name, {item.commandLine}};
|
||||||
});
|
});
|
||||||
|
|
||||||
return deviceItems;
|
return deviceItems;
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ struct ShellModelPrivate;
|
|||||||
struct ShellModelItem
|
struct ShellModelItem
|
||||||
{
|
{
|
||||||
QString name;
|
QString name;
|
||||||
QIcon icon;
|
|
||||||
Utils::Terminal::OpenTerminalParameters openParameters;
|
Utils::Terminal::OpenTerminalParameters openParameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <utils/terminalhooks.h>
|
#include <utils/terminalhooks.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
|
#include <QFileIconProvider>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
@@ -134,7 +135,18 @@ void TerminalPane::openTerminal(const OpenTerminalParameters ¶meters)
|
|||||||
terminalWidget->unlockGlobalAction(NEXTTERMINAL);
|
terminalWidget->unlockGlobalAction(NEXTTERMINAL);
|
||||||
terminalWidget->unlockGlobalAction(PREVTERMINAL);
|
terminalWidget->unlockGlobalAction(PREVTERMINAL);
|
||||||
|
|
||||||
m_tabWidget.setCurrentIndex(m_tabWidget.addTab(terminalWidget, Tr::tr("Terminal")));
|
QIcon icon;
|
||||||
|
if (HostOsInfo::isWindowsHost()) {
|
||||||
|
icon = parametersCopy.icon;
|
||||||
|
if (icon.isNull()) {
|
||||||
|
QFileIconProvider iconProvider;
|
||||||
|
const FilePath command = parametersCopy.shellCommand
|
||||||
|
? parametersCopy.shellCommand->executable()
|
||||||
|
: TerminalSettings::instance().shell.filePath();
|
||||||
|
icon = iconProvider.icon(command.toFileInfo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_tabWidget.setCurrentIndex(m_tabWidget.addTab(terminalWidget, icon, Tr::tr("Terminal")));
|
||||||
setupTerminalWidget(terminalWidget);
|
setupTerminalWidget(terminalWidget);
|
||||||
|
|
||||||
if (!m_isVisible)
|
if (!m_isVisible)
|
||||||
@@ -306,7 +318,7 @@ void TerminalPane::createShellMenu()
|
|||||||
|
|
||||||
const auto addItems = [this](const QList<Internal::ShellModelItem> &items) {
|
const auto addItems = [this](const QList<Internal::ShellModelItem> &items) {
|
||||||
for (const Internal::ShellModelItem &item : items) {
|
for (const Internal::ShellModelItem &item : items) {
|
||||||
QAction *action = new QAction(item.icon, item.name, &m_shellMenu);
|
QAction *action = new QAction(item.openParameters.icon, item.name, &m_shellMenu);
|
||||||
|
|
||||||
connect(action, &QAction::triggered, action, [item, this]() {
|
connect(action, &QAction::triggered, action, [item, this]() {
|
||||||
openTerminal(item.openParameters);
|
openTerminal(item.openParameters);
|
||||||
|
|||||||
Reference in New Issue
Block a user