changeset 18902:2b82d2f29a7b

maint: Periodic merge of gui-release to default.
author John W. Eaton <jwe@octave.org>
date Fri, 27 Jun 2014 11:56:19 -0400
parents a0fd65914811 (current diff) 589354cf668f (diff)
children 4586051a5ff1
files configure.ac libgui/src/m-editor/find-dialog.cc libinterp/corefcn/data.cc libinterp/corefcn/gl-render.h libinterp/corefcn/load-save.cc m4/acinclude.m4 scripts/io/strread.m
diffstat 8 files changed, 226 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Thu Jun 26 09:33:38 2014 -0700
+++ b/configure.ac	Fri Jun 27 11:56:19 2014 -0400
@@ -2769,6 +2769,7 @@
     OCTAVE_CHECK_QFONT_MONOSPACE
     OCTAVE_CHECK_FUNC_SETPLACEHOLDERTEXT
     OCTAVE_CHECK_FUNC_QTABWIDGET_SETMOVABLE
+    OCTAVE_CHECK_FUNC_QSCI_FINDSELECTION
   fi
 
   if test $build_gui = yes; then
--- a/libgui/src/m-editor/find-dialog.cc	Thu Jun 26 09:33:38 2014 -0700
+++ b/libgui/src/m-editor/find-dialog.cc	Fri Jun 27 11:56:19 2014 -0400
@@ -107,8 +107,13 @@
   _regex_check_box = new QCheckBox (tr ("Regular E&xpressions"));
   _backward_check_box = new QCheckBox (tr ("Search &backward"));
   _search_selection_check_box = new QCheckBox (tr ("Search se&lection"));
-  _search_selection_check_box->setCheckable (false); // TODO: Not implemented.
+#ifdef HAVE_QSCI_FINDSELECTION
+  _search_selection_check_box->setCheckable (true);
+  _search_selection_check_box->setEnabled (edit_area->hasSelectedText ());
+#else
+  _search_selection_check_box->setCheckable (false);
   _search_selection_check_box->setEnabled (false);
+#endif
 
   _edit_area = edit_area;
   connect (_find_next_button,   SIGNAL (clicked ()),
@@ -125,6 +130,15 @@
            this,                SLOT (handle_backward_search_changed (int)));
   connect (_button_box,         SIGNAL (rejected ()),
            this,                SLOT (close ()));
+  connect (_search_line_edit,   SIGNAL (textChanged (QString)),
+           this,                SLOT (handle_search_text_changed (QString)));
+
+#ifdef HAVE_QSCI_FINDSELECTION
+  connect (_edit_area, SIGNAL (copyAvailable (bool)),
+           this,       SLOT (handle_selection_changed (bool)));
+  connect (_search_selection_check_box, SIGNAL (stateChanged (int)),
+           this,                        SLOT (handle_sel_search_changed (int)));
+#endif
 
   QVBoxLayout *extension_layout = new QVBoxLayout ();
   extension_layout->setMargin (0);
@@ -158,6 +172,7 @@
   _find_next_button->setDefault (true);
   _find_result_available = false;
   _rep_all = 0;
+  _rep_active = false;
 
   // move dialog to side of the parent if there is room on the desktop to do so.
   QWidget * desktop = QApplication::desktop ();
@@ -183,6 +198,35 @@
     _from_start_check_box->setText (tr ("Search from start"));
 }
 
+// search text has changed: reset the search
+void
+find_dialog::handle_search_text_changed (QString)
+{
+  if (_search_selection_check_box->isChecked ())
+    _find_result_available = false;
+}
+
+#ifdef HAVE_QSCI_FINDSELECTION
+void
+find_dialog::handle_sel_search_changed (int selected)
+{
+  _from_start_check_box->setEnabled (! selected);
+  _find_result_available = false;
+}
+
+void
+find_dialog::handle_selection_changed (bool has_selected)
+{
+  if (_rep_active)
+    return;
+
+  _search_selection_check_box->setEnabled (has_selected);
+  _find_result_available = false;
+  if (! has_selected)
+    _search_selection_check_box->setChecked (false);
+}
+#endif
+
 // initialize search text with selected text if this is in one single line
 void
 find_dialog::init_search_text ()
@@ -216,17 +260,6 @@
   bool do_wrap = _wrap_check_box->isChecked ();
   bool do_forward = forward;
 
