26 #if defined (HAVE_CONFIG_H)
30 #include "builtin-defun-decls.h"
54 : m_interpreter (interp), instance (nullptr),
55 event_queue_mutex (new
mutex ()), gui_event_queue (),
56 debugging (false), link_enabled (false)
88 warning (
"event_manager: must have connected link to enable");
132 DEFMETHOD (__event_manager_enabled__, interp, , ,
143 DEFMETHOD (__event_manager_edit_file__, interp, args, ,
153 if (args.length () == 1)
156 = args(0).xstring_value (
"first argument must be filename");
162 else if (args.length () == 2)
165 = args(0).xstring_value (
"first argument must be filename");
175 DEFMETHOD (__event_manager_question_dialog__, interp, args, ,
183 if (args.length () == 6)
185 std::string msg = args(0).xstring_value (
"invalid arguments");
186 std::string title = args(1).xstring_value (
"invalid arguments");
187 std::string btn1 = args(2).xstring_value (
"invalid arguments");
188 std::string btn2 = args(3).xstring_value (
"invalid arguments");
189 std::string btn3 = args(4).xstring_value (
"invalid arguments");
190 std::string btndef = args(5).xstring_value (
"invalid arguments");
202 DEFMETHOD (__event_manager_file_dialog__, interp, args, ,
208 if (args.length () != 6)
214 std::string title = args(1).string_value ();
215 std::string filename = args(2).string_value ();
216 Matrix pos = args(3).matrix_value ();
217 std::string multi_on = args(4).string_value ();
218 std::string pathname = args(5).string_value ();
225 filter_lst.push_back (std::make_pair (flist(i,0),
227 ? flist(i,1) :
"")));
233 std::list<std::string> items_lst
234 = evmgr.
file_dialog (filter_lst, title, filename, pathname, multi_on);
236 nel = items_lst.size ();
241 if (items_lst.front ().empty ())
246 for (
auto& str : items_lst)
251 retval(idx++) = atoi (str.c_str ());
261 auto it = items_lst.begin ();
263 for (
int idx = 0; idx < nel; idx++, it++)
264 items.
xelem (idx) = *it;
266 retval =
ovl (items, *it++, atoi (it->c_str ()));
272 DEFMETHOD (__event_manager_list_dialog__, interp, args, ,
278 if (args.length () != 8)
281 Cell list = args(0).cell_value ();
284 std::list<std::string> list_lst;
286 list_lst.push_back (tlist(i));
288 std::string mode = args(1).string_value ();
290 Matrix size_matrix = args(2).matrix_value ();
291 int width = size_matrix(0);
292 int height = size_matrix(1);
294 Matrix initial_matrix = args(3).matrix_value ();
295 nel = initial_matrix.
numel ();
296 std::list<int> initial_lst;
298 initial_lst.push_back (initial_matrix(i));
300 std::string
name = args(4).string_value ();
301 list = args(5).cell_value ();
303 nel = plist.
numel ();
304 std::list<std::string> prompt_lst;
306 prompt_lst.push_back (plist(i));
307 std::string ok_string = args(6).string_value ();
308 std::string cancel_string = args(7).string_value ();
314 std::pair<std::list<int>,
int> result
315 = evmgr.
list_dialog (list_lst, mode, width, height, initial_lst,
316 name, prompt_lst, ok_string, cancel_string);
318 std::list<int> items_lst = result.first;
319 nel = items_lst.size ();
322 for (
const auto& int_el : items_lst)
323 items.
xelem(i++) = int_el;
325 return ovl (items, result.second);
328 DEFMETHOD (__event_manager_input_dialog__, interp, args, ,
334 if (args.length () != 4)
337 Cell prompt = args(0).cell_value ();
340 std::list<std::string> prompt_lst;
342 prompt_lst.push_back (tmp(i));
344 std::string title = args(1).string_value ();
346 Matrix rc = args(2).matrix_value ();
352 nr.push_back (rc(i,0));
353 nc.push_back (rc(i,1));
356 Cell defaults = args(3).cell_value ();
359 std::list<std::string> defaults_lst;
361 defaults_lst.push_back (tmp(i));
367 std::list<std::string> items_lst
368 = evmgr.
input_dialog (prompt_lst, title, nr, nc, defaults_lst);
370 nel = items_lst.size ();
373 for (
const auto& str_el : items_lst)
374 items.
xelem(i++) = str_el;
380 DEFMETHOD (__event_manager_named_icon__, interp, args, ,
388 if (args.length () > 0)
390 std::string icon_name = args(0).xstring_value (
"invalid arguments");
400 DEFMETHOD (__event_manager_show_preferences__, interp, , ,
411 DEFMETHOD (__event_manager_apply_preferences__, interp, , ,
422 DEFMETHOD (__event_manager_gui_preference__, interp, args, ,
429 std::string value =
"";
431 if (args.length () >= 1)
432 key = args(0).string_value();
434 error (
"__event_manager_gui_preference__: "
435 "first argument must be the preference key");
437 if (args.length () >= 2)
438 value = args(1).string_value();
450 DEFMETHOD (__event_manager_file_remove__, interp, args, ,
456 std::string old_name, new_name;
458 if (args.length () == 2)
460 old_name = args(0).string_value();
461 new_name = args(1).string_value();
464 error (
"__event_manager_file_remove__: "
465 "old and new name expected as arguments");
474 DEFMETHOD (__event_manager_file_renamed__, interp, args, ,
482 if (args.length () == 1)
483 load_new = args(0).bool_value();
485 error (
"__event_manager_file_renamed__: "
486 "first argument must be boolean for reload new named file");
501 if (args.length () != 1)
504 if (! args(0).is_string ())
505 error (
"openvar: NAME must be a string");
507 std::string
name = args(0).string_value ();
510 warning (
"openvar: GUI is not running, can't start Variable Editor");
516 error (
"openvar: '%s' is not a variable",
name.c_str ());
532 DEFMETHOD (__event_manager_show_doc__, interp, args, ,
540 if (args.length () >= 1)
541 file = args(0).string_value();
548 DEFMETHOD (__event_manager_register_doc__, interp, args, ,
556 if (args.length () >= 1)
557 file = args(0).string_value();
564 DEFMETHOD (__event_manager_unregister_doc__, interp, args, ,
572 if (args.length () >= 1)
573 file = args(0).string_value();
580 DEFMETHOD (__event_manager_copy_image_to_clipboard__, interp, args, ,
588 if (args.length () >= 1)
589 file = args(0).string_value();
596 DEFMETHOD (commandhistory, interp, args, ,
603 if (args.length () != 0)
611 DEFMETHOD (commandwindow, interp, args, ,
618 if (args.length () != 0)
633 if (args.length () != 0)
648 if (args.length () != 0)
octave_idx_type columns(void) const
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type rows(void) const
Array< std::string > cellstr_value(void) const
Vector representing the dimensions (size) of an Array.
static bool is_gui_running(void)
static void add_event_hook(event_hook_fcn f)
Provides threadsafe access to octave.
void file_renamed(bool load_new)
std::string gui_preference(const std::string &key, const std::string &value)
std::list< std::pair< std::string, std::string > > filter_list
octave::event_queue gui_event_queue
bool copy_image_to_clipboard(const std::string &file)
bool show_doc(const std::string &file)
std::list< std::string > file_dialog(const filter_list &filter, const std::string &title, const std::string &filename, const std::string &dirname, const std::string &multimode)
bool unregister_doc(const std::string &file)
uint8NDArray get_named_icon(const std::string &icon_name)
event_manager(interpreter &interp)
void discard_events(void)
virtual void focus_window(const std::string win_name)
bool edit_variable(const std::string &name, const octave_value &val)
bool show_preferences(void)
bool register_doc(const std::string &file)
bool prompt_new_edit_file(const std::string &file)
bool apply_preferences(void)
void file_remove(const std::string &old_name, const std::string &new_name)
std::pair< std::list< int >, int > list_dialog(const std::list< std::string > &list, const std::string &mode, int width, int height, const std::list< int > &initial_value, const std::string &name, const std::list< std::string > &prompt, const std::string &ok_string, const std::string &cancel_string)
virtual ~event_manager(void)
std::string question_dialog(const std::string &msg, const std::string &title, const std::string &btn1, const std::string &btn2, const std::string &btn3, const std::string &btndef)
interpreter & m_interpreter
void connect_link(const std::shared_ptr< interpreter_events > &obj)
octave::mutex * event_queue_mutex
std::list< std::string > input_dialog(const std::list< std::string > &prompt, const std::string &title, const std::list< float > &nr, const std::list< float > &nc, const std::list< std::string > &defaults)
bool edit_file(const std::string &file)
std::shared_ptr< interpreter_events > instance
void process_events(bool disable=false)
tree_evaluator & get_evaluator(void)
bool at_top_level(void) const
symbol_info_list get_symbol_info(void)
bool is_undefined(void) const
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
void warning(const char *fmt,...)
void error(const char *fmt,...)
bool is_true(const std::string &s)
event_manager & __get_event_manager__(const std::string &who)
static int readline_event_hook(void)
OCTAVE_EXPORT octave_value_list Fisguirunning(const octave_value_list &args, int)
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.