mirror of
https://github.com/x-tools-author/x-tools.git
synced 2025-09-15 15:28:40 +08:00
Compare commits
4 Commits
5217fdaca5
...
393da176ca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
393da176ca | ||
|
|
4b8409ce7a | ||
|
|
c316fb2c93 | ||
|
|
56e8355c5f |
@ -51,5 +51,5 @@ set_property(TARGET SingleApplication PROPERTY FOLDER "3rd")
|
||||
set_target_properties(SingleApplication PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${sapp_lib_dir})
|
||||
|
||||
list(APPEND X_LIBS SingleApplication)
|
||||
add_compile_definitions(X_ENABLE_SINGLEAPPLICATION)
|
||||
set(X_ENABLE_SINGLEAPPLICATION ON)
|
||||
add_compile_definitions(X_ENABLE_SINGLE_APPLICATION)
|
||||
set(X_ENABLE_SINGLE_APPLICATION ON)
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
#include "application.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
#if defined(X_ENABLE_SINGLEAPPLICATION)
|
||||
#if defined(X_ENABLE_SINGLE_APPLICATION)
|
||||
#include "singleapplication.h"
|
||||
#endif
|
||||
|
||||
@ -24,7 +24,7 @@ int main(int argc, char *argv[])
|
||||
Application::setupHdpi();
|
||||
Application app(argc, argv);
|
||||
|
||||
#if defined(X_ENABLE_SINGLEAPPLICATION)
|
||||
#if defined(X_ENABLE_SINGLE_APPLICATION)
|
||||
SingleApplication sApp(argc, argv);
|
||||
if (sApp.isSecondary()) {
|
||||
return 0;
|
||||
@ -44,7 +44,7 @@ int main(int argc, char *argv[])
|
||||
window.load();
|
||||
window.moveToCenter();
|
||||
|
||||
#if defined(X_ENABLE_SINGLEAPPLICATION)
|
||||
#if defined(X_ENABLE_SINGLE_APPLICATION)
|
||||
QObject::connect(&sApp, &SingleApplication::instanceStarted, &window, [&window]() {
|
||||
window.show();
|
||||
window.raise();
|
||||
|
||||
@ -9,14 +9,85 @@
|
||||
#include "scriptbase.h"
|
||||
#include "ui_scriptbase.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include "scriptrunner.h"
|
||||
|
||||
ScriptBase::ScriptBase(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::ScriptBase)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->toolButtonOpen, &QToolButton::clicked, this, &ScriptBase::onRunButtonClicked);
|
||||
connect(ui->toolButtonNew, &QToolButton::clicked, this, &ScriptBase::onNewButtonClicked);
|
||||
connect(ui->toolButtonOpen, &QToolButton::clicked, this, &ScriptBase::onOpenButtonClicked);
|
||||
connect(ui->toolButtonRefresh, &QToolButton::clicked, this, &ScriptBase::onRefreshButtonClicked);
|
||||
connect(ui->toolButtonHelp, &QToolButton::clicked, this, &ScriptBase::onHelpButtonClicked);
|
||||
}
|
||||
|
||||
ScriptBase::~ScriptBase()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
ScriptRunner *ScriptBase::newRunner()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QString ScriptBase::helpUrl() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
void ScriptBase::onRunButtonClicked(bool checked)
|
||||
{
|
||||
ui->toolButtonOpen->setEnabled(false);
|
||||
if (checked) {
|
||||
startRunner();
|
||||
} else {
|
||||
stopRunner();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptBase::onNewButtonClicked() {}
|
||||
|
||||
void ScriptBase::onOpenButtonClicked() {}
|
||||
|
||||
void ScriptBase::onRefreshButtonClicked() {}
|
||||
|
||||
void ScriptBase::onHelpButtonClicked()
|
||||
{
|
||||
QString url = helpUrl();
|
||||
if (url.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDesktopServices::openUrl(QUrl(url));
|
||||
}
|
||||
|
||||
void ScriptBase::startRunner()
|
||||
{
|
||||
stopRunner();
|
||||
|
||||
m_runner = newRunner();
|
||||
if (!m_runner) {
|
||||
return;
|
||||
}
|
||||
|
||||
connect(m_runner, &QThread::finished, this, [this]() { ui->toolButtonOpen->setEnabled(true); });
|
||||
connect(m_runner, &QThread::started, this, [this]() { ui->toolButtonOpen->setEnabled(true); });
|
||||
m_runner->start();
|
||||
}
|
||||
|
||||
void ScriptBase::stopRunner()
|
||||
{
|
||||
if (m_runner) {
|
||||
m_runner->requestInterruption();
|
||||
m_runner->exit();
|
||||
m_runner->wait();
|
||||
m_runner->deleteLater();
|
||||
m_runner = nullptr;
|
||||
}
|
||||
}
|
||||
@ -14,6 +14,7 @@ namespace Ui {
|
||||
class ScriptBase;
|
||||
}
|
||||
|
||||
class ScriptRunner;
|
||||
class ScriptBase : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -21,6 +22,21 @@ public:
|
||||
explicit ScriptBase(QWidget *parent = nullptr);
|
||||
~ScriptBase() override;
|
||||
|
||||
protected:
|
||||
virtual ScriptRunner *newRunner();
|
||||
virtual QString helpUrl() const;
|
||||
|
||||
private:
|
||||
void onRunButtonClicked(bool checked);
|
||||
void onNewButtonClicked();
|
||||
void onOpenButtonClicked();
|
||||
void onRefreshButtonClicked();
|
||||
void onHelpButtonClicked();
|
||||
|
||||
void startRunner();
|
||||
void stopRunner();
|
||||
|
||||
private:
|
||||
Ui::ScriptBase *ui = nullptr;
|
||||
ScriptRunner *m_runner = nullptr;
|
||||
};
|
||||
17
src/page/scripts/scriptrunnerjs.cpp
Normal file
17
src/page/scripts/scriptrunnerjs.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright 2025-2025 x-tools-author(x-tools@outlook.com). All rights reserved.
|
||||
*
|
||||
* The file is encoded using "utf8 with bom", it is a part of eTools project.
|
||||
*
|
||||
* eTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
|
||||
* code directory.
|
||||
**************************************************************************************************/
|
||||
#include "scriptrunnerjs.h"
|
||||
|
||||
ScriptRunnerJs::ScriptRunnerJs(QObject *parent)
|
||||
: ScriptRunner(parent)
|
||||
{}
|
||||
|
||||
ScriptRunnerJs::~ScriptRunnerJs() {}
|
||||
|
||||
void ScriptRunnerJs::run() {}
|
||||
22
src/page/scripts/scriptrunnerjs.h
Normal file
22
src/page/scripts/scriptrunnerjs.h
Normal file
@ -0,0 +1,22 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright 2025-2025 x-tools-author(x-tools@outlook.com). All rights reserved.
|
||||
*
|
||||
* The file is encoded using "utf8 with bom", it is a part of eTools project.
|
||||
*
|
||||
* eTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
|
||||
* code directory.
|
||||
**************************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "scriptrunner.h"
|
||||
|
||||
class ScriptRunnerJs : public ScriptRunner
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScriptRunnerJs(QObject *parent = nullptr);
|
||||
~ScriptRunnerJs();
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
};
|
||||
17
src/page/scripts/scriptrunnerlua.cpp
Normal file
17
src/page/scripts/scriptrunnerlua.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright 2025-2025 x-tools-author(x-tools@outlook.com). All rights reserved.
|
||||
*
|
||||
* The file is encoded using "utf8 with bom", it is a part of eTools project.
|
||||
*
|
||||
* eTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
|
||||
* code directory.
|
||||
**************************************************************************************************/
|
||||
#include "scriptrunnerlua.h"
|
||||
|
||||
ScriptRunnerLua::ScriptRunnerLua(QObject *parent)
|
||||
: ScriptRunner(parent)
|
||||
{}
|
||||
|
||||
ScriptRunnerLua::~ScriptRunnerLua() {}
|
||||
|
||||
void ScriptRunnerLua::run() {}
|
||||
22
src/page/scripts/scriptrunnerlua.h
Normal file
22
src/page/scripts/scriptrunnerlua.h
Normal file
@ -0,0 +1,22 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright 2025-2025 x-tools-author(x-tools@outlook.com). All rights reserved.
|
||||
*
|
||||
* The file is encoded using "utf8 with bom", it is a part of eTools project.
|
||||
*
|
||||
* eTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
|
||||
* code directory.
|
||||
**************************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "scriptrunner.h"
|
||||
|
||||
class ScriptRunnerLua : public ScriptRunner
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScriptRunnerLua(QObject *parent = nullptr);
|
||||
~ScriptRunnerLua();
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user