comparison libgui/src/m-editor/octave-qscintilla.cc @ 33479:a583e8d66a19

do not change gui settings when running selected code by F9 (bug #65617) * gui-preferences-ed.cc/h: new gui preference for storing the name of the temp. file used for running selected code by F9 * file-editor.cc (request_open_file): if breakpoint oder debug marker is used and file name is equal to temp file, just return and do not open the file * octave-qscintilla.cc (contextmenu_run): do not handle lines with keyboard in a special way anymore, store file name of temp. file in settings, variable show_dbg_file and update signal and function calls accordingly; (ctx_menu_run_finished): remove temp file name from settings * octave-qscintilla.h: remove first argument show_dbg_file in signal ctx_menu_run_finished_signal and slot ctx_menu_run_finished
author Torsten Lilge <ttl-octave@mailbox.org>
date Sun, 28 Apr 2024 21:28:00 +0200
parents f31a0d826776
children 7afc314f2998
comparison
equal deleted inserted replaced
33477:3362e398d702 33479:a583e8d66a19
906 906
907 QString line_escaped = line; 907 QString line_escaped = line;
908 line_escaped.replace (QString ("'"), QString ("''")); 908 line_escaped.replace (QString ("'"), QString ("''"));
909 QString line_history = line; 909 QString line_history = line;
910 910
911 // Prevent output of breakpoint in temp. file for keyboard
912 QString next_bp_quiet;
913 QString next_bp_quiet_reset;
914 if (line.contains ("keyboard"))
915 {
916 // Define commands for not showing bp location and for resetting
917 // this in case "keyboard" was within a comment
918 next_bp_quiet = "__db_next_breakpoint_quiet__;\n";
919 next_bp_quiet_reset = "\n__db_next_breakpoint_quiet__(false);";
920 }
921
922 // Add codeline 911 // Add codeline
923 code += next_bp_quiet + line + next_bp_quiet_reset + "\n"; 912 code += line + "\n";
924 hist += line_history + "\n"; 913 hist += line_history + "\n";
925 } 914 }
926 915
927 octave_stdout << hist.toStdString (); 916 octave_stdout << hist.toStdString ();
928 917
935 { 924 {
936 // tmp files not working: use old way to run selection 925 // tmp files not working: use old way to run selection
937 contextmenu_run_temp_error (); 926 contextmenu_run_temp_error ();
938 return; 927 return;
939 } 928 }
929
930 // Store file in settings in order to avoid opening it in editor
931 gui_settings settings;
932 settings.setValue (ed_run_selection_tmp_file.settings_key (), tmp_file->fileName ());
940 933
941 // Create tmp file required for adding command to history 934 // Create tmp file required for adding command to history
942 QPointer<QTemporaryFile> tmp_hist = create_tmp_file ("", hist); 935 QPointer<QTemporaryFile> tmp_hist = create_tmp_file ("", hist);
943 936
944 if (tmp_hist && tmp_hist->open ()) 937 if (tmp_hist && tmp_hist->open ())
963 std::string path = tmp_hist->fileName ().toStdString (); 956 std::string path = tmp_hist->fileName ().toStdString ();
964 957
965 Fhistory (interp, ovl (opt, path)); 958 Fhistory (interp, ovl (opt, path));
966 }); 959 });
967 960
968 // Disable opening a file at a breakpoint in case keyboard () is used
969 gui_settings settings;
970
971 bool show_dbg_file = settings.bool_value (ed_show_dbg_file);
972 settings.setValue (ed_show_dbg_file.settings_key (), false);
973
974 // The interpreter_event callback function below emits a signal. 961 // The interpreter_event callback function below emits a signal.
975 // Because we don't control when that happens, use a guarded pointer 962 // Because we don't control when that happens, use a guarded pointer
976 // so that the callback can abort if this object is no longer valid. 963 // so that the callback can abort if this object is no longer valid.
977 964
978 QPointer<octave_qscintilla> this_oq (this); 965 QPointer<octave_qscintilla> this_oq (this);
979 966
980 // Let the interpreter execute the tmp file 967 // Let the interpreter execute the tmp file
981 emit interpreter_event 968 emit interpreter_event
982 ([this, this_oq, tmp_file, tmp_hist, show_dbg_file] (interpreter& interp) 969 ([this, this_oq, tmp_file, tmp_hist] (interpreter& interp)
983 { 970 {
984 // INTERPRETER THREAD 971 // INTERPRETER THREAD
985 972
986 // FIXME: For now, just skip the entire callback if THIS_OQ is 973 // FIXME: For now, just skip the entire callback if THIS_OQ is
987 // no longer valid. Maybe there is a better way to do this 974 // no longer valid. Maybe there is a better way to do this
1064 stack.pop_back (); 1051 stack.pop_back ();
1065 if (dbg && (stack.size () > 0)) 1052 if (dbg && (stack.size () > 0))
1066 stack.pop_back (); 1053 stack.pop_back ();
1067 1054
1068 // Clean up before throwing the modified error. 1055 // Clean up before throwing the modified error.
1069 emit ctx_menu_run_finished_signal (show_dbg_file, err_line, 1056 emit ctx_menu_run_finished_signal (err_line,
1070 tmp_file, tmp_hist, 1057 tmp_file, tmp_hist,
1071 dbg, auto_repeat); 1058 dbg, auto_repeat);
1072 1059
1073 // New exception with updated message and stack 1060 // New exception with updated message and stack
1074 execution_exception nee (ee.err_type (), ee.identifier (), 1061 execution_exception nee (ee.err_type (), ee.identifier (),
1078 throw (nee); 1065 throw (nee);
1079 } 1066 }
1080 1067
1081 // Clean up 1068 // Clean up
1082 1069
1083 emit ctx_menu_run_finished_signal (show_dbg_file, err_line, 1070 emit ctx_menu_run_finished_signal (err_line,
1084 tmp_file, tmp_hist, 1071 tmp_file, tmp_hist,
1085 dbg, auto_repeat); 1072 dbg, auto_repeat);
1086 1073
1087 command_editor::erase_empty_line (true); 1074 command_editor::erase_empty_line (true);
1088 command_editor::replace_line (""); 1075 command_editor::replace_line ("");
1094 1081
1095 }); 1082 });
1096 } 1083 }
1097 1084
1098 void octave_qscintilla::ctx_menu_run_finished 1085 void octave_qscintilla::ctx_menu_run_finished
1099 (bool show_dbg_file, int, QPointer<QTemporaryFile> tmp_file, 1086 (int, QPointer<QTemporaryFile> tmp_file,
1100 QPointer<QTemporaryFile> tmp_hist, bool dbg, bool auto_repeat) 1087 QPointer<QTemporaryFile> tmp_hist, bool dbg, bool auto_repeat)
1101 { 1088 {
1102 emit focus_console_after_command_signal (); 1089 emit focus_console_after_command_signal ();
1103 1090
1104 // TODO: Use line nr. (int argument) of possible error for removing 1091 // TODO: Use line nr. (int argument) of possible error for removing
1105 // lines from history that were never executed. For this, 1092 // lines from history that were never executed. For this,
1106 // possible lines from commands at a debug prompt must be 1093 // possible lines from commands at a debug prompt must be
1107 // taken into consideration. 1094 // taken into consideration.
1108 1095
1109 gui_settings settings;
1110
1111 settings.setValue (ed_show_dbg_file.settings_key (), show_dbg_file);
1112
1113 if (tmp_file && tmp_file->exists ()) 1096 if (tmp_file && tmp_file->exists ())
1114 tmp_file->remove (); 1097 {
1098 tmp_file->remove ();
1099 gui_settings settings;
1100 settings.setValue (ed_run_selection_tmp_file.settings_key (), QString ());
1101 }
1115 1102
1116 if (tmp_hist && tmp_hist->exists ()) 1103 if (tmp_hist && tmp_hist->exists ())
1117 tmp_hist->remove (); 1104 tmp_hist->remove ();
1118 1105
1119 emit interpreter_event 1106 emit interpreter_event