# HG changeset patch # User ttl # Date 1311364897 -7200 # Node ID 8c7390b78911770465e0a535e8b5a52d58ac19cc # Parent 8e87f3ba3bebd4cdea33a9aa315a5490b2380fa9 gui-editor: open new editor window via interface menu diff -r 8e87f3ba3beb -r 8c7390b78911 gui/src/FileEditorMdiSubWindow.cpp --- a/gui/src/FileEditorMdiSubWindow.cpp Thu Jul 21 22:06:21 2011 +0200 +++ b/gui/src/FileEditorMdiSubWindow.cpp Fri Jul 22 22:01:37 2011 +0200 @@ -52,6 +52,25 @@ } void +FileEditorMdiSubWindow::openFile () +{ + if (checkFileModified ("Open File")==QMessageBox::Cancel) + { + return; // existing file not saved and opening another file canceled by user + } + QString openFileName = + QFileDialog::getOpenFileName (this, "Open File", QDir::homePath(), SAVE_FILE_FILTER); + if (openFileName.isEmpty ()) + { + return; + } + else + { + loadFile(openFileName); + } +} + +void FileEditorMdiSubWindow::loadFile (QString fileName) { QFile file (fileName); @@ -137,7 +156,7 @@ QString saveFileName; if (fileName.isEmpty ()) { - saveFileName = QFileDialog::getSaveFileName (this, "Save File", fileName); + saveFileName = QFileDialog::getSaveFileName (this, "Save File", fileName,SAVE_FILE_FILTER); if (saveFileName.isEmpty ()) return; } @@ -178,56 +197,42 @@ if(saveFileName.isEmpty()) return; saveFile(saveFileName); -/* QFile file(saveFileName); - if (!file.open (QFile::WriteOnly)) - { - QMessageBox::warning (this, tr ("File Editor"), - tr ("Cannot write file %1:\n%2."). - arg (m_fileName).arg (file.errorString ())); - return; - } - - if(file.write(m_simpleEditor->toPlainText().toLocal8Bit()) == -1) { - QMessageBox::warning(this, - "Error Saving File", - QString("The file could not be saved: %1.").arg(file.errorString())); - } else { - m_simpleEditor->document()->setModified(false); - m_fileName = saveFileName; - setWindowTitle(m_fileName); - } - - file.close(); */ } void FileEditorMdiSubWindow::showToolTipNew () { - m_statusBar->showMessage ("Create a new file.", 2000); + m_statusBar->showMessage ("Create a new file", 2000); +} + +void +FileEditorMdiSubWindow::showToolTipOpen () +{ + m_statusBar->showMessage ("Open a file", 2000); } void FileEditorMdiSubWindow::showToolTipSave () { - m_statusBar->showMessage ("Save the file.", 2000); + m_statusBar->showMessage ("Save the file", 2000); } void FileEditorMdiSubWindow::showToolTipSaveAs () { - m_statusBar->showMessage ("Save the file as.", 2000); + m_statusBar->showMessage ("Save the file as", 2000); } void FileEditorMdiSubWindow::showToolTipUndo () { - m_statusBar->showMessage ("Revert previous changes.", 2000); + m_statusBar->showMessage ("Revert previous changes", 2000); } void FileEditorMdiSubWindow::showToolTipRedo () { - m_statusBar->showMessage ("Append previous changes.", 2000); + m_statusBar->showMessage ("Append previous changes", 2000); } void @@ -269,6 +274,8 @@ QAction *newAction = new QAction (style->standardIcon (QStyle::SP_FileIcon), "", m_toolBar); + QAction *openAction = new QAction (style->standardIcon (QStyle::SP_DirOpenIcon), + "", m_toolBar); QAction *saveAction = new QAction (style->standardIcon (QStyle::SP_DriveHDIcon), "", m_toolBar); @@ -283,6 +290,7 @@ "", m_toolBar); m_toolBar->addAction (newAction); + m_toolBar->addAction (openAction); m_toolBar->addAction (saveAction); m_toolBar->addAction (saveActionAs); m_toolBar->addAction (undoAction); @@ -296,12 +304,14 @@ widget ()->setLayout (layout); connect (newAction, SIGNAL (triggered ()), this, SLOT (newFile ())); + connect (openAction, SIGNAL (triggered ()), this, SLOT (openFile ())); connect (undoAction, SIGNAL (triggered ()), m_editor, SLOT (undo ())); connect (redoAction, SIGNAL (triggered ()), m_editor, SLOT (redo ())); connect (saveAction, SIGNAL (triggered ()), this, SLOT (saveFile ())); connect (saveActionAs, SIGNAL (triggered ()), this, SLOT (saveFileAs ())); connect (newAction, SIGNAL (hovered ()), this, SLOT (showToolTipNew ())); + connect (openAction, SIGNAL (hovered ()), this, SLOT (showToolTipOpen ())); connect (undoAction, SIGNAL (hovered ()), this, SLOT (showToolTipUndo ())); connect (redoAction, SIGNAL (hovered ()), this, SLOT (showToolTipRedo ())); connect (saveAction, SIGNAL (hovered ()), this, SLOT (showToolTipSave ())); diff -r 8e87f3ba3beb -r 8c7390b78911 gui/src/FileEditorMdiSubWindow.h --- a/gui/src/FileEditorMdiSubWindow.h Thu Jul 21 22:06:21 2011 +0200 +++ b/gui/src/FileEditorMdiSubWindow.h Fri Jul 22 22:01:37 2011 +0200 @@ -41,11 +41,13 @@ public slots: void newFile (); + void openFile (); void saveFile (); void saveFile (QString fileName); void saveFileAs (); void showToolTipNew (); + void showToolTipOpen (); void showToolTipSave (); void showToolTipSaveAs (); void showToolTipUndo (); diff -r 8e87f3ba3beb -r 8c7390b78911 gui/src/MainWindow.cpp --- a/gui/src/MainWindow.cpp Thu Jul 21 22:06:21 2011 +0200 +++ b/gui/src/MainWindow.cpp Fri Jul 22 22:01:37 2011 +0200 @@ -58,8 +58,7 @@ } else { - FileEditorMdiSubWindow *subWindow = - new FileEditorMdiSubWindow (m_centralMdiArea); + FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow (m_centralMdiArea); subWindow->setAttribute (Qt::WA_DeleteOnClose); subWindow->loadFile (fileName); } @@ -126,6 +125,14 @@ } void +MainWindow::openEditor () +{ + FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow (m_centralMdiArea); + subWindow->setAttribute (Qt::WA_DeleteOnClose); + subWindow->newFile (); +} + +void MainWindow::openBugTrackerPage () { QDesktopServices:: @@ -229,6 +236,8 @@ QMenu *interfaceMenu = menuBar ()->addMenu (tr ("Interface")); QAction *alignWindowsAction = interfaceMenu->addAction (tr ("Align Windows")); + QAction *openEditorAction = + interfaceMenu->addAction (tr ("Open New Editor Window")); QMenu *workspaceMenu = menuBar ()->addMenu (tr ("Workspace")); QAction *loadWorkspaceAction = workspaceMenu->addAction (tr ("Load")); @@ -244,6 +253,8 @@ connect (exitAction, SIGNAL (triggered ()), this, SLOT (close ())); connect (alignWindowsAction, SIGNAL (triggered ()), this, SLOT (alignMdiWindows ())); + connect (openEditorAction, SIGNAL (triggered ()), this, + SLOT (openEditor ())); connect (reportBugAction, SIGNAL (triggered ()), this, SLOT (openBugTrackerPage ())); diff -r 8e87f3ba3beb -r 8c7390b78911 gui/src/MainWindow.h --- a/gui/src/MainWindow.h Thu Jul 21 22:06:21 2011 +0200 +++ b/gui/src/MainWindow.h Fri Jul 22 22:01:37 2011 +0200 @@ -77,6 +77,7 @@ void handleClearWorkspaceRequest (); void handleCommandDoubleClicked (QString command); void alignMdiWindows (); + void openEditor (); void openBugTrackerPage (); void processSettingsDialogRequest ();