KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_package.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef PANEL_PACKAGE_H_
22#define PANEL_PACKAGE_H_
23
24#include <functional>
25
26#include "panel_package_base.h"
27#include "pcm.h"
28
31{
33 wxBitmap* bitmap;
35 bool pinned;
36 wxString repository_id;
41 PACKAGE_VIEW_DATA( const PCM_PACKAGE aPackage ) :
42 package( std::move( aPackage ) ),
43 bitmap( nullptr ),
45 pinned( false ),
46 swig_warning( false )
47 {};
49 package( std::move( aEntry.package ) ), bitmap( nullptr )
50 {
55 pinned = aEntry.pinned;
56 swig_warning = false;
57 }
58};
59
60
62using ActionCallback = std::function<void( const PACKAGE_VIEW_DATA& aData,
63 PCM_PACKAGE_ACTION aAction, const wxString& aVersion )>;
64
65using PinCallback = std::function<void( const wxString& aPackageId, const PCM_PACKAGE_STATE aState,
66 const bool aPinned )>;
67
68
70{
71public:
72 PANEL_PACKAGE( wxWindow* parent, const ActionCallback& aCallback,
73 const PinCallback& aPinCallback, const PACKAGE_VIEW_DATA& aData );
74
76 void SetSelectCallback( const std::function<void()>& aCallback );
77
79 void SetSelected( bool aSelected );
80
81 void OnButtonClicked( wxCommandEvent& event ) override;
82
84 void SetState( PCM_PACKAGE_STATE aState, bool aPinned );
85
87 void OnClick( wxMouseEvent& event ) override;
88
89 void OnUninstallClick( wxCommandEvent& event );
90
91 void OnPinVersionClick( wxCommandEvent& event );
92
93 void OnSize( wxSizeEvent& event ) override;
94
96 wxString GetPreferredVersion() const;
97
98 const PACKAGE_VIEW_DATA& GetPackageData() const { return m_data; };
99
100private:
101 void OnPaint( wxPaintEvent& event ) override;
102
103private:
105 wxMenuItem* m_actionMenuItem;
106 std::function<void()> m_selectCallback;
107 bool m_selected = false;
112};
113
114
115#endif // PANEL_PACKAGE_H_
PANEL_PACKAGE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxBORDER_NONE|wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void OnClick(wxMouseEvent &event) override
void OnUninstallClick(wxCommandEvent &event)
wxMenuItem * m_actionMenuItem
void OnPinVersionClick(wxCommandEvent &event)
const PACKAGE_VIEW_DATA & GetPackageData() const
void OnPaint(wxPaintEvent &event) override
void SetSelected(bool aSelected)
void OnButtonClicked(wxCommandEvent &event) override
Changes state of the (un)install button.
const ActionCallback & m_actionCallback
const PinCallback & m_pinCallback
wxMenuItem * m_pinVersionMenuItem
PACKAGE_VIEW_DATA m_data
void SetState(PCM_PACKAGE_STATE aState, bool aPinned)
Called when anywhere on the panel is clicked (except install button)
PANEL_PACKAGE(wxWindow *parent, const ActionCallback &aCallback, const PinCallback &aPinCallback, const PACKAGE_VIEW_DATA &aData)
Sets callback for OnClick action.
void OnSize(wxSizeEvent &event) override
Get preferred version. If criteria are not met, return wxEmptyString.
std::function< void()> m_selectCallback
void SetSelectCallback(const std::function< void()> &aCallback)
Marks panel as selected.
wxString GetPreferredVersion() const
STL namespace.
std::function< void(const wxString &aPackageId, const PCM_PACKAGE_STATE aState, const bool aPinned)> PinCallback
std::function< void(const PACKAGE_VIEW_DATA &aData, PCM_PACKAGE_ACTION aAction, const wxString &aVersion)> ActionCallback
PCM_PACKAGE_STATE
Definition pcm.h:58
@ PPS_INSTALLED
Definition pcm.h:61
PCM_PACKAGE_ACTION
Definition pcm.h:71
< Collection of data relevant to the package display panelCallback for (un)install button
wxString update_version
wxString current_version
const PCM_PACKAGE package
wxString repository_name
PACKAGE_VIEW_DATA(const PCM_INSTALLATION_ENTRY &aEntry)
PCM_PACKAGE_STATE state
PACKAGE_VIEW_DATA(const PCM_PACKAGE aPackage)
Definition pcm_data.h:159
wxString repository_name
Definition pcm_data.h:163
wxString repository_id
Definition pcm_data.h:162
wxString current_version
Definition pcm_data.h:161
bool pinned
Definition pcm_data.h:165
Repository reference to a resource.
Definition pcm_data.h:114