mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
GM_Settings: Add button to create new user script
This commit is contained in:
parent
1c6e9fd036
commit
26f0912845
@ -20,11 +20,13 @@
|
||||
#include "gm_settingsscriptinfo.h"
|
||||
#include "../gm_manager.h"
|
||||
#include "../gm_script.h"
|
||||
#include "qztools.h"
|
||||
|
||||
#include "mainapplication.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QMessageBox>
|
||||
#include <QInputDialog>
|
||||
|
||||
GM_Settings::GM_Settings(GM_Manager* manager, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
@ -40,6 +42,8 @@ GM_Settings::GM_Settings(GM_Manager* manager, QWidget* parent)
|
||||
this, SLOT(removeItem(QListWidgetItem*)));
|
||||
connect(ui->openDirectory, SIGNAL(clicked()),
|
||||
this, SLOT(openScriptsDirectory()));
|
||||
connect(ui->newScript, SIGNAL(clicked()),
|
||||
this, SLOT(newScript()));
|
||||
connect(ui->link, SIGNAL(clicked(QPoint)),
|
||||
this, SLOT(openUserJs()));
|
||||
connect(manager, SIGNAL(scriptsChanged()),
|
||||
@ -101,6 +105,35 @@ void GM_Settings::openScriptsDirectory()
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(m_manager->scriptsDirectory()));
|
||||
}
|
||||
|
||||
void GM_Settings::newScript()
|
||||
{
|
||||
const QString name = QInputDialog::getText(this, tr("Add script"), tr("Choose name for script:"));
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
|
||||
const QString script = QL1S("// ==UserScript== \n"
|
||||
"// @name %1 \n"
|
||||
"// @namespace qupzilla.com \n"
|
||||
"// @description Script description \n"
|
||||
"// @include * \n"
|
||||
"// @version 1 \n"
|
||||
"// ==/UserScript==\n"
|
||||
"\n"
|
||||
"// Your script implementation\n");
|
||||
|
||||
const QString fileName = QSL("%1/%2.user.js").arg(m_manager->scriptsDirectory(), QzTools::filterCharsFromFilename(name));
|
||||
|
||||
QFile file(QzTools::ensureUniqueFilename(fileName));
|
||||
file.open(QFile::WriteOnly);
|
||||
file.write(script.arg(name).toUtf8());
|
||||
file.close();
|
||||
|
||||
GM_Script *gmScript = new GM_Script(m_manager, file.fileName());
|
||||
m_manager->addScript(gmScript);
|
||||
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(file.fileName()));
|
||||
}
|
||||
|
||||
void GM_Settings::loadScripts()
|
||||
{
|
||||
disconnect(ui->listWidget, SIGNAL(itemChanged(QListWidgetItem*)),
|
||||
|
@ -45,6 +45,7 @@ private slots:
|
||||
void itemChanged(QListWidgetItem* item);
|
||||
|
||||
void openScriptsDirectory();
|
||||
void newScript();
|
||||
void openUserJs();
|
||||
|
||||
void loadScripts();
|
||||
|
@ -197,6 +197,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="newScript">
|
||||
<property name="text">
|
||||
<string>New user script</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
|
Loading…
Reference in New Issue
Block a user