diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 0804f8bba1..e9500d8308 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -54,6 +54,7 @@ #endif /* KICAD_SPICE */ #include "common.h" +#include "eda_doc.h" #include @@ -590,7 +591,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::showButtonHandler( wxCommandEvent& even { wxString datasheet_uri = fieldValueTextCtrl->GetValue(); datasheet_uri = resolveUriByEnvVars( datasheet_uri ); - ::wxLaunchDefaultBrowser( datasheet_uri ); + GetAssociatedDocument( this, datasheet_uri ); } else if( fieldNdx == FOOTPRINT ) { diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp index d70f05a865..23341a5bdf 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp @@ -45,6 +45,7 @@ #include #include +#include "eda_doc.h" #include #ifdef KICAD_SPICE @@ -501,7 +502,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::showButtonHandler( wxCommandEvent& even if( fieldNdx == DATASHEET ) { wxString datasheet_uri = fieldValueTextCtrl->GetValue(); - ::wxLaunchDefaultBrowser( datasheet_uri ); + GetAssociatedDocument( this, datasheet_uri ); } else if( fieldNdx == FOOTPRINT ) { diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index ac7deec23e..8e8401add9 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -254,6 +254,18 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( // Set the component value that can differ from component name in lib, for aliases component->GetField( VALUE )->SetText( sel.Name ); + // If there is no field defined in the component, copy one over from the library + // ( from the .dcm file ) + // This way the Datasheet field will not be empty and can be changed from the schematic + auto libs = Prj().SchLibs(); + if( component->GetField( DATASHEET )->GetText().IsEmpty() ) + { + LIB_ALIAS* entry = libs->FindLibraryAlias( component->GetLibId() ); + + if( entry && !!entry->GetDocFileName() ) + component->GetField( DATASHEET )->SetText( entry->GetDocFileName() ); + } + MSG_PANEL_ITEMS items; component->SetCurrentSheetPath( &GetCurrentSheet() ); diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index e84e44246a..ab2c712e1e 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -397,7 +397,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component, PART_LIBS* msg = AddHotkeyName( _( "Autoplace Fields" ), g_Schematic_Hokeys_Descr, HK_AUTOPLACE_FIELDS ); AddMenuItem( PopMenu, ID_AUTOPLACE_FIELDS, msg, KiBitmap( autoplace_fields_xpm ) ); - if( libEntry && !libEntry->GetDocFileName().IsEmpty() ) + if( !Component->GetFieldText("Datasheet").IsEmpty() ) AddMenuItem( PopMenu, ID_POPUP_SCH_DISPLAYDOC_CMP, _( "Open Documentation" ), KiBitmap( datasheet_xpm ) ); } diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 23d4bdafa2..906a129da9 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -302,16 +302,11 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) // Ensure the struct is a component (could be a piece of a component, like Field, text..) if( item && item->Type() == SCH_COMPONENT_T ) { - if( PART_LIBS* libs = Prj().SchLibs() ) + auto text = static_cast( item )->GetFieldText( "Datasheet" ); + + if( !text.IsEmpty() ) { - LIB_ALIAS* entry = libs->FindLibraryAlias( ( (SCH_COMPONENT*) item )->GetLibId() ); - - if( entry && !!entry->GetDocFileName() ) - { - SEARCH_STACK* lib_search = Prj().SchSearchS(); - - GetAssociatedDocument( this, entry->GetDocFileName(), lib_search ); - } + GetAssociatedDocument( this, text ); } } break;