Commit 2f18203f authored by Michal Humpula's avatar Michal Humpula Committed by Christoph Cullmann
Browse files

addons/project: add Open Terminal folder action

Focuses bottom window project tool view and respawns terminal in new
directory.

There is no standard way to interact with foreground process in terminal
so instead of complicated heuristic for shell and other applications the
simple destroy terminal and create new one strategy is chosen.

callgraph:
  KateProjectTreeViewContextMenu ->
  KateProjectViewTree ->
  KateProjectPluginView ->
  KateProjectInfoView ->
  KateProjectInfoViewTerminal
parent e72a9b01
......@@ -20,6 +20,7 @@
KateProjectInfoView::KateProjectInfoView(KateProjectPluginView *pluginView, KateProject *project)
: m_pluginView(pluginView)
, m_project(project)
, m_terminal(nullptr)
{
/**
* skip terminal toolviews if no terminal aka KonsolePart around
......@@ -30,7 +31,8 @@ KateProjectInfoView::KateProjectInfoView(KateProjectPluginView *pluginView, Kate
*/
const QString projectPath = QFileInfo(QFileInfo(m_project->fileName()).path()).canonicalFilePath();
if (!projectPath.isEmpty()) {
addTab(new KateProjectInfoViewTerminal(pluginView, projectPath), i18n("Terminal (.kateproject)"));
m_terminal = new KateProjectInfoViewTerminal(pluginView, projectPath);
addTab(m_terminal, i18n("Terminal (.kateproject)"));
}
/**
......@@ -77,3 +79,10 @@ bool KateProjectInfoView::ignoreEsc() const
// else: always hide toolview, nothing to ignore
return false;
}
void KateProjectInfoView::resetTerminal(const QString &directory)
{
if (m_terminal) {
m_terminal->respawn(directory);
}
}
......@@ -12,6 +12,7 @@
class KateProjectPluginView;
class KateProject;
class KateProjectInfoViewTerminal;
/**
* Class representing a view of a project.
......@@ -52,6 +53,8 @@ public:
*/
bool ignoreEsc() const;
void resetTerminal(const QString &directory);
private:
/**
* our plugin view
......@@ -62,6 +65,8 @@ private:
* our project
*/
KateProject *m_project;
KateProjectInfoViewTerminal *m_terminal;
};
#endif
......@@ -130,3 +130,20 @@ bool KateProjectInfoViewTerminal::isLoadable()
{
return (pluginFactory() != nullptr);
}
void KateProjectInfoViewTerminal::respawn(const QString &directory)
{
if (!isLoadable()) {
return;
}
m_directory = directory;
disconnect(m_konsolePart, &KParts::ReadOnlyPart::destroyed, this, &KateProjectInfoViewTerminal::loadTerminal);
if (m_konsolePart != nullptr) {
delete m_konsolePart;
}
loadTerminal();
}
......@@ -50,6 +50,8 @@ public:
*/
static bool isLoadable();
void respawn(const QString &dirPath);
private Q_SLOTS:
/**
* Construct a new terminal for this view
......@@ -90,7 +92,7 @@ private:
/**
* our start directory for the terminal
*/
const QString m_directory;
QString m_directory;
/**
* our layout
......
......@@ -734,4 +734,13 @@ void KateProjectPluginView::showDiffInFixedView(const QByteArray &contents)
m_mainWindow->activateView(m_fixedView.view->document());
}
void KateProjectPluginView::openTerminal(const QString &dirPath, KateProject *project)
{
m_mainWindow->showToolView(m_toolInfoView);
if (m_project2View.contains(project)) {
m_project2View.find(project)->second->resetTerminal(dirPath);
}
}
#include "kateprojectpluginview.moc"
......@@ -122,6 +122,11 @@ public:
cb(m_fixedView.view);
}
/**
* Open terminal view at \p dirPath location for project \p project
*/
void openTerminal(const QString &dirPath, KateProject *project);
public Q_SLOTS:
/**
* Create views for given project.
......
......@@ -70,6 +70,9 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
if (index.data(KateProjectItem::TypeRole).toInt() == KateProjectItem::Directory) {
addFile = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("Add File"));
addFolder = menu.addAction(QIcon::fromTheme(QStringLiteral("folder-new")), i18n("Add Folder"));
menu.addAction(QIcon::fromTheme(QStringLiteral("terminal")), i18n("Open Terminal"), [parent, &filename]() {
parent->openTerminal(filename);
});
}
// we can ATM only handle file renames
......
......@@ -193,6 +193,11 @@ void KateProjectViewTree::removeFile(const QModelIndex& idx, const QString& full
}
}
void KateProjectViewTree::openTerminal(const QString &dirPath)
{
m_pluginView->openTerminal(dirPath, m_project);
}
void KateProjectViewTree::slotClicked(const QModelIndex &index)
{
/**
......
......@@ -68,6 +68,11 @@ public:
*/
void removeFile(const QModelIndex &idx, const QString &fullFilePath);
/**
* Open project terminal at location dirPath
*/
void openTerminal(const QString &dirPath);
private Q_SLOTS:
/**
* item got clicked, do stuff, like open document
......
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