From 533b26e8a1c59a5911cdcd17f300ec2f7b95ee48 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 24 Sep 2018 15:31:35 +0100 Subject: [PATCH] Add hotkey for viewing symbol datasheet. Also fixes a bug when there are multiple datasheets to choose from. Fixes: lp:1793978 * https://bugs.launchpad.net/kicad/+bug/1793978 --- eeschema/eeschema_id.h | 2 +- eeschema/hotkeys.cpp | 12 ++++++++++-- eeschema/hotkeys.h | 2 ++ eeschema/lib_edit_frame.cpp | 3 ++- eeschema/menubar_libedit.cpp | 6 ++++-- eeschema/onrightclick.cpp | 9 +++++++++ eeschema/sch_collectors.cpp | 9 +++++++-- eeschema/sch_collectors.h | 5 +++++ eeschema/sch_component.cpp | 4 ++++ eeschema/sch_edit_frame.cpp | 1 + eeschema/schedit.cpp | 27 ++++++++++++++------------- include/core/typeinfo.h | 1 + 12 files changed, 60 insertions(+), 21 deletions(-) diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index c210d1c123..886b081bee 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -156,7 +156,6 @@ enum id_eeschema_frm ID_POPUP_SCH_GENERIC_EDIT_CMP, ID_POPUP_SCH_EDIT_CONVERT_CMP, ID_POPUP_SCH_EDIT_FIELD, - ID_POPUP_SCH_DISPLAYDOC_CMP, ID_POPUP_SCH_ENTER_SHEET, ID_POPUP_SCH_LEAVE_SHEET, ID_POPUP_SCH_SELECT_ON_PCB, @@ -166,6 +165,7 @@ enum id_eeschema_frm ID_POPUP_SCH_GETINFO_MARKER, ID_POPUP_END_RANGE, + ID_POPUP_SCH_DISPLAYDOC_CMP, ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, // Unit select context menus command IDs. diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index 5a42e4bbc4..55c2e14e62 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -169,10 +169,13 @@ static EDA_HOTKEY HkEditComponentReference( _HKI( "Edit Symbol Reference" ), static EDA_HOTKEY HkEditComponentFootprint( _HKI( "Edit Symbol Footprint" ), HK_EDIT_COMPONENT_FOOTPRINT, 'F', ID_SCH_EDIT_COMPONENT_FOOTPRINT ); +static EDA_HOTKEY HkShowComponentDatasheet( _HKI( "Show Symbol Datasheet" ), + HK_SHOW_COMPONENT_DATASHEET, 'D' + GR_KB_CTRL, + ID_POPUP_SCH_DISPLAYDOC_CMP ); static EDA_HOTKEY HkEditComponentWithLibedit( _HKI( "Edit with Symbol Editor" ), - HK_EDIT_COMPONENT_WITH_LIBEDIT, - 'E' + GR_KB_CTRL, + HK_EDIT_COMPONENT_WITH_LIBEDIT, 'E' + GR_KB_CTRL, ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP ); + static EDA_HOTKEY HkMove( _HKI( "Move Schematic Item" ), HK_MOVE_COMPONENT_OR_ITEM, 'M', ID_SCH_MOVE_ITEM ); @@ -203,6 +206,8 @@ static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ), HK_ZOOM_SELECTIO static EDA_HOTKEY HkCreatePin( _HKI( "Create Pin" ), HK_LIBEDIT_CREATE_PIN, 'P' ); static EDA_HOTKEY HkInsertPin( _HKI( "Repeat Pin" ), HK_REPEAT_LAST, WXK_INSERT ); static EDA_HOTKEY HkMoveLibItem( _HKI( "Move Library Item" ), HK_LIBEDIT_MOVE_GRAPHIC_ITEM, 'M' ); +static EDA_HOTKEY HkViewDoc( _HKI( "Show Datasheet" ), HK_LIBEDIT_VIEW_DOC, 'D' + GR_KB_CTRL, + ID_LIBEDIT_VIEW_DOC ); // Autoplace fields static EDA_HOTKEY HkAutoplaceFields( _HKI( "Autoplace Fields" ), HK_AUTOPLACE_FIELDS, 'O', @@ -295,6 +300,7 @@ static EDA_HOTKEY* schematic_Hotkey_List[] = &HkEditComponentValue, &HkEditComponentReference, &HkEditComponentFootprint, + &HkShowComponentDatasheet, &HkEditComponentWithLibedit, &HkBeginWire, &HkBeginBus, @@ -325,6 +331,7 @@ static EDA_HOTKEY* libEdit_Hotkey_List[] = &HkMoveLibItem, &HkMirrorX, &HkMirrorY, + &HkViewDoc, NULL }; @@ -610,6 +617,7 @@ bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, case HK_EDIT_COMPONENT_VALUE: // Edit component value field. case HK_EDIT_COMPONENT_REFERENCE: // Edit component value reference. case HK_EDIT_COMPONENT_FOOTPRINT: // Edit component footprint field. + case HK_SHOW_COMPONENT_DATASHEET: // Show component datasheet in browser. case HK_MIRROR_Y: // Mirror Y case HK_MIRROR_X: // Mirror X case HK_ORIENT_NORMAL_COMPONENT: // Orient 0, no mirror (Component) diff --git a/eeschema/hotkeys.h b/eeschema/hotkeys.h index 6b497ec6df..239f064bc4 100644 --- a/eeschema/hotkeys.h +++ b/eeschema/hotkeys.h @@ -43,12 +43,14 @@ enum hotkey_id_commnand { HK_LIBEDIT_MOVE_GRAPHIC_ITEM, HK_MOVEBLOCK_TO_DRAGBLOCK, HK_LIBEDIT_CREATE_PIN, + HK_LIBEDIT_VIEW_DOC, HK_DELETE_PIN, HK_ROTATE, HK_EDIT, HK_EDIT_COMPONENT_VALUE, HK_EDIT_COMPONENT_REFERENCE, HK_EDIT_COMPONENT_FOOTPRINT, + HK_SHOW_COMPONENT_DATASHEET, HK_EDIT_COMPONENT_WITH_LIBEDIT, HK_MIRROR_X, HK_MIRROR_Y, diff --git a/eeschema/lib_edit_frame.cpp b/eeschema/lib_edit_frame.cpp index d89e41e703..9b3ec9fb0f 100644 --- a/eeschema/lib_edit_frame.cpp +++ b/eeschema/lib_edit_frame.cpp @@ -580,11 +580,12 @@ void LIB_EDIT_FRAME::OnViewEntryDoc( wxCommandEvent& event ) { CONTEXT_MENU popup; wxString msg; + int id = 0; for( LIB_ALIAS* alias : part->GetAliases() ) { msg.Printf( wxT( "%s (%s)" ), alias->GetName(), alias->GetDocFileName() ); - popup.Append( wxID_ANY, msg ); + popup.Append( id++, msg ); } PopupMenu( &popup ); diff --git a/eeschema/menubar_libedit.cpp b/eeschema/menubar_libedit.cpp index 4675e04335..7784034696 100644 --- a/eeschema/menubar_libedit.cpp +++ b/eeschema/menubar_libedit.cpp @@ -265,9 +265,11 @@ void LIB_EDIT_FRAME::ReCreateMenuBar() // Menu Inspect: wxMenu* inspectMenu = new wxMenu; + + text = AddHotkeyName( _( "Show Datasheet" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_VIEW_DOC ); AddMenuItem( inspectMenu, ID_LIBEDIT_VIEW_DOC, - _( "Show Datasheet" ), + text, _( "Open associated datasheet in web browser" ), KiBitmap( datasheet_xpm ) ); @@ -322,7 +324,7 @@ void LIB_EDIT_FRAME::ReCreateMenuBar() _( "Open the \"Getting Started in KiCad\" guide for beginners" ), KiBitmap( help_xpm ) ); - text = AddHotkeyName( _( "&List Hotkeys..." ), g_Eeschema_Hokeys_Descr, HK_HELP ); + text = AddHotkeyName( _( "&List Hotkeys..." ), g_Libedit_Hokeys_Descr, HK_HELP ); AddMenuItem( helpMenu, ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, text, diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index f4d4d3376f..f43dd2169c 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -350,6 +350,10 @@ void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field ) id = HK_EDIT_COMPONENT_FOOTPRINT; name = _( "Edit Footprint Field..." ); break; + case DATASHEET: + id = HK_SHOW_COMPONENT_DATASHEET; + name = _( "Show Datasheet" ); + break; default: id = HK_EDIT; name = _( "Edit Field..." ); @@ -460,6 +464,11 @@ void AddMenusForEditComponent( wxMenu* PopMenu, SCH_COMPONENT* Component, SYMBOL HK_EDIT_COMPONENT_FOOTPRINT ); AddMenuItem( editmenu, ID_SCH_EDIT_COMPONENT_FOOTPRINT, msg, KiBitmap( edit_comp_footprint_xpm ) ); + + msg = AddHotkeyName( _( "Show Datasheet" ), g_Schematic_Hokeys_Descr, + HK_SHOW_COMPONENT_DATASHEET ); + AddMenuItem( editmenu, ID_POPUP_SCH_DISPLAYDOC_CMP, msg, + KiBitmap( datasheet_xpm ) ); } if( part && part->HasConversion() ) diff --git a/eeschema/sch_collectors.cpp b/eeschema/sch_collectors.cpp index 4f97439649..40a829b9d9 100644 --- a/eeschema/sch_collectors.cpp +++ b/eeschema/sch_collectors.cpp @@ -103,8 +103,13 @@ const KICAD_T SCH_COLLECTOR::CmpFieldReferenceOnly[] = { }; const KICAD_T SCH_COLLECTOR::CmpFieldFootprintOnly[] = { - SCH_FIELD_LOCATE_FOOTPRINT_T, - EOT + SCH_FIELD_LOCATE_FOOTPRINT_T, + EOT +}; + +const KICAD_T SCH_COLLECTOR::CmpFieldDatasheetOnly[] = { + SCH_FIELD_LOCATE_DATASHEET_T, + EOT }; diff --git a/eeschema/sch_collectors.h b/eeschema/sch_collectors.h index df4accddb0..8533a51e7f 100644 --- a/eeschema/sch_collectors.h +++ b/eeschema/sch_collectors.h @@ -68,6 +68,11 @@ public: */ static const KICAD_T CmpFieldFootprintOnly[]; + /** + * A scan list for a specific editable field: Datasheet. + */ + static const KICAD_T CmpFieldDatasheetOnly[]; + /** * A scan list for all movable schematic items. */ diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 8c09d18c2c..838c6cf767 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -1770,6 +1770,10 @@ SEARCH_RESULT SCH_COMPONENT::Visit( INSPECTOR aInspector, void* aTestData, return SEARCH_QUIT; break; + case SCH_FIELD_LOCATE_DATASHEET_T: + if( SEARCH_QUIT == aInspector( GetField( DATASHEET ), (void*) this ) ) + return SEARCH_QUIT; + break; case LIB_PIN_T: if( PART_SPTR part = m_part.lock() ) diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 16d6bef643..c25f008562 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -313,6 +313,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_MENU_RANGE( ID_SCH_MIRROR_X, ID_SCH_ORIENT_NORMAL, SCH_EDIT_FRAME::OnOrient ) EVT_MENU_RANGE( ID_POPUP_START_RANGE, ID_POPUP_END_RANGE, SCH_EDIT_FRAME::Process_Special_Functions ) + EVT_MENU( ID_POPUP_SCH_DISPLAYDOC_CMP, SCH_EDIT_FRAME::OnEditItem ) // Tools and buttons options toolbar EVT_TOOL( ID_TB_OPTIONS_HIDDEN_PINS, SCH_EDIT_FRAME::OnSelectOptionToolbar ) diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 383a44c0e4..83889815af 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -79,7 +79,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_SCH_RESIZE_SHEET: case ID_POPUP_IMPORT_HLABEL_TO_SHEETPIN: case ID_POPUP_SCH_INIT_CMP: - case ID_POPUP_SCH_DISPLAYDOC_CMP: case ID_POPUP_SCH_EDIT_CONVERT_CMP: case ID_POPUP_DELETE_BLOCK: case ID_POPUP_PLACE_BLOCK: @@ -281,18 +280,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; - case ID_POPUP_SCH_DISPLAYDOC_CMP: - // Ensure the struct is a component (could be a piece of a component, like Field, text..) - if( item && item->Type() == SCH_COMPONENT_T ) - { - wxString text = static_cast( item )->GetField( DATASHEET )->GetText(); - text = ResolveUriByEnvVars( text ); - - if( !text.IsEmpty() ) - GetAssociatedDocument( this, text ); - } - break; - case ID_POPUP_SCH_ENTER_SHEET: if( item && (item->Type() == SCH_SHEET_T) ) @@ -1000,6 +987,10 @@ void SCH_EDIT_FRAME::OnEditItem( wxCommandEvent& aEvent ) filterListAux = SCH_COLLECTOR::ComponentsOnly; break; + case ID_POPUP_SCH_DISPLAYDOC_CMP: + filterList = SCH_COLLECTOR::CmpFieldDatasheetOnly; + filterListAux = SCH_COLLECTOR::ComponentsOnly; + default: break; } @@ -1033,6 +1024,16 @@ void SCH_EDIT_FRAME::OnEditItem( wxCommandEvent& aEvent ) EditComponentFieldText( ( (SCH_COMPONENT*) item )->GetField( FOOTPRINT ) ); break; + case ID_POPUP_SCH_DISPLAYDOC_CMP: + { + wxString text = static_cast( item )->GetField( DATASHEET )->GetText(); + text = ResolveUriByEnvVars( text ); + + if( !text.IsEmpty() ) + GetAssociatedDocument( this, text ); + } + break; + case ID_SCH_EDIT_ITEM: EditComponent( (SCH_COMPONENT*) item ); break; diff --git a/include/core/typeinfo.h b/include/core/typeinfo.h index 4c176239f6..ad4962efec 100644 --- a/include/core/typeinfo.h +++ b/include/core/typeinfo.h @@ -128,6 +128,7 @@ enum KICAD_T SCH_FIELD_LOCATE_REFERENCE_T, SCH_FIELD_LOCATE_VALUE_T, SCH_FIELD_LOCATE_FOOTPRINT_T, + SCH_FIELD_LOCATE_DATASHEET_T, // General SCH_SCREEN_T,