diff --git a/common/string.cpp b/common/string.cpp index d0bfe33edf..8f35b83d64 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -167,6 +167,30 @@ std::string EscapedUTF8( const wxString& aString ) } +wxString EscapedHTML( const wxString& aString ) +{ + wxString converted; + + for( wxUniChar c: aString ) + { + if( c == '\"' ) + converted += """; + else if( c == '\'' ) + converted += "'"; + else if( c == '&' ) + converted += "&"; + else if( c == '<' ) + converted += "<"; + else if( c == '>' ) + converted += ">"; + else + converted += c; + } + + return converted; +} + + char* StrPurge( char* text ) { static const char whitespace[] = " \t\n\r\f\v"; diff --git a/eeschema/dialogs/dialog_choose_component.cpp b/eeschema/dialogs/dialog_choose_component.cpp index 04728a0d56..6401827133 100644 --- a/eeschema/dialogs/dialog_choose_component.cpp +++ b/eeschema/dialogs/dialog_choose_component.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 Henner Zeller - * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,6 +29,7 @@ #include #include #include +#include // Tree navigation helpers. static wxTreeItemId GetPrevItem( const wxTreeCtrl& tree, const wxTreeItemId& item ); @@ -44,7 +45,6 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const m_external_browser_requested = false; m_received_doubleclick_in_tree = false; m_search_container->SetTree( m_libraryComponentTree ); - m_componentDetails->SetEditable( false ); m_componentView->SetLayoutDirection( wxLayout_LeftToRight ); m_libraryComponentTree->ScrollTo( m_libraryComponentTree->GetFocusedItem() ); @@ -221,70 +221,83 @@ bool DIALOG_CHOOSE_COMPONENT::updateSelection() m_componentView->Refresh(); - m_componentDetails->Clear(); + m_componentDetails->SetPage( wxEmptyString ); if( selection == NULL ) return false; m_componentDetails->Freeze(); - wxFont font_normal = m_componentDetails->GetFont(); - wxFont font_bold = m_componentDetails->GetFont(); - font_bold.SetWeight( wxFONTWEIGHT_BOLD ); - - wxTextAttr headline_attribute; - headline_attribute.SetFont( font_bold ); - wxTextAttr text_attribute; - text_attribute.SetFont( font_normal ); const wxString name = selection->GetName(); + wxString description = selection->GetDescription(); if ( !name.empty() ) { - m_componentDetails->SetDefaultStyle( headline_attribute ); - m_componentDetails->AppendText( name ); + m_componentDetails->AppendToPage( "" ); + m_componentDetails->AppendToPage( EscapedHTML( name ) ); + m_componentDetails->AppendToPage( "" ); } - const wxString description = selection->GetDescription(); + if( !selection->IsRoot() ) + { + LIB_PART* root_part = selection->GetPart(); + const wxString root_name( root_part ? root_part->GetName() : _( "Unknown" ) ); + + m_componentDetails->AppendToPage( + "
" + _( "Alias of " ) + EscapedHTML( root_name ) + "" ); + + // For some reason descriptions are a property of aliases, even though + // only the root component's main LIB_ALIAS can actually have a description. + // If the description was empty, go through the alias list and find an alias + // that actually has one. + + if( description.empty() ) + { + for( size_t i = 0; i < root_part->GetAliasCount(); ++i ) + { + LIB_ALIAS* alias = root_part->GetAlias( i ); + + if( !alias ) + continue; + + description = alias->GetDescription(); + + if( !description.empty() ) + break; + } + } + } if( !description.empty() ) { - if ( !m_componentDetails->IsEmpty() ) - m_componentDetails->AppendText( wxT( "\n\n" ) ); - - m_componentDetails->SetDefaultStyle( headline_attribute ); - m_componentDetails->AppendText( _( "Description\n" ) ); - m_componentDetails->SetDefaultStyle( text_attribute ); - m_componentDetails->AppendText( description ); + m_componentDetails->AppendToPage( "
" ); + m_componentDetails->AppendToPage( EscapedHTML( description ) ); } - const wxString keywords = selection->GetKeyWords(); - + wxString keywords = selection->GetKeyWords(); if( !keywords.empty() ) { - if ( !m_componentDetails->IsEmpty() ) - m_componentDetails->AppendText( wxT( "\n\n" ) ); - - m_componentDetails->SetDefaultStyle( headline_attribute ); - m_componentDetails->AppendText( _( "Keywords\n" ) ); - m_componentDetails->SetDefaultStyle( text_attribute ); - m_componentDetails->AppendText( keywords ); + m_componentDetails->AppendToPage( "
" + _( "Keywords:" ) + " " ); + m_componentDetails->AppendToPage( EscapedHTML( keywords ) ); } - if ( !selection->IsRoot() ) + m_componentDetails->AppendToPage( "
" ); + + + LIB_FIELDS fields; + selection->GetPart()->GetFields( fields ); + + for( auto const & field: fields ) { - LIB_PART* root_part = selection->GetPart(); - const wxString root_component_name( root_part ? root_part->GetName() : _( "Unknown" ) ); + wxString name = field.GetName(); + wxString text = field.GetFullText(); - if ( !m_componentDetails->IsEmpty() ) - m_componentDetails->AppendText( wxT( "\n\n" ) ); - - m_componentDetails->SetDefaultStyle( headline_attribute ); - m_componentDetails->AppendText( _( "Alias of " ) ); - m_componentDetails->SetDefaultStyle( text_attribute ); - m_componentDetails->AppendText( root_component_name ); + m_componentDetails->AppendToPage( "" ); + m_componentDetails->AppendToPage( "" ); } - m_componentDetails->SetInsertionPoint( 0 ); // scroll up. + m_componentDetails->AppendToPage( "
" + EscapedHTML( name ) + "" + EscapedHTML( text ) + "
" ); + m_componentDetails->Thaw(); return true; diff --git a/eeschema/dialogs/dialog_choose_component_base.cpp b/eeschema/dialogs/dialog_choose_component_base.cpp index 2c332c9533..a255497d55 100644 --- a/eeschema/dialogs/dialog_choose_component_base.cpp +++ b/eeschema/dialogs/dialog_choose_component_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jan 15 2017) +// C++ code generated with wxFormBuilder (version Jan 5 2017) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -40,12 +40,10 @@ DIALOG_CHOOSE_COMPONENT_BASE::DIALOG_CHOOSE_COMPONENT_BASE( wxWindow* parent, wx m_componentView = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER ); m_componentView->SetMinSize( wxSize( 200,200 ) ); - bSizerView->Add( m_componentView, 4, wxEXPAND | wxALL, 5 ); + bSizerView->Add( m_componentView, 1, wxEXPAND | wxALL, 5 ); - m_componentDetails = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( -1,-1 ), wxTE_MULTILINE ); - m_componentDetails->SetMinSize( wxSize( 200,200 ) ); - - bSizerView->Add( m_componentDetails, 3, wxALL|wxEXPAND, 5 ); + m_componentDetails = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO ); + bSizerView->Add( m_componentDetails, 1, wxALL|wxEXPAND, 5 ); bSizerMain->Add( bSizerView, 1, wxEXPAND, 5 ); diff --git a/eeschema/dialogs/dialog_choose_component_base.fbp b/eeschema/dialogs/dialog_choose_component_base.fbp index a07bd5bca2..432f72b403 100644 --- a/eeschema/dialogs/dialog_choose_component_base.fbp +++ b/eeschema/dialogs/dialog_choose_component_base.fbp @@ -392,7 +392,7 @@ 5 wxEXPAND | wxALL - 4 + 1 1 1 @@ -469,11 +469,11 @@ - + 5 wxALL|wxEXPAND - 3 - + 1 + 1 1 1 @@ -504,10 +504,9 @@ 0 - 0 - 200,200 + 1 m_componentDetails 1 @@ -518,22 +517,20 @@ Resizable 1 - -1,-1 - wxTE_MULTILINE + + wxHW_SCROLLBAR_AUTO 0 - - wxFILTER_NONE - wxDefaultValidator - - + + + @@ -553,10 +550,6 @@ - - - - diff --git a/eeschema/dialogs/dialog_choose_component_base.h b/eeschema/dialogs/dialog_choose_component_base.h index 4d1fa40774..4a05e0ef93 100644 --- a/eeschema/dialogs/dialog_choose_component_base.h +++ b/eeschema/dialogs/dialog_choose_component_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jan 15 2017) +// C++ code generated with wxFormBuilder (version Jan 5 2017) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -24,6 +24,7 @@ class DIALOG_SHIM; #include #include #include +#include #include #include @@ -42,7 +43,7 @@ class DIALOG_CHOOSE_COMPONENT_BASE : public DIALOG_SHIM wxTextCtrl* m_searchBox; wxTreeCtrl* m_libraryComponentTree; wxPanel* m_componentView; - wxTextCtrl* m_componentDetails; + wxHtmlWindow* m_componentDetails; wxStdDialogButtonSizer* m_stdButtons; wxButton* m_stdButtonsOK; wxButton* m_stdButtonsCancel; diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index b6e8cd0009..a443203efe 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -528,7 +528,7 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, } -wxString LIB_FIELD::GetFullText( int unit ) +wxString LIB_FIELD::GetFullText( int unit ) const { if( m_id != REFERENCE ) return GetText(); diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index 9e48a45e9f..0715e984ce 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -189,7 +189,7 @@ public: * @param unit - The package unit number. Only effects reference field. * @return Field text. */ - wxString GetFullText( int unit = 1 ); + wxString GetFullText( int unit = 1 ) const; EDA_COLOR_T GetDefaultColor() override; diff --git a/include/kicad_string.h b/include/kicad_string.h index d3136a3085..abf6a82004 100644 --- a/include/kicad_string.h +++ b/include/kicad_string.h @@ -73,6 +73,11 @@ int ReadDelimitedText( wxString* aDest, const char* aSource ); */ std::string EscapedUTF8( const wxString& aString ); +/** + * Return a new wxString escaped for embedding in HTML. + */ +wxString EscapedHTML( const wxString& aString ); + /** * Function GetLine * reads one line line from \a aFile.