diff -r c2ffbc9b832d -r f867269ab8a1 simplescripteditor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simplescripteditor.cpp Mon Mar 05 23:22:51 2007 +0000 @@ -0,0 +1,109 @@ +#include "simplescripteditor.h" + + +#include +#include +#include + + +extern QString vymName; + +SimpleScriptEditor::SimpleScriptEditor (QWidget *parent):QDialog(parent) +{ + ui.setupUi (this); + + connect ( ui.loadButton, SIGNAL (clicked() ), this, SLOT (loadScriptClicked() )); + connect ( ui.saveButton, SIGNAL (clicked() ), this, SLOT (saveScriptClicked() )); + connect ( ui.runButton, SIGNAL (clicked() ), this, SLOT (runScriptClicked() )); +} + + +void SimpleScriptEditor::saveScript() +{ + QFile f( filename ); + if ( !f.open( QIODevice::WriteOnly ) ) + { + return; + } + + QTextStream t( &f ); + t << ui.editor->text(); + f.close(); +} + +void SimpleScriptEditor::saveScriptClicked() +{ + QString fn = QFileDialog::getSaveFileName( + this, + QString (vymName + " - " +tr("Save script")), + QString (), + "VYM script (HTML) (*.vys);;All files (*)", + 0, + QFileDialog::DontConfirmOverwrite); + + if ( !fn.isEmpty() ) + { + QFile file (fn); + if (file.exists()) + { + QMessageBox mb( vymName, + tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save as'").arg(fn), + QMessageBox::Warning, + QMessageBox::Yes | QMessageBox::Default, + QMessageBox::Cancel | QMessageBox::Escape, + Qt::NoButton ); + mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); + mb.setButtonText( QMessageBox::No, tr("Cancel")); + switch( mb.exec() ) + { + case QMessageBox::Yes: + // save + filename = fn; + saveScript(); + return; + case QMessageBox::Cancel: + // do nothing + return; + } + } + filename=fn; + saveScript(); + } +} + +void SimpleScriptEditor::loadScriptClicked() +{ + QFileDialog *fd=new QFileDialog( this); + QStringList types; + types<< "VYM scripts (*.vys)" << + "All (*)" ; + fd->setFilters (types); + fd->setDirectory (QDir().current()); + fd->setCaption (vymName + " - " + tr("Load script")); + fd->show(); + QString fn; + if ( fd->exec() == QDialog::Accepted ) + fn = fd->selectedFile(); + + if ( !fn.isEmpty() ) + { + QFile f( fn ); + if ( !f.open( QIODevice::ReadOnly ) ) + { + QMessageBox::warning(0, + tr("Error"), + tr("Couldn't open %1.\n").arg(fn)); + return; + } + + QTextStream ts( &f ); + ui.editor->setText( ts.read() ); + f.close(); + } + +} + +void SimpleScriptEditor::runScriptClicked() +{ + emit runScript (ui.editor->text() ); +}