Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 135 additions & 62 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <set>
//#include <chrono>
#include <fstream>

#include <wx/wx.h>
#include <wx/frame.h>
#include <wx/stc/stc.h>
#include <fstream>

#if defined(__WXMSW__)||defined(__WXOSX__)
#include <wx/webview.h>
#else
#include <wx/html/htmlwin.h> // for linux - avoid webkitgtk dependencies
#endif

#include <wx/html/htmlwin.h>
#include <wx/simplebook.h>
#include <wx/panel.h>
#include <wx/busyinfo.h>
Expand All @@ -53,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <wx/datstrm.h>
#include <wx/grid.h>
#include <wx/stdpaths.h>
#include <wx/webview.h>
#include <wx/txtstrm.h>
#include <wx/buffer.h>
#include <wx/display.h>
Expand All @@ -66,7 +59,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <wex/icons/qmark.cpng>
#include <wex/utils.h>


#include "../resource/menu.cpng"
#include "../resource/notes_white.cpng"

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

static PythonConfig pythonConfig;


enum { __idFirst = wxID_HIGHEST+592,

ID_MAIN_MENU, ID_CASE_TABS, ID_PAGE_NOTES,
ID_CASE_CREATE, ID_RUN_ALL_CASES, ID_SAVE_HOURLY,
ID_MAIN_MENU,
ID_CASE_TABS,
ID_PAGE_NOTES,
ID_RELEASE_NOTES,
ID_BROWSER,
ID_CASE_CREATE,
ID_RUN_ALL_CASES,
ID_SAVE_HOURLY,
ID_IMPORT_CASES,
ID_NEW_SCRIPT, ID_OPEN_SCRIPT, ID_BROWSE_INPUTS,
ID_NEW_SCRIPT,
ID_OPEN_SCRIPT,
ID_BROWSE_INPUTS,
__idCaseMenuFirst,
ID_CASE_CONFIG,
ID_CASE_RENAME,
Expand All @@ -137,8 +136,6 @@ enum { __idFirst = wxID_HIGHEST+592,

BEGIN_EVENT_TABLE( MainWindow, wxFrame )
EVT_CLOSE( MainWindow::OnClose )
EVT_MENU( wxID_ABOUT, MainWindow::OnCommand )
EVT_MENU( wxID_HELP, MainWindow::OnCommand )
EVT_MENU( ID_SAVE_HOURLY, MainWindow::OnCommand )
EVT_MENU( ID_IMPORT_CASES, MainWindow::OnCommand )
EVT_MENU( wxID_NEW, MainWindow::OnCommand )
Expand All @@ -156,6 +153,7 @@ BEGIN_EVENT_TABLE( MainWindow, wxFrame )
EVT_BUTTON(ID_MAIN_MENU, MainWindow::OnCommand)
EVT_LISTBOX( ID_CASE_TABS, MainWindow::OnCaseTabChange )
EVT_BUTTON( ID_CASE_TABS, MainWindow::OnCaseTabButton )
EVT_BUTTON(wxID_ABOUT, MainWindow::OnCommand)
EVT_BUTTON( wxID_HELP, MainWindow::OnCommand )
EVT_BUTTON( ID_PAGE_NOTES, MainWindow::OnCommand )
EVT_MENU_RANGE( __idCaseMenuFirst, __idCaseMenuLast, MainWindow::OnCaseMenu )
Expand Down Expand Up @@ -238,7 +236,8 @@ MainWindow::MainWindow()
tools->Add( metbut = new wxMetroButton( m_caseTabPanel, ID_PAGE_NOTES, wxEmptyString, wxBITMAP_PNG_FROM_DATA( notes_white ), wxDefaultPosition, wxDefaultSize), 0, wxALL|wxEXPAND, 0 );
metbut->SetToolTip( "Add a page note" );

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

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

Expand Down Expand Up @@ -2456,67 +2455,141 @@ wxArrayString SamApp::RecentFiles()
return files;
}

void SamApp::ShowHelp( const wxString &context )
class HelpWin : public wxFrame
{
wxString url;
if ( context.Left(1) == ":" )
url = context; // for things like :about, etc
else
wxHtmlWindow* m_htmlView;

wxString m_aboutHtml;
public:
HelpWin(wxWindow* parent)
: wxFrame(parent, wxID_ANY, "About System Advisor Model (SAM)", wxDefaultPosition, wxScaleSize(1000, 600))
{
wxFileName fn( SamApp::GetRuntimePath() + "/help/html/" );
fn.MakeAbsolute();
url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + "index.html";
#ifdef __WXGTK__
if ( ! context.IsEmpty() )
url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + context + ".html";
wxLaunchDefaultBrowser( url );
return;
#else
if ( ! context.IsEmpty() )
url += "?" + context + ".html";
CreateAboutHtml();

#ifdef __WXMSW__
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding!

SetIcon(wxICON(appicon));
#endif

SetBackgroundColour(wxMetroTheme::Colour(wxMT_FOREGROUND));

m_htmlView = new wxHtmlWindow(this, ID_BROWSER);
m_htmlView->SetPage(m_aboutHtml);

wxBoxSizer* tools = new wxBoxSizer(wxHORIZONTAL);
tools->AddStretchSpacer();
tools->Add( new wxMetroButton( this, ID_RELEASE_NOTES, "Open NLR release notes..." ), 0, wxALL|wxEXPAND, 0 );

wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add( tools, 0, wxALL|wxEXPAND, 0 );
sizer->Add(m_htmlView, 1, wxALL | wxEXPAND, 0);
SetSizer(sizer);
}

wxWindow *modal_active = 0;
wxWindow *nonmodal_tlw = 0;
for( wxWindowList::iterator wl = wxTopLevelWindows.begin();
wl != wxTopLevelWindows.end();
++wl )
void CreateAboutHtml()
{
wxTopLevelWindow *tlw = dynamic_cast<wxTopLevelWindow*>( *wl );
wxDialog *dia = dynamic_cast<wxDialog*>( *wl );

if ( tlw != 0 && (dia == 0 || !dia->IsModal()) )
nonmodal_tlw = tlw;
m_aboutHtml = SamApp::AboutSAM();
}

if ( dia != 0 && dia->IsActive() && dia->IsModal() )
modal_active = dia;
void LoadPage(wxString url)
{
if (url == ":about")
{
m_htmlView->SetPage(m_aboutHtml);
}
else if (url == ":release_notes")
{
wxLaunchDefaultBrowser(SamApp::WebApi("release_notes"));
}
else
{
wxLaunchDefaultBrowser(url);
}
}

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

if ( modal_active && gs_helpWin != 0 && gs_helpWin->IsShown() )
void OnClose(wxCloseEvent& evt)
{
wxRect h_rect = gs_helpWin->GetRect();
Hide();
evt.Veto();
}

if (gs_helpWin->Destroy())
void OnCommand(wxCommandEvent& evt)
{
switch (evt.GetId())
{
gs_helpWin = new HelpWin( parent );
gs_helpWin->SetSize(h_rect);
case ID_RELEASE_NOTES:
LoadPage(":release_notes");
break;
}
}
else if ( 0 == gs_helpWin )
gs_helpWin = new HelpWin( parent );

gs_helpWin->Show( );
gs_helpWin->LoadPage( url );
gs_helpWin->Raise();
DECLARE_EVENT_TABLE();
};

BEGIN_EVENT_TABLE(HelpWin, wxFrame)
EVT_BUTTON(ID_RELEASE_NOTES, HelpWin::OnCommand)
EVT_CLOSE(HelpWin::OnClose)
END_EVENT_TABLE()

class HelpWin;
static HelpWin* gs_helpWin = 0;

void SamApp::ShowHelp( const wxString &help_context )
{
wxString url;
url = help_context;
if ( url.Left(1) == ":" ) // display things like :about in custom window
{
wxWindow *modal_active = 0;
wxWindow *nonmodal_tlw = 0;
for( wxWindowList::iterator wl = wxTopLevelWindows.begin(); wl != wxTopLevelWindows.end(); ++wl )
{
wxTopLevelWindow *tlw = dynamic_cast<wxTopLevelWindow*>( *wl );
wxDialog *dia = dynamic_cast<wxDialog*>( *wl );

if ( tlw != 0 && (dia == 0 || !dia->IsModal()) )
nonmodal_tlw = tlw;

if ( dia != 0 && dia->IsActive() && dia->IsModal() )
modal_active = dia;
}

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

if ( modal_active && gs_helpWin != 0 && gs_helpWin->IsShown() )
{
wxRect h_rect = gs_helpWin->GetRect();

if (gs_helpWin->Destroy())
{
gs_helpWin = new HelpWin( parent );
gs_helpWin->SetSize(h_rect);
}
}
else if ( 0 == gs_helpWin )
gs_helpWin = new HelpWin( parent );

gs_helpWin->Show( );
gs_helpWin->LoadPage( url );
gs_helpWin->Raise();
}
else // display help topics in default browser
{
wxFileName fn( SamApp::GetRuntimePath() + "/help/html/" );
fn.MakeAbsolute();
if ( help_context.IsEmpty() )
url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + "index.html";
else
url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + help_context + ".html";
wxLaunchDefaultBrowser( url );
}

}

int SamApp::RevisionNumber()
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ class SamApp : public wxApp
static wxFileHistory &FileHistory();
static wxArrayString RecentFiles();
static void ShowHelp( const wxString &context = wxEmptyString );
static wxString AboutSAM();
static wxString VersionStr( bool with_patches = false, bool short_style = false );
static int VersionMajor();
static int VersionMinor();
Expand Down
Loading
Loading