Mercurial > octave
comparison libgui/src/m-editor/octave-qscintilla.cc @ 31690:1a1f47f17ed4
eliminate resource_manager class
* gui-settings.cc, gui-settings.h
(gui_settings::get_gui_translation_dir,
gui_settings::config_translators,
gui_settings::get_valid_lexer_styles,
gui_settings::read_lexer_settings, gui_settings::update_settings_key,
gui_settings::update_network_settings, gui_settings::get_codecs,
gui_settings::combo_encoding): Move here from resource_manager class.
* file-editor-tab.cc, find-dialog.cc, main-window.cc,
octave-qobject.h, octave-qobject.cc, qt-interpreter-events.cc,
settings-dialog.cc: Change all uses of resource_manager class to use
gui_settings instead.
* octave-qscintilla.h, octave-qscintilla.cc
(octave_qscintilla::create_tmp_file): Move here from resource_manager
class.
(octave_qscintilla::ctx_menu_run_finished_signal,
octave_qscintilla::ctx_menu_run_finished): Use
QPointer<QTemporaryFile> instead of bare pointer in signal/slot
functions.
* octave-qobject.h, octave-qobject.cc
(octave_base_qobject::m_resource_manager): Delete data member.
(octave_base_qobject::get_resource_manager): Delete.
* resource-manager.h, resource-manager.cc: Delete.
* libgui/src/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 27 Dec 2022 14:55:03 -0500 |
parents | deb553ac2c54 |
children | 2422fb7f1e6c |
comparison
equal
deleted
inserted
replaced
31689:a8a7207a7341 | 31690:1a1f47f17ed4 |
---|---|
34 #include <QDir> | 34 #include <QDir> |
35 #include <QKeySequence> | 35 #include <QKeySequence> |
36 #include <QMessageBox> | 36 #include <QMessageBox> |
37 #include <QMimeData> | 37 #include <QMimeData> |
38 #include <QShortcut> | 38 #include <QShortcut> |
39 #include <QPointer> | |
40 #include <QTemporaryFile> | |
39 #include <QToolTip> | 41 #include <QToolTip> |
40 #include <QVBoxLayout> | 42 #include <QVBoxLayout> |
41 #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H) | 43 #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H) |
42 # define HAVE_LEXER_OCTAVE 1 | 44 # define HAVE_LEXER_OCTAVE 1 |
43 # include <Qsci/qscilexeroctave.h> | 45 # include <Qsci/qscilexeroctave.h> |
64 | 66 |
65 #include "builtin-defun-decls.h" | 67 #include "builtin-defun-decls.h" |
66 #include "cmd-edit.h" | 68 #include "cmd-edit.h" |
67 #include "interpreter-private.h" | 69 #include "interpreter-private.h" |
68 #include "interpreter.h" | 70 #include "interpreter.h" |
71 #include "oct-env.h" | |
69 | 72 |
70 // Return true if CANDIDATE is a "closing" that matches OPENING, | 73 // Return true if CANDIDATE is a "closing" that matches OPENING, |
71 // such as "end" or "endif" for "if", or "catch" for "try". | 74 // such as "end" or "endif" for "if", or "catch" for "try". |
72 // Used for testing the last word of an "if" etc. line, | 75 // Used for testing the last word of an "if" etc. line, |
73 // or the first word of the following line. | 76 // or the first word of the following line. |
823 "\"Run Selection\" requires temporary files.").arg (QDir::tempPath ())); | 826 "\"Run Selection\" requires temporary files.").arg (QDir::tempPath ())); |
824 } | 827 } |
825 | 828 |
826 void octave_qscintilla::contextmenu_run (bool) | 829 void octave_qscintilla::contextmenu_run (bool) |
827 { | 830 { |
828 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); | |
829 | |
830 // Take selected code and extend it by commands for echoing each | 831 // Take selected code and extend it by commands for echoing each |
831 // evaluated line and for adding the line to the history (use script) | 832 // evaluated line and for adding the line to the history (use script) |
832 QString code = QString (); | 833 QString code = QString (); |
833 QString hist = QString (); | 834 QString hist = QString (); |
834 | 835 |
865 } | 866 } |
866 | 867 |
867 octave_stdout << hist.toStdString (); | 868 octave_stdout << hist.toStdString (); |
868 | 869 |
869 // Create tmp file with the code to be executed by the interpreter | 870 // Create tmp file with the code to be executed by the interpreter |
870 QPointer<QTemporaryFile> tmp_file | 871 QPointer<QTemporaryFile> tmp_file = create_tmp_file ("m", code); |
871 = rmgr.create_tmp_file ("m", code); | 872 |
872 | 873 if (tmp_file && tmp_file->open ()) |
873 bool tmp = (tmp_file && tmp_file->open ()); | 874 tmp_file->close (); |
874 if (! tmp) | 875 else |
875 { | 876 { |
876 // tmp files not working: use old way to run selection | 877 // tmp files not working: use old way to run selection |
877 contextmenu_run_temp_error (); | 878 contextmenu_run_temp_error (); |
878 return; | 879 return; |
879 } | 880 } |
880 | 881 |
881 tmp_file->close (); | |
882 | |
883 // Create tmp file required for adding command to history | 882 // Create tmp file required for adding command to history |
884 QPointer<QTemporaryFile> tmp_hist | 883 QPointer<QTemporaryFile> tmp_hist = create_tmp_file ("", hist); |
885 = rmgr.create_tmp_file ("", hist); // empty tmp file for history | 884 |
886 | 885 if (tmp_hist && tmp_hist->open ()) |
887 tmp = (tmp_hist && tmp_hist->open ()); | 886 tmp_hist->close (); |
888 if (! tmp) | 887 else |
889 { | 888 { |
890 // tmp files not working: use old way to run selection | 889 // tmp files not working: use old way to run selection |
891 contextmenu_run_temp_error (); | 890 contextmenu_run_temp_error (); |
892 return; | 891 return; |
893 } | 892 } |
894 | |
895 tmp_hist->close (); | |
896 | 893 |
897 // Add commands to the history | 894 // Add commands to the history |
898 emit interpreter_event | 895 emit interpreter_event |
899 ([=] (interpreter& interp) | 896 ([=] (interpreter& interp) |
900 { | 897 { |
1022 command_editor::erase_empty_line (true); | 1019 command_editor::erase_empty_line (true); |
1023 | 1020 |
1024 }); | 1021 }); |
1025 } | 1022 } |
1026 | 1023 |
1027 void octave_qscintilla::ctx_menu_run_finished (bool show_dbg_file, int, | 1024 void octave_qscintilla::ctx_menu_run_finished |
1028 QTemporaryFile* tmp_file, QTemporaryFile* tmp_hist, | 1025 (bool show_dbg_file, int, QPointer<QTemporaryFile> tmp_file, |
1029 bool dbg, bool auto_repeat) | 1026 QPointer<QTemporaryFile> tmp_hist, bool dbg, bool auto_repeat) |
1030 { | 1027 { |
1031 emit focus_console_after_command_signal (); | 1028 emit focus_console_after_command_signal (); |
1032 | 1029 |
1033 // TODO: Use line nr. (int argument) of possible error for removing | 1030 // TODO: Use line nr. (int argument) of possible error for removing |
1034 // lines from history that were never executed. For this, | 1031 // lines from history that were never executed. For this, |
1035 // possible lines from commands at a debug prompt must be | 1032 // possible lines from commands at a debug prompt must be |
1036 // taken into consideration. | 1033 // taken into consideration. |
1037 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); | 1034 |
1038 gui_settings settings; | 1035 gui_settings settings; |
1039 | 1036 |
1040 settings.setValue (ed_show_dbg_file.key, show_dbg_file); | 1037 settings.setValue (ed_show_dbg_file.key, show_dbg_file); |
1041 | 1038 |
1042 rmgr.remove_tmp_file (tmp_file); | 1039 if (tmp_file && tmp_file->exists ()) |
1043 rmgr.remove_tmp_file (tmp_hist); | 1040 tmp_file->remove (); |
1041 | |
1042 if (tmp_hist && tmp_hist->exists ()) | |
1043 tmp_hist->remove (); | |
1044 | 1044 |
1045 emit interpreter_event | 1045 emit interpreter_event |
1046 ([=] (interpreter& interp) | 1046 ([=] (interpreter& interp) |
1047 { | 1047 { |
1048 // INTERPRETER THREAD | 1048 // INTERPRETER THREAD |
1364 void octave_qscintilla::handle_exit_debug_mode (void) | 1364 void octave_qscintilla::handle_exit_debug_mode (void) |
1365 { | 1365 { |
1366 m_debug_mode = false; | 1366 m_debug_mode = false; |
1367 } | 1367 } |
1368 | 1368 |
1369 QPointer<QTemporaryFile> | |
1370 octave_qscintilla::create_tmp_file (const QString& extension, | |
1371 const QString& contents) | |
1372 { | |
1373 QString ext = extension; | |
1374 if ((! ext.isEmpty ()) && (! ext.startsWith ('.'))) | |
1375 ext = QString (".") + ext; | |
1376 | |
1377 // Create octave dir within temp. dir | |
1378 QString tmp_dir = QString::fromStdString (sys::env::get_temp_directory ()); | |
1379 | |
1380 QString tmp_name = tmp_dir + QDir::separator() + "octave_XXXXXX" + ext; | |
1381 | |
1382 QPointer<QTemporaryFile> tmp_file (new QTemporaryFile (tmp_name, this)); | |
1383 | |
1384 if (! contents.isEmpty () && tmp_file && tmp_file->open ()) | |
1385 { | |
1386 tmp_file->write (contents.toUtf8 ()); | |
1387 tmp_file->close (); | |
1388 } | |
1389 | |
1390 return tmp_file; | |
1391 } | |
1392 | |
1369 OCTAVE_END_NAMESPACE(octave) | 1393 OCTAVE_END_NAMESPACE(octave) |
1370 | 1394 |
1371 #endif | 1395 #endif |