2018-05-14 17:34:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-01-08 19:26:10 +00:00
|
|
|
* Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-05-14 17:34:18 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <confirm.h>
|
2020-07-15 23:08:16 +00:00
|
|
|
#include <widgets/resettable_panel.h>
|
2023-05-10 17:13:52 +00:00
|
|
|
#include <widgets/wx_infobar.h>
|
|
|
|
#include <widgets/wx_panel.h>
|
|
|
|
#include <widgets/paged_dialog.h>
|
|
|
|
#include <widgets/wx_treebook.h>
|
2024-04-27 19:57:24 +00:00
|
|
|
#include <widgets/ui_common.h>
|
2023-05-10 17:13:52 +00:00
|
|
|
|
2021-06-03 01:19:20 +00:00
|
|
|
#include <wx/button.h>
|
2018-05-14 17:34:18 +00:00
|
|
|
#include <wx/grid.h>
|
2021-06-03 01:19:20 +00:00
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/treebook.h>
|
|
|
|
#include <wx/treectrl.h>
|
2023-05-10 17:13:52 +00:00
|
|
|
#include <wx/listctrl.h>
|
2020-05-24 14:54:26 +00:00
|
|
|
#include <wx/stc/stc.h>
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2023-09-23 23:53:22 +00:00
|
|
|
#include <paths.h>
|
2023-07-13 14:10:31 +00:00
|
|
|
|
|
|
|
#include <launch_ext.h>
|
|
|
|
|
2020-07-11 09:37:22 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2018-05-14 17:34:18 +00:00
|
|
|
// Maps from dialogTitle <-> pageTitle for keeping track of last-selected pages.
|
|
|
|
// This is not a simple page index because some dialogs have dynamic page sets.
|
|
|
|
std::map<wxString, wxString> g_lastPage;
|
|
|
|
std::map<wxString, wxString> g_lastParentPage;
|
|
|
|
|
|
|
|
|
2023-07-13 14:10:31 +00:00
|
|
|
PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aShowReset, bool aShowOpenFolder,
|
2023-06-16 14:42:15 +00:00
|
|
|
const wxString& aAuxiliaryAction, const wxSize& aInitialSize ) :
|
|
|
|
DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, aInitialSize,
|
2018-05-14 17:34:18 +00:00
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
|
2021-06-03 17:08:29 +00:00
|
|
|
m_auxiliaryButton( nullptr ),
|
|
|
|
m_resetButton( nullptr ),
|
2023-07-16 18:29:38 +00:00
|
|
|
m_openPrefsDirButton( nullptr ),
|
2022-09-10 08:12:22 +00:00
|
|
|
m_title( aTitle )
|
2018-05-14 17:34:18 +00:00
|
|
|
{
|
2023-01-11 01:00:47 +00:00
|
|
|
wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
|
2018-05-14 17:34:18 +00:00
|
|
|
SetSizer( mainSizer );
|
|
|
|
|
2020-08-25 02:17:21 +00:00
|
|
|
m_infoBar = new WX_INFOBAR( this );
|
|
|
|
mainSizer->Add( m_infoBar, 0, wxEXPAND, 0 );
|
|
|
|
|
2023-01-11 01:00:47 +00:00
|
|
|
WX_PANEL* treebookPanel = new WX_PANEL( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxBORDER_NONE | wxTAB_TRAVERSAL );
|
|
|
|
treebookPanel->SetBorders( false, false, false, true );
|
|
|
|
wxBoxSizer* treebookSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
treebookPanel->SetSizer( treebookSizer );
|
|
|
|
|
2023-05-10 17:13:52 +00:00
|
|
|
m_treebook = new WX_TREEBOOK( treebookPanel, wxID_ANY );
|
2021-09-12 11:17:22 +00:00
|
|
|
m_treebook->SetFont( KIUI::GetControlFont( this ) );
|
2023-06-16 14:56:01 +00:00
|
|
|
m_treebook->SetFitToCurrentPage( true );
|
2023-01-11 01:00:47 +00:00
|
|
|
|
|
|
|
long treeCtrlFlags = m_treebook->GetTreeCtrl()->GetWindowStyleFlag();
|
|
|
|
treeCtrlFlags = ( treeCtrlFlags & ~wxBORDER_MASK ) | wxBORDER_NONE;
|
|
|
|
m_treebook->GetTreeCtrl()->SetWindowStyleFlag( treeCtrlFlags );
|
|
|
|
|
|
|
|
treebookSizer->Add( m_treebook, 1, wxEXPAND|wxBOTTOM, 2 );
|
|
|
|
mainSizer->Add( treebookPanel, 1, wxEXPAND, 0 );
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2021-02-12 03:19:46 +00:00
|
|
|
m_buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2021-03-16 14:28:01 +00:00
|
|
|
if( aShowReset )
|
2020-07-15 23:08:16 +00:00
|
|
|
{
|
|
|
|
m_resetButton = new wxButton( this, wxID_ANY, _( "Reset to Defaults" ) );
|
2021-03-20 00:01:02 +00:00
|
|
|
m_buttonsSizer->Add( m_resetButton, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
|
2020-07-15 23:08:16 +00:00
|
|
|
}
|
|
|
|
|
2023-07-13 14:10:31 +00:00
|
|
|
if( aShowOpenFolder )
|
|
|
|
{
|
2023-07-16 18:29:38 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
m_openPrefsDirButton = new wxButton( this, wxID_ANY, _( "Reveal Preferences in Finder" ) );
|
|
|
|
#else
|
|
|
|
m_openPrefsDirButton = new wxButton( this, wxID_ANY, _( "Open Preferences Directory" ) );
|
|
|
|
#endif
|
|
|
|
m_buttonsSizer->Add( m_openPrefsDirButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, 5 );
|
2023-07-13 14:10:31 +00:00
|
|
|
}
|
|
|
|
|
2023-07-16 19:47:27 +00:00
|
|
|
|
2018-05-14 17:34:18 +00:00
|
|
|
if( !aAuxiliaryAction.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_auxiliaryButton = new wxButton( this, wxID_ANY, aAuxiliaryAction );
|
2021-03-16 14:28:01 +00:00
|
|
|
m_buttonsSizer->Add( m_auxiliaryButton, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
|
2018-05-14 17:34:18 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 03:19:46 +00:00
|
|
|
m_buttonsSizer->AddStretchSpacer();
|
2020-07-15 23:08:16 +00:00
|
|
|
|
2021-03-16 14:28:01 +00:00
|
|
|
wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
|
2020-07-15 23:08:16 +00:00
|
|
|
wxButton* sdbSizerOK = new wxButton( this, wxID_OK );
|
2018-05-14 17:34:18 +00:00
|
|
|
sdbSizer->AddButton( sdbSizerOK );
|
2020-07-15 23:08:16 +00:00
|
|
|
wxButton* sdbSizerCancel = new wxButton( this, wxID_CANCEL );
|
2018-05-14 17:34:18 +00:00
|
|
|
sdbSizer->AddButton( sdbSizerCancel );
|
|
|
|
sdbSizer->Realize();
|
|
|
|
|
2021-02-12 03:19:46 +00:00
|
|
|
m_buttonsSizer->Add( sdbSizer, 1, 0, 5 );
|
|
|
|
mainSizer->Add( m_buttonsSizer, 0, wxALL|wxEXPAND, 5 );
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2018-05-14 17:34:18 +00:00
|
|
|
|
|
|
|
// We normally save the dialog size and position based on its class-name. This class
|
|
|
|
// substitutes the title so that each distinctly-titled dialog can have its own saved
|
|
|
|
// size and position.
|
|
|
|
m_hash_key = aTitle;
|
|
|
|
|
|
|
|
if( m_auxiliaryButton )
|
2021-03-16 14:28:01 +00:00
|
|
|
{
|
2022-09-10 08:12:22 +00:00
|
|
|
m_auxiliaryButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onAuxiliaryAction,
|
2021-12-27 23:40:12 +00:00
|
|
|
this );
|
2021-03-16 14:28:01 +00:00
|
|
|
}
|
2020-04-02 12:50:58 +00:00
|
|
|
|
2020-07-15 23:08:16 +00:00
|
|
|
if( m_resetButton )
|
2021-03-16 14:28:01 +00:00
|
|
|
{
|
2022-09-10 08:12:22 +00:00
|
|
|
m_resetButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onResetButton, this );
|
2021-03-16 14:28:01 +00:00
|
|
|
}
|
2020-07-15 23:08:16 +00:00
|
|
|
|
2023-07-16 18:29:38 +00:00
|
|
|
if( m_openPrefsDirButton )
|
2023-07-13 14:10:31 +00:00
|
|
|
{
|
2023-07-16 18:29:38 +00:00
|
|
|
m_openPrefsDirButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onOpenPreferencesButton, this );
|
2023-07-13 14:10:31 +00:00
|
|
|
}
|
|
|
|
|
2022-09-10 08:12:22 +00:00
|
|
|
m_treebook->Bind( wxEVT_CHAR_HOOK, &PAGED_DIALOG::onCharHook, this );
|
|
|
|
m_treebook->Bind( wxEVT_TREEBOOK_PAGE_CHANGED, &PAGED_DIALOG::onPageChanged, this );
|
|
|
|
m_treebook->Bind( wxEVT_TREEBOOK_PAGE_CHANGING, &PAGED_DIALOG::onPageChanging, this );
|
2018-05-14 17:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PAGED_DIALOG::finishInitialization()
|
|
|
|
{
|
2022-09-24 22:22:05 +00:00
|
|
|
for( size_t i = 1; i < m_treebook->GetPageCount(); ++i )
|
|
|
|
m_macHack.push_back( true );
|
|
|
|
|
2018-05-14 17:34:18 +00:00
|
|
|
// For some reason adding page labels to the treeCtrl doesn't invalidate its bestSize
|
|
|
|
// cache so we have to do it by hand
|
|
|
|
m_treebook->GetTreeCtrl()->InvalidateBestSize();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
|
|
|
|
m_treebook->GetPage( i )->Layout();
|
|
|
|
|
|
|
|
m_treebook->Layout();
|
2021-12-14 13:14:49 +00:00
|
|
|
m_treebook->Fit();
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2018-05-14 17:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-17 00:33:20 +00:00
|
|
|
void PAGED_DIALOG::SetInitialPage( const wxString& aPage, const wxString& aParentPage )
|
|
|
|
{
|
|
|
|
g_lastPage[ m_title ] = aPage;
|
|
|
|
g_lastParentPage[ m_title ] = aParentPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-14 17:34:18 +00:00
|
|
|
PAGED_DIALOG::~PAGED_DIALOG()
|
|
|
|
{
|
|
|
|
// Store the current parentPageTitle/pageTitle hierarchy so we can re-select it
|
|
|
|
// next time.
|
|
|
|
wxString lastPage = wxEmptyString;
|
|
|
|
wxString lastParentPage = wxEmptyString;
|
|
|
|
|
|
|
|
int selected = m_treebook->GetSelection();
|
|
|
|
|
|
|
|
if( selected != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
lastPage = m_treebook->GetPageText( (unsigned) selected );
|
|
|
|
|
|
|
|
int parent = m_treebook->GetPageParent( (unsigned) selected );
|
|
|
|
|
|
|
|
if( parent != wxNOT_FOUND )
|
|
|
|
lastParentPage = m_treebook->GetPageText( (unsigned) parent );
|
|
|
|
}
|
|
|
|
|
|
|
|
g_lastPage[ m_title ] = lastPage;
|
|
|
|
g_lastParentPage[ m_title ] = lastParentPage;
|
|
|
|
|
|
|
|
if( m_auxiliaryButton )
|
2021-03-16 14:28:01 +00:00
|
|
|
{
|
2022-09-10 08:12:22 +00:00
|
|
|
m_auxiliaryButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onAuxiliaryAction,
|
2021-12-27 23:40:12 +00:00
|
|
|
this );
|
2021-03-16 14:28:01 +00:00
|
|
|
}
|
2020-04-02 12:50:58 +00:00
|
|
|
|
2020-07-15 23:08:16 +00:00
|
|
|
if( m_resetButton )
|
2021-03-16 14:28:01 +00:00
|
|
|
{
|
2022-09-10 08:12:22 +00:00
|
|
|
m_resetButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onResetButton, this );
|
2021-03-16 14:28:01 +00:00
|
|
|
}
|
2020-11-11 14:24:35 +00:00
|
|
|
|
2023-07-16 18:29:38 +00:00
|
|
|
if( m_openPrefsDirButton )
|
2023-07-13 14:10:31 +00:00
|
|
|
{
|
2023-07-16 18:29:38 +00:00
|
|
|
m_openPrefsDirButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onOpenPreferencesButton, this );
|
2023-07-13 14:10:31 +00:00
|
|
|
}
|
|
|
|
|
2022-09-10 08:12:22 +00:00
|
|
|
m_treebook->Unbind( wxEVT_CHAR_HOOK, &PAGED_DIALOG::onCharHook, this );
|
|
|
|
m_treebook->Unbind( wxEVT_TREEBOOK_PAGE_CHANGED, &PAGED_DIALOG::onPageChanged, this );
|
|
|
|
m_treebook->Unbind( wxEVT_TREEBOOK_PAGE_CHANGING, &PAGED_DIALOG::onPageChanging, this );
|
2018-05-14 17:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PAGED_DIALOG::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
finishInitialization();
|
|
|
|
|
2019-07-17 14:46:25 +00:00
|
|
|
// Call TransferDataToWindow() only once:
|
|
|
|
// this is enough on wxWidgets 3.1
|
2018-05-14 17:34:18 +00:00
|
|
|
if( !DIALOG_SHIM::TransferDataToWindow() )
|
|
|
|
return false;
|
2019-07-17 14:46:25 +00:00
|
|
|
|
2018-05-14 17:34:18 +00:00
|
|
|
// Search for a page matching the lastParentPageTitle/lastPageTitle hierarchy
|
|
|
|
wxString lastPage = g_lastPage[ m_title ];
|
|
|
|
wxString lastParentPage = g_lastParentPage[ m_title ];
|
|
|
|
int lastPageIndex = wxNOT_FOUND;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
|
|
|
|
{
|
|
|
|
if( m_treebook->GetPageText( i ) == lastPage )
|
|
|
|
{
|
2018-11-17 00:33:20 +00:00
|
|
|
if( lastParentPage.IsEmpty() )
|
2018-05-14 17:34:18 +00:00
|
|
|
{
|
2018-11-17 00:33:20 +00:00
|
|
|
lastPageIndex = i;
|
|
|
|
break;
|
2018-05-14 17:34:18 +00:00
|
|
|
}
|
2018-11-17 00:33:20 +00:00
|
|
|
|
|
|
|
if( m_treebook->GetPageParent( i ) >= 0
|
|
|
|
&& m_treebook->GetPageText( (unsigned) m_treebook->GetPageParent( i ) ) == lastParentPage )
|
2018-05-14 17:34:18 +00:00
|
|
|
{
|
2018-11-17 00:33:20 +00:00
|
|
|
lastPageIndex = i;
|
|
|
|
break;
|
2018-05-14 17:34:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-14 21:18:04 +00:00
|
|
|
lastPageIndex = std::max( 0, lastPageIndex );
|
2023-06-16 14:56:01 +00:00
|
|
|
m_treebook->SetSelection( lastPageIndex );
|
2022-07-14 21:18:04 +00:00
|
|
|
UpdateResetButton( lastPageIndex );
|
2018-05-14 17:34:18 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PAGED_DIALOG::TransferDataFromWindow()
|
|
|
|
{
|
2021-02-24 05:07:17 +00:00
|
|
|
bool ret = true;
|
|
|
|
|
2019-07-17 14:46:25 +00:00
|
|
|
// Call TransferDataFromWindow() only once:
|
|
|
|
// this is enough on wxWidgets 3.1
|
2018-05-14 17:34:18 +00:00
|
|
|
if( !DIALOG_SHIM::TransferDataFromWindow() )
|
2021-02-24 05:07:17 +00:00
|
|
|
ret = false;
|
2019-07-17 14:46:25 +00:00
|
|
|
|
2021-02-24 05:07:17 +00:00
|
|
|
return ret;
|
2018-05-14 17:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-10 17:13:52 +00:00
|
|
|
PAGED_DIALOG* PAGED_DIALOG::GetDialog( wxWindow* aParent )
|
|
|
|
{
|
|
|
|
while( aParent )
|
|
|
|
{
|
|
|
|
if( PAGED_DIALOG* parentDialog = dynamic_cast<PAGED_DIALOG*>( aParent ) )
|
|
|
|
return parentDialog;
|
|
|
|
|
|
|
|
aParent = aParent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-24 14:54:26 +00:00
|
|
|
void PAGED_DIALOG::SetError( const wxString& aMessage, const wxString& aPageName, int aCtrlId,
|
|
|
|
int aRow, int aCol )
|
|
|
|
{
|
|
|
|
SetError( aMessage, FindWindow( aPageName ), FindWindow( aCtrlId ), aRow, aCol );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PAGED_DIALOG::SetError( const wxString& aMessage, wxWindow* aPage, wxWindow* aCtrl,
|
2018-05-14 17:34:18 +00:00
|
|
|
int aRow, int aCol )
|
|
|
|
{
|
2023-05-10 17:13:52 +00:00
|
|
|
m_infoBar->ShowMessageFor( aMessage, 10000, wxICON_WARNING );
|
|
|
|
|
|
|
|
if( wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( aCtrl ) )
|
2018-05-14 17:34:18 +00:00
|
|
|
{
|
2023-05-10 17:13:52 +00:00
|
|
|
textCtrl->SetSelection( -1, -1 );
|
|
|
|
textCtrl->SetFocus();
|
|
|
|
return;
|
|
|
|
}
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2023-05-10 17:13:52 +00:00
|
|
|
if( wxStyledTextCtrl* scintilla = dynamic_cast<wxStyledTextCtrl*>( aCtrl ) )
|
|
|
|
{
|
|
|
|
if( aRow > 0 )
|
2018-05-14 17:34:18 +00:00
|
|
|
{
|
2023-05-10 17:13:52 +00:00
|
|
|
int pos = scintilla->PositionFromLine( aRow - 1 ) + ( aCol - 1 );
|
|
|
|
scintilla->GotoPos( pos );
|
2018-05-14 17:34:18 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 17:13:52 +00:00
|
|
|
scintilla->SetFocus();
|
|
|
|
return;
|
|
|
|
}
|
2020-05-24 14:54:26 +00:00
|
|
|
|
2023-05-10 17:13:52 +00:00
|
|
|
if( wxGrid* grid = dynamic_cast<wxGrid*>( aCtrl ) )
|
|
|
|
{
|
|
|
|
grid->SetFocus();
|
|
|
|
grid->MakeCellVisible( aRow, aCol );
|
|
|
|
grid->SetGridCursor( aRow, aCol );
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2023-05-10 17:13:52 +00:00
|
|
|
grid->EnableCellEditControl( true );
|
|
|
|
grid->ShowCellEditControl();
|
|
|
|
return;
|
2018-05-14 17:34:18 +00:00
|
|
|
}
|
2021-12-27 23:40:12 +00:00
|
|
|
}
|
2020-08-29 19:52:39 +00:00
|
|
|
|
2021-12-27 23:40:12 +00:00
|
|
|
|
2022-07-14 21:18:04 +00:00
|
|
|
void PAGED_DIALOG::UpdateResetButton( int aPage )
|
2021-12-27 23:40:12 +00:00
|
|
|
{
|
2023-05-21 17:15:10 +00:00
|
|
|
wxWindow* panel = m_treebook->ResolvePage( aPage );
|
2021-12-27 23:40:12 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
// Enable the reset button only if the page is re-settable
|
2020-07-15 23:08:16 +00:00
|
|
|
if( m_resetButton )
|
|
|
|
{
|
2022-07-14 21:18:04 +00:00
|
|
|
if( panel && ( panel->GetWindowStyle() & wxRESETTABLE ) )
|
2020-07-15 23:08:16 +00:00
|
|
|
{
|
2021-07-27 16:56:17 +00:00
|
|
|
m_resetButton->SetLabel( wxString::Format( _( "Reset %s to Defaults" ),
|
2022-07-14 21:18:04 +00:00
|
|
|
m_treebook->GetPageText( aPage ) ) );
|
2021-11-01 11:20:13 +00:00
|
|
|
m_resetButton->SetToolTip( panel->GetHelpTextAtPoint( wxPoint( -INT_MAX, INT_MAX ),
|
2022-08-08 21:20:41 +00:00
|
|
|
wxHelpEvent::Origin_Unknown ) );
|
2020-07-15 23:08:16 +00:00
|
|
|
m_resetButton->Enable( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-27 16:56:17 +00:00
|
|
|
m_resetButton->SetLabel( _( "Reset to Defaults" ) );
|
2020-07-15 23:08:16 +00:00
|
|
|
m_resetButton->SetToolTip( wxString() );
|
|
|
|
m_resetButton->Enable( false );
|
|
|
|
}
|
|
|
|
|
2021-11-01 11:20:13 +00:00
|
|
|
m_resetButton->GetParent()->Layout();
|
2020-07-15 23:08:16 +00:00
|
|
|
}
|
2022-07-14 21:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-10 08:12:22 +00:00
|
|
|
void PAGED_DIALOG::onCharHook( wxKeyEvent& aEvent )
|
|
|
|
{
|
2022-09-16 15:52:26 +00:00
|
|
|
if( dynamic_cast<wxTextEntry*>( aEvent.GetEventObject() )
|
|
|
|
|| dynamic_cast<wxStyledTextCtrl*>( aEvent.GetEventObject() )
|
2024-02-27 18:10:55 +00:00
|
|
|
|| dynamic_cast<wxListView*>( aEvent.GetEventObject() )
|
|
|
|
|| dynamic_cast<wxGrid*>( FindFocus() ) )
|
2022-09-16 15:52:26 +00:00
|
|
|
{
|
|
|
|
aEvent.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-10 08:12:22 +00:00
|
|
|
if( aEvent.GetKeyCode() == WXK_UP )
|
|
|
|
{
|
|
|
|
int page = m_treebook->GetSelection();
|
|
|
|
|
|
|
|
if( page >= 1 )
|
|
|
|
{
|
|
|
|
if( m_treebook->GetPage( page - 1 )->GetChildren().IsEmpty() )
|
|
|
|
m_treebook->SetSelection( std::max( page - 2, 0 ) );
|
|
|
|
else
|
|
|
|
m_treebook->SetSelection( page - 1 );
|
|
|
|
}
|
2022-09-10 19:10:39 +00:00
|
|
|
|
2024-02-27 18:10:55 +00:00
|
|
|
m_treebook->GetTreeCtrl()->SetFocus(); // Don't allow preview canvas to steal gridFocus
|
2022-09-10 19:10:39 +00:00
|
|
|
}
|
|
|
|
else if( aEvent.GetKeyCode() == WXK_DOWN )
|
|
|
|
{
|
|
|
|
int page = m_treebook->GetSelection();
|
|
|
|
|
|
|
|
m_treebook->SetSelection( std::min<int>( page + 1, m_treebook->GetPageCount() - 1 ) );
|
|
|
|
|
2024-02-27 18:10:55 +00:00
|
|
|
m_treebook->GetTreeCtrl()->SetFocus(); // Don't allow preview canvas to steal gridFocus
|
2022-09-10 08:12:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PAGED_DIALOG::onPageChanged( wxBookCtrlEvent& event )
|
2022-07-14 21:18:04 +00:00
|
|
|
{
|
2022-09-24 22:22:05 +00:00
|
|
|
size_t page = event.GetSelection();
|
2022-07-14 21:18:04 +00:00
|
|
|
|
|
|
|
// Use the first sub-page when a tree level node is selected.
|
2022-09-24 22:22:05 +00:00
|
|
|
if( m_treebook->GetCurrentPage()->GetChildren().IsEmpty()
|
|
|
|
&& page + 1 < m_treebook->GetPageCount() )
|
2022-07-14 21:18:04 +00:00
|
|
|
{
|
2022-09-24 22:22:05 +00:00
|
|
|
m_treebook->ChangeSelection( ++page );
|
2022-07-14 21:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateResetButton( page );
|
2020-07-15 23:08:16 +00:00
|
|
|
|
2023-06-16 14:56:01 +00:00
|
|
|
// Make sure the dialog size is enough to fit the page content.
|
|
|
|
m_treebook->InvalidateBestSize();
|
|
|
|
|
|
|
|
SetMinSize( wxDefaultSize );
|
|
|
|
wxSize minSize = GetBestSize();
|
2024-01-16 20:33:07 +00:00
|
|
|
minSize.IncTo( FromDIP( wxSize( 600, 500 ) ) );
|
|
|
|
minSize.DecTo( FromDIP( wxSize( 1500, 900 ) ) ); // Failsafe
|
2023-06-16 14:56:01 +00:00
|
|
|
SetMinSize( minSize );
|
|
|
|
|
|
|
|
wxSize currentSize = GetSize();
|
|
|
|
wxSize newSize = currentSize;
|
|
|
|
newSize.IncTo( minSize );
|
|
|
|
|
|
|
|
if( newSize != currentSize )
|
|
|
|
SetSize( newSize );
|
|
|
|
|
2022-09-24 22:22:05 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
// Work around an OSX wxWidgets issue where the wxGrid children don't get placed correctly
|
|
|
|
// until the first resize event
|
|
|
|
if( page < m_macHack.size() && m_macHack[ page ] )
|
|
|
|
{
|
|
|
|
wxSize pageSize = m_treebook->GetPage( page )->GetSize();
|
2023-01-11 01:00:47 +00:00
|
|
|
pageSize.x += 1;
|
2022-09-24 22:22:05 +00:00
|
|
|
pageSize.y += 2;
|
2021-12-27 23:40:12 +00:00
|
|
|
|
2022-09-24 22:22:05 +00:00
|
|
|
m_treebook->GetPage( page )->SetSize( pageSize );
|
|
|
|
m_macHack[ page ] = false;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
wxSizeEvent evt( wxDefaultSize );
|
2021-12-28 14:43:57 +00:00
|
|
|
wxQueueEvent( m_treebook, evt.Clone() );
|
2022-09-24 22:22:05 +00:00
|
|
|
#endif
|
2020-04-02 12:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-10 08:12:22 +00:00
|
|
|
void PAGED_DIALOG::onPageChanging( wxBookCtrlEvent& aEvent )
|
2021-12-27 23:40:12 +00:00
|
|
|
{
|
|
|
|
int currentPage = aEvent.GetOldSelection();
|
|
|
|
|
|
|
|
if( currentPage == wxNOT_FOUND )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxWindow* page = m_treebook->GetPage( currentPage );
|
|
|
|
|
|
|
|
wxCHECK( page, /* void */ );
|
|
|
|
|
|
|
|
// If there is a validation error on the current page, don't allow the page change.
|
|
|
|
if( !page->Validate() || !page->TransferDataFromWindow() )
|
|
|
|
{
|
|
|
|
aEvent.Veto();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-10 08:12:22 +00:00
|
|
|
void PAGED_DIALOG::onResetButton( wxCommandEvent& aEvent )
|
2020-07-15 23:08:16 +00:00
|
|
|
{
|
|
|
|
int sel = m_treebook->GetSelection();
|
|
|
|
|
|
|
|
if( sel == wxNOT_FOUND )
|
|
|
|
return;
|
|
|
|
|
2021-11-01 11:20:13 +00:00
|
|
|
// NB: dynamic_cast doesn't work over Kiway
|
2023-05-21 17:15:10 +00:00
|
|
|
wxWindow* panel = m_treebook->ResolvePage( sel );
|
2020-07-15 23:08:16 +00:00
|
|
|
|
|
|
|
if( panel )
|
2021-11-01 11:20:13 +00:00
|
|
|
{
|
|
|
|
wxCommandEvent resetCommand( wxEVT_COMMAND_BUTTON_CLICKED, ID_RESET_PANEL );
|
|
|
|
panel->ProcessWindowEvent( resetCommand );
|
|
|
|
}
|
2020-07-15 23:08:16 +00:00
|
|
|
}
|
2023-07-13 14:10:31 +00:00
|
|
|
|
|
|
|
void PAGED_DIALOG::onOpenPreferencesButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
2023-09-23 23:53:22 +00:00
|
|
|
wxString dir( PATHS::GetUserSettingsPath() );
|
2023-07-13 14:10:31 +00:00
|
|
|
LaunchExternal( dir );
|
|
|
|
}
|