# HG changeset patch # User John Donoghue # Date 1374159404 14400 # Node ID c50ee84842a972b1b07507c8a060634ced97e328 # Parent adf06e03fbdd0b7a58e6c3d8a66fec0729e0c454 Add preferences and prefdir functions * scripts/prefs/private/prefsfile.m (prefsfile): Use prefdir() instread of ~ for folder part of file. * scripts/prefs/preferences.m: New file. * scripts/prefs/prefdir.m: New file. * scripts/prefs/module.mk: Add preferences.m and prefdir.m * libinterp/corefcn/octave-link.h, libinterp/corefcn/octave-link.cc (octave_link::show_preferences): New function. (octave_link)::do_show_preferences: New fuction. (__octave_link_show_preferences__): New function. * libgui/src/octave-qt-link.h, libgui/src/octave-qt-link.cc (octave_qt_link::show_preferences_signal): New signal. (octave_qt_link::do_show_preferences): New function. * libgui/src/main-window.cc (main_window::construct_octave_qt_link): connect octave link to show settings dialog slot. diff -r adf06e03fbdd -r c50ee84842a9 libgui/src/main-window.cc --- a/libgui/src/main-window.cc Thu Jul 18 14:30:31 2013 -0400 +++ b/libgui/src/main-window.cc Thu Jul 18 10:56:44 2013 -0400 @@ -912,6 +912,10 @@ connect (_octave_qt_link, SIGNAL (exit_debugger_signal ()), this, SLOT (handle_exit_debugger ())); + connect (_octave_qt_link, + SIGNAL (show_preferences_signal (void)), + this, SLOT (process_settings_dialog_request ())); + #ifdef HAVE_QSCINTILLA connect (_octave_qt_link, SIGNAL (edit_file_signal (const QString&)), diff -r adf06e03fbdd -r c50ee84842a9 libgui/src/octave-qt-link.cc --- a/libgui/src/octave-qt-link.cc Thu Jul 18 14:30:31 2013 -0400 +++ b/libgui/src/octave-qt-link.cc Thu Jul 18 10:56:44 2013 -0400 @@ -491,3 +491,11 @@ return ok; } + +void +octave_qt_link::do_show_preferences () +{ + emit show_preferences_signal (); +} + + diff -r adf06e03fbdd -r c50ee84842a9 libgui/src/octave-qt-link.h --- a/libgui/src/octave-qt-link.h Thu Jul 18 14:30:31 2013 -0400 +++ b/libgui/src/octave-qt-link.h Thu Jul 18 10:56:44 2013 -0400 @@ -121,6 +121,7 @@ static bool file_in_path (const std::string& file, const std::string& dir); + void do_show_preferences (void); private: // No copying! @@ -166,6 +167,8 @@ void insert_debugger_pointer_signal (const QString&, int); void delete_debugger_pointer_signal (const QString&, int); + + void show_preferences_signal (void); }; #endif diff -r adf06e03fbdd -r c50ee84842a9 libinterp/corefcn/octave-link.cc --- a/libinterp/corefcn/octave-link.cc Thu Jul 18 14:30:31 2013 -0400 +++ b/libinterp/corefcn/octave-link.cc Thu Jul 18 10:56:44 2013 -0400 @@ -402,3 +402,18 @@ return retval; } + +DEFUN (__octave_link_show_preferences__, , , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} __octave_link_show_preferences__ ()\n\ +Undocumented internal function.\n\ +@end deftypefn") +{ + octave_value retval; + + retval = octave_link::show_preferences (); + + return retval; +} + + diff -r adf06e03fbdd -r c50ee84842a9 libinterp/corefcn/octave-link.h --- a/libinterp/corefcn/octave-link.h Thu Jul 18 14:30:31 2013 -0400 +++ b/libinterp/corefcn/octave-link.h Thu Jul 18 10:56:44 2013 -0400 @@ -307,6 +307,18 @@ return instance_ok () ? instance->link_enabled : false; } + static bool + show_preferences () + { + if (enabled ()) + { + instance->do_show_preferences (); + return true; + } + else + return false; + } + private: static octave_link *instance; @@ -425,6 +437,8 @@ virtual void do_set_default_prompts (std::string& ps1, std::string& ps2, std::string& ps4) = 0; + + virtual void do_show_preferences (void) = 0; }; #endif // OCTAVELINK_H diff -r adf06e03fbdd -r c50ee84842a9 scripts/prefs/module.mk --- a/scripts/prefs/module.mk Thu Jul 18 14:30:31 2013 -0400 +++ b/scripts/prefs/module.mk Thu Jul 18 10:56:44 2013 -0400 @@ -9,6 +9,8 @@ prefs/addpref.m \ prefs/getpref.m \ prefs/ispref.m \ + prefs/prefdir.m \ + prefs/preferences.m \ prefs/rmpref.m \ prefs/setpref.m \ $(prefs_PRIVATE_FCN_FILES) diff -r adf06e03fbdd -r c50ee84842a9 scripts/prefs/prefdir.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/prefs/prefdir.m Thu Jul 18 10:56:44 2013 -0400 @@ -0,0 +1,44 @@ +## Copyright (C) 2013 John Donoghue +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} prefdir +## @deftypefnx {Function File} {folder =} prefdir +## Return the folder that contains the preferences for octave. +## +## Examples: +## +## Display the preferences folder +## @example +## prefdir +## @end example +## +## Change to the preferences folder +## @example +## cd(prefdir) +## @end example +## @end deftypefn + +## Author: John Donoghue +## Version: 0.01 + +function folder = prefdir () + + folder = getenv("HOME"); + +endfunction \ No newline at end of file diff -r adf06e03fbdd -r c50ee84842a9 scripts/prefs/preferences.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/prefs/preferences.m Thu Jul 18 10:56:44 2013 -0400 @@ -0,0 +1,42 @@ +## Copyright (C) 2013 John Donoghue +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} preferences +## Display the preferences settings. If in GUI mode, display using the preferences dialog, otherwise display in EDITOR. +## +## Example: +# +## @example +## preferences +## @end example +## +## @end deftypefn + +## Author: John Donoghue +## Version: 0.01 + +function preferences () + if (! __octave_link_enabled__ ()) + prefs_file = [ getenv("HOME") "/.octave_prefs" ]; + + edit (prefs_file); + else + __octave_link_show_preferences__ (); + endif +endfunction \ No newline at end of file diff -r adf06e03fbdd -r c50ee84842a9 scripts/prefs/private/prefsfile.m --- a/scripts/prefs/private/prefsfile.m Thu Jul 18 14:30:31 2013 -0400 +++ b/scripts/prefs/private/prefsfile.m Thu Jul 18 10:56:44 2013 -0400 @@ -25,7 +25,8 @@ function retval = prefsfile () - retval = "~/.octave_prefs"; + retval = [ prefdir() "/.octave_prefs" ]; + endfunction