Commit f0c285b4 authored by Anthony Fieroni's avatar Anthony Fieroni

[Project plugin] Shortcut (Alt+1) and context menu actions to lookup in ctags index

REVIEW: 127511
Signed-off-by: Anthony Fieroni's avatarAnthony Fieroni <bvbfan@abv.bg>
parent 7feb4df4
......@@ -64,6 +64,7 @@ KateProjectInfoViewIndex::KateProjectInfoViewIndex(KateProjectPluginView *plugin
/**
* connect needed signals
*/
connect(m_pluginView, SIGNAL(projectLookupWord(const QString &)), this, SLOT(slotTextChanged(const QString &)));
connect(m_lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(slotTextChanged(const QString &)));
connect(m_treeView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotClicked(const QModelIndex &)));
connect(m_project, SIGNAL(indexChanged()), this, SLOT(indexAvailable()));
......
......@@ -28,12 +28,15 @@
#include <ktexteditor/codecompletioninterface.h>
#include <kactioncollection.h>
#include <kstringhandler.h>
#include <kpluginfactory.h>
#include <kpluginloader.h>
#include <kactionmenu.h>
#include <kaboutdata.h>
#include <KLocalizedString>
#include <KXMLGUIFactory>
#include <QMenu>
#include <QAction>
#include <QDialog>
#include <QHBoxLayout>
......@@ -47,6 +50,7 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
, m_mainWindow(mainWin)
, m_toolView(nullptr)
, m_toolInfoView(nullptr)
, m_lookupAction(nullptr)
{
KXMLGUIClient::setComponentName(QStringLiteral("kateproject"), i18n("Kate Project Manager"));
setXMLFile(QStringLiteral("ui.rc"));
......@@ -83,6 +87,16 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Left));
a = actionCollection()->addAction(KStandardAction::Forward, QStringLiteral("projects_next_project"), this, SLOT(slotProjectNext()));
actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Right));
a = actionCollection()->addAction(KStandardAction::Goto, QStringLiteral("projects_goto_index"), this, SLOT(slotProjectIndex()));
actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::ALT | Qt::Key_1));
// popup menu
auto popup = new KActionMenu(i18n("Project"), this);
actionCollection()->addAction(QLatin1String("popup_project"), popup);
m_lookupAction = popup->menu()->addAction(i18n("Lookup: %1", QString()), this, SLOT(slotProjectIndex()));
connect(popup->menu(), SIGNAL(aboutToShow()), this, SLOT(slotContextMenuAboutToShow()));
/**
* add us to gui
......@@ -464,4 +478,42 @@ void KateProjectPluginView::slotProjectReload()
}
}
QString KateProjectPluginView::currentWord() const
{
KTextEditor::View *kv = m_activeTextEditorView;
if (!kv) {
return QString();
}
if (kv->selection() && kv->selectionRange().onSingleLine()) {
return kv->selectionText();
}
return kv->document()->wordAt(kv->cursorPosition());
}
void KateProjectPluginView::slotProjectIndex()
{
const QString word = currentWord();
if (!word.isEmpty()) {
auto tabView = qobject_cast<QTabWidget*>(m_stackedProjectInfoViews->currentWidget());
if (tabView) {
tabView->setCurrentIndex(1);
}
m_mainWindow->showToolView(m_toolInfoView);
emit projectLookupWord(word);
}
}
void KateProjectPluginView::slotContextMenuAboutToShow()
{
const QString word = currentWord();
if (word.isEmpty()) {
return;
}
const QString squeezed = KStringHandler::csqueeze(word, 30);
m_lookupAction->setText(i18n("Lookup: %1", squeezed));
}
#include "kateprojectpluginview.moc"
......@@ -33,6 +33,8 @@
#include <KXMLGUIClient>
class QAction;
class KateProjectPluginView : public QObject, public KXMLGUIClient
{
Q_OBJECT
......@@ -137,6 +139,11 @@ private Q_SLOTS:
*/
void slotProjectReload();
/**
* Lookup current word
*/
void slotProjectIndex();
Q_SIGNALS:
/**
* Emitted if projectFileName changed.
......@@ -148,6 +155,12 @@ Q_SIGNALS:
*/
void projectMapChanged();
/**
* Emitted when a ctags lookup in requested
* @param word lookup word
*/
void projectLookupWord(const QString &word);
private Q_SLOTS:
/**
* This slot is called whenever the active view changes in our main window.
......@@ -165,6 +178,17 @@ private Q_SLOTS:
*/
void slotDocumentUrlChanged(KTextEditor::Document *document);
/**
* Show context menu
*/
void slotContextMenuAboutToShow();
private:
/**
* find current selected or under cursor word
*/
QString currentWord() const;
private:
/**
* our plugin
......@@ -221,6 +245,11 @@ private:
* remember for which text views we might need to cleanup stuff
*/
QSet<QObject *> m_textViews;
/**
* lookup action
*/
QAction *m_lookupAction;
};
#endif
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kpartgui>
<gui name="kateprojectplugin" library="kateprojectplugin" version="7" translationDomain="kateproject">
<gui name="kateprojectplugin" library="kateprojectplugin" version="8" translationDomain="kateproject">
<MenuBar>
<Menu name="projects">
<text>&amp;Projects</text>
<Action name="projects_prev_project"/>
<Action name="projects_next_project"/>
<Action name="projects_goto_index" />
</Menu>
</MenuBar>
<Menu name="ktexteditor_popup" noMerge="1">
<Action name="popup_project"/>
</Menu>
</gui>
<!-- kate: space-indent on; indent-width 4; replace-tabs on; -->
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment