Skip to content

Commit 099b283

Browse files
authored
Update Help and About Windows (#2141)
* Initial implementation * Use native web browser to display Help * Use `wxHtmlWindow` to display version information regardless of platform * Move HelpWin to main.cpp * Updates for macOS tests * Restore SAM icon to help window * Clean up code for removed Help window buttons * Remove unused webview references * Delete commented code * Remove commented code
1 parent 6493441 commit 099b283

File tree

3 files changed

+162
-261
lines changed

3 files changed

+162
-261
lines changed

src/main.cpp

Lines changed: 135 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232

3333
#include <set>
3434
//#include <chrono>
35+
#include <fstream>
3536

3637
#include <wx/wx.h>
3738
#include <wx/frame.h>
3839
#include <wx/stc/stc.h>
39-
#include <fstream>
40-
41-
#if defined(__WXMSW__)||defined(__WXOSX__)
42-
#include <wx/webview.h>
43-
#else
44-
#include <wx/html/htmlwin.h> // for linux - avoid webkitgtk dependencies
45-
#endif
46-
40+
#include <wx/html/htmlwin.h>
4741
#include <wx/simplebook.h>
4842
#include <wx/panel.h>
4943
#include <wx/busyinfo.h>
@@ -53,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5347
#include <wx/datstrm.h>
5448
#include <wx/grid.h>
5549
#include <wx/stdpaths.h>
56-
#include <wx/webview.h>
5750
#include <wx/txtstrm.h>
5851
#include <wx/buffer.h>
5952
#include <wx/display.h>
@@ -66,7 +59,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6659
#include <wex/icons/qmark.cpng>
6760
#include <wex/utils.h>
6861

69-
7062
#include "../resource/menu.cpng"
7163
#include "../resource/notes_white.cpng"
7264

@@ -106,13 +98,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10698

10799
static PythonConfig pythonConfig;
108100

109-
110101
enum { __idFirst = wxID_HIGHEST+592,
111102

112-
ID_MAIN_MENU, ID_CASE_TABS, ID_PAGE_NOTES,
113-
ID_CASE_CREATE, ID_RUN_ALL_CASES, ID_SAVE_HOURLY,
103+
ID_MAIN_MENU,
104+
ID_CASE_TABS,
105+
ID_PAGE_NOTES,
106+
ID_RELEASE_NOTES,
107+
ID_BROWSER,
108+
ID_CASE_CREATE,
109+
ID_RUN_ALL_CASES,
110+
ID_SAVE_HOURLY,
114111
ID_IMPORT_CASES,
115-
ID_NEW_SCRIPT, ID_OPEN_SCRIPT, ID_BROWSE_INPUTS,
112+
ID_NEW_SCRIPT,
113+
ID_OPEN_SCRIPT,
114+
ID_BROWSE_INPUTS,
116115
__idCaseMenuFirst,
117116
ID_CASE_CONFIG,
118117
ID_CASE_RENAME,
@@ -137,8 +136,6 @@ enum { __idFirst = wxID_HIGHEST+592,
137136

138137
BEGIN_EVENT_TABLE( MainWindow, wxFrame )
139138
EVT_CLOSE( MainWindow::OnClose )
140-
EVT_MENU( wxID_ABOUT, MainWindow::OnCommand )
141-
EVT_MENU( wxID_HELP, MainWindow::OnCommand )
142139
EVT_MENU( ID_SAVE_HOURLY, MainWindow::OnCommand )
143140
EVT_MENU( ID_IMPORT_CASES, MainWindow::OnCommand )
144141
EVT_MENU( wxID_NEW, MainWindow::OnCommand )
@@ -156,6 +153,7 @@ BEGIN_EVENT_TABLE( MainWindow, wxFrame )
156153
EVT_BUTTON(ID_MAIN_MENU, MainWindow::OnCommand)
157154
EVT_LISTBOX( ID_CASE_TABS, MainWindow::OnCaseTabChange )
158155
EVT_BUTTON( ID_CASE_TABS, MainWindow::OnCaseTabButton )
156+
EVT_BUTTON(wxID_ABOUT, MainWindow::OnCommand)
159157
EVT_BUTTON( wxID_HELP, MainWindow::OnCommand )
160158
EVT_BUTTON( ID_PAGE_NOTES, MainWindow::OnCommand )
161159
EVT_MENU_RANGE( __idCaseMenuFirst, __idCaseMenuLast, MainWindow::OnCaseMenu )
@@ -238,7 +236,8 @@ MainWindow::MainWindow()
238236
tools->Add( metbut = new wxMetroButton( m_caseTabPanel, ID_PAGE_NOTES, wxEmptyString, wxBITMAP_PNG_FROM_DATA( notes_white ), wxDefaultPosition, wxDefaultSize), 0, wxALL|wxEXPAND, 0 );
239237
metbut->SetToolTip( "Add a page note" );
240238

241-
tools->Add( new wxMetroButton( m_caseTabPanel, wxID_HELP, "Help",/* wxBITMAP_PNG_FROM_DATA(qmark) */ wxNullBitmap, wxDefaultPosition, wxDefaultSize), 0, wxALL|wxEXPAND, 0 );
239+
tools->Add(new wxMetroButton(m_caseTabPanel, wxID_ABOUT, "About",wxNullBitmap, wxDefaultPosition, wxDefaultSize), 0, wxALL | wxEXPAND, 0);
240+
tools->Add( new wxMetroButton( m_caseTabPanel, wxID_HELP, "Help",/*wxBITMAP_PNG_FROM_DATA(qmark)*/ wxNullBitmap, wxDefaultPosition, wxDefaultSize), 0, wxALL | wxEXPAND, 0);
242241

243242
m_caseNotebook = new wxSimplebook( m_caseTabPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE );
244243

@@ -2456,67 +2455,141 @@ wxArrayString SamApp::RecentFiles()
24562455
return files;
24572456
}
24582457

2459-
void SamApp::ShowHelp( const wxString &context )
2458+
class HelpWin : public wxFrame
24602459
{
2461-
wxString url;
2462-
if ( context.Left(1) == ":" )
2463-
url = context; // for things like :about, etc
2464-
else
2460+
wxHtmlWindow* m_htmlView;
2461+
2462+
wxString m_aboutHtml;
2463+
public:
2464+
HelpWin(wxWindow* parent)
2465+
: wxFrame(parent, wxID_ANY, "About System Advisor Model (SAM)", wxDefaultPosition, wxScaleSize(1000, 600))
24652466
{
2466-
wxFileName fn( SamApp::GetRuntimePath() + "/help/html/" );
2467-
fn.MakeAbsolute();
2468-
url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + "index.html";
2469-
#ifdef __WXGTK__
2470-
if ( ! context.IsEmpty() )
2471-
url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + context + ".html";
2472-
wxLaunchDefaultBrowser( url );
2473-
return;
2474-
#else
2475-
if ( ! context.IsEmpty() )
2476-
url += "?" + context + ".html";
2467+
CreateAboutHtml();
2468+
2469+
#ifdef __WXMSW__
2470+
SetIcon(wxICON(appicon));
24772471
#endif
2472+
2473+
SetBackgroundColour(wxMetroTheme::Colour(wxMT_FOREGROUND));
2474+
2475+
m_htmlView = new wxHtmlWindow(this, ID_BROWSER);
2476+
m_htmlView->SetPage(m_aboutHtml);
2477+
2478+
wxBoxSizer* tools = new wxBoxSizer(wxHORIZONTAL);
2479+
tools->AddStretchSpacer();
2480+
tools->Add( new wxMetroButton( this, ID_RELEASE_NOTES, "Open NLR release notes..." ), 0, wxALL|wxEXPAND, 0 );
2481+
2482+
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
2483+
sizer->Add( tools, 0, wxALL|wxEXPAND, 0 );
2484+
sizer->Add(m_htmlView, 1, wxALL | wxEXPAND, 0);
2485+
SetSizer(sizer);
24782486
}
24792487

2480-
wxWindow *modal_active = 0;
2481-
wxWindow *nonmodal_tlw = 0;
2482-
for( wxWindowList::iterator wl = wxTopLevelWindows.begin();
2483-
wl != wxTopLevelWindows.end();
2484-
++wl )
2488+
void CreateAboutHtml()
24852489
{
2486-
wxTopLevelWindow *tlw = dynamic_cast<wxTopLevelWindow*>( *wl );
2487-
wxDialog *dia = dynamic_cast<wxDialog*>( *wl );
2488-
2489-
if ( tlw != 0 && (dia == 0 || !dia->IsModal()) )
2490-
nonmodal_tlw = tlw;
2490+
m_aboutHtml = SamApp::AboutSAM();
2491+
}
24912492

2492-
if ( dia != 0 && dia->IsActive() && dia->IsModal() )
2493-
modal_active = dia;
2493+
void LoadPage(wxString url)
2494+
{
2495+
if (url == ":about")
2496+
{
2497+
m_htmlView->SetPage(m_aboutHtml);
2498+
}
2499+
else if (url == ":release_notes")
2500+
{
2501+
wxLaunchDefaultBrowser(SamApp::WebApi("release_notes"));
2502+
}
2503+
else
2504+
{
2505+
wxLaunchDefaultBrowser(url);
2506+
}
24942507
}
24952508

2496-
// try several different parent windows for the help window
2497-
// if possible, use the SAM main window
2498-
// otherwise, choose any top level window that is not modal
2499-
// last resort, choose a currently modal dialog box
2500-
wxWindow *parent = SamApp::Window();
2501-
if ( !parent ) parent = nonmodal_tlw;
2502-
if ( !parent ) parent = modal_active;
25032509

2504-
if ( modal_active && gs_helpWin != 0 && gs_helpWin->IsShown() )
2510+
void OnClose(wxCloseEvent& evt)
25052511
{
2506-
wxRect h_rect = gs_helpWin->GetRect();
2512+
Hide();
2513+
evt.Veto();
2514+
}
25072515

2508-
if (gs_helpWin->Destroy())
2516+
void OnCommand(wxCommandEvent& evt)
2517+
{
2518+
switch (evt.GetId())
25092519
{
2510-
gs_helpWin = new HelpWin( parent );
2511-
gs_helpWin->SetSize(h_rect);
2520+
case ID_RELEASE_NOTES:
2521+
LoadPage(":release_notes");
2522+
break;
25122523
}
25132524
}
2514-
else if ( 0 == gs_helpWin )
2515-
gs_helpWin = new HelpWin( parent );
25162525

2517-
gs_helpWin->Show( );
2518-
gs_helpWin->LoadPage( url );
2519-
gs_helpWin->Raise();
2526+
DECLARE_EVENT_TABLE();
2527+
};
2528+
2529+
BEGIN_EVENT_TABLE(HelpWin, wxFrame)
2530+
EVT_BUTTON(ID_RELEASE_NOTES, HelpWin::OnCommand)
2531+
EVT_CLOSE(HelpWin::OnClose)
2532+
END_EVENT_TABLE()
2533+
2534+
class HelpWin;
2535+
static HelpWin* gs_helpWin = 0;
2536+
2537+
void SamApp::ShowHelp( const wxString &help_context )
2538+
{
2539+
wxString url;
2540+
url = help_context;
2541+
if ( url.Left(1) == ":" ) // display things like :about in custom window
2542+
{
2543+
wxWindow *modal_active = 0;
2544+
wxWindow *nonmodal_tlw = 0;
2545+
for( wxWindowList::iterator wl = wxTopLevelWindows.begin(); wl != wxTopLevelWindows.end(); ++wl )
2546+
{
2547+
wxTopLevelWindow *tlw = dynamic_cast<wxTopLevelWindow*>( *wl );
2548+
wxDialog *dia = dynamic_cast<wxDialog*>( *wl );
2549+
2550+
if ( tlw != 0 && (dia == 0 || !dia->IsModal()) )
2551+
nonmodal_tlw = tlw;
2552+
2553+
if ( dia != 0 && dia->IsActive() && dia->IsModal() )
2554+
modal_active = dia;
2555+
}
2556+
2557+
// try several different parent windows for the help window
2558+
// if possible, use the SAM main window
2559+
// otherwise, choose any top level window that is not modal
2560+
// last resort, choose a currently modal dialog box
2561+
wxWindow *parent = SamApp::Window();
2562+
if ( !parent ) parent = nonmodal_tlw;
2563+
if ( !parent ) parent = modal_active;
2564+
2565+
if ( modal_active && gs_helpWin != 0 && gs_helpWin->IsShown() )
2566+
{
2567+
wxRect h_rect = gs_helpWin->GetRect();
2568+
2569+
if (gs_helpWin->Destroy())
2570+
{
2571+
gs_helpWin = new HelpWin( parent );
2572+
gs_helpWin->SetSize(h_rect);
2573+
}
2574+
}
2575+
else if ( 0 == gs_helpWin )
2576+
gs_helpWin = new HelpWin( parent );
2577+
2578+
gs_helpWin->Show( );
2579+
gs_helpWin->LoadPage( url );
2580+
gs_helpWin->Raise();
2581+
}
2582+
else // display help topics in default browser
2583+
{
2584+
wxFileName fn( SamApp::GetRuntimePath() + "/help/html/" );
2585+
fn.MakeAbsolute();
2586+
if ( help_context.IsEmpty() )
2587+
url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + "index.html";
2588+
else
2589+
url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + help_context + ".html";
2590+
wxLaunchDefaultBrowser( url );
2591+
}
2592+
25202593
}
25212594

25222595
int SamApp::RevisionNumber()

src/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ class SamApp : public wxApp
375375
static wxFileHistory &FileHistory();
376376
static wxArrayString RecentFiles();
377377
static void ShowHelp( const wxString &context = wxEmptyString );
378+
static wxString AboutSAM();
378379
static wxString VersionStr( bool with_patches = false, bool short_style = false );
379380
static int VersionMajor();
380381
static int VersionMinor();

0 commit comments

Comments
 (0)