Enable URLs in PCM metadata.

Going to HTML_WINDOW also sidesteps the bullet size issue between
platforms.
This commit is contained in:
Jeff Young 2021-11-11 23:41:31 +00:00
parent 992fc83870
commit f9bbaed7a1
7 changed files with 94 additions and 84 deletions

View File

@ -42,7 +42,7 @@ DIALOG_PCM_BASE::DIALOG_PCM_BASE( wxWindow* parent, wxWindowID id, const wxStrin
m_contentNotebook = new wxNotebook( m_panelRepository, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
bSizer4->Add( m_contentNotebook, 1, wxEXPAND|wxBOTTOM, 5 );
bSizer4->Add( m_contentNotebook, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_panelRepository->SetSizer( bSizer4 );

View File

@ -335,7 +335,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxBOTTOM</property>
<property name="flag">wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT</property>
<property name="proportion">1</property>
<object class="wxNotebook" expanded="1">
<property name="BottomDockable">1</property>

View File

@ -19,10 +19,12 @@
*/
#include "panel_packages_view.h"
#include "grid_tricks.h"
#include "kicad_settings.h"
#include "pgm_base.h"
#include "settings/settings_manager.h"
#include <grid_tricks.h>
#include <kicad_settings.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <string_utils.h>
#include <html_window.h>
#include <cmath>
#include <fstream>
@ -73,18 +75,6 @@ PANEL_PACKAGES_VIEW::PANEL_PACKAGES_VIEW( wxWindow*
m_packageListWindow->SetBackgroundColour( wxStaticText::GetClassDefaultAttributes().colBg );
m_infoScrollWindow->SetBackgroundColour( wxStaticText::GetClassDefaultAttributes().colBg );
m_infoText->SetBackgroundColour( wxStaticText::GetClassDefaultAttributes().colBg );
m_infoText->EnableVerticalScrollbar( false );
// Try to disable the caret on platforms that show it even in read-only controls
m_infoText->Bind( wxEVT_SET_FOCUS,
[&]( wxFocusEvent& event )
{
wxCaret* caret = m_infoText->GetCaret();
if( caret )
caret->Hide();
} );
ClearData();
}
@ -147,28 +137,18 @@ void PANEL_PACKAGES_VIEW::setPackageDetails( const PACKAGE_VIEW_DATA& aPackageDa
const PCM_PACKAGE& package = aPackageData.package;
// Details
m_infoText->Clear();
wxString details;
m_infoText->BeginBold();
m_infoText->WriteText( package.name );
m_infoText->EndBold();
m_infoText->Newline();
details << "<h5>" + package.name + "</h5>";
m_infoText->BeginParagraphSpacing( 0, 30 );
m_infoText->WriteText( package.description_full );
m_infoText->Newline();
m_infoText->EndParagraphSpacing();
wxString desc = package.description_full;
desc.Replace( "\n", "</p><p>", true );
details << "<p>" + desc + "</p>";
m_infoText->BeginFontSize( floor( m_infoText->GetDefaultStyle().GetFontSize() * 1.1 ) );
m_infoText->WriteText( _( "Metadata" ) );
m_infoText->Newline();
m_infoText->EndFontSize();
m_infoText->BeginParagraphSpacing( 0, 10 );
m_infoText->BeginSymbolBullet( wxString::FromUTF8( u8"\u2022" ), 30, 40 );
m_infoText->WriteText( wxString::Format( _( "Package identifier: %s\n" ),
package.identifier ) );
m_infoText->WriteText( wxString::Format( _( "License: %s\n" ), package.license ) );
details << "<p><b>" + _( "Metadata" ) + "</b></p>";
details << "<ul>";
details << "<li>" + _( "Package identifier: " ) + package.identifier + "</li>";
details << "<li>" + _( "License: " ) + package.license + "</li>";
if( package.tags.size() > 0 )
{
@ -182,24 +162,29 @@ void PANEL_PACKAGES_VIEW::setPackageDetails( const PACKAGE_VIEW_DATA& aPackageDa
tags_str += tag;
}
m_infoText->WriteText( wxString::Format( _( "Tags: %s\n" ), tags_str ) );
details << "<li>" + _( "Tags: " ) + tags_str + "</li>";
}
const auto write_contact =
auto format_url =
[]( const std::pair<const std::string, wxString>& entry ) -> wxString
{
wxString url = entry.second;
if( entry.first == "email" )
url = "mailto:" + url;
return "<a href='" + EscapeHTML( url ) + "'>" + EscapeHTML( url ) + "</a>";
};
auto write_contact =
[&]( const wxString& type, const PCM_CONTACT& contact )
{
m_infoText->WriteText( wxString::Format( "%s: %s\n", type, contact.name ) );
m_infoText->BeginLeftIndent( 60, 40 );
details << "<li>" + type + ": " + contact.name + "<ul>";
for( const std::pair<const std::string, wxString>& entry : contact.contact )
{
m_infoText->WriteText( wxString::Format( "%s: %s\n",
entry.first,
entry.second ) );
}
details << "<li>" + entry.first + ": " + format_url( entry ) + "</li>";
m_infoText->EndLeftIndent();
details << "</ul>";
};
write_contact( _( "Author" ), package.author );
@ -209,19 +194,17 @@ void PANEL_PACKAGES_VIEW::setPackageDetails( const PACKAGE_VIEW_DATA& aPackageDa
if( package.resources.size() > 0 )
{
m_infoText->WriteText( _( "Resources" ) );
m_infoText->Newline();
m_infoText->BeginLeftIndent( 60, 40 );
details << "<li>" + _( "Resources" ) + "<ul>";
for( const std::pair<const std::string, wxString>& entry : package.resources )
m_infoText->WriteText( wxString::Format( "%s: %s\n", entry.first, entry.second ) );
details << "<li>" + entry.first + wxS( ": " ) + format_url( entry ) + "</li>";
m_infoText->EndLeftIndent();
details << "</ul>";
}
m_infoText->EndSymbolBullet();
m_infoText->EndParagraphSpacing();
details << "</ul>";
m_infoText->SetPage( details );
wxSizeEvent dummy;
OnSizeInfoBox( dummy );
@ -281,6 +264,7 @@ void PANEL_PACKAGES_VIEW::setPackageDetails( const PACKAGE_VIEW_DATA& aPackageDa
else
m_buttonInstall->Disable();
m_infoText->Show( true );
m_sizerVersions->Show( true );
m_sizerVersions->Layout();
@ -291,7 +275,8 @@ void PANEL_PACKAGES_VIEW::setPackageDetails( const PACKAGE_VIEW_DATA& aPackageDa
void PANEL_PACKAGES_VIEW::unsetPackageDetails()
{
m_infoText->ChangeValue( wxEmptyString );
m_infoText->SetPage( wxEmptyString );
m_infoText->Show( false );
m_sizerVersions->Show( false );
wxSize size = m_infoScrollWindow->GetTargetWindow()->GetBestVirtualSize();
@ -538,19 +523,32 @@ void PANEL_PACKAGES_VIEW::updatePackageList()
}
void PANEL_PACKAGES_VIEW::OnSizeInfoBox( wxSizeEvent& event )
void PANEL_PACKAGES_VIEW::OnSizeInfoBox( wxSizeEvent& aEvent )
{
wxSize infoSize = m_infoText->GetParent()->GetClientSize();
infoSize.x -= 20; // approximation of scrollbars should they be needed
m_infoText->SetMinSize( infoSize );
m_infoText->SetMaxSize( infoSize );
m_infoText->SetSize( infoSize );
m_infoText->LayoutContent();
infoSize.y = m_infoText->GetBuffer().GetCachedSize().y + m_infoText->GetBuffer().GetTopMargin();
infoSize.y *= m_infoText->GetScale();
m_infoText->SetMinSize( infoSize );
m_infoText->SetMaxSize( infoSize );
m_infoText->SetSize( infoSize );
m_infoText->Layout();
infoSize.y = m_infoText->GetInternalRepresentation()->GetHeight() + 20;
m_infoText->SetMinSize( infoSize );
m_infoText->SetMaxSize( infoSize );
m_infoText->SetSize( infoSize );
m_infoText->Layout();
}
void PANEL_PACKAGES_VIEW::OnURLClicked( wxHtmlLinkEvent& aEvent )
{
const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
::wxLaunchDefaultBrowser( info.GetHref() );
}
void PANEL_PACKAGES_VIEW::OnInfoMouseWheel( wxMouseEvent& event )
{
// Transfer scrolling from the info window to its parent scroll window
m_infoScrollWindow->HandleOnMouseWheel( event );
}

View File

@ -72,7 +72,12 @@ public:
///< Ranks packages for entered search term and rearranges/hides panels according to their rank
void OnSearchTextChanged( wxCommandEvent& event );
void OnSizeInfoBox( wxSizeEvent& event ) override;
void OnSizeInfoBox( wxSizeEvent& aEvent ) override;
///< Respond to a URL in the info window
void OnURLClicked( wxHtmlLinkEvent& event ) override;
void OnInfoMouseWheel( wxMouseEvent& event ) override;
private:
///< Updates package listing according to search term

View File

@ -5,6 +5,8 @@
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "html_window.h"
#include "panel_packages_view_base.h"
///////////////////////////////////////////////////////////////////////////
@ -54,11 +56,10 @@ PANEL_PACKAGES_VIEW_BASE::PANEL_PACKAGES_VIEW_BASE( wxWindow* parent, wxWindowID
wxBoxSizer* bSizerScrolledWindow;
bSizerScrolledWindow = new wxBoxSizer( wxVERTICAL );
m_infoText = new wxRichTextCtrl( m_infoScrollWindow, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_AUTO_URL );
m_infoText->Enable( false );
m_infoText->SetMinSize( wxSize( -1,300 ) );
m_infoText = new HTML_WINDOW( m_infoScrollWindow, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_NEVER );
m_infoText->SetMinSize( wxSize( -1,100 ) );
bSizerScrolledWindow->Add( m_infoText, 0, wxEXPAND, 5 );
bSizerScrolledWindow->Add( m_infoText, 0, wxALL|wxEXPAND, 5 );
m_sizerVersions = new wxBoxSizer( wxVERTICAL );
@ -135,6 +136,8 @@ PANEL_PACKAGES_VIEW_BASE::PANEL_PACKAGES_VIEW_BASE( wxWindow* parent, wxWindowID
// Connect Events
m_infoScrollWindow->Connect( wxEVT_SIZE, wxSizeEventHandler( PANEL_PACKAGES_VIEW_BASE::OnSizeInfoBox ), NULL, this );
m_infoText->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( PANEL_PACKAGES_VIEW_BASE::OnURLClicked ), NULL, this );
m_infoText->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PACKAGES_VIEW_BASE::OnInfoMouseWheel ), NULL, this );
m_gridVersions->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( PANEL_PACKAGES_VIEW_BASE::OnVersionsCellClicked ), NULL, this );
m_showAllVersions->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( PANEL_PACKAGES_VIEW_BASE::OnShowAllVersionsClicked ), NULL, this );
m_buttonDownload->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PACKAGES_VIEW_BASE::OnDownloadVersionClicked ), NULL, this );
@ -145,6 +148,8 @@ PANEL_PACKAGES_VIEW_BASE::~PANEL_PACKAGES_VIEW_BASE()
{
// Disconnect Events
m_infoScrollWindow->Disconnect( wxEVT_SIZE, wxSizeEventHandler( PANEL_PACKAGES_VIEW_BASE::OnSizeInfoBox ), NULL, this );
m_infoText->Disconnect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( PANEL_PACKAGES_VIEW_BASE::OnURLClicked ), NULL, this );
m_infoText->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PACKAGES_VIEW_BASE::OnInfoMouseWheel ), NULL, this );
m_gridVersions->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( PANEL_PACKAGES_VIEW_BASE::OnVersionsCellClicked ), NULL, this );
m_showAllVersions->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( PANEL_PACKAGES_VIEW_BASE::OnShowAllVersionsClicked ), NULL, this );
m_buttonDownload->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PACKAGES_VIEW_BASE::OnDownloadVersionClicked ), NULL, this );

