Menu

[2179ca]: / simplescripteditor.cpp  Maximize  Restore  History

Download this file

129 lines (108 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "simplescripteditor.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QTextStream>
extern QString vymName;
SimpleScriptEditor::SimpleScriptEditor (QWidget *parent):QDialog(parent)
{
ui.setupUi (this);
connect ( ui.openButton, SIGNAL (clicked() ), this, SLOT (openClicked() ));
connect ( ui.saveButton, SIGNAL (clicked() ), this, SLOT (saveClicked() ));
connect ( ui.saveAsButton, SIGNAL (clicked() ), this, SLOT (saveAsClicked() ));
connect ( ui.runButton, SIGNAL (clicked() ), this, SLOT (runClicked() ));
// Initialize Editor
QFont font;
font.setFamily("Courier");
font.setFixedPitch(true);
font.setPointSize(12);
ui.editor->setFont(font);
highlighter = new Highlighter(ui.editor->document());
}
void SimpleScriptEditor::saveScript()
{
QFile f( filename );
if ( !f.open( QIODevice::WriteOnly ) )
{
return;
}
QTextStream t( &f );
t << ui.editor->toPlainText();
f.close();
}
void SimpleScriptEditor::setScript(const QString &s)
{
ui.editor->setText(s);
}
void SimpleScriptEditor::saveClicked()
{
if (filename.isEmpty() )
saveAsClicked();
else
saveScript();
}
void SimpleScriptEditor::saveAsClicked()
{
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::openClicked()
{
QFileDialog *fd=new QFileDialog( this);
QStringList types;
types<< "VYM scripts (*.vys)" <<
"All (*)" ;
fd->setFilters (types);
fd->setDirectory (QDir().current());
fd->setWindowTitle (vymName + " - " + tr("Load script"));
fd->show();
if ( fd->exec() == QDialog::Accepted &&!fd->selectedFiles().isEmpty() )
filename = fd->selectedFiles().first();
QFile f( filename );
if ( !f.open( QIODevice::ReadOnly ) )
{
QMessageBox::warning(0,
tr("Error"),
tr("Couldn't open %1.\n").arg(filename));
return;
}
QTextStream ts( &f );
ui.editor->setText( ts.readAll() );
f.close();
}
void SimpleScriptEditor::runClicked()
{
emit runScript (ui.editor->toPlainText() );
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.