r19485 by jghali - #12670: Edit/Delete crashes Scribus using JavaScripts
scribus-commit
scribus-commit at lists.scribus.net
Sat Sep 6 12:07:38 UTC 2014
Author: jghali
Date: Sat Sep 6 12:07:38 2014
New Revision: 19485
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19485
Log:
#12670: Edit/Delete crashes Scribus using JavaScripts
Modified:
trunk/Scribus/scribus/ui/javadocs.cpp
trunk/Scribus/scribus/ui/javadocs.h
Modified: trunk/Scribus/scribus/ui/javadocs.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19485&path=/trunk/Scribus/scribus/ui/javadocs.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/javadocs.cpp (original)
+++ trunk/Scribus/scribus/ui/javadocs.cpp Sat Sep 6 12:07:38 2014
@@ -8,8 +8,8 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
+#include <QListWidget>
#include <QMessageBox>
-#include <QListWidget>
#include <QPixmap>
#include <QPushButton>
#include <QRegExp>
@@ -71,6 +71,7 @@
connect(DeleteScript, SIGNAL(clicked()), this, SLOT(slotDelete()));
connect(ExitDia, SIGNAL(clicked()), this, SLOT(accept()));
connect(Scripts, SIGNAL(itemActivated (QListWidgetItem *)), this, SLOT(slotEdit()));
+ connect(Scripts, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
AddScript->setToolTip( "<qt>" + tr( "Adds a new Script, predefines a function with the same name. If you want to use this script as an \"Open Action\" script be sure not to change the name of the function." ) + "</qt>" );
}
@@ -88,10 +89,9 @@
dia2->EditTex->setText("function "+nam+"()\n{\n}");
if (dia2->exec())
{
- EditScript->setEnabled(true);
- DeleteScript->setEnabled(true);
m_Doc->JavaScripts[nam] = dia2->EditTex->toPlainText();
Scripts->addItem(nam);
+ Scripts->setCurrentRow(Scripts->count() - 1);
emit docChanged(false);
}
delete dia2;
@@ -100,11 +100,14 @@
void JavaDocs::slotEdit()
{
- QString nam = Scripts->currentItem()->text();
- Editor* dia2 = new Editor(this, m_Doc->JavaScripts[nam], m_View);
+ QListWidgetItem* currentItem = Scripts->currentItem();
+ if (!currentItem)
+ return;
+ QString name = currentItem->text();
+ Editor* dia2 = new Editor(this, m_Doc->JavaScripts[name], m_View);
if (dia2->exec())
{
- m_Doc->JavaScripts[nam] = dia2->EditTex->toPlainText();
+ m_Doc->JavaScripts[name] = dia2->EditTex->toPlainText();
emit docChanged(false);
}
delete dia2;
@@ -112,14 +115,18 @@
void JavaDocs::slotDelete()
{
+ QListWidgetItem* currentItem = Scripts->currentItem();
+ if (!currentItem)
+ return;
+
int exit = QMessageBox::warning(this,
CommonStrings::trWarning,
tr("Do you really want to delete this script?"),
QMessageBox::Yes | QMessageBox::No);
if (exit == QMessageBox::Yes)
{
- QString nam = Scripts->currentItem()->text();
- m_Doc->JavaScripts.remove(nam);
+ QString name = currentItem->text();
+ m_Doc->JavaScripts.remove(name);
Scripts->clear();
QMap<QString,QString>::Iterator it;
for (it = m_Doc->JavaScripts.begin(); it != m_Doc->JavaScripts.end(); ++it)
@@ -132,3 +139,10 @@
emit docChanged(false);
}
}
+
+void JavaDocs::slotSelectionChanged()
+{
+ QListWidgetItem* currentItem = Scripts->currentItem();
+ EditScript->setEnabled(currentItem != 0);
+ DeleteScript->setEnabled(currentItem != 0);
+}
Modified: trunk/Scribus/scribus/ui/javadocs.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19485&path=/trunk/Scribus/scribus/ui/javadocs.h
==============================================================================
--- trunk/Scribus/scribus/ui/javadocs.h (original)
+++ trunk/Scribus/scribus/ui/javadocs.h Sat Sep 6 12:07:38 2014
@@ -35,6 +35,7 @@
void slotAdd();
void slotEdit();
void slotDelete();
+ void slotSelectionChanged();
signals:
void docChanged(bool);
More information about the scribus-commit
mailing list