comparison libgui/src/qt-interpreter-events.cc @ 31648:29d734430e5f stable

maint: Re-indent code after switch to using namespace macros. * BaseControl.cc, BaseControl.h, ButtonControl.cc, ButtonControl.h, ButtonGroup.cc, ButtonGroup.h, Canvas.cc, Canvas.h, CheckBoxControl.cc, CheckBoxControl.h, Container.cc, Container.h, ContextMenu.cc, ContextMenu.h, EditControl.cc, EditControl.h, Figure.cc, Figure.h, FigureWindow.cc, FigureWindow.h, GLCanvas.cc, GLCanvas.h, GenericEventNotify.h, KeyMap.cc, KeyMap.h, ListBoxControl.cc, ListBoxControl.h, Logger.cc, Logger.h, Menu.cc, Menu.h, MenuContainer.h, Object.cc, Object.h, ObjectProxy.cc, ObjectProxy.h, Panel.cc, Panel.h, PopupMenuControl.cc, PopupMenuControl.h, PushButtonControl.cc, PushButtonControl.h, PushTool.cc, PushTool.h, QtHandlesUtils.cc, QtHandlesUtils.h, RadioButtonControl.cc, RadioButtonControl.h, SliderControl.cc, SliderControl.h, Table.cc, Table.h, TextControl.cc, TextControl.h, TextEdit.cc, TextEdit.h, ToggleButtonControl.cc, ToggleButtonControl.h, ToggleTool.cc, ToggleTool.h, ToolBar.cc, ToolBar.h, ToolBarButton.cc, ToolBarButton.h, annotation-dialog.cc, annotation-dialog.h, gl-select.cc, gl-select.h, qopengl-functions.h, qt-graphics-toolkit.cc, qt-graphics-toolkit.h, module.mk, QTerminal.h, color-picker.cc, color-picker.h, command-widget.cc, command-widget.h, community-news.cc, community-news.h, dialog.cc, dialog.h, documentation-bookmarks.cc, documentation-bookmarks.h, documentation-dock-widget.cc, documentation-dock-widget.h, documentation.cc, documentation.h, dw-main-window.cc, dw-main-window.h, external-editor-interface.cc, external-editor-interface.h, files-dock-widget.cc, files-dock-widget.h, find-files-dialog.cc, find-files-dialog.h, find-files-model.cc, find-files-model.h, graphics-init.cc, graphics-init.h, gui-settings.cc, gui-settings.h, gui-utils.cc, gui-utils.h, history-dock-widget.cc, history-dock-widget.h, interpreter-qobject.cc, interpreter-qobject.h, led-indicator.cc, led-indicator.h, file-editor-interface.h, file-editor-tab.cc, file-editor-tab.h, file-editor.cc, file-editor.h, find-dialog.cc, find-dialog.h, marker.cc, marker.h, octave-qscintilla.cc, octave-qscintilla.h, octave-txt-lexer.cc, octave-txt-lexer.h, main-window.cc, main-window.h, news-reader.cc, news-reader.h, octave-dock-widget.cc, octave-dock-widget.h, octave-qobject.cc, octave-qobject.h, qt-application.cc, qt-application.h, qt-interpreter-events.cc, qt-interpreter-events.h, qt-utils.h, release-notes.cc, release-notes.h, resource-manager.cc, resource-manager.h, set-path-dialog.cc, set-path-dialog.h, set-path-model.cc, set-path-model.h, settings-dialog.cc, settings-dialog.h, shortcut-manager.cc, shortcut-manager.h, tab-bar.cc, tab-bar.h, terminal-dock-widget.cc, terminal-dock-widget.h, variable-editor-model.cc, variable-editor-model.h, variable-editor.cc, variable-editor.h, welcome-wizard.cc, welcome-wizard.h, workspace-model.cc, workspace-model.h, workspace-view.cc, workspace-view.h: Re-indent code after switch to using namespace macros.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Dec 2022 14:53:00 -0500
parents c6d54dd31a7e
children deb553ac2c54 597f3ee61a48
comparison
equal deleted inserted replaced
31646:c6d54dd31a7e 31648:29d734430e5f
62 Q_DECLARE_METATYPE (octave::fcn_callback) 62 Q_DECLARE_METATYPE (octave::fcn_callback)
63 Q_DECLARE_METATYPE (octave::meth_callback) 63 Q_DECLARE_METATYPE (octave::meth_callback)
64 64
65 OCTAVE_BEGIN_NAMESPACE(octave) 65 OCTAVE_BEGIN_NAMESPACE(octave)
66 66
67 static QStringList 67 static QStringList
68 make_qstring_list (const std::list<std::string>& lst) 68 make_qstring_list (const std::list<std::string>& lst)
69 { 69 {
70 QStringList retval; 70 QStringList retval;
71 71
72 for (const auto& s : lst) 72 for (const auto& s : lst)
73 retval.append (QString::fromStdString (s)); 73 retval.append (QString::fromStdString (s));
74 74
75 return retval; 75 return retval;
76 } 76 }
77 77
78 static QStringList 78 static QStringList
79 make_filter_list (const event_manager::filter_list& lst) 79 make_filter_list (const event_manager::filter_list& lst)
80 { 80 {
81 QStringList retval; 81 QStringList retval;
82 82
83 // We have pairs of data, first being the list of extensions 83 // We have pairs of data, first being the list of extensions
84 // exta;exb;extc etc second the name to use as filter name 84 // exta;exb;extc etc second the name to use as filter name
85 // (optional). Qt wants a list of filters in the format of 85 // (optional). Qt wants a list of filters in the format of
86 // 'FilterName (space separated exts)'. 86 // 'FilterName (space separated exts)'.
87 87
88 for (const auto& ext_name : lst) 88 for (const auto& ext_name : lst)
89 { 89 {
90 QString ext = QString::fromStdString (ext_name.first); 90 QString ext = QString::fromStdString (ext_name.first);
91 QString name = QString::fromStdString (ext_name.second); 91 QString name = QString::fromStdString (ext_name.second);
92 92
93 // Strip out extensions from name and replace ';' with spaces in list. 93 // Strip out extensions from name and replace ';' with spaces in list.
94 94
95 name.replace (QRegExp (R"(\(.*\))"), ""); 95 name.replace (QRegExp (R"(\(.*\))"), "");
96 ext.replace (";", " "); 96 ext.replace (";", " ");
97 97
98 if (name.isEmpty ()) 98 if (name.isEmpty ())
99 { 99 {
100 // No name field. Build one from the extensions. 100 // No name field. Build one from the extensions.
101 name = ext.toUpper () + " Files"; 101 name = ext.toUpper () + " Files";
102 } 102 }
103 103
104 retval.append (name + " (" + ext + ')'); 104 retval.append (name + " (" + ext + ')');
105 } 105 }
106 106
107 return retval; 107 return retval;
108 } 108 }
109 109
110 qt_interpreter_events::qt_interpreter_events (base_qobject& oct_qobj) 110 qt_interpreter_events::qt_interpreter_events (base_qobject& oct_qobj)
111 : interpreter_events (), m_octave_qobj (oct_qobj), 111 : interpreter_events (), m_octave_qobj (oct_qobj),
112 m_uiwidget_creator (oct_qobj), m_result (), m_mutex (), 112 m_uiwidget_creator (oct_qobj), m_result (), m_mutex (),
113 m_waitcondition () 113 m_waitcondition ()
114 { 114 {
115 qRegisterMetaType<QIntList> ("QIntList"); 115 qRegisterMetaType<QIntList> ("QIntList");
116 qRegisterMetaType<QFloatList> ("QFloatList"); 116 qRegisterMetaType<QFloatList> ("QFloatList");
117 117
118 qRegisterMetaType<octave_value> ("octave_value"); 118 qRegisterMetaType<octave_value> ("octave_value");
119 qRegisterMetaType<symbol_info_list> ("symbol_info_list"); 119 qRegisterMetaType<symbol_info_list> ("symbol_info_list");
120 120
121 qRegisterMetaType<fcn_callback> ("fcn_callback"); 121 qRegisterMetaType<fcn_callback> ("fcn_callback");
122 qRegisterMetaType<meth_callback> ("meth_callback"); 122 qRegisterMetaType<meth_callback> ("meth_callback");
123 123
124 connect (this, &qt_interpreter_events::confirm_shutdown_signal, 124 connect (this, &qt_interpreter_events::confirm_shutdown_signal,
125 this, &qt_interpreter_events::confirm_shutdown_octave); 125 this, &qt_interpreter_events::confirm_shutdown_octave);
126 126
127 connect (this, &qt_interpreter_events::get_named_icon_signal, 127 connect (this, &qt_interpreter_events::get_named_icon_signal,
128 this, &qt_interpreter_events::get_named_icon_slot); 128 this, &qt_interpreter_events::get_named_icon_slot);
129 129
130 connect (this, &qt_interpreter_events::gui_preference_signal, 130 connect (this, &qt_interpreter_events::gui_preference_signal,
131 this, &qt_interpreter_events::gui_preference_slot); 131 this, &qt_interpreter_events::gui_preference_slot);
132 } 132 }
133 133
134 void qt_interpreter_events::start_gui (bool gui_app) 134 void qt_interpreter_events::start_gui (bool gui_app)
135 { 135 {
136 if (m_octave_qobj.experimental_terminal_widget ()) 136 if (m_octave_qobj.experimental_terminal_widget ())
137 emit start_gui_signal (gui_app); 137 emit start_gui_signal (gui_app);
138 } 138 }
139 139
140 void qt_interpreter_events::close_gui (void) 140 void qt_interpreter_events::close_gui (void)
141 { 141 {
142 if (m_octave_qobj.experimental_terminal_widget ()) 142 if (m_octave_qobj.experimental_terminal_widget ())
143 emit close_gui_signal (); 143 emit close_gui_signal ();
144 } 144 }
145 145
146 std::list<std::string> 146 std::list<std::string>
147 qt_interpreter_events::file_dialog (const filter_list& filter, 147 qt_interpreter_events::file_dialog (const filter_list& filter,
148 const std::string& title, 148 const std::string& title,
149 const std::string& filename, 149 const std::string& filename,
150 const std::string& dirname, 150 const std::string& dirname,
151 const std::string& multimode) 151 const std::string& multimode)
152 { 152 {
153 QStringList lst 153 QStringList lst
154 = m_uiwidget_creator.file_dialog (make_filter_list (filter), 154 = m_uiwidget_creator.file_dialog (make_filter_list (filter),
155 QString::fromStdString (title), 155 QString::fromStdString (title),
156 QString::fromStdString (filename), 156 QString::fromStdString (filename),
157 QString::fromStdString (dirname), 157 QString::fromStdString (dirname),
158 QString::fromStdString (multimode)); 158 QString::fromStdString (multimode));
159 159
160 std::list<std::string> retval; 160 std::list<std::string> retval;
161 161
162 for (const auto& s : lst) 162 for (const auto& s : lst)
163 retval.push_back (s.toStdString ()); 163 retval.push_back (s.toStdString ());
164 164
165 return retval; 165 return retval;
166 } 166 }
167 167
168 std::list<std::string> 168 std::list<std::string>
169 qt_interpreter_events::input_dialog (const std::list<std::string>& prompt, 169 qt_interpreter_events::input_dialog (const std::list<std::string>& prompt,
170 const std::string& title, 170 const std::string& title,
171 const std::list<float>& nr, 171 const std::list<float>& nr,
172 const std::list<float>& nc, 172 const std::list<float>& nc,
173 const std::list<std::string>& defaults) 173 const std::list<std::string>& defaults)
174 { 174 {
175 QStringList lst 175 QStringList lst
176 = m_uiwidget_creator.input_dialog (make_qstring_list (prompt), 176 = m_uiwidget_creator.input_dialog (make_qstring_list (prompt),
177 QString::fromStdString (title),
178 std_list_to_qt_list<float> (nr),
179 std_list_to_qt_list<float> (nc),
180 make_qstring_list (defaults));
181 std::list<std::string> retval;
182
183 for (const auto& s : lst)
184 retval.push_back (s.toStdString ());
185
186 return retval;
187 }
188
189 std::pair<std::list<int>, int>
190 qt_interpreter_events::list_dialog (const std::list<std::string>& list,
191 const std::string& mode,
192 int width, int height,
193 const std::list<int>& initial,
194 const std::string& name,
195 const std::list<std::string>& prompt,
196 const std::string& ok_string,
197 const std::string& cancel_string)
198 {
199 QPair<QIntList, int> result
200 = m_uiwidget_creator.list_dialog (make_qstring_list (list),
201 QString::fromStdString (mode),
202 width, height,
203 std_list_to_qt_list<int> (initial),
204 QString::fromStdString (name),
205 make_qstring_list (prompt),
206 QString::fromStdString (ok_string),
207 QString::fromStdString (cancel_string));
208
209 QIntList& lst = result.first;
210 return std::pair<std::list<int>, int> (std::list<int> (lst.begin (),
211 lst.end ()),
212 result.second);
213 }
214
215 std::string
216 qt_interpreter_events::question_dialog (const std::string& msg,
217 const std::string& title,
218 const std::string& btn1,
219 const std::string& btn2,
220 const std::string& btn3,
221 const std::string& btndef)
222 {
223 QString icon = "quest";
224 QStringList buttons;
225 QStringList role;
226
227 // Must use ResetRole which is left-aligned for all OS and WM.
228 role << "ResetRole" << "ResetRole" << "ResetRole";
229
230 buttons << QString::fromStdString (btn1);
231 if (btn2 == "")
232 role.removeAt (0);
233 else
234 buttons << QString::fromStdString (btn2);
235 buttons << QString::fromStdString (btn3);
236
237 QString answer
238 = m_uiwidget_creator.message_dialog (QString::fromStdString (msg),
177 QString::fromStdString (title), 239 QString::fromStdString (title),
178 std_list_to_qt_list<float> (nr), 240 icon, buttons,
179 std_list_to_qt_list<float> (nc), 241 QString::fromStdString (btndef),
180 make_qstring_list (defaults)); 242 role);
181 std::list<std::string> retval; 243
182 244 return answer.toStdString ();
183 for (const auto& s : lst) 245 }
184 retval.push_back (s.toStdString ()); 246
185 247 void qt_interpreter_events::update_path_dialog (void)
186 return retval; 248 {
187 } 249 emit update_path_dialog_signal ();
188 250 }
189 std::pair<std::list<int>, int> 251
190 qt_interpreter_events::list_dialog (const std::list<std::string>& list, 252 void qt_interpreter_events::show_preferences (void)
191 const std::string& mode, 253 {
192 int width, int height, 254 emit show_preferences_signal ();
193 const std::list<int>& initial, 255 }
194 const std::string& name, 256
195 const std::list<std::string>& prompt, 257 void qt_interpreter_events::apply_preferences (void)
196 const std::string& ok_string, 258 {
197 const std::string& cancel_string) 259 emit apply_new_settings ();
198 { 260 }
199 QPair<QIntList, int> result 261
200 = m_uiwidget_creator.list_dialog (make_qstring_list (list), 262 void qt_interpreter_events::show_terminal_window (void)
201 QString::fromStdString (mode), 263 {
202 width, height, 264 emit show_terminal_window_signal ();
203 std_list_to_qt_list<int> (initial), 265 }
204 QString::fromStdString (name), 266
205 make_qstring_list (prompt), 267 bool qt_interpreter_events::show_documentation (const std::string& file)
206 QString::fromStdString (ok_string), 268 {
207 QString::fromStdString (cancel_string)); 269 emit show_documentation_signal (QString::fromStdString (file));
208 270
209 QIntList& lst = result.first; 271 return true;
210 return std::pair<std::list<int>, int> (std::list<int> (lst.begin (), 272 }
211 lst.end ()), 273
212 result.second); 274 void qt_interpreter_events::show_file_browser (void)
213 } 275 {
214 276 emit show_file_browser_signal ();
215 std::string 277 }
216 qt_interpreter_events::question_dialog (const std::string& msg, 278
217 const std::string& title, 279 void qt_interpreter_events::show_command_history (void)
218 const std::string& btn1, 280 {
219 const std::string& btn2, 281 emit show_command_history_signal ();
220 const std::string& btn3, 282 }
221 const std::string& btndef) 283
222 { 284 void qt_interpreter_events::show_workspace (void)
223 QString icon = "quest"; 285 {
224 QStringList buttons; 286 emit show_workspace_signal ();
225 QStringList role; 287 }
226 288
227 // Must use ResetRole which is left-aligned for all OS and WM. 289 void qt_interpreter_events::show_community_news (int serial)
228 role << "ResetRole" << "ResetRole" << "ResetRole"; 290 {
229 291 emit show_community_news_signal (serial);
230 buttons << QString::fromStdString (btn1); 292 }
231 if (btn2 == "") 293
232 role.removeAt (0); 294 void qt_interpreter_events::show_release_notes (void)
233 else 295 {
234 buttons << QString::fromStdString (btn2); 296 emit show_release_notes_signal ();
235 buttons << QString::fromStdString (btn3); 297 }
236 298
237 QString answer 299 bool qt_interpreter_events::edit_file (const std::string& file)
238 = m_uiwidget_creator.message_dialog (QString::fromStdString (msg), 300 {
239 QString::fromStdString (title), 301 emit edit_file_signal (QString::fromStdString (file));
240 icon, buttons, 302
241 QString::fromStdString (btndef), 303 return true;
242 role); 304 }
243 305
244 return answer.toStdString (); 306 void qt_interpreter_events::edit_variable (const std::string& expr,
245 } 307 const octave_value& val)
246 308 {
247 void qt_interpreter_events::update_path_dialog (void) 309 emit edit_variable_signal (QString::fromStdString (expr), val);
248 { 310 }
249 emit update_path_dialog_signal (); 311
250 } 312 bool qt_interpreter_events::confirm_shutdown (void)
251 313 {
252 void qt_interpreter_events::show_preferences (void) 314 QMutexLocker autolock (&m_mutex);
253 { 315
254 emit show_preferences_signal (); 316 emit confirm_shutdown_signal ();
255 } 317
256 318 // Wait for result.
257 void qt_interpreter_events::apply_preferences (void) 319 wait ();
258 { 320
259 emit apply_new_settings (); 321 return m_result.toBool ();
260 } 322 }
261 323
262 void qt_interpreter_events::show_terminal_window (void) 324 bool qt_interpreter_events::prompt_new_edit_file (const std::string& file)
263 { 325 {
264 emit show_terminal_window_signal (); 326 resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
265 } 327 gui_settings *settings = rmgr.get_settings ();
266 328
267 bool qt_interpreter_events::show_documentation (const std::string& file) 329 if (! settings || settings->value (ed_create_new_file).toBool ())
268 {
269 emit show_documentation_signal (QString::fromStdString (file));
270
271 return true; 330 return true;
272 } 331
273 332 std::string abs_fname = sys::env::make_absolute (file);
274 void qt_interpreter_events::show_file_browser (void) 333
275 { 334 QStringList btn;
276 emit show_file_browser_signal (); 335 QStringList role;
277 } 336 role << "YesRole" << "RejectRole";
278 337 btn << tr ("Create") << tr ("Cancel");
279 void qt_interpreter_events::show_command_history (void) 338
280 { 339 QString answer = m_uiwidget_creator.message_dialog
281 emit show_command_history_signal (); 340 (tr ("File\n%1\ndoes not exist. Do you want to create it?").
282 } 341 arg (QString::fromStdString (abs_fname)),
283 342 tr ("Octave Editor"), "quest", btn, tr ("Create"), role);
284 void qt_interpreter_events::show_workspace (void) 343
285 { 344 return (answer == tr ("Create"));
286 emit show_workspace_signal (); 345 }
287 } 346
288 347 // Prompt to allow file to be run by setting cwd (or if
289 void qt_interpreter_events::show_community_news (int serial) 348 // addpath_option==true, alternatively setting the path).
290 { 349
291 emit show_community_news_signal (serial); 350 int
292 } 351 qt_interpreter_events::debug_cd_or_addpath_error (const std::string& file,
293 352 const std::string& dir,
294 void qt_interpreter_events::show_release_notes (void) 353 bool addpath_option)
295 { 354 {
296 emit show_release_notes_signal (); 355 int retval = -1;
297 } 356
298 357 QString qdir = QString::fromStdString (dir);
299 bool qt_interpreter_events::edit_file (const std::string& file) 358 QString qfile = QString::fromStdString (file);
300 { 359 QString msg
301 emit edit_file_signal (QString::fromStdString (file)); 360 = (addpath_option
302 361 ? 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)
303 return true; 362 : 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));
304 } 363
305 364 QString title = tr ("Change Directory or Add Directory to Load Path");
306 void qt_interpreter_events::edit_variable (const std::string& expr, 365
307 const octave_value& val) 366 QString cd_txt = tr ("&Change Directory");
308 { 367 QString addpath_txt = tr ("&Add Directory to Load Path");
309 emit edit_variable_signal (QString::fromStdString (expr), val); 368 QString cancel_txt = tr ("Cancel");
310 } 369
311 370 QStringList btn;
312 bool qt_interpreter_events::confirm_shutdown (void) 371 QStringList role;
313 { 372 btn << cd_txt;
314 QMutexLocker autolock (&m_mutex); 373 role << "YesRole";
315 374 if (addpath_option)
316 emit confirm_shutdown_signal (); 375 {
317 376 btn << addpath_txt;
318 // Wait for result. 377 role << "AcceptRole";
319 wait (); 378 }
320 379 btn << cancel_txt;
321 return m_result.toBool (); 380 role << "RejectRole";
322 } 381
323 382 QString result
324 bool qt_interpreter_events::prompt_new_edit_file (const std::string& file) 383 = m_uiwidget_creator.message_dialog (msg, title, "quest", btn,
325 { 384 cancel_txt, role);
326 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); 385
327 gui_settings *settings = rmgr.get_settings (); 386 if (result == cd_txt)
328 387 retval = 1;
329 if (! settings || settings->value (ed_create_new_file).toBool ()) 388 else if (result == addpath_txt)
330 return true; 389 retval = 2;
331 390
332 std::string abs_fname = sys::env::make_absolute (file); 391 return retval;
333 392 }
334 QStringList btn; 393
335 QStringList role; 394 uint8NDArray qt_interpreter_events::get_named_icon (const std::string& name)
336 role << "YesRole" << "RejectRole"; 395 {
337 btn << tr ("Create") << tr ("Cancel"); 396 QMutexLocker autolock (&m_mutex);
338 397
339 QString answer = m_uiwidget_creator.message_dialog 398 emit get_named_icon_signal (QString::fromStdString (name));
340 (tr ("File\n%1\ndoes not exist. Do you want to create it?"). 399
341 arg (QString::fromStdString (abs_fname)), 400 // Wait for result.
342 tr ("Octave Editor"), "quest", btn, tr ("Create"), role); 401 wait ();
343 402
344 return (answer == tr ("Create")); 403 uint8NDArray empty_img;
345 } 404
346 405 QIcon icon = m_result.value<QIcon> ();
347 // Prompt to allow file to be run by setting cwd (or if 406
348 // addpath_option==true, alternatively setting the path). 407 if (icon.isNull ())
349 408 return empty_img;
350 int 409
351 qt_interpreter_events::debug_cd_or_addpath_error (const std::string& file, 410 QImage img = icon.pixmap (QSize (32, 32)).toImage ();
352 const std::string& dir, 411
353 bool addpath_option) 412 if (img.format () != QImage::Format_ARGB32_Premultiplied)
354 { 413 return empty_img;
355 int retval = -1; 414
356 415 dim_vector dims (img.height (), img.width (), 4);
357 QString qdir = QString::fromStdString (dir); 416
358 QString qfile = QString::fromStdString (file); 417 uint8NDArray retval (dims, 0);
359 QString msg 418
360 = (addpath_option 419 uint8_t *bits = img.bits ();
361 ? 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) 420
362 : 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)); 421 for (int i = 0; i < img.height (); i++)
363 422 {
364 QString title = tr ("Change Directory or Add Directory to Load Path"); 423 for (int j = 0; j < img.width (); j++)
365 424 {
366 QString cd_txt = tr ("&Change Directory"); 425 retval(i, j, 2) = bits[0];
367 QString addpath_txt = tr ("&Add Directory to Load Path"); 426 retval(i, j, 1) = bits[1];
368 QString cancel_txt = tr ("Cancel"); 427 retval(i, j, 0) = bits[2];
369 428 retval(i, j, 3) = bits[3];
370 QStringList btn; 429
371 QStringList role; 430 bits += 4;
372 btn << cd_txt; 431 }
373 role << "YesRole"; 432 }
374 if (addpath_option) 433
375 { 434 return retval;
376 btn << addpath_txt; 435 }
377 role << "AcceptRole"; 436
378 } 437 void qt_interpreter_events::get_named_icon_slot (const QString& name)
379 btn << cancel_txt; 438 {
380 role << "RejectRole"; 439 QMutexLocker autolock (&m_mutex);
381 440
382 QString result 441 resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
383 = m_uiwidget_creator.message_dialog (msg, title, "quest", btn, 442 m_result = QVariant::fromValue (rmgr.icon (name));
384 cancel_txt, role); 443
385 444 wake_all ();
386 if (result == cd_txt) 445 }
387 retval = 1; 446
388 else if (result == addpath_txt) 447 std::string
389 retval = 2; 448 qt_interpreter_events::gui_preference (const std::string& key,
390 449 const std::string& value)
391 return retval; 450 {
392 } 451 QString pref_value;
393 452
394 uint8NDArray qt_interpreter_events::get_named_icon (const std::string& name) 453 QMutexLocker autolock (&m_mutex);
395 { 454
396 QMutexLocker autolock (&m_mutex); 455 // Emit the signal for changing or getting a preference
397 456 emit gui_preference_signal (QString::fromStdString (key),
398 emit get_named_icon_signal (QString::fromStdString (name)); 457 QString::fromStdString (value));
399 458
400 // Wait for result. 459 // Wait for response (pref_value).
401 wait (); 460 wait ();
402 461
403 uint8NDArray empty_img; 462 QString pref = m_result.toString ();
404 463
405 QIcon icon = m_result.value<QIcon> (); 464 return pref.toStdString ();
406 465 }
407 if (icon.isNull ()) 466
408 return empty_img; 467 bool qt_interpreter_events::copy_image_to_clipboard (const std::string& file)
409 468 {
410 QImage img = icon.pixmap (QSize (32, 32)).toImage (); 469 emit copy_image_to_clipboard_signal (QString::fromStdString (file), true);
411 470
412 if (img.format () != QImage::Format_ARGB32_Premultiplied) 471 return true;
413 return empty_img; 472 }
414 473
415 dim_vector dims (img.height (), img.width (), 4); 474 void qt_interpreter_events::focus_window (const std::string win_name)
416 475 {
417 uint8NDArray retval (dims, 0); 476 emit focus_window_signal (QString::fromStdString (win_name));
418 477 }
419 uint8_t *bits = img.bits (); 478
420 479 void qt_interpreter_events::execute_command_in_terminal
421 for (int i = 0; i < img.height (); i++) 480 (const std::string& command)
422 { 481 {
423 for (int j = 0; j < img.width (); j++) 482 emit execute_command_in_terminal_signal (QString::fromStdString (command));
424 { 483 }
425 retval(i, j, 2) = bits[0]; 484
426 retval(i, j, 1) = bits[1]; 485 void qt_interpreter_events::register_documentation (const std::string& file)
427 retval(i, j, 0) = bits[2]; 486 {
428 retval(i, j, 3) = bits[3]; 487 emit register_documentation_signal (QString::fromStdString (file));
429 488 }
430 bits += 4; 489
431 } 490 void qt_interpreter_events::unregister_documentation (const std::string& file)
432 } 491 {
433 492 emit unregister_documentation_signal (QString::fromStdString (file));
434 return retval; 493 }
435 } 494
436 495 void qt_interpreter_events::interpreter_output (const std::string& msg)
437 void qt_interpreter_events::get_named_icon_slot (const QString& name) 496 {
438 { 497 if (m_octave_qobj.experimental_terminal_widget ()
439 QMutexLocker autolock (&m_mutex); 498 && m_octave_qobj.have_terminal_window ())
440 499 emit interpreter_output_signal (QString::fromStdString (msg));
441 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); 500 else
442 m_result = QVariant::fromValue (rmgr.icon (name)); 501 {
443 502 // FIXME: is this the correct thing to do?
444 wake_all (); 503 std::cout << msg;
445 } 504 }
446 505 }
447 std::string 506
448 qt_interpreter_events::gui_preference (const std::string& key, 507 void qt_interpreter_events::display_exception (const execution_exception& ee,
449 const std::string& value) 508 bool beep)
450 { 509 {
451 QString pref_value; 510 if (m_octave_qobj.experimental_terminal_widget ()
452 511 && m_octave_qobj.have_terminal_window ())
453 QMutexLocker autolock (&m_mutex); 512 {
454 513 // Output the exception message
455 // Emit the signal for changing or getting a preference 514 std::ostringstream buf;
456 emit gui_preference_signal (QString::fromStdString (key), 515 ee.display (buf);
457 QString::fromStdString (value)); 516 emit interpreter_output_signal (QString::fromStdString (buf.str ()));
458 517 // Create w new command line
459 // Wait for response (pref_value). 518 emit new_command_line_signal ();
460 wait (); 519 }
461 520 else
462 QString pref = m_result.toString (); 521 {
463 522 if (beep)
464 return pref.toStdString (); 523 std::cerr << "\a";
465 } 524
466 525 ee.display (std::cerr);
467 bool qt_interpreter_events::copy_image_to_clipboard (const std::string& file) 526 }
468 { 527 }
469 emit copy_image_to_clipboard_signal (QString::fromStdString (file), true); 528
470 529 void qt_interpreter_events::gui_status_update (const std::string& feature,
471 return true; 530 const std::string& status)
472 } 531 {
473 532 emit gui_status_update_signal (QString::fromStdString (feature),
474 void qt_interpreter_events::focus_window (const std::string win_name) 533 QString::fromStdString (status));
475 { 534 }
476 emit focus_window_signal (QString::fromStdString (win_name)); 535
477 } 536 void qt_interpreter_events::update_gui_lexer (void)
478 537 {
479 void qt_interpreter_events::execute_command_in_terminal 538 emit update_gui_lexer_signal (true);
480 (const std::string& command) 539 }
481 { 540
482 emit execute_command_in_terminal_signal (QString::fromStdString (command)); 541 void qt_interpreter_events::directory_changed (const std::string& dir)
483 } 542 {
484 543 emit directory_changed_signal (QString::fromStdString (dir));
485 void qt_interpreter_events::register_documentation (const std::string& file) 544 }
486 { 545
487 emit register_documentation_signal (QString::fromStdString (file)); 546 void qt_interpreter_events::file_remove (const std::string& old_name,
488 } 547 const std::string& new_name)
489 548 {
490 void qt_interpreter_events::unregister_documentation (const std::string& file) 549 QMutexLocker autolock (&m_mutex);
491 { 550
492 emit unregister_documentation_signal (QString::fromStdString (file)); 551 // Emit the signal for the editor for closing the file if it is open
493 } 552 emit file_remove_signal (QString::fromStdString (old_name),
494 553 QString::fromStdString (new_name));
495 void qt_interpreter_events::interpreter_output (const std::string& msg) 554
496 { 555 // Wait for file removal to complete before continuing.
497 if (m_octave_qobj.experimental_terminal_widget () 556 wait ();
498 && m_octave_qobj.have_terminal_window ()) 557 }
499 emit interpreter_output_signal (QString::fromStdString (msg)); 558
500 else 559 void qt_interpreter_events::file_renamed (bool load_new)
501 { 560 {
502 // FIXME: is this the correct thing to do? 561 emit file_renamed_signal (load_new);
503 std::cout << msg; 562 }
504 } 563
505 } 564 void qt_interpreter_events::set_workspace (bool top_level, bool debug,
506 565 const symbol_info_list& syminfo,
507 void qt_interpreter_events::display_exception (const execution_exception& ee, 566 bool update_variable_editor)
508 bool beep) 567 {
509 { 568 if (! top_level && ! debug)
510 if (m_octave_qobj.experimental_terminal_widget () 569 return;
511 && m_octave_qobj.have_terminal_window ()) 570
512 { 571 emit set_workspace_signal (top_level, debug, syminfo);
513 // Output the exception message 572
514 std::ostringstream buf; 573 if (update_variable_editor)
515 ee.display (buf); 574 emit refresh_variable_editor_signal ();
516 emit interpreter_output_signal (QString::fromStdString (buf.str ())); 575 }
517 // Create w new command line 576
518 emit new_command_line_signal (); 577 void qt_interpreter_events::clear_workspace (void)
519 } 578 {
520 else 579 emit clear_workspace_signal ();
521 { 580 }
522 if (beep) 581
523 std::cerr << "\a"; 582 void qt_interpreter_events::update_prompt (const std::string& prompt)
524 583 {
525 ee.display (std::cerr); 584 emit update_prompt_signal (QString::fromStdString (prompt));
526 } 585 }
527 } 586
528 587 void qt_interpreter_events::set_history (const string_vector& hist)
529 void qt_interpreter_events::gui_status_update (const std::string& feature, 588 {
530 const std::string& status) 589 QStringList qt_hist;
531 { 590
532 emit gui_status_update_signal (QString::fromStdString (feature), 591 for (octave_idx_type i = 0; i < hist.numel (); i++)
533 QString::fromStdString (status)); 592 qt_hist.append (QString::fromStdString (hist[i]));
534 } 593
535 594 emit set_history_signal (qt_hist);
536 void qt_interpreter_events::update_gui_lexer (void) 595 }
537 { 596
538 emit update_gui_lexer_signal (true); 597 void qt_interpreter_events::append_history (const std::string& hist_entry)
539 } 598 {
540 599 emit append_history_signal (QString::fromStdString (hist_entry));
541 void qt_interpreter_events::directory_changed (const std::string& dir) 600 }
542 { 601
543 emit directory_changed_signal (QString::fromStdString (dir)); 602 void qt_interpreter_events::clear_history (void)
544 } 603 {
545 604 emit clear_history_signal ();
546 void qt_interpreter_events::file_remove (const std::string& old_name, 605 }
547 const std::string& new_name) 606
548 { 607 void qt_interpreter_events::pre_input_event (void)
549 QMutexLocker autolock (&m_mutex); 608 { }
550 609
551 // Emit the signal for the editor for closing the file if it is open 610 void qt_interpreter_events::post_input_event (void)
552 emit file_remove_signal (QString::fromStdString (old_name), 611 { }
553 QString::fromStdString (new_name)); 612
554 613 void qt_interpreter_events::enter_debugger_event (const std::string& /*fcn_name*/,
555 // Wait for file removal to complete before continuing. 614 const std::string& fcn_file_name,
556 wait ();
557 }
558
559 void qt_interpreter_events::file_renamed (bool load_new)
560 {
561 emit file_renamed_signal (load_new);
562 }
563
564 void qt_interpreter_events::set_workspace (bool top_level, bool debug,
565 const symbol_info_list& syminfo,
566 bool update_variable_editor)
567 {
568 if (! top_level && ! debug)
569 return;
570
571 emit set_workspace_signal (top_level, debug, syminfo);
572
573 if (update_variable_editor)
574 emit refresh_variable_editor_signal ();
575 }
576
577 void qt_interpreter_events::clear_workspace (void)
578 {
579 emit clear_workspace_signal ();
580 }
581
582 void qt_interpreter_events::update_prompt (const std::string& prompt)
583 {
584 emit update_prompt_signal (QString::fromStdString (prompt));
585 }
586
587 void qt_interpreter_events::set_history (const string_vector& hist)
588 {
589 QStringList qt_hist;
590
591 for (octave_idx_type i = 0; i < hist.numel (); i++)
592 qt_hist.append (QString::fromStdString (hist[i]));
593
594 emit set_history_signal (qt_hist);
595 }
596
597 void qt_interpreter_events::append_history (const std::string& hist_entry)
598 {
599 emit append_history_signal (QString::fromStdString (hist_entry));
600 }
601
602 void qt_interpreter_events::clear_history (void)
603 {
604 emit clear_history_signal ();
605 }
606
607 void qt_interpreter_events::pre_input_event (void)
608 { }
609
610 void qt_interpreter_events::post_input_event (void)
611 { }
612
613 void qt_interpreter_events::enter_debugger_event (const std::string& /*fcn_name*/,
614 const std::string& fcn_file_name,
615 int line)
616 {
617 if (fcn_file_name.empty ())
618 return;
619
620 insert_debugger_pointer (fcn_file_name, line);
621
622 emit enter_debugger_signal ();
623 }
624
625 void
626 qt_interpreter_events::execute_in_debugger_event (const std::string& file,
627 int line)
628 {
629 delete_debugger_pointer (file, line);
630 }
631
632 void qt_interpreter_events::exit_debugger_event (void)
633 {
634 emit exit_debugger_signal ();
635 }
636
637 // Display (if @insert true) or remove the appropriate symbol for a breakpoint
638 // in @file at @line with condition @cond.
639 void qt_interpreter_events::update_breakpoint (bool insert,
640 const std::string& file,
641 int line,
642 const std::string& cond)
643 {
644 emit update_breakpoint_marker_signal (insert, QString::fromStdString (file),
645 line, QString::fromStdString (cond));
646 }
647
648 void
649 qt_interpreter_events::insert_debugger_pointer (const std::string& file,
650 int line) 615 int line)
651 { 616 {
652 emit insert_debugger_pointer_signal (QString::fromStdString (file), line); 617 if (fcn_file_name.empty ())
653 } 618 return;
654 619
655 void 620 insert_debugger_pointer (fcn_file_name, line);
656 qt_interpreter_events::delete_debugger_pointer (const std::string& file, 621
622 emit enter_debugger_signal ();
623 }
624
625 void
626 qt_interpreter_events::execute_in_debugger_event (const std::string& file,
657 int line) 627 int line)
658 { 628 {
659 emit delete_debugger_pointer_signal (QString::fromStdString (file), line); 629 delete_debugger_pointer (file, line);
660 } 630 }
661 631
662 void 632 void qt_interpreter_events::exit_debugger_event (void)
663 qt_interpreter_events::confirm_shutdown_octave (void) 633 {
664 { 634 emit exit_debugger_signal ();
665 QMutexLocker autolock (&m_mutex); 635 }
666 636
667 m_result = m_octave_qobj.confirm_shutdown (); 637 // Display (if @insert true) or remove the appropriate symbol for a breakpoint
668 638 // in @file at @line with condition @cond.
669 wake_all (); 639 void qt_interpreter_events::update_breakpoint (bool insert,
670 } 640 const std::string& file,
671 641 int line,
672 // If VALUE is empty, return current value of preference named by KEY. 642 const std::string& cond)
673 // 643 {
674 // If VALUE is not empty, set preference named by KEY to VALUE return 644 emit update_breakpoint_marker_signal (insert, QString::fromStdString (file),
675 // previous value. 645 line, QString::fromStdString (cond));
676 // 646 }
677 // FIXME: should we have separate get and set functions? With only 647
678 // one, we don't allow a preference value to be set to the empty 648 void
679 // string. 649 qt_interpreter_events::insert_debugger_pointer (const std::string& file,
680 650 int line)
681 void 651 {
682 qt_interpreter_events::gui_preference_slot (const QString& key, 652 emit insert_debugger_pointer_signal (QString::fromStdString (file), line);
653 }
654
655 void
656 qt_interpreter_events::delete_debugger_pointer (const std::string& file,
657 int line)
658 {
659 emit delete_debugger_pointer_signal (QString::fromStdString (file), line);
660 }
661
662 void
663 qt_interpreter_events::confirm_shutdown_octave (void)
664 {
665 QMutexLocker autolock (&m_mutex);
666
667 m_result = m_octave_qobj.confirm_shutdown ();
668
669 wake_all ();
670 }
671
672 // If VALUE is empty, return current value of preference named by KEY.
673 //
674 // If VALUE is not empty, set preference named by KEY to VALUE return
675 // previous value.
676 //
677 // FIXME: should we have separate get and set functions? With only
678 // one, we don't allow a preference value to be set to the empty
679 // string.
680
681 void
682 qt_interpreter_events::gui_preference_slot (const QString& key,
683 const QString& value)
684 {
685 QMutexLocker autolock (&m_mutex);
686
687 resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
688 gui_settings *settings = rmgr.get_settings ();
689
690 QString read_value = settings->value (key).toString ();
691
692 // Some preferences need extra handling
693 QString adjusted_value = gui_preference_adjust (key, value);
694
695 if (! adjusted_value.isEmpty () && (read_value != adjusted_value))
696 {
697 // Change settings only for new, non-empty values
698 settings->setValue (key, QVariant (adjusted_value));
699
700 emit settings_changed (settings, true); // true: changed by worker
701 }
702
703 m_result = read_value;
704
705 wake_all ();
706 }
707
708 QString
709 qt_interpreter_events::gui_preference_adjust (const QString& key,
683 const QString& value) 710 const QString& value)
684 { 711 {
685 QMutexLocker autolock (&m_mutex); 712 // Immediately return if no new value is given.
686 713
687 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); 714 if (value.isEmpty ())
688 gui_settings *settings = rmgr.get_settings (); 715 return value;
689 716
690 QString read_value = settings->value (key).toString (); 717 QString adjusted_value = value;
691 718
692 // Some preferences need extra handling 719 // Not all encodings are available. Encodings are uppercase and do
693 QString adjusted_value = gui_preference_adjust (key, value); 720 // not use CPxxx but IBMxxx or WINDOWS-xxx.
694 721
695 if (! adjusted_value.isEmpty () && (read_value != adjusted_value)) 722 if (key == ed_default_enc.key)
696 { 723 {
697 // Change settings only for new, non-empty values 724 adjusted_value = adjusted_value.toUpper ();
698 settings->setValue (key, QVariant (adjusted_value)); 725
699 726 QStringList codecs;
700 emit settings_changed (settings, true); // true: changed by worker 727 resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
701 } 728 rmgr.get_codecs (&codecs);
702 729
703 m_result = read_value; 730 QRegExp re ("^CP(\\d+)$");
704 731
705 wake_all (); 732 if (adjusted_value == "SYSTEM")
706 } 733 adjusted_value =
707 734 QString ("SYSTEM (") +
708 QString 735 QString (octave_locale_charset_wrapper ()).toUpper () +
709 qt_interpreter_events::gui_preference_adjust (const QString& key, 736 QString (")");
710 const QString& value) 737 else if (re.indexIn (adjusted_value) > -1)
711 { 738 {
712 // Immediately return if no new value is given. 739 if (codecs.contains ("IBM" + re.cap (1)))
713 740 adjusted_value = "IBM" + re.cap (1);
714 if (value.isEmpty ()) 741 else if (codecs.contains ("WINDOWS-" + re.cap (1)))
715 return value; 742 adjusted_value = "WINDOWS-" + re.cap (1);
716 743 else
717 QString adjusted_value = value; 744 adjusted_value.clear ();
718 745 }
719 // Not all encodings are available. Encodings are uppercase and do 746 else if (! codecs.contains (adjusted_value))
720 // not use CPxxx but IBMxxx or WINDOWS-xxx. 747 adjusted_value.clear ();
721 748 }
722 if (key == ed_default_enc.key) 749
723 { 750 return adjusted_value;
724 adjusted_value = adjusted_value.toUpper (); 751 }
725
726 QStringList codecs;
727 resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
728 rmgr.get_codecs (&codecs);
729
730 QRegExp re ("^CP(\\d+)$");
731
732 if (adjusted_value == "SYSTEM")
733 adjusted_value =
734 QString ("SYSTEM (") +
735 QString (octave_locale_charset_wrapper ()).toUpper () +
736 QString (")");
737 else if (re.indexIn (adjusted_value) > -1)
738 {
739 if (codecs.contains ("IBM" + re.cap (1)))
740 adjusted_value = "IBM" + re.cap (1);
741 else if (codecs.contains ("WINDOWS-" + re.cap (1)))
742 adjusted_value = "WINDOWS-" + re.cap (1);
743 else
744 adjusted_value.clear ();
745 }
746 else if (! codecs.contains (adjusted_value))
747 adjusted_value.clear ();
748 }
749
750 return adjusted_value;
751 }
752 752
753 OCTAVE_END_NAMESPACE(octave) 753 OCTAVE_END_NAMESPACE(octave)