View File

@ -427,9 +427,9 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxRichTextCtrl" expanded="1">
<object class="wxHtmlWindow" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -450,7 +450,7 @@
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">0</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
@ -460,9 +460,9 @@
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size">-1,-1</property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">-1,300</property>
<property name="minimum_size">-1,100</property>
<property name="moveable">1</property>
<property name="name">m_infoText</property>
<property name="pane_border">1</property>
@ -474,17 +474,15 @@
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxTE_AUTO_URL</property>
<property name="subclass">; ; forward_declare</property>
<property name="style">wxHW_SCROLLBAR_NEVER</property>
<property name="subclass">HTML_WINDOW; html_window.h; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnHtmlLinkClicked">OnURLClicked</event>
<event name="OnMouseWheel">OnInfoMouseWheel</event>
</object>
</object>
<object class="sizeritem" expanded="1">

View File

@ -10,6 +10,8 @@
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
class HTML_WINDOW;
#include "widgets/wx_grid.h"
#include <wx/string.h>
#include <wx/srchctrl.h>
@ -20,7 +22,7 @@
#include <wx/sizer.h>
#include <wx/scrolwin.h>
#include <wx/panel.h>
#include <wx/richtext/richtextctrl.h>
#include <wx/html/htmlwin.h>
#include <wx/grid.h>
#include <wx/checkbox.h>
#include <wx/bitmap.h>
@ -46,7 +48,7 @@ class PANEL_PACKAGES_VIEW_BASE : public wxPanel
wxScrolledWindow* m_packageListWindow;
wxPanel* m_panelDetails;
wxScrolledWindow* m_infoScrollWindow;
wxRichTextCtrl* m_infoText;
HTML_WINDOW* m_infoText;
wxBoxSizer* m_sizerVersions;
WX_GRID* m_gridVersions;
wxCheckBox* m_showAllVersions;
@ -55,6 +57,8 @@ class PANEL_PACKAGES_VIEW_BASE : public wxPanel
// Virtual event handlers, overide them in your derived class
virtual void OnSizeInfoBox( wxSizeEvent& event ) { event.Skip(); }
virtual void OnURLClicked( wxHtmlLinkEvent& event ) { event.Skip(); }
virtual void OnInfoMouseWheel( wxMouseEvent& event ) { event.Skip(); }
virtual void OnVersionsCellClicked( wxGridEvent& event ) { event.Skip(); }
virtual void OnShowAllVersionsClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnDownloadVersionClicked( wxCommandEvent& event ) { event.Skip(); }