changeset 21311:718332a58d35

Fix left mouse button in editor margin bug from cset 65827e9cccb8 * octave-qt-link.cc (do_debug_cd_or_addpath_error): Back out 65827e9cccb8 to use uiwidget_creator instead of QMessageBox. * file_editor_tab.cc (handle_context_menu_break_condition): Validate condition using bp_table::condition_valid, to allow file_in_path to be called from a callback.jo * debug.{cc,h} (condition_valid): make member method, not static function.
author Lachlan Andrew <lachlanbis@gmail.com>
date Thu, 11 Feb 2016 19:59:32 +1100
parents fc6a9bd59094
children 4dda463ca576
files libgui/src/m-editor/file-editor-tab.cc libgui/src/octave-qt-link.cc libinterp/corefcn/debug.cc libinterp/corefcn/debug.h
diffstat 4 files changed, 58 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sun Feb 14 13:16:05 2016 +1100
+++ b/libgui/src/m-editor/file-editor-tab.cc	Thu Feb 11 19:59:32 2016 +1100
@@ -327,15 +327,14 @@
 void
 file_editor_tab::handle_context_menu_break_condition (int linenr)
 {
-  QString cond;
-  bp_info info (_file_name, linenr);  // Get function name & dir from filename.
-
   // Ensure editor line numbers match Octave core's line numbers.
   // Give users the option to save modifications if necessary.
-  if (! unchanged_or_saved ()
-     || !(octave_qt_link::file_in_path (info.file, info.dir)))
+  if (! unchanged_or_saved ())
     return;
 
+  QString cond;
+  bp_info info (_file_name, linenr+1); // Get function name & dir from filename.
+
   // Search for previous condition.  FIXME -- is there a more direct way?
   if (_edit_area->markersAtLine (linenr) & (1 << marker::cond_break))
     {
@@ -363,18 +362,15 @@
 
   bool valid = false;
   std::string prompt = "dbstop if";
+  bool ok;
   while (!valid)
     {
-      bool ok;
       QString new_condition
         = QInputDialog::getText (this, tr ("Breakpoint condition"),
                                  tr (prompt.c_str ()), QLineEdit::Normal, cond,
                                  &ok);
       if (ok)     // If cancel, don't change breakpoint condition.
         {
-          bp_table::intmap line;
-          line[0] = linenr + 1;
-
           try
             {
               // Suppress error messages on the console.
@@ -382,13 +378,16 @@
               frame.protect_var (buffer_error_messages);
               buffer_error_messages++;
 
-              bp_table::add_breakpoint (info.function_name, line,
-                                        new_condition.toStdString ());
+              bp_table::condition_valid (new_condition.toStdString ());
               valid = true;
             }
-          catch (const octave_interrupt_exception&) { valid = true; }
           catch (const index_exception& e) { }
           catch (const octave_execution_exception& e) { }
+          catch (const octave_interrupt_exception&)
+            {
+              ok = false;
+              valid = true;
+            }
 
           // In case we repeat, set new prompt.
           prompt = "ERROR: " + last_error_message () + "\n\ndbstop if";
@@ -397,6 +396,14 @@
       else
         valid = true;
     }
+
+  if (ok)       // If the user didn't cancel, actually set the breakpoint.
+    {
+      info.condition = cond.toStdString ();
+
+      octave_link::post_event
+        (this, &file_editor_tab::add_breakpoint_callback, info);
+    }
 }
 
 void
--- a/libgui/src/octave-qt-link.cc	Sun Feb 14 13:16:05 2016 +1100
+++ b/libgui/src/octave-qt-link.cc	Thu Feb 11 19:59:32 2016 +1100
@@ -44,6 +44,7 @@
 
 #include "resource-manager.h"
 
+#include <unistd.h>
 octave_qt_link::octave_qt_link (QWidget *p)
   : octave_link (), main_thread (new QThread ()),
     command_interpreter (new octave_interpreter ())
@@ -387,31 +388,46 @@
 
   QString qdir = QString::fromStdString (dir);
   QString qfile = QString::fromStdString (file);
+  QString msg
+    = (addpath_option
+       ? 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)
+       : 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));
 
-  QMessageBox msgBox;
+  QString title = tr ("Change Directory or Add Directory to Load Path");
 
-  msgBox.setText ("File not in load path");
-  QPushButton *cd_btn = msgBox.addButton (tr ("Change Directory"),
-                                          QMessageBox::YesRole);
+  QString cd_txt = tr ("Change Directory");
+  QString addpath_txt = tr ("Add Directory to Load Path");
+  QString cancel_txt = tr ("Cancel");
 
-  QPushButton *addpath_btn = 0;
+  QStringList btn;
+  QStringList role;
+  btn << cd_txt;
+  role << "YesRole";
   if (addpath_option)
     {
-      msgBox.setInformativeText (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));
-      addpath_btn = msgBox.addButton (tr ("Add Directory to Load Path"),
-                                     QMessageBox::AcceptRole);
-    }
-    else
-    {
-      msgBox.setInformativeText (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));
-    }
-  msgBox.setStandardButtons (QMessageBox::Cancel);
+      btn << addpath_txt;
+      role << "AcceptRole";
+     }
+  btn << cancel_txt;
+  role << "RejectRole";
+
+  // Lock mutex before signaling.
+  uiwidget_creator.mutex.lock ();
+
+  uiwidget_creator.signal_dialog (msg, title, "quest", btn, cancel_txt, role);
 
-  msgBox.exec ();
+  // Wait while the user is responding to message box.
+  uiwidget_creator.waitcondition.wait (&uiwidget_creator.mutex);
+
+  // The GUI has sent a signal and the thread has been awakened.
 
-  if (msgBox.clickedButton () == cd_btn)
-    retval = 1;
-  else if (msgBox.clickedButton () == addpath_btn)
+  QString result = uiwidget_creator.get_dialog_button ();
+
+  uiwidget_creator.mutex.unlock ();
+
+  if (result == cd_txt)
+     retval = 1;
+  else if (result == addpath_txt)
     retval = 2;
 
   return retval;
--- a/libinterp/corefcn/debug.cc	Sun Feb 14 13:16:05 2016 +1100
+++ b/libinterp/corefcn/debug.cc	Thu Feb 11 19:59:32 2016 +1100
@@ -600,8 +600,8 @@
 // Currently allows conditions with side-effects, like 'y+=10' and 'y++';
 // it is odd that the former is not flagged by "is_assignment_expression".
 // Throws an exception if not valid.
-static bool
-condition_valid (const std::string& cond)
+bool
+bp_table::condition_valid (const std::string& cond)
 {
   if (cond.length () > 0)
     {
@@ -649,7 +649,7 @@
   if (! dbg_fcn)
     error ("add_breakpoint: unable to find function '%s'\n", fname.c_str ());
 
-  condition_valid (condition);  // throws error if condition not valid
+  condition_valid (condition); // Throw error if condition not valid.
 
   intmap retval;
 
--- a/libinterp/corefcn/debug.h	Sun Feb 14 13:16:05 2016 +1100
+++ b/libinterp/corefcn/debug.h	Thu Feb 11 19:59:32 2016 +1100
@@ -148,6 +148,8 @@
 
   static void dbclear_all_signals (void);
 
+  static bool condition_valid (const std::string& cond);
+
   friend void parse_dbfunction_params (const char *, const octave_value_list&,
                                        std::string&, bp_table::intmap&,
                                        std::string&);