terminal plugin
This commit is contained in:
parent
a3c62b11f0
commit
42be6f557a
|
@ -56,6 +56,7 @@ SOURCES += \
|
|||
src/navigator.cpp \
|
||||
src/style.cpp \
|
||||
src/tabslist.cpp \
|
||||
src/terminalinterface.cpp \
|
||||
src/tooltip.cpp \
|
||||
src/breadcrumbs.cpp \
|
||||
src/helpwords.cpp \
|
||||
|
@ -107,6 +108,7 @@ HEADERS += \
|
|||
include/navigator.h \
|
||||
include/style.h \
|
||||
include/tabslist.h \
|
||||
include/terminalinterface.h \
|
||||
include/tooltip.h \
|
||||
include/breadcrumbs.h \
|
||||
include/helpwords.h \
|
||||
|
|
Binary file not shown.
|
@ -10,6 +10,7 @@
|
|||
#include <QList>
|
||||
#include "plugininterface.h"
|
||||
#include "spellcheckerinterface.h"
|
||||
#include "terminalinterface.h"
|
||||
|
||||
extern const QString APPLICATION_NAME;
|
||||
extern const QString APPLICATION_VERSION;
|
||||
|
@ -54,6 +55,7 @@ public:
|
|||
static bool isPluginExists(QString name, QString path = "");
|
||||
static SpellCheckerInterface * loadSpellChecker(QString path = "");
|
||||
static bool loadStylePlugin(QString name, QString path, bool light = false);
|
||||
static TerminalInterface * loadTerminalPlugin(QString path = "");
|
||||
static QStringList getInstalledStylePlugins(QString path);
|
||||
static QString getExistingDirectory(QWidget * parent, QString title, QString directory);
|
||||
static QWidget * getWindowWidget();
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "project.h"
|
||||
#include "git.h"
|
||||
#include "spellcheckerinterface.h"
|
||||
#include "terminalinterface.h"
|
||||
#include "quickaccess.h"
|
||||
#include "progressline.h"
|
||||
#include "progressinfo.h"
|
||||
|
@ -225,6 +226,9 @@ private slots:
|
|||
void editorPaneResize();
|
||||
void tabsListTriggered();
|
||||
void tabsListSelected(int index);
|
||||
void terminalCopy();
|
||||
void terminalPaste();
|
||||
void showTerminal();
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
Settings * settings;
|
||||
|
@ -241,6 +245,7 @@ private:
|
|||
Project * project;
|
||||
Git * git;
|
||||
SpellCheckerInterface * spellChecker;
|
||||
TerminalInterface * terminal;
|
||||
QToolButton * tabsListButton;
|
||||
QString outputMsgErrorTpl;
|
||||
QString outputMsgWarningTpl;
|
||||
|
@ -274,6 +279,7 @@ private:
|
|||
QStringList args;
|
||||
bool tmpDisableParser;
|
||||
Welcome * welcomeScreen;
|
||||
int terminalTabIndex;
|
||||
signals:
|
||||
void disableWorker();
|
||||
void parseLint(int tabIndex, QString path);
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef TERMINALINTERFACE_H
|
||||
#define TERMINALINTERFACE_H
|
||||
|
||||
#include "plugininterface.h"
|
||||
#include <QFont>
|
||||
|
||||
extern const QString TERMINAL_PLUGIN_NAME;
|
||||
|
||||
class TerminalInterface : public PluginInterface
|
||||
{
|
||||
public:
|
||||
TerminalInterface(QObject *parent = nullptr);
|
||||
virtual ~TerminalInterface();
|
||||
virtual QWidget * getWidget() = 0;
|
||||
virtual void setFont(QFont font) = 0;
|
||||
virtual void exec(QString text) = 0;
|
||||
virtual void changeDir(QString path) = 0;
|
||||
virtual void copy() = 0;
|
||||
virtual void paste() = 0;
|
||||
};
|
||||
|
||||
#define TerminalInterface_iid "com.github.ziracms.editor.TerminalInterface"
|
||||
Q_DECLARE_INTERFACE(TerminalInterface, TerminalInterface_iid)
|
||||
|
||||
#endif // TERMINALINTERFACE_H
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"Keys" : [ ]
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
QT += gui
|
||||
QT += widgets
|
||||
|
||||
TEMPLATE = lib
|
||||
CONFIG += plugin
|
||||
|
||||
CONFIG += c++11
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any Qt feature that has been marked deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
INCLUDEPATH += ../ZiraEditor/include
|
||||
|
||||
SOURCES += \
|
||||
../ZiraEditor/src/plugininterface.cpp \
|
||||
../ZiraEditor/src/terminalinterface.cpp \
|
||||
terminalplugin.cpp
|
||||
|
||||
HEADERS += \
|
||||
../ZiraEditor/include/plugininterface.h \
|
||||
../ZiraEditor/include/terminalinterface.h \
|
||||
terminalplugin.h
|
||||
|
||||
DISTFILES += TerminalPlugin.json
|
||||
|
||||
# Default rules for deployment.
|
||||
unix {
|
||||
target.path = $$[QT_INSTALL_PLUGINS]/generic
|
||||
}
|
||||
!isEmpty(target.path): INSTALLS += target
|
||||
|
||||
unix:!macx: LIBS += -lqtermwidget5
|
|
@ -0,0 +1,50 @@
|
|||
#include "terminalplugin.h"
|
||||
|
||||
TerminalPlugin::TerminalPlugin(QObject *parent)
|
||||
: TerminalInterface(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TerminalPlugin::initialize(QString path)
|
||||
{
|
||||
console = new QTermWidget(0);
|
||||
console->setEnvironment(QStringList() << "TERM=konsole-256color");
|
||||
console->setColorScheme("Linux"); // "GreenOnBlack", "Linux", "SolarizedLight", "BlackOnWhite", "DarkPastels", "BlackOnRandomLight", "WhiteOnBlack", "BlackOnLightYellow", "Solarized", "BreezeModified"
|
||||
console->setWorkingDirectory(path);
|
||||
console->startShellProgram();
|
||||
}
|
||||
|
||||
QString TerminalPlugin::getDirName()
|
||||
{
|
||||
return TERMINAL_PLUGIN_NAME;
|
||||
}
|
||||
|
||||
QWidget * TerminalPlugin::getWidget()
|
||||
{
|
||||
return console;
|
||||
}
|
||||
|
||||
void TerminalPlugin::copy()
|
||||
{
|
||||
console->copyClipboard();
|
||||
}
|
||||
|
||||
void TerminalPlugin::paste()
|
||||
{
|
||||
console->pasteClipboard();
|
||||
}
|
||||
|
||||
void TerminalPlugin::setFont(QFont font)
|
||||
{
|
||||
console->setTerminalFont(font);
|
||||
}
|
||||
|
||||
void TerminalPlugin::exec(QString text)
|
||||
{
|
||||
console->sendText(text+"\n");
|
||||
}
|
||||
|
||||
void TerminalPlugin::changeDir(QString path)
|
||||
{
|
||||
console->changeDir(path);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef TERMINALPLUGIN_H
|
||||
#define TERMINALPLUGIN_H
|
||||
|
||||
#include "terminalinterface.h"
|
||||
#include "qtermwidget5/qtermwidget.h"
|
||||
|
||||
class TerminalPlugin : public TerminalInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
#if QT_VERSION >= 0x050000
|
||||
Q_PLUGIN_METADATA(IID TerminalInterface_iid FILE "TerminalPlugin.json")
|
||||
Q_INTERFACES(TerminalInterface)
|
||||
#endif // QT_VERSION >= 0x050000
|
||||
|
||||
public:
|
||||
explicit TerminalPlugin(QObject *parent = nullptr);
|
||||
void initialize(QString path) override;
|
||||
QString getDirName() override;
|
||||
QWidget * getWidget() override;
|
||||
void setFont(QFont font) override;
|
||||
void exec(QString text) override;
|
||||
void changeDir(QString path) override;
|
||||
void copy() override;
|
||||
void paste() override;
|
||||
private:
|
||||
QTermWidget * console;
|
||||
};
|
||||
|
||||
#endif // TERMINALPLUGIN_H
|
|
@ -12,7 +12,8 @@
|
|||
<tr><td>Context help:</td><td><b>F1</b></td> <td> </td><td> </td> <td>Search in files:</td><td><b>Ctrl+Shift+F</b></td></tr>
|
||||
<tr><td>Duplicate line:</td><td><b>Ctrl+D</b></td> <td> </td><td> </td> <td>Focus on tree:</td><td><b>Alt+↓</b></td></tr>
|
||||
<tr><td>Delete line:</td><td><b>Ctrl+Shift+D</b></td> <td> </td><td> </td> <td>Quick Access: </td><td><b>F3 / Ctrl+P</b></td></tr>
|
||||
<tr><td>Show Toolbar:</td><td><b>Ctrl+T</b></td> <td> </td><td> </td> <td>Close tab:</td><td><b>Ctrl+Q</b></td></tr>
|
||||
<tr><td>Show Terminal:</td><td><b>Ctrl+T</b></td> <td> </td><td> </td> <td>Execute file:</td><td><b>F5</b></td></tr>
|
||||
<tr><td>Show Toolbar:</td><td><b>Ctrl+Shift+T</b></td> <td> </td><td> </td> <td>Close tab:</td><td><b>Ctrl+Q</b></td></tr>
|
||||
<tr><td>Show Sidebar:</td><td><b>Ctrl+Enter</b></td> <td> </td><td> </td> <td>Close project:</td><td><b>Ctrl+Shift+Q</b></td></tr>
|
||||
<tr><td>Show Output:</td><td><b>Ctrl+Shift+Enter</b></td> <td> </td><td> </td> <td>Exit:</td><td><b>Ctrl+Alt+Q</b></td></tr>
|
||||
</table>
|
||||
|
|
|
@ -332,6 +332,19 @@ QStringList Helper::getInstalledStylePlugins(QString path)
|
|||
return pluginsList;
|
||||
}
|
||||
|
||||
TerminalInterface * Helper::loadTerminalPlugin(QString path)
|
||||
{
|
||||
QObject * plugin = loadPlugin(TERMINAL_PLUGIN_NAME, path);
|
||||
if (!plugin) return nullptr;
|
||||
TerminalInterface * terminal = qobject_cast<TerminalInterface *>(plugin);
|
||||
if (!terminal) {
|
||||
delete plugin;
|
||||
return nullptr;
|
||||
}
|
||||
terminal->initialize(QDir::homePath());
|
||||
return terminal;
|
||||
}
|
||||
|
||||
bool Helper::isPluginExists(QString name, QString path)
|
||||
{
|
||||
QString pluginFile = getPluginFile(name, path);
|
||||
|
|
|
@ -139,6 +139,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
// plugins
|
||||
spellChecker = Helper::loadSpellChecker(pluginsDir);
|
||||
terminal = Helper::loadTerminalPlugin(pluginsDir);
|
||||
|
||||
// load words
|
||||
highlightWords = new HighlightWords(settings);
|
||||
|
@ -419,6 +420,32 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
ui->outputEdit->setFont(outputFont);
|
||||
ui->todoEdit->setFont(outputFont);
|
||||
|
||||
if (terminal != nullptr) {
|
||||
terminal->setFont(outputFont);
|
||||
|
||||
QVBoxLayout * terminalLayout = new QVBoxLayout();
|
||||
terminalLayout->setContentsMargins(3, 3, 3, 3);
|
||||
terminalLayout->addWidget(terminal->getWidget());
|
||||
QWidget * terminalTab = new QWidget(ui->outputTabWidget);
|
||||
terminalTab->setLayout(terminalLayout);
|
||||
terminalTab->setStyleSheet("background:black");
|
||||
terminalTabIndex = ui->outputTabWidget->addTab(terminalTab, tr("Terminal"));
|
||||
|
||||
QString shortcutCopyStr = QString::fromStdString("Ctrl+Shift+C");
|
||||
QShortcut * shortcutCopy = new QShortcut(QKeySequence(shortcutCopyStr), this);
|
||||
connect(shortcutCopy, SIGNAL(activated()), this, SLOT(terminalCopy()));
|
||||
|
||||
QString shortcutPasteStr = QString::fromStdString("Ctrl+Shift+V");
|
||||
QShortcut * shortcutPaste = new QShortcut(QKeySequence(shortcutPasteStr), this);
|
||||
connect(shortcutPaste, SIGNAL(activated()), this, SLOT(terminalPaste()));
|
||||
|
||||
QString showTerminalStr = QString::fromStdString(settings->get("shortcut_terminal"));
|
||||
QShortcut * showTerminal = new QShortcut(QKeySequence(showTerminalStr), this);
|
||||
connect(showTerminal, SIGNAL(activated()), this, SLOT(showTerminal()));
|
||||
} else {
|
||||
terminalTabIndex = -1;
|
||||
}
|
||||
|
||||
QPalette outputPalette;
|
||||
outputPalette.setColor(QPalette::Base, outputBgColor);
|
||||
outputPalette.setColor(QPalette::Text, outputColor);
|
||||
|
@ -883,6 +910,9 @@ void MainWindow::on_actionCloseProject_triggered()
|
|||
// update window title
|
||||
setWindowTitleText("");
|
||||
gitTabRefreshRequested();
|
||||
if (terminal != nullptr) {
|
||||
terminal->changeDir(QDir::homePath());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionSave_triggered()
|
||||
|
@ -1948,6 +1978,9 @@ void MainWindow::projectOpenRequested(QString path)
|
|||
setStatusBarText(tr("Scanning project..."));
|
||||
emit parseProject(project->getPath());
|
||||
gitTabRefreshRequested();
|
||||
if (terminal != nullptr) {
|
||||
terminal->changeDir(project->getPath());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::openTabsRequested(QStringList files, bool initHighlight)
|
||||
|
@ -2409,3 +2442,29 @@ void MainWindow::tabsListSelected(int index)
|
|||
if (index >= ui->tabWidget->count()) return;
|
||||
editorTabs->setActiveTab(index);
|
||||
}
|
||||
|
||||
void MainWindow::showTerminal()
|
||||
{
|
||||
if (terminal == nullptr) return;
|
||||
if (terminalTabIndex < 0) return;
|
||||
hideQAPanel();
|
||||
if (!ui->outputDockWidget->isVisible() || !terminal->getWidget()->hasFocus()) {
|
||||
if (!ui->outputDockWidget->isVisible()) ui->outputDockWidget->show();
|
||||
ui->outputTabWidget->setCurrentIndex(terminalTabIndex);
|
||||
terminal->getWidget()->setFocus();
|
||||
} else {
|
||||
ui->outputDockWidget->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::terminalCopy()
|
||||
{
|
||||
if (terminal == nullptr) return;
|
||||
terminal->copy();
|
||||
}
|
||||
|
||||
void MainWindow::terminalPaste()
|
||||
{
|
||||
if (terminal == nullptr) return;
|
||||
terminal->paste();
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ Settings::Settings(QObject * parent) : QObject(parent)
|
|||
{"shortcut_help", "F1"},
|
||||
{"shortcut_execute", "F5"},
|
||||
{"shortcut_sidebar", "Ctrl+Return"},
|
||||
{"shortcut_toolbar", "Ctrl+T"},
|
||||
{"shortcut_toolbar", "Ctrl+Shift+T"},
|
||||
{"shortcut_output", "Ctrl+Shift+Return"},
|
||||
{"shortcut_quick_access", "F3"},
|
||||
{"shortcut_quick_access_alt", "Ctrl+P"},
|
||||
|
@ -100,6 +100,7 @@ Settings::Settings(QObject * parent) : QObject(parent)
|
|||
{"shortcut_previous_tab", "Alt+Left"},
|
||||
{"shortcut_next_tab", "Alt+Right"},
|
||||
{"shortcut_tabs_list", "Alt+Up"},
|
||||
{"shortcut_terminal", "Ctrl+T"},
|
||||
{"shortcut_close_tab", "Ctrl+Q"},
|
||||
{"shortcut_close_project", "Ctrl+Shift+Q"},
|
||||
{"shortcut_close_app", "Ctrl+Alt+Q"},
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#include "terminalinterface.h"
|
||||
|
||||
const QString TERMINAL_PLUGIN_NAME = "TerminalWidget";
|
||||
|
||||
TerminalInterface::TerminalInterface(QObject *parent) : PluginInterface(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TerminalInterface::~TerminalInterface()
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in New Issue