26 #if defined (HAVE_CONFIG_H)
34 #include <QPushButton>
35 #include <QStringList>
47 #include "builtin-defun-decls.h"
65 make_qstring_list (
const std::list<std::string>& lst)
69 for (
const auto& s : lst)
85 for (
const auto& ext_name : lst)
92 name.replace (QRegExp (R
"(\(.*\))"), "");
93 ext.replace (
";",
" ");
98 name = ext.toUpper () +
" Files";
108 : interpreter_events (), m_octave_qobj (oct_qobj),
109 m_uiwidget_creator (oct_qobj), m_result (), m_mutex (),
112 qRegisterMetaType<QIntList> (
"QIntList");
113 qRegisterMetaType<QFloatList> (
"QFloatList");
115 qRegisterMetaType<octave_value> (
"octave_value");
116 qRegisterMetaType<symbol_info_list> (
"symbol_info_list");
118 qRegisterMetaType<fcn_callback> (
"fcn_callback");
119 qRegisterMetaType<meth_callback> (
"meth_callback");
121 connect (
this, SIGNAL (confirm_shutdown_signal (
void)),
122 this, SLOT (confirm_shutdown_octave (
void)));
124 connect (
this, SIGNAL (get_named_icon_signal (
const QString&)),
125 this, SLOT (get_named_icon_slot (
const QString&)));
128 SIGNAL (gui_preference_signal (
const QString&,
const QString&)),
130 SLOT (gui_preference_slot (
const QString&,
const QString&)));
133 std::list<std::string>
134 qt_interpreter_events::file_dialog (
const filter_list&
filter,
135 const std::string& title,
136 const std::string& filename,
138 const std::string& multimode)
141 = m_uiwidget_creator.file_dialog (make_filter_list (
filter),
147 std::list<std::string>
retval;
149 for (
const auto& s : lst)
150 retval.push_back (s.toStdString ());
155 std::list<std::string>
156 qt_interpreter_events::input_dialog (
const std::list<std::string>& prompt,
157 const std::string& title,
158 const std::list<float>& nr,
159 const std::list<float>& nc,
160 const std::list<std::string>& defaults)
163 = m_uiwidget_creator.input_dialog (make_qstring_list (prompt),
165 std_list_to_qt_list<float> (nr),
166 std_list_to_qt_list<float> (nc),
167 make_qstring_list (defaults));
168 std::list<std::string>
retval;
170 for (
const auto& s : lst)
171 retval.push_back (s.toStdString ());
176 std::pair<std::list<int>,
int>
177 qt_interpreter_events::list_dialog (
const std::list<std::string>& list,
178 const std::string& mode,
179 int width,
int height,
180 const std::list<int>& initial,
181 const std::string&
name,
182 const std::list<std::string>& prompt,
183 const std::string& ok_string,
184 const std::string& cancel_string)
186 QPair<QIntList, int> result
187 = m_uiwidget_creator.list_dialog (make_qstring_list (list),
190 std_list_to_qt_list<int> (initial),
192 make_qstring_list (prompt),
197 return std::pair<std::list<int>,
int> (std::list<int> (lst.begin (),
203 qt_interpreter_events::question_dialog (
const std::string& msg,
204 const std::string& title,
205 const std::string& btn1,
206 const std::string& btn2,
207 const std::string& btn3,
208 const std::string& btndef)
210 QString icon =
"quest";
215 role <<
"ResetRole" <<
"ResetRole" <<
"ResetRole";
231 return answer.toStdString ();
234 void qt_interpreter_events::update_path_dialog (
void)
236 emit update_path_dialog_signal ();
239 void qt_interpreter_events::show_preferences (
void)
241 emit show_preferences_signal ();
244 void qt_interpreter_events::apply_preferences (
void)
246 emit apply_new_settings ();
249 void qt_interpreter_events::show_doc (
const std::string& file)
254 bool qt_interpreter_events::edit_file (
const std::string& file)
261 void qt_interpreter_events::edit_variable (
const std::string& expr,
267 bool qt_interpreter_events::confirm_shutdown (
void)
269 QMutexLocker autolock (&m_mutex);
271 emit confirm_shutdown_signal ();
276 return m_result.toBool ();
279 bool qt_interpreter_events::prompt_new_edit_file (
const std::string& file)
281 resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
282 gui_settings *settings = rmgr.get_settings ();
291 role <<
"YesRole" <<
"RejectRole";
292 btn << tr (
"Create") << tr (
"Cancel");
294 QString answer = m_uiwidget_creator.message_dialog
295 (tr (
"File\n%1\ndoes not exist. Do you want to create it?").
297 tr (
"Octave Editor"),
"quest", btn, tr (
"Create"), role);
299 return (answer == tr (
"Create"));
306 qt_interpreter_events::debug_cd_or_addpath_error (
const std::string& file,
307 const std::string& dir,
316 ? tr (
"The file %1 does not exist in the load path. To run or debug the function you are editing, you must either change to the directory %2 or add that directory to the load path.").arg (qfile).arg (qdir)
317 : tr (
"The file %1 is shadowed by a file with the same name in the load path. To run or debug the function you are editing, change to the directory %2.").arg (qfile).arg (qdir));
319 QString title = tr (
"Change Directory or Add Directory to Load Path");
321 QString cd_txt = tr (
"&Change Directory");
322 QString addpath_txt = tr (
"&Add Directory to Load Path");
323 QString cancel_txt = tr (
"Cancel");
332 role <<
"AcceptRole";
335 role <<
"RejectRole";
338 = m_uiwidget_creator.message_dialog (msg, title,
"quest", btn,
341 if (result == cd_txt)
343 else if (result == addpath_txt)
349 uint8NDArray qt_interpreter_events::get_named_icon (
const std::string&
name)
351 QMutexLocker autolock (&m_mutex);
360 QIcon icon = m_result.value<QIcon> ();
365 QImage img = icon.pixmap (QSize (32, 32)).toImage ();
367 if (img.format () != QImage::Format_ARGB32_Premultiplied)
370 dim_vector dims (img.height (), img.width (), 4);
374 uint8_t *bits = img.bits ();
376 for (
int i = 0; i < img.height (); i++)
378 for (
int j = 0; j < img.width (); j++)
392 void qt_interpreter_events::get_named_icon_slot (
const QString&
name)
394 QMutexLocker autolock (&m_mutex);
396 resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
397 m_result = QVariant::fromValue (rmgr.icon (
name));
403 qt_interpreter_events::gui_preference (
const std::string& key,
404 const std::string& value)
408 QMutexLocker autolock (&m_mutex);
417 QString pref = m_result.toString ();
419 return pref.toStdString ();
422 bool qt_interpreter_events::copy_image_to_clipboard (
const std::string& file)
429 void qt_interpreter_events::focus_window (
const std::string win_name)
434 void qt_interpreter_events::execute_command_in_terminal
435 (
const std::string& command)
440 void qt_interpreter_events::register_doc (
const std::string& file)
445 void qt_interpreter_events::unregister_doc (
const std::string& file)
450 void qt_interpreter_events::directory_changed (
const std::string& dir)
455 void qt_interpreter_events::file_remove (
const std::string& old_name,
456 const std::string& new_name)
458 QMutexLocker autolock (&m_mutex);
468 void qt_interpreter_events::file_renamed (
bool load_new)
470 emit file_renamed_signal (load_new);
473 void qt_interpreter_events::set_workspace (
bool top_level,
bool debug,
474 const symbol_info_list& syminfo,
475 bool update_variable_editor)
477 if (! top_level && !
debug)
480 emit set_workspace_signal (top_level,
debug, syminfo);
482 if (update_variable_editor)
483 emit refresh_variable_editor_signal ();
486 void qt_interpreter_events::clear_workspace (
void)
488 emit clear_workspace_signal ();
491 void qt_interpreter_events::set_history (
const string_vector& hist)
498 emit set_history_signal (qt_hist);
501 void qt_interpreter_events::append_history (
const std::string& hist_entry)
506 void qt_interpreter_events::clear_history (
void)
508 emit clear_history_signal ();
511 void qt_interpreter_events::pre_input_event (
void)
514 void qt_interpreter_events::post_input_event (
void)
517 void qt_interpreter_events::enter_debugger_event (
const std::string& ,
518 const std::string& fcn_file_name,
521 if (fcn_file_name.empty ())
524 insert_debugger_pointer (fcn_file_name,
line);
526 emit enter_debugger_signal ();
530 qt_interpreter_events::execute_in_debugger_event (
const std::string& file,
533 delete_debugger_pointer (file,
line);
536 void qt_interpreter_events::exit_debugger_event (
void)
538 emit exit_debugger_signal ();
543 void qt_interpreter_events::update_breakpoint (
bool insert,
544 const std::string& file,
546 const std::string& cond)
553 qt_interpreter_events::insert_debugger_pointer (
const std::string& file,
560 qt_interpreter_events::delete_debugger_pointer (
const std::string& file,
567 qt_interpreter_events::confirm_shutdown_octave (
void)
569 QMutexLocker autolock (&m_mutex);
571 m_result = m_octave_qobj.confirm_shutdown ();
586 qt_interpreter_events::gui_preference_slot (
const QString& key,
587 const QString& value)
589 QMutexLocker autolock (&m_mutex);
591 resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
592 gui_settings *settings = rmgr.get_settings ();
594 QString read_value = settings->value (key).toString ();
597 QString adjusted_value = gui_preference_adjust (key, value);
599 if (! adjusted_value.isEmpty () && (read_value != adjusted_value))
602 settings->setValue (key, QVariant (adjusted_value));
604 emit settings_changed (settings,
true);
607 m_result = read_value;
613 qt_interpreter_events::gui_preference_adjust (
const QString& key,
614 const QString& value)
618 if (value.isEmpty ())
621 QString adjusted_value = value;
628 adjusted_value = adjusted_value.toUpper ();
631 resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
632 rmgr.get_codecs (&codecs);
634 QRegExp re (
"^CP(\\d+)$");
636 if (adjusted_value ==
"SYSTEM")
638 QString (
"SYSTEM (") +
641 else if (re.indexIn (adjusted_value) > -1)
643 if (codecs.contains (
"IBM" + re.cap (1)))
644 adjusted_value =
"IBM" + re.cap (1);
645 else if (codecs.contains (
"WINDOWS-" + re.cap (1)))
646 adjusted_value =
"WINDOWS-" + re.cap (1);
648 adjusted_value.clear ();
650 else if (! codecs.contains (adjusted_value))
651 adjusted_value.clear ();
654 return adjusted_value;
Vector representing the dimensions (size) of an Array.
std::list< std::pair< std::string, std::string > > filter_list
qt_interpreter_events(base_qobject &oct_qobj)
octave_idx_type numel(void) const
MArray< T > filter(MArray< T > &b, MArray< T > &a, MArray< T > &x, MArray< T > &si, int dim=0)
const gui_pref ed_create_new_file("editor/create_new_file", QVariant(false))
const gui_pref ed_default_enc("editor/default_encoding", QVariant(QString("SYSTEM (")+QString(octave_locale_charset_wrapper()).toUpper()+QString(")")))
const char * octave_locale_charset_wrapper(void)
QString fromStdString(const std::string &s)
std::string dirname(const std::string &path)
std::function< void(octave::interpreter &)> meth_callback
std::function< void(void)> fcn_callback
static string_vector make_absolute(const string_vector &sv)
octave_value::octave_value(const Array< char > &chm, char type) return retval