-  if (!forward && _find_result_available)
-    { // we found a match last time, cursor is at the end of the match
-      // backward: go to start of selection or we will find the same again
-      int line_end, col_end;
-      _edit_area->getSelection (&line,&col,&line_end,&col_end);
-      if (line > -1)
-        _edit_area->setCursorPosition (line,col);
-    }
-
-  _find_result_available = false;
-
   if (_rep_all)
     {
       if (_rep_all == 1)
@@ -235,49 +268,102 @@
           col = 0;
         }
       do_wrap = false;
-      do_forward = true;
+      // The following line is a workaround for the issue that when replacing
+      // a text with a new one with different size within the selection,
+      // the selection is not updated leading to missing or extra replacements.
+      // This does not happen, when the selection is search backwards
+      do_forward = ! _search_selection_check_box->isChecked ();
     }
   else
     {
       if (_from_start_check_box->isChecked ())
         {
-          line = 0;
-          col  = 0;
-          if (_backward_check_box->isChecked ())
-            do_wrap = true;
+          if (do_forward)
+            {
+              line = 0;
+              col = 0;
+            }
+          else
+            {
+              line = _edit_area->lines () - 1;
+              col  = _edit_area->text (line).length () - 1;
+              if (col == -1)
+                col = 0;
+            }
         }
     }
 
   if (_edit_area)
     {
-      _find_result_available
-        = _edit_area->findFirst (_search_line_edit->text (),
-                                _regex_check_box->isChecked (),
-                                _case_check_box->isChecked (),
-                                _whole_words_check_box->isChecked (),
-                                do_wrap,
-                                do_forward,
-                                line,col,
-                                true
+      if (_edit_area->hasSelectedText ()
+          && _search_selection_check_box->isChecked ())
+        {
+#ifdef HAVE_QSCI_FINDSELECTION
+           if (_find_result_available)
+             _find_result_available = _edit_area->findNext ();
+           else
+            _find_result_available
+              = _edit_area->findFirstInSelection (
+                                      _search_line_edit->text (),
+                                      _regex_check_box->isChecked (),
+                                      _case_check_box->isChecked (),
+                                      _whole_words_check_box->isChecked (),
+                                      do_forward,
+                                      true
 #ifdef HAVE_QSCI_VERSION_2_6_0
-                                , true
+                                      , true
+#endif
+                                      );
 #endif
-                                );
+        }
+      else
+        {
+          _find_result_available
+            = _edit_area->findFirst (_search_line_edit->text (),
+                                    _regex_check_box->isChecked (),
+                                    _case_check_box->isChecked (),
+                                    _whole_words_check_box->isChecked (),
+                                    do_wrap,
+                                    do_forward,
+                                    line,col,
+                                    true
+#ifdef HAVE_QSCI_VERSION_2_6_0
+                                    , true
+#endif
+                                    );
+        }
     }
+
   if (_find_result_available)
     _from_start_check_box->setChecked (0);
   else if (! _rep_all)
     no_matches_message ();
 }
 
+void
+find_dialog::do_replace ()
+{
+  _rep_active = true;  // changes in selection not made by the user
+  _edit_area->replace (_replace_line_edit->text ());
+  _rep_active = false;
+}
 
 void
 find_dialog::replace ()
 {
   if (_edit_area)
     {
+      // The following line is a workaround for the issue that when replacing
+      // a text with a new one with different size within the selection,
+      // the selection is not updated leading to missing or extra replacements.
+      // This does not happen, when the selection is search backwards
+      if (_search_selection_check_box->isChecked ())
+        _backward_check_box->setChecked (true);
+
+      // do the replace if we have selected text
       if (_find_result_available && _edit_area->hasSelectedText ())
-        _edit_area->replace (_replace_line_edit->text ());
+        do_replace ();
+
       find_next ();
     }
 }
@@ -295,7 +381,7 @@
       find_next ();  // find first occurence (forward)
       while (_find_result_available)   // while search string is found
         {
-          _edit_area->replace (_replace_line_edit->text ());   // replace
+          do_replace ();
           _rep_all++;                                          // inc counter
           find_next ();                                        // find next
         }
@@ -306,7 +392,10 @@
       msg_box.exec ();
 
       _rep_all = 0;
