From f9bbaed7a168f129cd5d5ad16461a9028c13bd26 Mon Sep 17 00:00:00 2001
From: Jeff Young
Date: Thu, 11 Nov 2021 23:41:31 +0000
Subject: [PATCH] Enable URLs in PCM metadata.
Going to HTML_WINDOW also sidesteps the bullet size issue between
platforms.
---
kicad/pcm/dialogs/dialog_pcm_base.cpp | 2 +-
kicad/pcm/dialogs/dialog_pcm_base.fbp | 2 +-
kicad/pcm/dialogs/panel_packages_view.cpp | 126 +++++++++---------
kicad/pcm/dialogs/panel_packages_view.h | 7 +-
.../pcm/dialogs/panel_packages_view_base.cpp | 13 +-
.../pcm/dialogs/panel_packages_view_base.fbp | 20 ++-
kicad/pcm/dialogs/panel_packages_view_base.h | 8 +-
7 files changed, 94 insertions(+), 84 deletions(-)
diff --git a/kicad/pcm/dialogs/dialog_pcm_base.cpp b/kicad/pcm/dialogs/dialog_pcm_base.cpp
index 7bfc72a1f5..68979ddaeb 100644
--- a/kicad/pcm/dialogs/dialog_pcm_base.cpp
+++ b/kicad/pcm/dialogs/dialog_pcm_base.cpp
@@ -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 );
diff --git a/kicad/pcm/dialogs/dialog_pcm_base.fbp b/kicad/pcm/dialogs/dialog_pcm_base.fbp
index 83d4ef5335..9959e7213f 100644
--- a/kicad/pcm/dialogs/dialog_pcm_base.fbp
+++ b/kicad/pcm/dialogs/dialog_pcm_base.fbp
@@ -335,7 +335,7 @@
", true );
+ details << "
" + desc + "
";
- 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 << "" + _( "Metadata" ) + "
";
+ details << "";
+ details << "- " + _( "Package identifier: " ) + package.identifier + "
";
+ details << "- " + _( "License: " ) + package.license + "
";
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 << "- " + _( "Tags: " ) + tags_str + "
";
}
- const auto write_contact =
+ auto format_url =
+ []( const std::pair& entry ) -> wxString
+ {
+ wxString url = entry.second;
+
+ if( entry.first == "email" )
+ url = "mailto:" + url;
+
+ return "" + EscapeHTML( url ) + "";
+ };
+
+ 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 << "- " + type + ": " + contact.name + "
";
for( const std::pair& entry : contact.contact )
- {
- m_infoText->WriteText( wxString::Format( "%s: %s\n",
- entry.first,
- entry.second ) );
- }
+ details << "- " + entry.first + ": " + format_url( entry ) + "
";
- m_infoText->EndLeftIndent();
+ details << "
";
};
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 << " - " + _( "Resources" ) + "
";
for( const std::pair& entry : package.resources )
- m_infoText->WriteText( wxString::Format( "%s: %s\n", entry.first, entry.second ) );
+ details << "- " + entry.first + wxS( ": " ) + format_url( entry ) + "
";
- m_infoText->EndLeftIndent();
+ details << "
";
}
- m_infoText->EndSymbolBullet();
- m_infoText->EndParagraphSpacing();
+ details << "
";
+
+ 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 );
}
\ No newline at end of file
diff --git a/kicad/pcm/dialogs/panel_packages_view.h b/kicad/pcm/dialogs/panel_packages_view.h
index a1ec6c0e34..89c8557fc8 100644
--- a/kicad/pcm/dialogs/panel_packages_view.h
+++ b/kicad/pcm/dialogs/panel_packages_view.h
@@ -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
diff --git a/kicad/pcm/dialogs/panel_packages_view_base.cpp b/kicad/pcm/dialogs/panel_packages_view_base.cpp
index ca849e358e..d168e3c108 100644
--- a/kicad/pcm/dialogs/panel_packages_view_base.cpp
+++ b/kicad/pcm/dialogs/panel_packages_view_base.cpp
@@ -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 );
diff --git a/kicad/pcm/dialogs/panel_packages_view_base.fbp b/kicad/pcm/dialogs/panel_packages_view_base.fbp
index 97551aaf72..a9bc4fba82 100644
--- a/kicad/pcm/dialogs/panel_packages_view_base.fbp
+++ b/kicad/pcm/dialogs/panel_packages_view_base.fbp
@@ -427,9 +427,9 @@
none
5
- wxEXPAND
+ wxALL|wxEXPAND
0
-
+
1
1
1
@@ -450,7 +450,7 @@
Dock
0
Left
- 0
+ 1
1
@@ -460,9 +460,9 @@
0
- -1,-1
+
0
- -1,300
+ -1,100
1
m_infoText
1
@@ -474,17 +474,15 @@
Resizable
1
- wxTE_AUTO_URL
- ; ; forward_declare
+ wxHW_SCROLLBAR_NEVER
+ HTML_WINDOW; html_window.h; forward_declare
0
-
- wxFILTER_NONE
- wxDefaultValidator
-
+ OnURLClicked
+ OnInfoMouseWheel
diff --git a/kicad/pcm/dialogs/panel_packages_view_base.h b/kicad/pcm/dialogs/panel_packages_view_base.h
index 8f9896a07f..0e98acf00f 100644
--- a/kicad/pcm/dialogs/panel_packages_view_base.h
+++ b/kicad/pcm/dialogs/panel_packages_view_base.h
@@ -10,6 +10,8 @@
#include
#include
#include
+class HTML_WINDOW;
+
#include "widgets/wx_grid.h"
#include
#include
@@ -20,7 +22,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
@@ -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(); }