Mercurial > hg > octave-lojdl
changeset 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 | 625be3eb27c5 |
children | 9d9eb9bac65e |
files | gui/default-settings gui/src/m-editor/file-editor-tab.cc gui/src/m-editor/file-editor-tab.h gui/src/main-window.cc gui/src/octave-adapter/octave-event.h gui/src/octave-adapter/octave-link.cc gui/src/octave-adapter/octave-link.h gui/src/octave-gui.cc gui/src/resource-manager.cc gui/src/resource-manager.h |
diffstat | 10 files changed, 193 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/gui/default-settings @@ -0,0 +1,37 @@ +[General] +connectOnStartup=true +showMessageOfTheDay=true +showTopic=true +autoIdentification=false +nickServPassword= +useCustomFileEditor=false +customFileEditor=emacs +showFilenames=true +showFileSize=false +showFileType=false +showLastModified=false +showHiddenFiles=false +useAlternatingRowColors=true +useProxyServer=false +proxyType= +proxyHostName=none +proxyPort=8080 +proxyUserName= +proxyPassword= + +[editor] +showLineNumbers=true +highlightCurrentLine=true +codeCompletion=true +fontName=Ubuntu Mono +fontSize=12 +shortWindowTitle=true +longWindowTitle=true + +[terminal] +fontSize=10 +fontName=Andale Mono + +[MainWindow] +geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\0\x31\0\0\0\x18\0\0\x4\xff\0\0\x3\xff\0\0\0\0\0\0\0\0\xff\xff\xff\xfe\xff\xff\xff\xfe\0\0\0\0\x2\0) +windowState=@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0\0\0\x1\0\0\0\x1\0\0\x4\xcf\0\0\x3\x91\xfc\x2\0\0\0\x1\xfc\0\0\0\x41\0\0\x3\x91\0\0\x1\xc7\0\xff\xff\xff\xfc\x1\0\0\0\x3\xfc\0\0\0\0\0\0\x1.\0\0\0R\0\xff\xff\xff\xfc\x2\0\0\0\x2\xfb\0\0\0\x1a\0W\0o\0r\0k\0s\0p\0\x61\0\x63\0\x65\0V\0i\0\x65\0w\x1\0\0\0\x41\0\0\x1\xe8\0\0\0k\0\xff\xff\xff\xfb\0\0\0\"\0H\0i\0s\0t\0o\0r\0y\0\x44\0o\0\x63\0k\0W\0i\0\x64\0g\0\x65\0t\x1\0\0\x2/\0\0\x1\xa3\0\0\0\x8c\0\xff\xff\xff\xfc\0\0\x1\x34\0\0\x2\x81\0\0\x2\x81\0\0\x2\x81\xfa\0\0\0\0\x2\0\0\0\x2\xfb\0\0\0$\0T\0\x65\0r\0m\0i\0n\0\x61\0l\0\x44\0o\0\x63\0k\0W\0i\0\x64\0g\0\x65\0t\x1\0\0\0\0\xff\xff\xff\xff\0\0\x1\xa9\0\xff\xff\xff\xfb\0\0\0\x14\0\x46\0i\0l\0\x65\0\x45\0\x64\0i\0t\0o\0r\x1\0\0\x1\xf0\0\0\x1\xe2\0\0\0j\0\xff\xff\xff\xfb\0\0\0\x1e\0\x46\0i\0l\0\x65\0s\0\x44\0o\0\x63\0k\0W\0i\0\x64\0g\0\x65\0t\x1\0\0\x3\xbb\0\0\x1\x14\0\0\0P\0\xff\xff\xff\0\0\0\0\0\0\x3\x91\0\0\0\x4\0\0\0\x4\0\0\0\b\0\0\0\b\xfc\0\0\0\x1\0\0\0\x2\0\0\0\x1\xff\xff\xff\xff\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0)
--- a/gui/src/m-editor/file-editor-tab.cc +++ b/gui/src/m-editor/file-editor-tab.cc @@ -17,11 +17,12 @@ #include "file-editor-tab.h" #include "file-editor.h" +#include "octave-link.h" #include <QMessageBox> #include <QVBoxLayout> file_editor_tab::file_editor_tab(file_editor *fileEditor) - : QWidget ((QWidget*)fileEditor) + : QWidget ((QWidget*)fileEditor), octave_event_observer () { QSettings *settings = resource_manager::instance ()->get_settings (); _file_editor = fileEditor; @@ -96,6 +97,26 @@ } void +file_editor_tab::event_accepted (octave_event *e) +{ + if (dynamic_cast<octave_run_file_event*> (e)) + { + // File was run successfully. + } + delete e; +} + +void +file_editor_tab::event_reject (octave_event *e) +{ + if (dynamic_cast<octave_run_file_event*> (e)) + { + // Running file failed. + } + delete e; +} + +void file_editor_tab::closeEvent (QCloseEvent *event) { if (_file_editor->get_main_window ()->is_closing ()) @@ -440,8 +461,15 @@ QFileDialog fileDialog(this); if (saveFileName == UNNAMED_FILE || saveFileName.isEmpty ()) { - saveFileName = QDir::homePath (); - fileDialog.setDirectory (saveFileName); + QString directory = QString::fromStdString + (octave_link::instance ()->get_last_working_directory ()); + + if (directory.isEmpty ()) + { + directory = QDir::homePath (); + } + + fileDialog.setDirectory (directory); } else { @@ -471,7 +499,9 @@ save_file(_file_name); _file_editor->terminal ()->sendText (QString ("run \'%1\'\n").arg (_file_name)); - _file_editor->terminal ()->setFocus (); + // TODO: Sending a run event crashes for long scripts. Find out why. + // octave_link::instance () + // ->post_event (new octave_run_file_event (*this, _file_name.toStdString ())); } void
--- a/gui/src/m-editor/file-editor-tab.h +++ b/gui/src/m-editor/file-editor-tab.h @@ -23,14 +23,19 @@ #include <QCloseEvent> #include <QFileSystemWatcher> +#include "octave-event-observer.h" + class file_editor; -class file_editor_tab : public QWidget +class file_editor_tab : public QWidget, public octave_event_observer { Q_OBJECT public: file_editor_tab (file_editor *fileEditor); bool copy_available (); + void event_accepted (octave_event *e); + void event_reject (octave_event *e); + public slots: void update_window_title(bool modified); void handle_copy_available(bool enableCopy);
--- a/gui/src/main-window.cc +++ b/gui/src/main-window.cc @@ -78,8 +78,9 @@ QString selectedFile = QFileDialog::getSaveFileName (this, tr ("Save Workspace"), resource_manager::instance ()->get_home_path ()); - _terminal->sendText (QString ("save \'%1\'\n").arg (selectedFile)); - _terminal->setFocus (); + octave_link::instance () + ->post_event (new octave_save_workspace_event (*this, + selectedFile.toStdString())); } void @@ -90,16 +91,17 @@ resource_manager::instance ()->get_home_path ()); if (!selectedFile.isEmpty ()) { - _terminal->sendText (QString ("load \'%1\'\n").arg (selectedFile)); - _terminal->setFocus (); + octave_link::instance () + ->post_event (new octave_load_workspace_event (*this, + selectedFile.toStdString())); } } void main_window::handle_clear_workspace_request () { - _terminal->sendText ("clear\n"); - _terminal->setFocus (); + octave_link::instance () + ->post_event (new octave_clear_workspace_event (*this)); } void
--- a/gui/src/octave-adapter/octave-event.h +++ b/gui/src/octave-adapter/octave-event.h @@ -20,6 +20,8 @@ #include <string> #include "octave-event-observer.h" +#include "octave/config.h" +#include "symtab.h" #include "oct-env.h" #include "pt-eval.h" #include "toplev.h" @@ -129,7 +131,30 @@ { clean_up_and_exit (0); return true; } }; -/** Implements a change directory events. */ +/** Implements an octave run file event. */ +class octave_run_file_event : public octave_event +{ + public: + /** Creates a new octave_run_file_event. */ + octave_run_file_event (octave_event_observer& o, + std::string file) + : octave_event (o) + { _file = file; } + + bool perform () + { + octave_value_list args; + args.append (octave_value (_file)); + call_octave_function ("run", args); + finish_readline_event (); + return true; + } + + private: + std::string _file; +}; + +/** Implements a change directory event. */ class octave_change_directory_event : public octave_event { public: @@ -146,6 +171,66 @@ std::string _directory; }; +/** Implements a clear workspace event. */ +class octave_clear_workspace_event : public octave_event +{ + public: + /** Creates a new octave_run_file_event. */ + octave_clear_workspace_event (octave_event_observer& o) + : octave_event (o) + { } + + bool perform () + { + call_octave_function ("clear"); + return true; + } +}; + +/** Implements a load workspace event. */ +class octave_load_workspace_event : public octave_event +{ + public: + /** Creates a new octave_change_directory_event. */ + octave_load_workspace_event (octave_event_observer& o, + std::string file) + : octave_event (o) + { _file = file; } + + bool perform () + { + octave_value_list args; + args.append (octave_value (_file)); + call_octave_function ("load", args); + return true; + } + + private: + std::string _file; +}; + +/** Implements a save workspace event. */ +class octave_save_workspace_event : public octave_event +{ + public: + /** Creates a new octave_change_directory_event. */ + octave_save_workspace_event (octave_event_observer& o, + std::string file) + : octave_event (o) + { _file = file; } + + bool perform () + { + octave_value_list args; + args.append (octave_value (_file)); + call_octave_function ("save", args); + return true; + } + + private: + std::string _file; +}; + class octave_debug_step_into_event : public octave_event { public:
--- a/gui/src/octave-adapter/octave-link.cc +++ b/gui/src/octave-adapter/octave-link.cc @@ -162,3 +162,9 @@ _performance_information_mutex->unlock (); return p; } + +std::string +octave_link::get_last_working_directory () +{ + return _last_working_directory; +}
--- a/gui/src/octave-adapter/octave-link.h +++ b/gui/src/octave-adapter/octave-link.h @@ -107,6 +107,8 @@ void finished_readline_hook (); performance_information get_performance_information (); + std::string get_last_working_directory (); + private: /** Singleton. */ octave_link ();
--- a/gui/src/octave-gui.cc +++ b/gui/src/octave-gui.cc @@ -31,42 +31,8 @@ if (resource_manager::instance ()->is_first_run ()) { welcome_wizard welcomeWizard; - int returnCode = welcomeWizard.exec (); - - QSettings *settings = resource_manager::instance ()->get_settings (); - settings->setValue ("connectOnStartup", true); - settings->setValue ("showMessageOfTheDay", true); - settings->setValue ("showTopic", true); - settings->setValue ("autoIdentification", false); - settings->setValue ("nickServPassword", ""); - settings->setValue ("useCustomFileEditor", false); - settings->setValue ("customFileEditor", "emacs"); - settings->setValue ("editor/showLineNumbers", true); - settings->setValue ("editor/highlightCurrentLine", true); - settings->setValue ("editor/codeCompletion", true); - settings->setValue ("editor/fontName", "Monospace"); - settings->setValue ("editor/fontSize", 10); - settings->setValue ("editor/shortWindowTitle", true); - settings->setValue ("showFilenames", true); - settings->setValue ("showFileSize", false); - settings->setValue ("showFileType", false); - settings->setValue ("showLastModified", false); - settings->setValue ("showHiddenFiles", false); - settings->setValue ("useAlternatingRowColors", true); - settings->setValue ("useProxyServer", false); - settings->setValue ("proxyType", "Sock5Proxy"); - settings->setValue ("proxyHostName", "none"); - settings->setValue ("proxyPort", 8080); - settings->setValue ("proxyUserName", ""); - settings->setValue ("proxyPassword", ""); - settings->sync (); + welcomeWizard.exec (); resource_manager::instance ()->reload_settings (); - - application.quit (); - // We are in an infinite loop, so everything else than a return - // will cause the application to restart from the very beginning. - if (returnCode == QDialog::Rejected) - return 0; } else { @@ -83,7 +49,6 @@ main_window w; w.show (); - //w.activateWindow(); return application.exec (); } }
--- a/gui/src/resource-manager.cc +++ b/gui/src/resource-manager.cc @@ -24,6 +24,7 @@ resource_manager::resource_manager () { _settings = 0; + _first_run = false; reload_settings (); } @@ -49,21 +50,23 @@ { QDesktopServices desktopServices; _home_path = desktopServices.storageLocation (QDesktopServices::HomeLocation); - set_settings(_home_path + "/.config/octave-gui/settings"); + QString settings_file = _home_path + "/.config/octave-gui/settings"; + + if (!QFile::exists (settings_file)) + { + QFile::copy ("../default-settings", settings_file); + _first_run = true; + } + else + _first_run = false; + + set_settings (settings_file); } void resource_manager::set_settings (QString file) { delete _settings; - - _first_run = false; - if (!QFile::exists (file)) - _first_run = true; - - // If the settings file does not exist, QSettings automatically creates it. - // Therefore we have to check if it exists before instantiating the settings object. - // That way we can detect if the user ran this application before. _settings = new QSettings (file, QSettings::IniFormat); } @@ -122,8 +125,6 @@ _icons [resource_manager::octave] = QIcon ("../media/logo.png"); _icons [resource_manager::terminal] = QIcon ("../media/terminal.png"); _icons [resource_manager::documentation] = QIcon ("../media/help_index.png"); - _icons [resource_manager::chat] = QIcon ("../media/chat.png"); - _icons [resource_manager::chat_new_message] = QIcon ("../media/jabber_protocol.png"); } const char*