comparison gui/src/m-editor/file-editor-tab.cc @ 14804:a565c560e654 gui

Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate. * default-settings: New file containing the default settings. * file-editor-tab: Subclassed event observer and added code to send a run event. * main-window: Sending workspace events instead of using the terminal. * octave-event: Added new event types. * octave-link: Added getter for the current working directory. * octave-gui: Adjusted code, so the default settings can be loaded. * resource-manager: Added code to handle the logic with a default settings file.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Tue, 26 Jun 2012 15:27:10 +0200
parents e10d7bcfdd9e
children eae0e9f2a8c6
comparison
equal deleted inserted replaced
14803:625be3eb27c5 14804:a565c560e654
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "file-editor-tab.h" 18 #include "file-editor-tab.h"
19 #include "file-editor.h" 19 #include "file-editor.h"
20 #include "octave-link.h"
20 #include <QMessageBox> 21 #include <QMessageBox>
21 #include <QVBoxLayout> 22 #include <QVBoxLayout>
22 23
23 file_editor_tab::file_editor_tab(file_editor *fileEditor) 24 file_editor_tab::file_editor_tab(file_editor *fileEditor)
24 : QWidget ((QWidget*)fileEditor) 25 : QWidget ((QWidget*)fileEditor), octave_event_observer ()
25 { 26 {
26 QSettings *settings = resource_manager::instance ()->get_settings (); 27 QSettings *settings = resource_manager::instance ()->get_settings ();
27 _file_editor = fileEditor; 28 _file_editor = fileEditor;
28 _file_name = ""; 29 _file_name = "";
29 _edit_area = new QsciScintilla (this); 30 _edit_area = new QsciScintilla (this);
91 92
92 bool 93 bool
93 file_editor_tab::copy_available () 94 file_editor_tab::copy_available ()
94 { 95 {
95 return _copy_available; 96 return _copy_available;
97 }
98
99 void
100 file_editor_tab::event_accepted (octave_event *e)
101 {
102 if (dynamic_cast<octave_run_file_event*> (e))
103 {
104 // File was run successfully.
105 }
106 delete e;
107 }
108
109 void
110 file_editor_tab::event_reject (octave_event *e)
111 {
112 if (dynamic_cast<octave_run_file_event*> (e))
113 {
114 // Running file failed.
115 }
116 delete e;
96 } 117 }
97 118
98 void 119 void
99 file_editor_tab::closeEvent (QCloseEvent *event) 120 file_editor_tab::closeEvent (QCloseEvent *event)
100 { 121 {
438 { 459 {
439 QString saveFileName(_file_name); 460 QString saveFileName(_file_name);
440 QFileDialog fileDialog(this); 461 QFileDialog fileDialog(this);
441 if (saveFileName == UNNAMED_FILE || saveFileName.isEmpty ()) 462 if (saveFileName == UNNAMED_FILE || saveFileName.isEmpty ())
442 { 463 {
443 saveFileName = QDir::homePath (); 464 QString directory = QString::fromStdString
444 fileDialog.setDirectory (saveFileName); 465 (octave_link::instance ()->get_last_working_directory ());
466
467 if (directory.isEmpty ())
468 {
469 directory = QDir::homePath ();
470 }
471
472 fileDialog.setDirectory (directory);
445 } 473 }
446 else 474 else
447 { 475 {
448 fileDialog.selectFile (saveFileName); 476 fileDialog.selectFile (saveFileName);
449 } 477 }
469 { 497 {
470 if (_edit_area->isModified ()) 498 if (_edit_area->isModified ())
471 save_file(_file_name); 499 save_file(_file_name);
472 500
473 _file_editor->terminal ()->sendText (QString ("run \'%1\'\n").arg (_file_name)); 501 _file_editor->terminal ()->sendText (QString ("run \'%1\'\n").arg (_file_name));
474 _file_editor->terminal ()->setFocus (); 502 // TODO: Sending a run event crashes for long scripts. Find out why.
503 // octave_link::instance ()
504 // ->post_event (new octave_run_file_event (*this, _file_name.toStdString ()));
475 } 505 }
476 506
477 void 507 void
478 file_editor_tab::file_has_changed (QString fileName) 508 file_editor_tab::file_has_changed (QString fileName)
479 { 509 {