-      _edit_area->setCursorPosition (line,col);
+      _find_result_available = false;
+
+      if (! _search_selection_check_box->isChecked ())
+        _edit_area->setCursorPosition (line,col);
     }
 }
 
--- a/libgui/src/m-editor/find-dialog.h	Thu Jun 26 09:33:38 2014 -0700
+++ b/libgui/src/m-editor/find-dialog.h	Fri Jun 27 11:56:19 2014 -0400
@@ -79,7 +79,13 @@
   void init_search_text ();
 
 private slots:
+#ifdef HAVE_QSCI_FINDSELECTION
+  void handle_sel_search_changed (int);
+  void handle_selection_changed (bool has_selected);
+#endif
   void handle_backward_search_changed (int);
+  void handle_search_text_changed (QString new_search_text);
+
   void find (bool forward = true);
   void find_next ();
   void find_prev ();
@@ -87,7 +93,10 @@
   void replace_all ();
 
 private:
+
   void no_matches_message ();
+  void do_replace ();
+
   QLabel            *_search_label;
   QLineEdit         *_search_line_edit;
   QLabel            *_replace_label;
@@ -109,6 +118,7 @@
   QsciScintilla     *_edit_area;
   bool               _find_result_available;
   int                _rep_all;
+  bool               _rep_active;
 };
 
 #endif // FIND_DIALOG_H
--- a/libinterp/corefcn/data.cc	Thu Jun 26 09:33:38 2014 -0700
+++ b/libinterp/corefcn/data.cc	Fri Jun 27 11:56:19 2014 -0400
@@ -569,6 +569,9 @@
 %! [f, e] = log2 (complex (zeros (3, 2), [0,-1; 2,-4; Inf,-Inf]));
 %! assert (f, complex (zeros (3, 2), [0,-0.5; 0.5,-0.5; Inf,-Inf]));
 %! assert (e(1:2,:), [0,1; 2,3]);
+
+# bug #42583
+%!assert (all (log2 (pow2 (-1074:1023)) == -1074:1023))
 */
 
 DEFUN (rem, args, ,
--- a/libinterp/corefcn/gl-render.h	Thu Jun 26 09:33:38 2014 -0700
+++ b/libinterp/corefcn/gl-render.h	Fri Jun 27 11:56:19 2014 -0400
@@ -40,6 +40,12 @@
 #include <OpenGL/glu.h>
 #endif
 
+#ifdef HAVE_GL_GLEXT_H
+#include <GL/glext.h>
+#elif defined HAVE_OPENGL_GLEXT_H || defined HAVE_FRAMEWORK_OPENGL
+#include <OpenGL/glext.h>
+#endif
+
 #include "graphics.h"
 #include "txt-eng-ft.h"
 
--- a/libinterp/corefcn/load-save.cc	Thu Jun 26 09:33:38 2014 -0700
+++ b/libinterp/corefcn/load-save.cc	Fri Jun 27 11:56:19 2014 -0400
@@ -265,9 +265,10 @@
               file.clear ();
               file.seekg (0, std::ios::beg);
 
-              std::string tmp = extract_keyword (file, "name");
+              std::string name_val = extract_keyword (file, "name");
+              std::string type_val = extract_keyword (file, "type");
 
-              if (! tmp.empty ())
+              if (name_val.empty () != true && type_val.empty () != true)
                 retval = LS_ASCII;
               else
                 {
--- a/m4/acinclude.m4	Thu Jun 26 09:33:38 2014 -0700
+++ b/m4/acinclude.m4	Fri Jun 27 11:56:19 2014 -0400
@@ -485,6 +485,38 @@
   fi
 ])
 dnl
