forked from qt-creator/qt-creator
Show some helpful hints in empty editor views
Change-Id: I123147930244df38f436afd3ad8257b5f23e0d7a Reviewed-by: David Schulz <david.schulz@theqtcompany.com> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
This commit is contained in:
@@ -1992,6 +1992,19 @@ void EditorManager::addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentM
|
||||
DocumentManager::populateOpenWithMenu(openWith, entry->fileName());
|
||||
}
|
||||
|
||||
void EditorManager::setPlaceholderText(const QString &text)
|
||||
{
|
||||
if (d->m_placeholderText == text)
|
||||
return;
|
||||
d->m_placeholderText = text;
|
||||
emit m_instance->placeholderTextChanged(d->m_placeholderText);
|
||||
}
|
||||
|
||||
QString EditorManager::placeholderText()
|
||||
{
|
||||
return d->m_placeholderText;
|
||||
}
|
||||
|
||||
void EditorManager::saveDocument()
|
||||
{
|
||||
EditorManagerPrivate::saveDocument(currentDocument());
|
||||
|
@@ -173,6 +173,9 @@ public:
|
||||
IEditor *editor = 0);
|
||||
static void addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentModel::Entry *entry);
|
||||
|
||||
static void setPlaceholderText(const QString &text);
|
||||
static QString placeholderText();
|
||||
|
||||
signals:
|
||||
void currentEditorChanged(Core::IEditor *editor);
|
||||
void currentDocumentStateChanged();
|
||||
@@ -181,6 +184,7 @@ signals:
|
||||
void editorAboutToClose(Core::IEditor *editor);
|
||||
void editorsClosed(QList<Core::IEditor *> editors);
|
||||
void findOnFileSystemRequest(const QString &path);
|
||||
void placeholderTextChanged(const QString &text);
|
||||
|
||||
public slots:
|
||||
static void saveDocument();
|
||||
|
@@ -242,6 +242,8 @@ private:
|
||||
|
||||
bool m_autoSaveEnabled;
|
||||
int m_autoSaveInterval;
|
||||
|
||||
QString m_placeholderText;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
|
@@ -34,10 +34,12 @@
|
||||
#include "editormanager_p.h"
|
||||
#include "documentmodel.h"
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/editortoolbar.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/infobar.h>
|
||||
#include <coreplugin/locator/locatorconstants.h>
|
||||
#include <coreplugin/minisplitter.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/findplaceholder.h>
|
||||
@@ -119,7 +121,15 @@ EditorView::EditorView(SplitterOrView *parentSplitterOrView, QWidget *parent) :
|
||||
}
|
||||
|
||||
// for the case of no document selected
|
||||
QWidget *empty = new QWidget;
|
||||
auto empty = new QWidget;
|
||||
empty->hide();
|
||||
auto emptyLayout = new QGridLayout(empty);
|
||||
empty->setLayout(emptyLayout);
|
||||
m_emptyViewLabel = new QLabel;
|
||||
connect(EditorManager::instance(), &EditorManager::placeholderTextChanged,
|
||||
m_emptyViewLabel, &QLabel::setText);
|
||||
m_emptyViewLabel->setText(EditorManager::placeholderText());
|
||||
emptyLayout->addWidget(m_emptyViewLabel);
|
||||
m_container->addWidget(empty);
|
||||
m_widgetEditorMap.insert(empty, 0);
|
||||
|
||||
|
@@ -145,6 +145,7 @@ private:
|
||||
QToolButton *m_statusWidgetButton;
|
||||
QList<IEditor *> m_editors;
|
||||
QMap<QWidget *, IEditor *> m_widgetEditorMap;
|
||||
QLabel *m_emptyViewLabel;
|
||||
|
||||
QList<EditLocation> m_navigationHistory;
|
||||
QList<EditLocation> m_editorHistory;
|
||||
|
@@ -44,6 +44,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <coreplugin/progressmanager/futureprogress.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
@@ -96,7 +97,7 @@ void Locator::initialize(CorePlugin *corePlugin, const QStringList &, QString *)
|
||||
m_corePlugin->addAutoReleasedObject(view);
|
||||
|
||||
QAction *action = new QAction(m_locatorWidget->windowIcon(), m_locatorWidget->windowTitle(), this);
|
||||
Command *cmd = ActionManager::registerAction(action, "QtCreator.Locate",
|
||||
Command *cmd = ActionManager::registerAction(action, Constants::LOCATE,
|
||||
Context(Constants::C_GLOBAL));
|
||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+K")));
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(openLocator()));
|
||||
@@ -148,6 +149,14 @@ void Locator::extensionsInitialized()
|
||||
return first->id().alphabeticallyBefore(second->id());
|
||||
});
|
||||
setFilters(m_filters);
|
||||
|
||||
Command *openCommand = ActionManager::command(Constants::OPEN);
|
||||
Command *locateCommand = ActionManager::command(Constants::LOCATE);
|
||||
connect(openCommand, &Command::keySequenceChanged,
|
||||
this, &Locator::updateEditorManagerPlaceholderText);
|
||||
connect(locateCommand, &Command::keySequenceChanged,
|
||||
this, &Locator::updateEditorManagerPlaceholderText);
|
||||
updateEditorManagerPlaceholderText();
|
||||
}
|
||||
|
||||
bool Locator::delayedInitialize()
|
||||
@@ -177,6 +186,50 @@ void Locator::loadSettings()
|
||||
m_settingsInitialized = true;
|
||||
}
|
||||
|
||||
void Locator::updateEditorManagerPlaceholderText()
|
||||
{
|
||||
Command *openCommand = ActionManager::command(Constants::OPEN);
|
||||
Command *locateCommand = ActionManager::command(Constants::LOCATE);
|
||||
const QString placeholderText = tr("<html><body style=\"color:#909090; font-size:14pt\">"
|
||||
"<div align='center'>"
|
||||
"<div style=\"font-size:20pt\">Open a document</div>"
|
||||
"<table><tr><td>"
|
||||
"<hr/>"
|
||||
"<div style=\"margin-top: 5px\">• File > Open File or Project (%1)</div>"
|
||||
"<div style=\"margin-top: 5px\">• File > Recent Files</div>"
|
||||
"<div style=\"margin-top: 5px\">• Tools > Locator (%2) and</div>"
|
||||
"<div style=\"margin-left: 1em\">- type to open file from any open project</div>"
|
||||
"%4"
|
||||
"%5"
|
||||
"<div style=\"margin-left: 1em\">- type <code>%3<space><filename></code> to open file from file system</div>"
|
||||
"<div style=\"margin-left: 1em\">- select one of the other filters for jumping to a location</div>"
|
||||
"<div style=\"margin-top: 5px\">• Drag and drop files here</div>"
|
||||
"</td></tr></table>"
|
||||
"</div>"
|
||||
"</body></html>")
|
||||
.arg(openCommand->keySequence().toString(QKeySequence::NativeText))
|
||||
.arg(locateCommand->keySequence().toString(QKeySequence::NativeText))
|
||||
.arg(m_fileSystemFilter->shortcutString());
|
||||
|
||||
QString classes;
|
||||
ILocatorFilter *classesFilter = Utils::findOrDefault(m_filters, [](const ILocatorFilter *filter) {
|
||||
return filter->id() == Id("Classes"); // not nice, but anyhow
|
||||
});
|
||||
if (classesFilter)
|
||||
classes = tr("<div style=\"margin-left: 1em\">- type <code>%1<space><pattern></code>"
|
||||
" to jump to a class definition</div>").arg(classesFilter->shortcutString());
|
||||
|
||||
QString methods;
|
||||
ILocatorFilter *methodsFilter = Utils::findOrDefault(m_filters, [](const ILocatorFilter *filter) {
|
||||
return filter->id() == Id("Methods"); // not nice, but anyhow
|
||||
});
|
||||
if (methodsFilter)
|
||||
methods = tr("<div style=\"margin-left: 1em\">- type <code>%1<space><pattern></code>"
|
||||
" to jump to a function definition</div>").arg(methodsFilter->shortcutString());
|
||||
|
||||
EditorManager::setPlaceholderText(placeholderText.arg(classes, methods));
|
||||
}
|
||||
|
||||
void Locator::saveSettings()
|
||||
{
|
||||
if (m_settingsInitialized) {
|
||||
@@ -222,6 +275,7 @@ QList<ILocatorFilter *> Locator::customFilters()
|
||||
void Locator::setFilters(QList<ILocatorFilter *> f)
|
||||
{
|
||||
m_filters = f;
|
||||
updateEditorManagerPlaceholderText(); // possibly some shortcut changed
|
||||
m_locatorWidget->updateFilterList();
|
||||
}
|
||||
|
||||
|
@@ -80,6 +80,7 @@ private slots:
|
||||
|
||||
private:
|
||||
void loadSettings();
|
||||
void updateEditorManagerPlaceholderText();
|
||||
|
||||
template <typename S>
|
||||
void loadSettingsHelper(S *settings);
|
||||
|
@@ -36,6 +36,7 @@
|
||||
namespace Core {
|
||||
namespace Constants {
|
||||
|
||||
const char LOCATE[] = "QtCreator.Locate";
|
||||
const char FILTER_OPTIONS_PAGE[] = QT_TRANSLATE_NOOP("Locator", "Locator");
|
||||
const char CUSTOM_FILTER_BASEID[] = "Locator.CustomFilter";
|
||||
const char TASK_INDEX[] = "Locator.Task.Index";
|
||||
|
Reference in New Issue
Block a user