| 1 | #include "includeeditor.h" |
| 2 | #include <QDialogButtonBox> |
| 3 | #include <QPushButton> |
| 4 | #include <QMessageBox> |
| 5 | |
| 6 | IncludeEditor::IncludeEditor(QString inclstr, const QString &_dir, QWidget *parent) : QDialog(parent){ |
| 7 | setWindowTitle(QString("included file :%1").arg(inclstr)); |
| 8 | fileName = inclstr.remove(QRegularExpression("^\\++")); |
| 9 | |
| 10 | dirName=_dir; |
| 11 | fileName=QString("%1/%2").arg(dirName).arg(fileName); |
| 12 | setMinimumWidth(500); |
| 13 | //qDebug()<<fileName; |
| 14 | //QVBoxLayout *pvla = new QVBoxLayout(); |
| 15 | edi = new CodeEditor(); |
| 16 | QString inspatternfile=":ins_res_style.ini"; |
| 17 | edi->highlighter->loadHighlightPatterns(inspatternfile); |
| 18 | QFont font; |
| 19 | font.setFamily(FONTFAM); |
| 20 | font.setFixedPitch(true); |
| 21 | font.setPointSize(9); |
| 22 | edi->setFont(font); |
| 23 | edi->setLineWrapMode(QPlainTextEdit::NoWrap); |
| 24 | QFile p(fileName); |
| 25 | p.open(QIODevice::ReadOnly|QIODevice::Text); |
| 26 | edi->setPlainText(p.readAll()); |
| 27 | p.close(); |
| 28 | edi->setReadOnly(false); |
| 29 | |
| 30 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel); |
| 31 | ok = buttonBox->button(QDialogButtonBox::Save); |
| 32 | |
| 33 | ok->setDisabled(false); |
| 34 | connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); |
| 35 | connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); |
| 36 | QVBoxLayout *lo = new QVBoxLayout(); |
| 37 | lo->addWidget(edi); |
| 38 | lo->addWidget(buttonBox); |
| 39 | setLayout(lo); |
| 40 | //this->setWindowState(Qt::WindowMaximized); |
| 41 | } |
| 42 | |
| 43 | void IncludeEditor::accept(){ |
| 44 | QFile f(fileName); |
| 45 | bool success = f.open(QIODevice::WriteOnly|QIODevice::Text); |
| 46 | if (success){ |
| 47 | f.write(edi->toPlainText().toLatin1()); |
| 48 | f.close(); |
| 49 | }else{ |
| 50 | QMessageBox::information(0,"information",QString("Can't write %1.").arg(fileName)); |
| 51 | f.close();// I don't know if this required bit I think it doesn't hurt. |
| 52 | |
| 53 | } |
| 54 | |
| 55 | done(QDialog::Accepted ); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | void IncludeEditor::setDirName(const QString &_dir){ |
| 60 | dirName=_dir; |
| 61 | } |