+dnl Check whether the QsciScintilla::findFirstInSelection () function exists.
+dnl This function was added in QScintilla 2.7.
+dnl
+AC_DEFUN([OCTAVE_CHECK_FUNC_QSCI_FINDSELECTION], [
+  AC_CACHE_CHECK([whether QSci has the QsciScintilla::findFirstInSelection () function],
+    [octave_cv_func_qsci_findfirstinselection],
+    [AC_LANG_PUSH(C++)
+    ac_octave_save_CPPFLAGS="$CPPFLAGS"
+    CPPFLAGS="$QT_CPPFLAGS $CPPFLAGS"
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        #include <Qsci/qsciscintilla.h>
+        class qsci : public QsciScintilla
+        {
+        public:
+          qsci (QWidget *parent = 0) : QsciScintilla (parent)
+          { this->findFirstInSelection (QString ("x"),true,true,true,true,true); }
+          ~qsci () {}
+        };
+        ]], [[
+        qsci edit;
+        ]])],
+      octave_cv_func_qsci_findfirstinselection=yes,
+      octave_cv_func_qsci_findfirstinselection=no)
+    CPPFLAGS="$ac_octave_save_CPPFLAGS"
+    AC_LANG_POP(C++)
+  ])
+  if test $octave_cv_func_qsci_findfirstinselection = yes; then
+    AC_DEFINE(HAVE_QSCI_FINDSELECTION, 1,
+      [Define to 1 if Qsci has the QsciScintilla::findFirstInSelection () function.])
+  fi
+])
+dnl
 dnl Check whether HDF5 library has version 1.6 API functions.
 dnl
 AC_DEFUN([OCTAVE_CHECK_HDF5_HAS_VER_16_API], [
@@ -905,6 +937,16 @@
     ])
 
     if test $have_opengl_incs = yes; then
+      AC_CHECK_HEADERS([GL/glext.h OpenGL/glext.h], [], [], [
+#ifdef HAVE_WINDOWS_H
+# include <windows.h>
+#endif
+#if defined (HAVE_GL_GL_H)
+# include <GL/gl.h>
+#elif defined (HAVE_OPENGL_GL_H)
+# include <OpenGL/gl.h>
+#endif
+      ])
       case $canonical_host_type in
         *-*-mingw32* | *-*-msdosmsvc)
           save_LIBS="$LIBS"
--- a/scripts/io/strread.m	Thu Jun 26 09:33:38 2014 -0700
+++ b/scripts/io/strread.m	Fri Jun 27 11:56:19 2014 -0400
@@ -192,6 +192,10 @@
     error ("strread: STR and FORMAT arguments must be strings");
   endif
 
+  if (strcmp (typeinfo (format), "sq_string"))
+    format = do_string_escapes (format);
+  endif
+
   ## Parse format string to compare number of conversion fields and nargout
   nfields = length (strfind (format, "%")) - length (strfind (format, "%*"));
   ## If str only has numeric fields, a (default) format ("%f") will do.
@@ -391,6 +395,15 @@
     white_spaces = strrep (white_spaces, eol_char, '');
   endif
 
+  ii = numel (fmt_words);
+  while (ii > 0)
+    if (ismember (fmt_words{ii}, delimiter_str)(1))
+      fmt_words(ii) = [];
+      --num_words_per_line;
+    endif
+    --ii;
+  endwhile
+
   pad_out = 0;
   ## Trim whitespace if needed
   if (! isempty (white_spaces))
@@ -974,6 +987,34 @@
 %!test
 %! assert (strread (",2,,4\n5,,7,", "", "delimiter", ","), [NaN; 2; NaN; 4; 5; NaN; 7]);
 
+%% Test #1 bug #42609
+%!test
+%! [a, b, c] = strread ("1 2 3\n4 5 6\n7 8 9\n", "%f %f %f\n");
+%! assert (a, [1; 4; 7]);
+%! assert (b, [2; 5; 8]);
+%! assert (c, [3; 6; 9]);
+
+%% Test #2 bug #42609
+%!test
+%! [a, b, c] = strread ("1 2\n3\n4 5\n6\n7 8\n9\n", "%f %f\n%f");
+%! assert (a, [1;4;7]);
+%! assert (b, [2; 5; 8]);
+%! assert (c, [3; 6; 9]);
+
+%% Test #3 bug #42609
+%!test
+%! [a, b, c] = strread ("1 2 3\n4 5 6\n7 8 9\n", '%f %f %f\n');
+%! assert (a, [1; 4; 7]);
+%! assert (b, [2; 5; 8]);
+%! assert (c, [3; 6; 9]);
+
+%% Test #3 bug #42609
+%!test
+%! [a, b, c] = strread ("1 2\n3\n4 5\n6\n7 8\n9\n", '%f %f\n%f');
+%! assert (a, [1;4;7]);
+%! assert (b, [2; 5; 8]);
+%! assert (c, [3; 6; 9]);
+
 %% Unsupported format specifiers
 %!test
 %!error <format specifiers are not supported> strread ("a", "%c")