Skip to content

Commit 4107c86

Browse files
committed
Move HelpWin to main.cpp
1 parent 60b2cb7 commit 4107c86

File tree

3 files changed

+179
-8
lines changed

3 files changed

+179
-8
lines changed

src/main.cpp

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,148 @@ wxArrayString SamApp::RecentFiles()
24572457
return files;
24582458
}
24592459

2460+
class HelpWin : public wxFrame
2461+
{
2462+
wxHtmlWindow* m_htmlView;
2463+
2464+
wxString m_aboutHtml;
2465+
public:
2466+
HelpWin(wxWindow* parent)
2467+
: wxFrame(parent, wxID_ANY, "About System Advisor Model (SAM)", wxDefaultPosition, wxScaleSize(1000, 600))
2468+
{
2469+
CreateAboutHtml();
2470+
2471+
SetBackgroundColour(wxMetroTheme::Colour(wxMT_FOREGROUND));
2472+
2473+
m_htmlView = new wxHtmlWindow(this, ID_BROWSER);
2474+
m_htmlView->SetPage(m_aboutHtml);
2475+
2476+
wxBoxSizer* tools = new wxBoxSizer(wxHORIZONTAL);
2477+
// tools->Add( new wxMetroButton( this, ID_HOME, "Home" ), 0, wxALL|wxEXPAND, 0 );
2478+
// tools->Add( new wxMetroButton( this, ID_WEBSITE, "Web site" ), 0, wxALL|wxEXPAND, 0 );
2479+
// tools->Add( new wxMetroButton( this, ID_FORUM, "Forum" ), 0, wxALL|wxEXPAND, 0 );
2480+
// tools->Add( new wxMetroButton( this, ID_EMAIL_SUPPORT, "Email support" ), 0, wxALL|wxEXPAND, 0 );
2481+
tools->AddStretchSpacer();
2482+
tools->Add( new wxMetroButton( this, ID_RELEASE_NOTES, "Release Notes" ), 0, wxALL|wxEXPAND, 0 );
2483+
// tools->Add( new wxMetroButton( this, ID_SCRIPT_REFERENCE, "Scripting reference" ), 0, wxALL|wxEXPAND, 0 );
2484+
// tools->Add( new wxMetroButton( this, wxID_ABOUT, "About" ), 0, wxALL|wxEXPAND, 0 );
2485+
// tools->Add( new wxMetroButton( this, wxID_CLOSE, "Close" ), 0, wxALL|wxEXPAND, 0 );
2486+
2487+
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
2488+
sizer->Add( tools, 0, wxALL|wxEXPAND, 0 );
2489+
sizer->Add(m_htmlView, 1, wxALL | wxEXPAND, 0);
2490+
SetSizer(sizer);
2491+
}
2492+
2493+
void CreateAboutHtml()
2494+
{
2495+
m_aboutHtml = SamApp::AboutSAM();
2496+
}
2497+
2498+
void LoadPage(wxString url)
2499+
{
2500+
if (url == ":about")
2501+
{
2502+
m_htmlView->SetPage(m_aboutHtml);
2503+
return;
2504+
}
2505+
else if (url == ":release_notes")
2506+
{
2507+
url = SamApp::WebApi("release_notes");
2508+
}
2509+
else if (url == ":email_support")
2510+
{
2511+
wxLaunchDefaultBrowser(SamApp::WebApi("support_email"));
2512+
return;
2513+
}
2514+
else if (url == ":script_ref")
2515+
{
2516+
wxFileName file(SamApp::GetRuntimePath() + "/help/lk_guide.pdf");
2517+
file.Normalize();
2518+
wxLaunchDefaultBrowser(file.GetFullPath());
2519+
return;
2520+
}
2521+
else if (url == ":forum")
2522+
url = SamApp::WebApi("website") + "/forum.html";
2523+
else if (url == ":website")
2524+
url = SamApp::WebApi("website");
2525+
2526+
wxLaunchDefaultBrowser(url);
2527+
}
2528+
2529+
2530+
void OnClose(wxCloseEvent& evt)
2531+
{
2532+
Hide();
2533+
evt.Veto();
2534+
}
2535+
2536+
void OnCommand(wxCommandEvent& evt)
2537+
{
2538+
switch (evt.GetId())
2539+
{
2540+
case ID_BACK:
2541+
break;
2542+
case ID_WEBSITE:
2543+
LoadPage(":website");
2544+
break;
2545+
case ID_FORUM:
2546+
LoadPage(":forum");
2547+
break;
2548+
case ID_EMAIL_SUPPORT:
2549+
LoadPage(":email_support");
2550+
break;
2551+
case ID_RELEASE_NOTES:
2552+
LoadPage(":release_notes");
2553+
break;
2554+
case ID_SCRIPT_REFERENCE:
2555+
LoadPage(":script_ref");
2556+
break;
2557+
case ID_HOME:
2558+
{
2559+
wxFileName fn(SamApp::GetRuntimePath() + "/help/html/index.html");
2560+
fn.MakeAbsolute();
2561+
LoadPage("file:///" + fn.GetFullPath());
2562+
}
2563+
break;
2564+
case wxID_ABOUT:
2565+
LoadPage(":about");
2566+
break;
2567+
case wxID_CLOSE:
2568+
Close();
2569+
break;
2570+
}
2571+
}
2572+
2573+
#if defined(__WXMSW__)||defined(__WXOSX__)
2574+
void OnNewWindow(wxWebViewEvent& evt)
2575+
{
2576+
wxLaunchDefaultBrowser(evt.GetURL());
2577+
}
2578+
#endif
2579+
2580+
DECLARE_EVENT_TABLE();
2581+
};
2582+
2583+
BEGIN_EVENT_TABLE(HelpWin, wxFrame)
2584+
EVT_BUTTON(ID_BACK, HelpWin::OnCommand)
2585+
EVT_BUTTON(ID_HOME, HelpWin::OnCommand)
2586+
EVT_BUTTON(ID_WEBSITE, HelpWin::OnCommand)
2587+
EVT_BUTTON(ID_FORUM, HelpWin::OnCommand)
2588+
EVT_BUTTON(ID_RELEASE_NOTES, HelpWin::OnCommand)
2589+
EVT_BUTTON(ID_SCRIPT_REFERENCE, HelpWin::OnCommand)
2590+
EVT_BUTTON(ID_EMAIL_SUPPORT, HelpWin::OnCommand)
2591+
EVT_BUTTON(wxID_CLOSE, HelpWin::OnCommand)
2592+
EVT_BUTTON(wxID_ABOUT, HelpWin::OnCommand)
2593+
#if defined(__WXMSW__)||defined(__WXOSX__)
2594+
EVT_WEBVIEW_NEWWINDOW(ID_BROWSER, HelpWin::OnNewWindow)
2595+
#endif
2596+
EVT_CLOSE(HelpWin::OnClose)
2597+
END_EVENT_TABLE()
2598+
2599+
class HelpWin;
2600+
static HelpWin* gs_helpWin = 0;
2601+
24602602
void SamApp::ShowHelp( const wxString &context )
24612603
{
24622604
wxString url;

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();

src/main_add.h

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ extern void RegisterReportObjectTypes();
470470
}
471471

