forked from qt-creator/qt-creator
Welcome: Added keyboard hotkeys to open sessions and recent projects
Change-Id: Ia7c1ec11b2fa3e4b61b842fd1e9e4df7aa6f7be3 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Thomas Hartmann <Thomas.Hartmann@theqtcompany.com>
This commit is contained in:
@@ -36,6 +36,11 @@ Rectangle {
|
|||||||
|
|
||||||
property alias projectName: projectNameText.text
|
property alias projectName: projectNameText.text
|
||||||
property alias projectPath: pathText.text
|
property alias projectPath: pathText.text
|
||||||
|
property alias projectTooltip: projectItemTooltip.text
|
||||||
|
|
||||||
|
function requestProject() {
|
||||||
|
projectWelcomePage.requestProject(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: icon
|
id: icon
|
||||||
@@ -65,10 +70,16 @@ Rectangle {
|
|||||||
font: fonts.smallPath
|
font: fonts.smallPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ToolTip {
|
||||||
|
id: projectItemTooltip
|
||||||
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: mouseArea
|
id: mouseArea
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onClicked: projectWelcomePage.requestProject(filePath);
|
onClicked: projectItem.requestProject()
|
||||||
|
onEntered: projectItemTooltip.showAt(mouseX, mouseY)
|
||||||
|
onExited: projectItemTooltip.hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,10 +39,34 @@ Rectangle {
|
|||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
id: repeater
|
id: repeater
|
||||||
|
|
||||||
ProjectItem {
|
ProjectItem {
|
||||||
projectName: displayName
|
function displayNameWithIndex() {
|
||||||
|
return "%1: %2".arg(index + 1).arg(displayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
function tooltipText() {
|
||||||
|
var shortcutText = welcomeMode.recentProjectsShortcuts[index];
|
||||||
|
if (shortcutText)
|
||||||
|
return qsTr("Opens project \"%1\" (%2)").arg(displayName).arg(shortcutText);
|
||||||
|
else
|
||||||
|
return qsTr("Opens project \"%1\"").arg(displayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
projectName: displayNameWithIndex()
|
||||||
projectPath: prettyFilePath
|
projectPath: prettyFilePath
|
||||||
|
projectTooltip: tooltipText()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: welcomeMode
|
||||||
|
onOpenRecentProjectTriggered: {
|
||||||
|
var item = repeater.itemAt(index);
|
||||||
|
if (item)
|
||||||
|
item.requestProject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ Item {
|
|||||||
height: columns.height
|
height: columns.height
|
||||||
width: columns.width
|
width: columns.width
|
||||||
property alias name: titleText.text
|
property alias name: titleText.text
|
||||||
|
property alias tooltip: titleAreaTooltip.text
|
||||||
|
|
||||||
|
function requestSession() {
|
||||||
|
projectWelcomePage.requestSession(sessionName);
|
||||||
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
id: columns
|
id: columns
|
||||||
@@ -65,15 +70,20 @@ Item {
|
|||||||
font.underline: titleArea.containsMouse
|
font.underline: titleArea.containsMouse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ToolTip {
|
||||||
|
id: titleAreaTooltip
|
||||||
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: titleArea
|
id: titleArea
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: delegate.requestSession()
|
||||||
projectWelcomePage.requestSession(sessionName);
|
onEntered: titleAreaTooltip.showAt(mouseX, mouseY)
|
||||||
}
|
onExited: titleAreaTooltip.hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
z: -1
|
z: -1
|
||||||
property int margin: 6
|
property int margin: 6
|
||||||
|
|||||||
@@ -51,7 +51,31 @@ Rectangle {
|
|||||||
newSessionName = qsTr("%1 (current session)").arg(sessionName);
|
newSessionName = qsTr("%1 (current session)").arg(sessionName);
|
||||||
return newSessionName;
|
return newSessionName;
|
||||||
}
|
}
|
||||||
name: fullSessionName()
|
|
||||||
|
function fullSessionNameWithIndex() {
|
||||||
|
return "%1: %2".arg(index + 1).arg(fullSessionName());
|
||||||
|
}
|
||||||
|
|
||||||
|
function tooltipText() {
|
||||||
|
var shortcutText = welcomeMode.sessionsShortcuts[index];
|
||||||
|
if (shortcutText)
|
||||||
|
return qsTr("Opens session \"%1\" (%2)").arg(sessionName).arg(shortcutText);
|
||||||
|
else
|
||||||
|
return qsTr("Opens session \"%1\"").arg(sessionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
name: fullSessionNameWithIndex()
|
||||||
|
tooltip: tooltipText()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: welcomeMode
|
||||||
|
onOpenSessionTriggered: {
|
||||||
|
if (index < content.count) {
|
||||||
|
content.currentIndex = index;
|
||||||
|
content.currentItem.requestSession();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,12 +59,18 @@ Item {
|
|||||||
toolTip.oldY = toolTip.y
|
toolTip.oldY = toolTip.y
|
||||||
var globalPos = mapFromItem(toolTip.originalParent, toolTip.oldX, toolTip.oldY);
|
var globalPos = mapFromItem(toolTip.originalParent, toolTip.oldX, toolTip.oldY);
|
||||||
|
|
||||||
toolTip.x = globalPos.x + toolTip.oldX
|
toolTip.x = Math.min(globalPos.x + toolTip.oldX, toolTip.parent.width - toolTip.width);
|
||||||
toolTip.y = globalPos.y + toolTip.oldY
|
toolTip.y = Math.min(globalPos.y + toolTip.oldY, toolTip.parent.height - toolTip.height);
|
||||||
|
|
||||||
toolTip.opacity = 1;
|
toolTip.opacity = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showAt(x, y) {
|
||||||
|
toolTip.x = x;
|
||||||
|
toolTip.y = y;
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
|
||||||
function hide() {
|
function hide() {
|
||||||
toolTip.opacity = 0;
|
toolTip.opacity = 0;
|
||||||
var oldClip = originalParent.clip
|
var oldClip = originalParent.clip
|
||||||
|
|||||||
@@ -1056,15 +1056,21 @@ void MainWindow::aboutToShowRecentFiles()
|
|||||||
QMenu *menu = aci->menu();
|
QMenu *menu = aci->menu();
|
||||||
menu->clear();
|
menu->clear();
|
||||||
|
|
||||||
bool hasRecentFiles = false;
|
const QList<DocumentManager::RecentFile> recentFiles = DocumentManager::recentFiles();
|
||||||
foreach (const DocumentManager::RecentFile &file, DocumentManager::recentFiles()) {
|
for (int i = 0; i < recentFiles.count(); ++i) {
|
||||||
hasRecentFiles = true;
|
const DocumentManager::RecentFile file = recentFiles[i];
|
||||||
QAction *action = menu->addAction(
|
|
||||||
QDir::toNativeSeparators(Utils::withTildeHomePath(file.first)));
|
int acceleratorKey = i + 1;
|
||||||
|
QString textPattern = acceleratorKey < 10 ? QStringLiteral("&%1: %2") : QStringLiteral("%1: %2");
|
||||||
|
QString filePath = QDir::toNativeSeparators(withTildeHomePath(file.first));
|
||||||
|
QString actionText = textPattern.arg(acceleratorKey).arg(filePath);
|
||||||
|
QAction *action = menu->addAction(actionText);
|
||||||
connect(action, &QAction::triggered, this, [file] {
|
connect(action, &QAction::triggered, this, [file] {
|
||||||
EditorManager::openEditor(file.first, file.second);
|
EditorManager::openEditor(file.first, file.second);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasRecentFiles = !recentFiles.isEmpty();
|
||||||
menu->setEnabled(hasRecentFiles);
|
menu->setEnabled(hasRecentFiles);
|
||||||
|
|
||||||
// add the Clear Menu item
|
// add the Clear Menu item
|
||||||
|
|||||||
@@ -2842,13 +2842,17 @@ void ProjectExplorerPluginPrivate::updateRecentProjectMenu()
|
|||||||
menu->clear();
|
menu->clear();
|
||||||
|
|
||||||
bool hasRecentProjects = false;
|
bool hasRecentProjects = false;
|
||||||
|
int acceleratorKey = 1;
|
||||||
//projects (ignore sessions, they used to be in this list)
|
//projects (ignore sessions, they used to be in this list)
|
||||||
const StringPairListConstIterator end = dd->m_recentProjects.constEnd();
|
const StringPairListConstIterator end = dd->m_recentProjects.constEnd();
|
||||||
for (StringPairListConstIterator it = dd->m_recentProjects.constBegin(); it != end; ++it) {
|
for (StringPairListConstIterator it = dd->m_recentProjects.constBegin(); it != end; ++it, ++acceleratorKey) {
|
||||||
const QString fileName = it->first;
|
const QString fileName = it->first;
|
||||||
if (fileName.endsWith(QLatin1String(".qws")))
|
if (fileName.endsWith(QLatin1String(".qws")))
|
||||||
continue;
|
continue;
|
||||||
QAction *action = menu->addAction(Utils::withTildeHomePath(fileName));
|
|
||||||
|
QString textTemplate = acceleratorKey < 10 ? QStringLiteral("&%1: %2") : QStringLiteral("%1: %2");
|
||||||
|
QString actionText = textTemplate.arg(acceleratorKey).arg(Utils::withTildeHomePath(fileName));
|
||||||
|
QAction *action = menu->addAction(actionText);
|
||||||
connect(action, &QAction::triggered, this, [this, fileName] {
|
connect(action, &QAction::triggered, this, [this, fileName] {
|
||||||
openRecentProject(fileName);
|
openRecentProject(fileName);
|
||||||
});
|
});
|
||||||
@@ -3319,8 +3323,15 @@ void ProjectExplorerPluginPrivate::updateSessionMenu()
|
|||||||
QActionGroup *ag = new QActionGroup(m_sessionMenu);
|
QActionGroup *ag = new QActionGroup(m_sessionMenu);
|
||||||
connect(ag, &QActionGroup::triggered, this, &ProjectExplorerPluginPrivate::setSession);
|
connect(ag, &QActionGroup::triggered, this, &ProjectExplorerPluginPrivate::setSession);
|
||||||
const QString activeSession = SessionManager::activeSession();
|
const QString activeSession = SessionManager::activeSession();
|
||||||
foreach (const QString &session, SessionManager::sessions()) {
|
|
||||||
QAction *act = ag->addAction(session);
|
const QStringList sessions = SessionManager::sessions();
|
||||||
|
for (int i = 0; i < sessions.size(); ++i) {
|
||||||
|
const QString &session = sessions[i];
|
||||||
|
|
||||||
|
const int acceleratorKey = i + 1;
|
||||||
|
QString textTemplate = acceleratorKey < 10 ? QStringLiteral("&%1: %2") : QStringLiteral("%1: %2");
|
||||||
|
QString actionText = textTemplate.arg(acceleratorKey).arg(session);
|
||||||
|
QAction *act = ag->addAction(actionText);
|
||||||
act->setData(session);
|
act->setData(session);
|
||||||
act->setCheckable(true);
|
act->setCheckable(true);
|
||||||
if (session == activeSession)
|
if (session == activeSession)
|
||||||
|
|||||||
@@ -27,6 +27,9 @@
|
|||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
|
#include <coreplugin/actionmanager/command.h>
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/imode.h>
|
#include <coreplugin/imode.h>
|
||||||
@@ -125,6 +128,8 @@ class WelcomeMode : public IMode
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int activePlugin READ activePlugin WRITE setActivePlugin NOTIFY activePluginChanged)
|
Q_PROPERTY(int activePlugin READ activePlugin WRITE setActivePlugin NOTIFY activePluginChanged)
|
||||||
|
Q_PROPERTY(QStringList recentProjectsShortcuts READ recentProjectsShortcuts NOTIFY recentProjectsShortcutsChanged)
|
||||||
|
Q_PROPERTY(QStringList sessionsShortcuts READ sessionsShortcuts NOTIFY sessionsShortcutsChanged)
|
||||||
public:
|
public:
|
||||||
WelcomeMode();
|
WelcomeMode();
|
||||||
~WelcomeMode();
|
~WelcomeMode();
|
||||||
@@ -133,6 +138,9 @@ public:
|
|||||||
void initPlugins();
|
void initPlugins();
|
||||||
int activePlugin() const { return m_activePlugin; }
|
int activePlugin() const { return m_activePlugin; }
|
||||||
|
|
||||||
|
QStringList recentProjectsShortcuts() const { return m_recentProjectsShortcuts; }
|
||||||
|
QStringList sessionsShortcuts() const { return m_sessionsShortcuts; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setActivePlugin(int pos)
|
void setActivePlugin(int pos)
|
||||||
{
|
{
|
||||||
@@ -145,12 +153,19 @@ public slots:
|
|||||||
signals:
|
signals:
|
||||||
void activePluginChanged(int pos);
|
void activePluginChanged(int pos);
|
||||||
|
|
||||||
|
void openSessionTriggered(int index);
|
||||||
|
void openRecentProjectTriggered(int index);
|
||||||
|
|
||||||
|
void recentProjectsShortcutsChanged(QStringList recentProjectsShortcuts);
|
||||||
|
void sessionsShortcutsChanged(QStringList sessionsShortcuts);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void welcomePluginAdded(QObject*);
|
void welcomePluginAdded(QObject*);
|
||||||
void sceneGraphError(QQuickWindow::SceneGraphError, const QString &message);
|
void sceneGraphError(QQuickWindow::SceneGraphError, const QString &message);
|
||||||
void facilitateQml(QQmlEngine *engine);
|
void facilitateQml(QQmlEngine *engine);
|
||||||
void addPages(const QList<IWelcomePage *> &pages);
|
void addPages(const QList<IWelcomePage *> &pages);
|
||||||
void applyTheme();
|
void applyTheme();
|
||||||
|
void addKeyboardShortcuts();
|
||||||
|
|
||||||
QWidget *m_modeWidget;
|
QWidget *m_modeWidget;
|
||||||
QuickContainer *m_welcomePage;
|
QuickContainer *m_welcomePage;
|
||||||
@@ -158,6 +173,8 @@ private:
|
|||||||
QList<IWelcomePage *> m_pluginList;
|
QList<IWelcomePage *> m_pluginList;
|
||||||
int m_activePlugin;
|
int m_activePlugin;
|
||||||
QQmlPropertyMap m_themeProperties;
|
QQmlPropertyMap m_themeProperties;
|
||||||
|
QStringList m_recentProjectsShortcuts;
|
||||||
|
QStringList m_sessionsShortcuts;
|
||||||
};
|
};
|
||||||
|
|
||||||
WelcomeMode::WelcomeMode()
|
WelcomeMode::WelcomeMode()
|
||||||
@@ -208,6 +225,8 @@ WelcomeMode::WelcomeMode()
|
|||||||
layout->addWidget(container);
|
layout->addWidget(container);
|
||||||
#endif // USE_QUICK_WIDGET
|
#endif // USE_QUICK_WIDGET
|
||||||
|
|
||||||
|
addKeyboardShortcuts();
|
||||||
|
|
||||||
setWidget(m_modeWidget);
|
setWidget(m_modeWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,6 +237,40 @@ void WelcomeMode::applyTheme()
|
|||||||
m_themeProperties.insert(it.key(), it.value());
|
m_themeProperties.insert(it.key(), it.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WelcomeMode::addKeyboardShortcuts()
|
||||||
|
{
|
||||||
|
const int actionsCount = 9;
|
||||||
|
Context welcomeContext(Core::Constants::C_WELCOME_MODE);
|
||||||
|
|
||||||
|
const Id sessionBase = "Welcome.OpenSession";
|
||||||
|
for (int i = 1; i <= actionsCount; ++i) {
|
||||||
|
auto act = new QAction(tr("Open Session #%1").arg(i), this);
|
||||||
|
Command *cmd = ActionManager::registerAction(act, sessionBase.withSuffix(i), welcomeContext);
|
||||||
|
cmd->setDefaultKeySequence(QKeySequence((UseMacShortcuts ? tr("Ctrl+Meta+%1") : tr("Ctrl+Alt+%1")).arg(i)));
|
||||||
|
m_sessionsShortcuts.append(cmd->keySequence().toString());
|
||||||
|
|
||||||
|
connect(act, &QAction::triggered, this, [this, i] { openSessionTriggered(i-1); });
|
||||||
|
connect(cmd, &Command::keySequenceChanged, this, [this, i, cmd] {
|
||||||
|
m_sessionsShortcuts[i-1] = cmd->keySequence().toString();
|
||||||
|
emit sessionsShortcutsChanged(m_sessionsShortcuts);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const Id projectBase = "Welcome.OpenRecentProject";
|
||||||
|
for (int i = 1; i <= actionsCount; ++i) {
|
||||||
|
auto act = new QAction(tr("Open Recent Project #%1").arg(i), this);
|
||||||
|
Command *cmd = ActionManager::registerAction(act, projectBase.withSuffix(i), welcomeContext);
|
||||||
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+%1").arg(i)));
|
||||||
|
m_recentProjectsShortcuts.append(cmd->keySequence().toString());
|
||||||
|
|
||||||
|
connect(act, &QAction::triggered, this, [this, i] { openRecentProjectTriggered(i-1); });
|
||||||
|
connect(cmd, &Command::keySequenceChanged, this, [this, i, cmd] {
|
||||||
|
m_recentProjectsShortcuts[i-1] = cmd->keySequence().toString();
|
||||||
|
emit recentProjectsShortcutsChanged(m_recentProjectsShortcuts);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WelcomeMode::~WelcomeMode()
|
WelcomeMode::~WelcomeMode()
|
||||||
{
|
{
|
||||||
QSettings *settings = ICore::settings();
|
QSettings *settings = ICore::settings();
|
||||||
|
|||||||
Reference in New Issue
Block a user