8 #include "GuiEditFile.h"
9 #include "UserInterface.h"
12 #include <QFileDialog>
14 #include <QPushButton>
17 #include <QTextStream>
19 #include <QMessageBox>
39 if (m_instance == NULL) {
43 m_instance->showWindow(psFile);
55 m_fileName = QString(psFile);
56 m_editWin->setWindowTitle (m_fileName);
72 m_fileName = QString(psFile);
76 m_editWin =
new QMainWindow(m_parent, Qt::SubWindow);
77 m_editWin->setWindowTitle (m_fileName);
78 m_editWin->resize (400, 600);
81 QStatusBar *statusBar =
new QStatusBar(m_editWin);
82 m_editWin->setStatusBar(statusBar);
85 QMenuBar *menuBar =
new QMenuBar(m_editWin);
86 QMenu *fileMenu = menuBar->addMenu(
"&File");
90 m_open->setShortcut(Qt::CTRL + Qt::Key_O);
91 m_open->setText(
"&Open...");
92 m_open->setToolTip(
"Open File");
93 QString whatsThis =
"Open a file to edit";
94 m_open->setWhatsThis(whatsThis);
95 connect(m_open, SIGNAL(triggered()),
this, SLOT(open()));
96 fileMenu->addAction(m_open);
100 m_save->setShortcut(Qt::CTRL + Qt::Key_S);
101 m_save->setText(
"&Save...");
102 m_save->setToolTip(
"Save File");
103 m_save->setWhatsThis(
"Save the current file");
104 connect(m_save, SIGNAL(triggered()),
this, SLOT(saveFile()));
105 fileMenu->addAction(m_save);
108 m_saveAs =
new QAction(menuBar);
109 m_saveAs->setText(
"Save &As...");
110 m_saveAs->setShortcut(Qt::CTRL + Qt::Key_A);
111 m_saveAs->setToolTip(
"Save As File");
112 m_saveAs->setWhatsThis(
"Save the current file into another file");
113 connect(m_saveAs, SIGNAL(triggered()),
this, SLOT(saveAs()));
114 fileMenu->addAction(m_saveAs);
117 m_close =
new QAction(menuBar);
118 m_close->setText(
"&Close...");
119 m_close->setShortcut(Qt::CTRL + Qt::Key_C);
120 m_close->setToolTip(
"Close File");
121 m_close->setWhatsThis(
"Close the current file");
122 connect(m_close, SIGNAL(triggered()),
this, SLOT(closeFile()));
123 fileMenu->addAction(m_close);
126 m_exit = menuBar->addAction(
"&Exit");
127 m_exit->setShortcut(Qt::CTRL + Qt::Key_E);
128 m_exit->setText(
"&Exit...");
129 m_exit->setToolTip(
"Exit");
130 m_exit->setWhatsThis(
"Exit the Editor");
132 connect(m_exit, SIGNAL(triggered()),
this, SLOT(closeWin()));
134 m_editWin->setMenuBar(menuBar);
137 m_textChanged =
false;
138 m_txtEdit =
new QTextEdit(m_editWin);
139 m_txtEdit->setUndoRedoEnabled(
true);
140 m_txtEdit->resize(400,500);
141 m_editWin->setCentralWidget(m_txtEdit);
142 if (m_fileName.length() > 0){
143 OpenFile(m_fileName);
145 connect(m_txtEdit, SIGNAL(textChanged()),
this, SLOT(setTextChanged()));
185 m_textChanged =
true;
197 if(QMessageBox::question((
QWidget *)parent(), tr(
"Save File?"),
198 tr(
"Are you sure you want to save this file?"),
199 tr(
"&Save"), tr(
"&Cancel"),
205 QString sFilterList(
"All files (*)");
206 QDir currDir = QDir::current();
207 QString sOpen(
"Open");
210 connect(fileDialog, SIGNAL(fileSelected(QString)),
this, SLOT(OpenFile(QString)));
220 if(QMessageBox::question((
QWidget *)parent(), tr(
"Save File?"),
221 tr(
"Changes have been made to the file. Do you want to Save?"),
222 QMessageBox::Save, QMessageBox::No) == QMessageBox::Save) {
228 m_textChanged =
false;
229 m_editWin->setWindowTitle(tr(
""));
241 if(psOutFile.isEmpty()){
242 QMessageBox::information((
QWidget *)parent(),
"Error",
"No output file selected");
246 if (m_editFile != NULL) {
250 m_editFile =
new QFile(psOutFile);
252 windowTitle(psOutFile);
254 if (m_editFile->open(QIODevice::ReadWrite)){
257 qint64 lineLength = m_editFile->readLine(buf,
sizeof(buf));
258 while (lineLength != -1) {
259 bufStr = QString(buf);
262 m_txtEdit->append(bufStr);
263 lineLength = m_editFile->readLine(buf,
sizeof(buf));
267 m_txtEdit->append(
"\nThis file cannot be edited. Please check the file's Write permissions");
269 m_textChanged =
false;
280 QTextStream out(m_editFile);
281 out << m_txtEdit->document()->toPlainText();
282 m_textChanged =
false;
292 QString sFilterList(
"All files (*)");
293 QDir currDir = QDir::current();
294 QString sOpen(
"Open");
299 allPButtons[0]->setText(
"&Save");
301 allPButtons[1]->setText(
"&Close");
303 saveAsDialog->show();
304 connect(saveAsDialog, SIGNAL(fileSelected(QString)),
this, SLOT(saveAsFile(QString)));
317 m_editFile =
new QFile(psNewFile);
318 m_editFile->open(QFile::ReadWrite);
320 windowTitle(psNewFile);
333 m_editFile->open(QFile::ReadWrite | QFile::Truncate);
345 m_editWin->setWindowTitle(
FileName(psfile).name());