changeset 13410:12697e9bb608

Files can be edited and saved.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Tue, 12 Apr 2011 12:48:55 +0200
parents 1e76b221bc4a
children 9969324c53c3
files gui//src/FileEditorMdiSubWindow.cpp gui//src/FileEditorMdiSubWindow.h
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/gui//src/FileEditorMdiSubWindow.cpp	Tue Apr 12 12:33:18 2011 +0200
+++ b/gui//src/FileEditorMdiSubWindow.cpp	Tue Apr 12 12:48:55 2011 +0200
@@ -2,6 +2,7 @@
 #include <QVBoxLayout>
 #include <QApplication>
 #include <QFile>
+#include <QFileDialog>
 
 FileEditorMdiSubWindow::FileEditorMdiSubWindow(QWidget *parent)
     : QMdiSubWindow(parent) {
@@ -9,6 +10,7 @@
 }
 
 void FileEditorMdiSubWindow::loadFile(QString fileName) {
+    m_fileName = fileName;
     setWindowTitle(fileName);
     QFile file(fileName);
     file.open(QFile::ReadOnly);
@@ -18,6 +20,14 @@
     file.close();
 }
 
+void FileEditorMdiSubWindow::saveFile() {
+    QString saveFileName = QFileDialog::getSaveFileName(this, "Save File", m_fileName);
+    QFile file(saveFileName);
+    file.open(QFile::WriteOnly);
+    file.write(m_codeEdit->toPlainText().toLocal8Bit());
+    file.close();
+}
+
 void FileEditorMdiSubWindow::construct() {
     QStyle *style = QApplication::style();
     setWidget(new QWidget());
@@ -50,4 +60,5 @@
 
     connect(undoAction, SIGNAL(triggered()), m_codeEdit, SLOT(undo()));
     connect(redoAction, SIGNAL(triggered()), m_codeEdit, SLOT(redo()));
+    connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));
 }
--- a/gui//src/FileEditorMdiSubWindow.h	Tue Apr 12 12:33:18 2011 +0200
+++ b/gui//src/FileEditorMdiSubWindow.h	Tue Apr 12 12:48:55 2011 +0200
@@ -7,15 +7,20 @@
 #include "CodeEdit.h"
 
 class FileEditorMdiSubWindow : public QMdiSubWindow {
+    Q_OBJECT
 public:
     FileEditorMdiSubWindow(QWidget *parent = 0);
     void loadFile(QString fileName);
 
+public slots:
+    void saveFile();
+
 private:
     void construct();
     QToolBar *m_toolBar;
     CodeEdit *m_codeEdit;
     QStatusBar *m_statusBar;
+    QString m_fileName;
 };
 
 #endif // FILEEDITORMDISUBWINDOW_H