diff libgui/src/main-window.cc @ 29836:56465c0739fa

allow release notes window to be opened from command line * main-window.h, main-window.cc (main_window::m_release_notes_windoow, main_window::m_release_notes_icon): Delete member variables and all uses. (main_window::display_release_notes): Delete. (main_window::show_release_notes_signal): New signal. (main_window::construct_news_menu): Use lambda function to emit show_release_notes_signal. * release-notes.h, release-notes.cc: New files. * libgui/src/module.mk: Update. * octave-qobject.h, octave-qobject.cc (base_qobject::base_qobject): Connect main_window show_release_notes_signal to base_qobject show_release_notes slot. If gui_app is true, connect main_window show_release_notes_signal to base_qobject show_release_notes slot. (base_qobject::start_gui): Also connect main_window show_release_notes_signal to base_qobject show_release_notes slot here. (base_qobject::m_release_notes): New member variable. (base_qobject::release_notes_widget, base_qobject::show_release_notes): New functions. * qt-interpreter-events.h, qt-interpreter-events.cc (qt_interpreter_events::show_release_notes): New function. (qt_interpreter_events::show_release_notes_signal): New signal. * event-manager.h, event-manager.cc (event_manager::show_release_notes): New function. (interpreter_events::show_release_notes): New virtual function. (F__event_manager_show_release_notes__): New function.
author John W. Eaton <jwe@octave.org>
date Sat, 26 Jun 2021 07:59:17 -0400
parents a946d742fb97
children b918ef934b71
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Fri Jun 25 17:27:17 2021 -0400
+++ b/libgui/src/main-window.cc	Sat Jun 26 07:59:17 2021 -0400
@@ -101,7 +101,6 @@
       m_external_editor (new external_editor_interface (this, m_octave_qobj)),
       m_active_editor (m_external_editor), m_settings_dlg (nullptr),
       m_find_files_dlg (nullptr), m_set_path_dlg (nullptr),
-      m_release_notes_window (nullptr),
       m_clipboard (QApplication::clipboard ()),
       m_prevent_readline_conflicts (true),
       m_prevent_readline_conflicts_menu (false),
@@ -210,14 +209,7 @@
     focus_command_window ();
   }
 
-  main_window::~main_window (void)
-  {
-    // These must be explicitly deleted because they are not
-    // intentionally not children of main_window.  See the comments in
-    // the functions where they are constructed.
-
-    delete m_release_notes_window;
-  }
+  main_window::~main_window (void) { }
 
   void main_window::adopt_dock_widgets (void)
   {
@@ -847,71 +839,6 @@
       (QUrl ("https://octave.org/doc/interpreter/index.html"));
   }
 
-  void main_window::display_release_notes (void)
-  {
-    if (! m_release_notes_window)
-      {
-        std::string news_file = config::oct_etc_dir () + "/NEWS";
-
-        QString news;
-
-        QFile *file = new QFile (QString::fromStdString (news_file));
-        if (file->open (QFile::ReadOnly))
-          {
-            QTextStream *stream = new QTextStream (file);
-            news = stream->readAll ();
-            if (! news.isEmpty ())
-              {
-                // Convert '<', '>' which would be interpreted as HTML
-                news.replace ("<", "&lt;");
-                news.replace (">", "&gt;");
-                // Add HTML tags for pre-formatted text
-                news.prepend ("<pre>");
-                news.append ("</pre>");
-              }
-            else
-              news = (tr ("The release notes file '%1' is empty.")
-                      . arg (QString::fromStdString (news_file)));
-          }
-        else
-          news = (tr ("The release notes file '%1' cannot be read.")
-                  . arg (QString::fromStdString (news_file)));
-
-        // We want the window manager to give the release notes window
-        // a title bar, so don't its parent to main_window.  Do remember
-        // to delete in the main_window destructor.
-
-        m_release_notes_window = new QWidget ();
-
-        QTextBrowser *browser = new QTextBrowser (m_release_notes_window);
-        browser->setText (news);
-
-        QVBoxLayout *vlayout = new QVBoxLayout;
-        vlayout->addWidget (browser);
-
-        m_release_notes_window->setLayout (vlayout);
-        m_release_notes_window->setWindowTitle (tr ("Octave Release Notes"));
-
-        browser->document ()->adjustSize ();
-
-        int win_x, win_y;
-        get_screen_geometry (win_x, win_y);
-
-        m_release_notes_window->resize (win_x*2/5, win_y*2/3);
-        m_release_notes_window->move (20, 20);  // move to the top left corner
-      }
-
-    if (! m_release_notes_window->isVisible ())
-      m_release_notes_window->show ();
-    else if (m_release_notes_window->isMinimized ())
-      m_release_notes_window->showNormal ();
-
-    m_release_notes_window->setWindowIcon (QIcon (m_release_notes_icon));
-
-    m_release_notes_window->raise ();
-    m_release_notes_window->activateWindow ();
-  }
-
   void main_window::open_bug_tracker_page (void)
   {
     QDesktopServices::openUrl (QUrl ("https://octave.org/bugs.html"));
@@ -1014,11 +941,6 @@
             widget->setWindowIcon (QIcon (icon));
           }
       }
-    if (dw_icon_set_names[icon_set_found].name != "NONE")
-      m_release_notes_icon = dw_icon_set_names[icon_set_found].path
-                             + "ReleaseWidget.png";
-    else
-      m_release_notes_icon = ":/actions/icons/logo.png";
 
     int size_idx = settings->value (global_icon_size).toInt ();
     size_idx = (size_idx > 0) - (size_idx < 0) + 1;  // Make valid index from 0 to 2
@@ -2586,10 +2508,14 @@
   {
     QMenu *news_menu = m_add_menu (p, tr ("&News"));
 
-    m_release_notes_action = add_action (news_menu, QIcon (),
-                                         tr ("Release Notes"), SLOT (display_release_notes ()));
-
-    // Currently a special case so we can use a lambda expression.
+    m_release_notes_action
+      = news_menu->addAction (QIcon (), tr ("Release Notes"),
+                              [=] () {
+                                emit show_release_notes_signal ();
+                              });
+    addAction (m_release_notes_action);
+    m_release_notes_action->setShortcutContext (Qt::ApplicationShortcut);
+
     m_current_news_action
       = news_menu->addAction (QIcon (), tr ("Community News"),
                               [=] () {