472472

473-
473+
/*
474474
class HelpWin : public wxFrame
475475
{
476476
wxHtmlWindow *m_htmlView;
@@ -486,18 +486,18 @@ class HelpWin : public wxFrame
486486
487487
m_htmlView = new wxHtmlWindow( this, ID_BROWSER );
488488
m_htmlView->SetPage( m_aboutHtml );
489-
/*
490-
wxBoxSizer* tools = new wxBoxSizer(wxHORIZONTAL);
491-
tools->Add( new wxMetroButton( this, ID_HOME, "Home" ), 0, wxALL|wxEXPAND, 0 );
489+
490+
//// wxBoxSizer* tools = new wxBoxSizer(wxHORIZONTAL);
491+
//// tools->Add( new wxMetroButton( this, ID_HOME, "Home" ), 0, wxALL|wxEXPAND, 0 );
492492
// tools->Add( new wxMetroButton( this, ID_WEBSITE, "Web site" ), 0, wxALL|wxEXPAND, 0 );
493493
// tools->Add( new wxMetroButton( this, ID_FORUM, "Forum" ), 0, wxALL|wxEXPAND, 0 );
494494
// tools->Add( new wxMetroButton( this, ID_EMAIL_SUPPORT, "Email support" ), 0, wxALL|wxEXPAND, 0 );
495495
// tools->Add( new wxMetroButton( this, ID_RELEASE_NOTES, "Release notes" ), 0, wxALL|wxEXPAND, 0 );
496496
// tools->Add( new wxMetroButton( this, ID_SCRIPT_REFERENCE, "Scripting reference" ), 0, wxALL|wxEXPAND, 0 );
497-
tools->AddStretchSpacer();
498-
tools->Add( new wxMetroButton( this, wxID_ABOUT, "About" ), 0, wxALL|wxEXPAND, 0 );
499-
tools->Add( new wxMetroButton( this, wxID_CLOSE, "Close" ), 0, wxALL|wxEXPAND, 0 );
500-
*/
497+
//// tools->AddStretchSpacer();
498+
//// tools->Add( new wxMetroButton( this, wxID_ABOUT, "About" ), 0, wxALL|wxEXPAND, 0 );
499+
//// tools->Add( new wxMetroButton( this, wxID_CLOSE, "Close" ), 0, wxALL|wxEXPAND, 0 );
500+
501501
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
502502
//sizer->Add( tools, 0, wxALL|wxEXPAND, 0 );
503503
sizer->Add( m_htmlView, 1, wxALL|wxEXPAND, 0 );
@@ -635,3 +635,31 @@ END_EVENT_TABLE()
635635
636636
class HelpWin;
637637
static HelpWin* gs_helpWin = 0;
638+
*/
639+
wxString SamApp::AboutSAM()
640+
{
641+
642+
wxString proxy(wxEasyCurl::GetProxyForURL(SamApp::WebApi("website")));
643+
if (proxy.IsEmpty()) proxy = "default";
644+
else proxy = "proxy: " + proxy;
645+
646+
int patch = SamApp::RevisionNumber();
647+
wxString patchStr;
648+
if (patch > 0)
649+
patchStr.Printf(", updated to revision %d", patch);
650+
651+
// int nbit = (sizeof(void*) == 8) ? 64 : 32;
652+
return "<html><body>"
653+
"<h1>System Advisor Model (SAM)</h1>"
654+
"<h2>Open Source Build</h2>"
655+
"<p>BSD 3-Clause License<br><br>Copyright (c) Alliance for Sustainable Energy, LLC. See also https://github.com/NREL/SAM/blob/develop/LICENSE.</p>"
656+
"<p>All rights reserved.</p>"
657+
"<p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:</p>"
658+
"<ol>"
659+
"<li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</li>"
660+
"<li>Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.</li>"
661+
"<li>Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.</li>"
662+
"</ol>"
663+
"<p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>"
664+
"</body></html>";
665+
}

0 commit comments

Comments
 (0)