void FOOTPRINT_EDIT_FRAME::updateTitle()
{
    wxString title   = _( "Module Editor " );

    wxString nickname = getLibNickName();

    if( !nickname )
    {
    L_none:
        title += _( "(no active library)" );
    }
    else
    {
        try
        {
            bool writable = FootprintLibs()->IsFootprintLibWritable( nickname );

            // no exception was thrown, this means libPath is valid, but it may be read only.
            title = _( "Module Editor (active library: " ) + nickname + wxT( ")" );

            if( !writable )
                title += _( " [Read Only]" );
        }
        catch( const IO_ERROR& ioe )
        {
            // user may be bewildered as to why after selecting a library it is not showing up
            // in the title, we could show an error message, but that should have been done at time
            // of libary selection UI.
            goto L_none;
        }
    }

    SetTitle( title );
}
Beispiel #2
0
void FOOTPRINT_EDIT_FRAME::Select_Active_Library()
{
    if( g_LibraryNames.GetCount() == 0 )
        return;

    EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, g_LibraryNames, getLibNickName() );

    if( dlg.ShowModal() != wxID_OK )
        return;

    wxFileName fileName = wxFileName( wxEmptyString, dlg.GetTextSelection(),
                                      LegacyFootprintLibPathExtension );

    fileName = wxGetApp().FindLibraryPath( fileName );

    if( fileName.IsOk() && fileName.FileExists() )
    {
        setLibNickName( fileName.GetName() );
        setLibPath( fileName.GetFullPath() );
    }
    else
    {
        wxString msg = wxString::Format( FMT_BAD_PATHS, GetChars( dlg.GetTextSelection() ) );

        DisplayError( this, msg );

        setLibNickName( wxEmptyString );
        setLibPath( wxEmptyString );
    }

    updateTitle();
}
void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
{
    if( GetScreen()->IsModify() )
    {
        int ii = DisplayExitDialog( this, _( "Save the changes in the module before closing?" ) );

        switch( ii )
        {
        case wxID_NO:
            break;

        case wxID_YES:
            // code from FOOTPRINT_EDIT_FRAME::Process_Special_Functions,
            // at case ID_MODEDIT_SAVE_LIBMODULE
            if( GetBoard()->m_Modules && getLibNickName().size() )
            {
                if( Save_Module_In_Library( getLibNickName(), GetBoard()->m_Modules, true, true ) )
                {
                    // save was correct
                    GetScreen()->ClrModify();
                    break;
                }
            }
            else
            {
                DisplayError( this, _( "Library is not set, the module could not be saved." ) );
            }
            // fall through: cancel the close because of an error

        case wxID_CANCEL:
            Event.Veto();
            return;
        }
    }

    //close the editor
    Destroy();
}
wxString FOOTPRINT_EDIT_FRAME::getLibPath()
{
    try
    {
        const wxString& nickname = getLibNickName();

        const FP_LIB_TABLE::ROW* row = FootprintLibs()->FindRow( nickname );

        return row->GetFullURI( true );
    }
    catch( const IO_ERROR& ioe )
    {
        return wxEmptyString;
    }
}
bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary()
{
    wxString    nickname = getLibNickName();

    if( !FootprintLibs()->IsFootprintLibWritable( nickname ) )
    {
        wxString msg = wxString::Format(
                _( "Library '%s' is read only" ),
                GetChars( nickname )
                );

        DisplayError( this, msg );
        return false;
    }

    wxString    fpid_txt = PCB_BASE_FRAME::SelectFootprint( this, nickname,
                        wxEmptyString, wxEmptyString, FootprintLibs() );

    if( !fpid_txt )
        return false;

    FPID        fpid( fpid_txt );
    wxString    fpname = fpid.GetFootprintName();

    // Confirmation
    wxString msg = wxString::Format( FMT_OK_DELETE, fpname.GetData(), nickname.GetData() );

    if( !IsOK( this, msg ) )
        return false;

    try
    {
        FootprintLibs()->FootprintDelete( nickname, fpname );
    }
    catch( const IO_ERROR& ioe )
    {
        DisplayError( this, ioe.errorText );
        return false;
    }

    msg.Printf( FMT_MOD_DELETED, fpname.GetData(), nickname.GetData() );

    SetStatusText( msg );

    return true;
}