Mercurial > hg > octave-lyh
changeset 16420:81ec95768520
use octave-link instead of hook for edit function
* octave-main-thread.cc (edit_hook_fcn): Delete.
(octave_main_thread::run): Don't install callback function for edit
function.
* octave-qt-link.h, octave-qt-link.cc (octave_qt_link::do_edit_file):
Pass file as string instead of octave_value_list. Return status.
* interpfcn/octave-link.h, interpfcn/octave-link.cc: Move here from
interp-core directory.
* libinterp/interp-core/module.mk, libinterp/interpfcn/module.mk:
Update file lists.
* octave-link.h: Don't include oct-obj.h.
(octave_link::edit_file, octave_link::do_edit_file): Return bool.
* octave-link.cc (F__octave_link_edit_file__): New function.
* edit.m: Call __octave_link_edit_file__ instead of
__execute_edit_hook__.
* __execute_edit_hook__.cc: Delete
* libinterp/corefcn/module.mk (COREFCN_SRC): Remove it from the list.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 03 Apr 2013 23:16:37 -0400 |
parents | 16bfbf9136d3 |
children | 40d1ddca4db5 |
files | libgui/src/octave-main-thread.cc libgui/src/octave-qt-link.cc libgui/src/octave-qt-link.h libinterp/corefcn/__execute_edit_hook__.cc libinterp/corefcn/module.mk libinterp/interp-core/module.mk libinterp/interp-core/octave-link.cc libinterp/interp-core/octave-link.h libinterp/interpfcn/module.mk libinterp/interpfcn/octave-link.cc libinterp/interpfcn/octave-link.h scripts/miscellaneous/edit.m |
diffstat | 10 files changed, 42 insertions(+), 188 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/octave-main-thread.cc +++ b/libgui/src/octave-main-thread.cc @@ -35,16 +35,6 @@ #include "octave-main-thread.h" #include "octave-link.h" -static octave_value_list -edit_hook_fcn (const octave_value_list& args, int) -{ - octave_value_list retval; - - octave_link::edit_file (args); - - return retval; -} - octave_main_thread::octave_main_thread () : QThread () { } @@ -60,10 +50,6 @@ octave_initialize_interpreter (octave_cmdline_argc, octave_cmdline_argv, octave_embedded); - octave_value edit_fcn (new octave_builtin (edit_hook_fcn)); - octave_value edit_fcn_handle (new octave_fcn_handle (edit_fcn)); - Fadd_edit_hook (edit_fcn_handle); - // Prime the history list. octave_link::update_history ();
--- a/libgui/src/octave-qt-link.cc +++ b/libgui/src/octave-qt-link.cc @@ -122,25 +122,19 @@ } } -void -octave_qt_link::do_edit_file (const octave_value_list& args) +bool +octave_qt_link::do_edit_file (const std::string& file) { + bool retval = false; + if (event_listener) { - if (args.length () == 1) - { - std::string file = args(0).string_value (); + event_listener->edit_file (file); - if (! error_state) - { - event_listener->edit_file (file); - do_process_events (); + do_process_events (); - } - else - ::error ("expecting file name in edit file callback"); - } - else - ::error ("invalid call to edit file callback"); + retval = true; } + + return retval; }
--- a/libgui/src/octave-qt-link.h +++ b/libgui/src/octave-qt-link.h @@ -68,7 +68,7 @@ void do_update_breakpoint (bool insert, const std::string& file, int line); - void do_edit_file (const octave_value_list& args); + bool do_edit_file (const std::string& file); private:
deleted file mode 100644 --- a/libinterp/corefcn/__execute_edit_hook__.cc +++ /dev/null @@ -1,143 +0,0 @@ -/* - -Copyright (C) 2013 John W. Eaton - -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 -<http://www.gnu.org/licenses/>. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "defun.h" -#include "error.h" -#include "defun.h" -#include "hook-fcn.h" -#include "oct-obj.h" - -static hook_function_list edit_hook_functions; - -DEFUN (add_edit_hook, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {@var{id} =} add_edit_hook (@var{fcn})\n\ -@deftypefnx {Built-in Function} {@var{id} =} add_edit_hook (@var{fcn}, @var{data})\n\ -Add the named function or function handle @var{fcn} to the list of functions to call\n\ -to handle editing files. The function should have the form\n\ -\n\ -@example\n\ -@var{fcn} (@var{file}, @var{data})\n\ -@end example\n\ -\n\ -If @var{data} is omitted, Octave calls the function without one argument.\n\ -\n\ -The returned identifier may be used to remove the function handle from\n\ -the list of input hook functions.\n\ -@seealso{remove_edit_hook}\n\ -@end deftypefn") -{ - octave_value retval; - - int nargin = args.length (); - - if (nargin == 1 || nargin == 2) - { - octave_value user_data; - - if (nargin == 2) - user_data = args(1); - - hook_function hook_fcn (args(0), user_data); - - if (! error_state) - { - edit_hook_functions.insert (hook_fcn.id (), hook_fcn); - - retval = hook_fcn.id (); - } - else - error ("add_edit_hook: expecting string as first arg"); - } - else - print_usage (); - - return retval; -} - -DEFUN (remove_edit_hook, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} remove_edit_hook (@var{name})\n\ -@deftypefnx {Built-in Function} {} remove_input_event_hook (@var{fcn_id})\n\ -Remove the named function or function handle with the given identifier\n\ -from the list of functions to call to handle editing files.\n\ -@seealso{add_edit_hook}\n\ -@end deftypefn") -{ - octave_value_list retval; - - int nargin = args.length (); - - if (nargin == 1 || nargin == 2) - { - std::string hook_fcn_id = args(0).string_value (); - - bool warn = (nargin < 2); - - if (! error_state) - { - hook_function_list::iterator p - = edit_hook_functions.find (hook_fcn_id); - - if (p != edit_hook_functions.end ()) - edit_hook_functions.erase (p); - else if (warn) - warning ("remove_edit_hook: %s not found in list", - hook_fcn_id.c_str ()); - } - else - error ("remove_edit_hook: argument not valid as a hook function name or id"); - } - else - print_usage (); - - return retval; -} - -DEFUN (__execute_edit_hook__, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {@var{status} =} __execute_edit_hook__ (@var{file})\n\ -Undocumented internal function.\n\ -@end deftypefn") -{ - octave_value retval; - - if (edit_hook_functions.empty ()) - retval = false; - else - { - edit_hook_functions.run (args); - - retval = true; - } - - return retval; -} - -/* -## No test needed for internal helper function. -%!assert (1) -*/
--- a/libinterp/corefcn/module.mk +++ b/libinterp/corefcn/module.mk @@ -27,7 +27,6 @@ COREFCN_SRC = \ corefcn/__contourc__.cc \ corefcn/__dispatch__.cc \ - corefcn/__execute_edit_hook__.cc \ corefcn/__lin_interpn__.cc \ corefcn/__pchip_deriv__.cc \ corefcn/__qp__.cc \
--- a/libinterp/interp-core/module.mk +++ b/libinterp/interp-core/module.mk @@ -36,7 +36,6 @@ interp-core/mexproto.h \ interp-core/mxarray.in.h \ interp-core/octave-event-listener.h \ - interp-core/octave-link.h \ interp-core/oct-errno.h \ interp-core/oct-fstrm.h \ interp-core/oct-hdf5.h \ @@ -92,7 +91,6 @@ interp-core/ls-oct-binary.cc \ interp-core/ls-utils.cc \ interp-core/mex.cc \ - interp-core/octave-link.cc \ interp-core/oct-fstrm.cc \ interp-core/oct-iostrm.cc \ interp-core/oct-lvalue.cc \
--- a/libinterp/interpfcn/module.mk +++ b/libinterp/interpfcn/module.mk @@ -16,6 +16,7 @@ interpfcn/load-path.h \ interpfcn/load-save.h \ interpfcn/ls-oct-ascii.h \ + interpfcn/octave-link.h \ interpfcn/oct-hist.h \ interpfcn/pager.h \ interpfcn/pr-output.h \ @@ -42,6 +43,7 @@ interpfcn/load-path.cc \ interpfcn/load-save.cc \ interpfcn/ls-oct-ascii.cc \ + interpfcn/octave-link.cc \ interpfcn/oct-hist.cc \ interpfcn/pager.cc \ interpfcn/pr-output.cc \
rename from libinterp/interp-core/octave-link.cc rename to libinterp/interpfcn/octave-link.cc --- a/libinterp/interp-core/octave-link.cc +++ b/libinterp/interpfcn/octave-link.cc @@ -27,6 +27,7 @@ #endif #include "cmd-edit.h" +#include "defun.h" #include "oct-env.h" #include "oct-mutex.h" #include "singleton-cleanup.h" @@ -144,3 +145,24 @@ { return instance != 0; } + +DEFUN (__octave_link_edit_file__, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} __octave_link_edit_file__ (@var{file})\n\ +Undocumented internal function.\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 1) + { + std::string file = args(0).string_value (); + + if (! error_state) + retval = octave_link::edit_file (file); + else + error ("expecting file name as argument"); + } + + return retval; +}
rename from libinterp/interp-core/octave-link.h rename to libinterp/interpfcn/octave-link.h --- a/libinterp/interp-core/octave-link.h +++ b/libinterp/interpfcn/octave-link.h @@ -27,13 +27,10 @@ #include <string> -class octave_mutex; - -#include "oct-obj.h" +#include "event-queue.h" +#include "octave-event-listener.h" -#include "event-queue.h" - -#include "octave-event-listener.h" +class octave_mutex; // \class OctaveLink // \brief Provides threadsafe access to octave. @@ -159,11 +156,10 @@ instance->do_update_breakpoint (insert, file, line); } - static void - edit_file (const octave_value_list& args) + static bool + edit_file (const std::string& file) { - if (instance_ok ()) - instance->do_edit_file (args); + return instance_ok () ? instance->do_edit_file (file) : false; } static void connect (octave_link *); @@ -246,7 +242,7 @@ virtual void do_update_breakpoint (bool insert, const std::string& file, int line) = 0; - virtual void do_edit_file (const octave_value_list& args) = 0; + virtual bool do_edit_file (const std::string& file) = 0; }; #endif // OCTAVELINK_H
--- a/scripts/miscellaneous/edit.m +++ b/scripts/miscellaneous/edit.m @@ -563,7 +563,7 @@ ## Give the hook function a chance. If that fails, fall back ## on running an editor with the system function. - status = __execute_edit_hook__ (file); + status = __octave_link_edit_file__ (file); if (! status) system (sprintf (undo_string_escapes (editor),