33#include <wx/hyperlink.h>
34#include <wx/propgrid/advprops.h>
36#include <wx/stc/stc.h>
48class PL_TEXT_PROPERTY :
public wxLongStringProperty
51 explicit PL_TEXT_PROPERTY( PL_EDITOR_FRAME* aFrame ) :
52 wxLongStringProperty(
_(
"Text" ), wxS(
"Text" ) ),
58 bool DisplayEditorDialog( wxPropertyGrid* aGrid, wxVariant& aValue )
override
60 DIALOG_SHIM dlg( m_frame, wxID_ANY,
_(
"Edit Text" ), wxDefaultPosition, wxDefaultSize,
61 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
62 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
63 wxStyledTextCtrl*
editor =
new wxStyledTextCtrl( &dlg, wxID_ANY );
64 editor->SetMinSize( dlg.FromDIP( wxSize( 450, 200 ) ) );
65 editor->SetEOLMode( wxSTC_EOL_LF );
67 editor->SetTechnology( wxSTC_TECHNOLOGY_DIRECTWRITE );
69 DS_DATA_ITEM_TEXT
text( wxEmptyString );
70 text.m_FullText = aValue.IsNull() ? wxString() : aValue.GetString();
71 text.ReplaceAntiSlashSequence();
74 SCINTILLA_TRICKS tricks(
editor, wxT(
"{}" ),
false );
76 auto autocomplete = [&]( wxStyledTextEvent& )
79 int pos =
editor->GetCurrentPos();
80 int start =
editor->WordStartPosition( pos,
true );
83 if( start >= 2 &&
editor->GetCharAt( start - 2 ) ==
'$' &&
editor->GetCharAt( start - 1 ) ==
'{' )
86 partial =
editor->GetTextRange( start, pos );
88 for(
const auto& [key, value] : m_frame->Prj().GetTextVars() )
89 tokens.push_back( key );
92 tricks.DoAutocomplete( partial, tokens );
95 editor->Bind( wxEVT_STC_CHARADDED, autocomplete );
96 editor->Bind( wxEVT_STC_AUTOCOMP_CHAR_DELETED, autocomplete );
97 sizer->Add(
editor, 1, wxEXPAND | wxALL, 10 );
99 wxHyperlinkCtrl*
help =
new wxHyperlinkCtrl( &dlg, wxID_ANY,
_(
"Text Variables" ), wxEmptyString );
100 help->Bind( wxEVT_HYPERLINK,
101 [&]( wxHyperlinkEvent& )
103 HTML_MESSAGE_BOX helpDlg( &dlg,
_(
"Predefined Keywords" ) );
104 helpDlg.AddHTML_Text(
_(
"Text can include variables using ${keyword} notation." ) );
105 wxArrayString tokens;
109 for(
const wxString& token : tokens )
110 list += token + wxS(
"\n" );
112 helpDlg.ListSet( list );
115 sizer->Add(
help, 0, wxLEFT | wxRIGHT | wxBOTTOM, 10 );
116 sizer->Add( dlg.CreateStdDialogButtonSizer( wxOK | wxCANCEL ), 0, wxEXPAND | wxALL, 10 );
117 dlg.SetSizerAndFit( sizer );
121 if( dlg.ShowModal() != wxID_OK )
124 aValue =
editor->GetText();
129 PL_EDITOR_FRAME* m_frame;
140 SetMinSize( FromDIP( wxSize( 150, -1 ) ) );
146 if( it != editors.end() )
195 std::set<DS_DATA_ITEM*> seen;
201 if( peer && seen.insert( peer ).second )
225 wxPGProperty* property;
227 if( aProperty->
Name() == wxS(
"Text" ) )
229 property =
new PL_TEXT_PROPERTY(
m_editor );
230 property->SetClientData(
const_cast<PROPERTY_BASE*
>( aProperty ) );
231 property->SetHelpString( wxGetTranslation( aProperty->
HelpString() ) );
233 else if( aProperty->
Name() == wxS(
"Comment" ) )
236 property =
new wxStringProperty( wxGetTranslation( aProperty->
Name() ), aProperty->
Name() );
237 property->SetClientData(
const_cast<PROPERTY_BASE*
>( aProperty ) );
245 color->SetBackgroundColor(
m_editor->GetDrawBgColor() );
262 if( !property || !property->Available( item ) || !property->Writeable( item ) )
268 if(
auto error = property->Validate( aEvent.GetPropertyValue().GetAny(), item ) )
270 m_editor->ShowInfoBarError( wxString::Format( wxS(
"%s: %s" ), wxGetTranslation( property->Name() ),
271 error->get()->Format(
m_editor ) ) );
292 item->Set( property, aEvent.GetPropertyValue() );
304 model.m_DefaultLineWidth = 0.15;
305 model.m_DefaultTextThickness = 0.15;
317 m_editor->GetCanvas()->DisplayDrawingSheet();
325 const auto& items = properties->GetItem()->GetDrawItems();
328 && std::ranges::none_of( items,
331 return aItem->IsSelected();
Drawing sheet structure type definitions.
Handle the graphic items list to draw/plot the frame and title block.
static DS_DATA_MODEL & GetTheInstance()
Return the instance of DS_DATA_MODEL used in the application.
Base class to handle basic graphic items.
static void GetTextVars(wxArrayString *aVars)
A base class for most all the KiCad significant classes used in schematics and boards.
static const TOOL_EVENT SelectedEvent
static const TOOL_EVENT UnselectedEvent
static const wxString EDITOR_NAME
static const wxString EDITOR_NAME
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
The main window used in the drawing sheet editor.
Drawing-sheet defaults and margins, shown when no item is selected.
void UpdateData() override
void valueChanged(wxPropertyGridEvent &aEvent) override
std::vector< std::unique_ptr< PL_ITEM_PROPERTIES > > m_itemProperties
~PL_PROPERTIES_PANEL() override
PL_PROPERTIES_PANEL(PL_EDITOR_FRAME *aFrame)
wxPGProperty * createPGProperty(const PROPERTY_BASE *aProperty) const override
void valueChanging(wxPropertyGridEvent &aEvent) override
std::unique_ptr< PL_PAGE_PROPERTIES > m_pageProperties
PL_EDITOR_FRAME * m_editor
PG_UNIT_EDITOR * m_unitEditor
void rebuildProperties(const SELECTION &aSelection) override
Generates the property grid for a given selection of items.
PROPERTIES_PANEL(wxWindow *aParent, EDA_BASE_FRAME *aFrame)
int m_SuppressGridChangeEvents
wxTimer m_deferredRebuildTimer
Not CallAfter(): on macOS the pending-event queue is drained from inside tool events,...
SELECTION m_deferredSelection
virtual void rebuildProperties(const SELECTION &aSelection)
Generates the property grid for a given selection of items.
void addCategoryButton(const wxString &aGroupKey, const wxString &aTooltip, BITMAPS aBitmap, std::function< void()> aAction, std::function< bool()> aEnableFunc=nullptr, bool aForceCategory=false)
Registers an overlay button on a category caption row.
const wxString & HelpString() const
const wxString & Name() const
static PROPERTY_MANAGER & Instance()
void Rebuild()
Rebuild the list of all registered properties.
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Return a property for a specific type.
#define TB_DEFAULT_TEXTSIZE
wxPGProperty * PGPropertyFactory(const PROPERTY_BASE *aProperty, EDA_DRAW_FRAME *aFrame)
APIIMPORT wxPGGlobalVarsClass * wxPGGlobalVars
VECTOR2< double > VECTOR2D