Fix library table panel path adding and cleanup duplicate dialog

When adding a .pretty library, if the actual .pretty folder were
selected then no folder would be added to the list of libraries.
This led to an assert when normalizing paths, and the library
not being added.
This commit is contained in:
Ian McInerney 2020-02-14 19:07:27 +00:00
parent 3ec360f15c
commit 4fef513a3f
4 changed files with 28 additions and 17 deletions

View File

@ -212,13 +212,16 @@ bool HandleUnsavedChanges( wxWindow* aParent, const wxString& aMessage,
int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxString& aMessage,
const wxString& aOKLabel, const wxString& aCancelLabel, bool* aApplyToAll )
const wxString& aDetailedMessage, const wxString& aOKLabel,
const wxString& aCancelLabel, bool* aApplyToAll )
{
wxRichMessageDialog dlg( aParent, aMessage, wxEmptyString,
wxRichMessageDialog dlg( aParent, aMessage, aWarning,
wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER );
dlg.ShowDetailedText( _( "If you don't save, all your changes will be permanently lost." ) );
dlg.SetOKCancelLabels( aOKLabel, aCancelLabel );
if( !aDetailedMessage.IsEmpty() )
dlg.ShowDetailedText( aDetailedMessage );
if( aApplyToAll )
dlg.ShowCheckBox( _( "Apply to all" ), true );

View File

@ -362,11 +362,13 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
m_lastBrowseDir = dlg.GetDirectory();
const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
bool addDuplicates = false;
bool applyToAll = false;
wxString warning = _( "Warning: Duplicate Nickname" );
wxString msg = _( "A library nicknamed \"%s\" already exists." );
const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
bool addDuplicates = false;
bool applyToAll = false;
wxString warning = _( "Warning: Duplicate Nickname" );
wxString msg = _( "A library nicknamed \"%s\" already exists." );
wxString detailedMsg = _( "Please change the library nickname after adding this library." );
wxArrayString files;
dlg.GetFilenames( files );
@ -381,9 +383,9 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
{
if( !applyToAll )
{
int ret = OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
_( "Skip" ), _( "Add Anyway" ), &applyToAll );
addDuplicates = (ret == wxID_CANCEL );
// The cancel button adds the library to the table anyway
addDuplicates = ( OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
detailedMsg, _( "Skip" ), _( "Add Anyway" ), &applyToAll ) == wxID_CANCEL );
}
doAdd = addDuplicates;

View File

@ -151,13 +151,16 @@ bool IsOK( wxWindow* aParent, const wxString& aMessage );
* @param aWarning is the warning to display in the top part of the dialog box using a bold font.
* @param aMessage is the message to display in the lower part of the dialog box using the
* default system UI font.
* @param aDetailedMessage is the message to display in the "Show detailed information" section.
* Passing wxEmptyString will hide this portion of the dialog.
* @param aOKLabel is the text to display in the OK button.
* @param aCancelLabel is the text to display in the cancel button.
*
* @return wxID_OK or wxID_CANCEL depending on the button the user selected.
*/
int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxString& aMessage,
const wxString& aOKLabel, const wxString& aCancelLabel, bool* aApplyToAll );
const wxString& aDetailedMessage, const wxString& aOKLabel,
const wxString& aCancelLabel, bool* aApplyToAll );

View File

@ -116,7 +116,9 @@ static const std::map<int, supportedFileType>& fileTypes()
class LIBRARY_TRAVERSER : public wxDirTraverser
{
public:
LIBRARY_TRAVERSER( wxString aSearchExtension ) : m_searchExtension( aSearchExtension )
LIBRARY_TRAVERSER( wxString aSearchExtension, wxString aInitialDir )
: m_searchExtension( aSearchExtension ),
m_currentDir( aInitialDir )
{
}
@ -758,7 +760,7 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
{
wxDir rootDir( dlg.GetPath() );
LIBRARY_TRAVERSER traverser( fileType.m_FolderSearchExtension );
LIBRARY_TRAVERSER traverser( fileType.m_FolderSearchExtension, rootDir.GetName() );
rootDir.Traverse( traverser );
traverser.GetPaths( files );
@ -793,6 +795,7 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
bool applyToAll = false;
wxString warning = _( "Warning: Duplicate Nickname" );
wxString msg = _( "A library nicknamed \"%s\" already exists." );
wxString detailedMsg = _( "Please change the library nickname after adding this library." );
for( const auto& filePath : files )
{
@ -804,9 +807,9 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
{
if( !applyToAll )
{
int ret = OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
_( "Skip" ), _( "Add Anyway" ), &applyToAll );
addDuplicates = ( ret == wxID_CANCEL );
// The cancel button adds the library to the table anyway
addDuplicates = ( OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
detailedMsg, _( "Skip" ), _( "Add Anyway" ), &applyToAll ) == wxID_CANCEL );
}
doAdd = addDuplicates;