Support (and save/recall) zoom in/out in Custom Rules editor.

Fixes https://gitlab.com/kicad/code/kicad/issues/5796
This commit is contained in:
Jeff Young 2022-01-23 23:04:19 +00:00
parent 3b87ab630e
commit 0036f44e37
7 changed files with 100 additions and 0 deletions

View File

@ -108,6 +108,9 @@ COMMON_SETTINGS::COMMON_SETTINGS() :
m_params.emplace_back( new PARAM<double>( "appearance.hicontrast_dimming_factor",
&m_Appearance.hicontrast_dimming_factor, 0.8f ) );
m_params.emplace_back( new PARAM<int>( "appearance.text_editor_zoom",
&m_Appearance.text_editor_zoom, 0 ) );
m_params.emplace_back( new PARAM<bool>( "auto_backup.enabled", &m_Backup.enabled, true ) );
m_params.emplace_back( new PARAM<bool>( "auto_backup.backup_on_autosave",

View File

@ -55,6 +55,7 @@ public:
bool use_icons_in_menus;
bool apply_icon_scale_to_fonts;
double hicontrast_dimming_factor;
int text_editor_zoom;
};
struct AUTO_BACKUP

View File

@ -38,6 +38,7 @@
#include <scintilla_tricks.h>
#include <drc/drc_rule_parser.h>
#include <tools/drc_tool.h>
#include <pgm_base.h>
PANEL_SETUP_RULES::PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ) :
PANEL_SETUP_RULES_BASE( aParent->GetTreebook() ),
@ -58,10 +59,14 @@ PANEL_SETUP_RULES::PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFr
m_netNameRegex.Compile( "NetName\\s*[!=]=\\s*$", wxRE_ADVANCED );
m_typeRegex.Compile( "Type\\s*[!=]=\\s*$", wxRE_ADVANCED );
m_padTypeRegex.Compile( "Pad_Type\\s*[!=]=\\s*$", wxRE_ADVANCED );
m_pinTypeRegex.Compile( "Pin_Type\\s*[!=]=\\s*$", wxRE_ADVANCED );
m_fabPropRegex.Compile( "Fabrication_Property\\s*[!=]=\\s*$", wxRE_ADVANCED );
m_compileButton->SetBitmap( KiBitmap( BITMAPS::drc ) );
m_textEditor->SetZoom( Pgm().GetCommonSettings()->m_Appearance.text_editor_zoom );
m_textEditor->UsePopUp( 0 );
m_textEditor->Bind( wxEVT_STC_CHARADDED, &PANEL_SETUP_RULES::onScintillaCharAdded, this );
m_textEditor->Bind( wxEVT_STC_AUTOCOMP_CHAR_DELETED, &PANEL_SETUP_RULES::onScintillaCharAdded, this );
m_textEditor->Bind( wxEVT_CHAR_HOOK, &PANEL_SETUP_RULES::onCharHook, this );
@ -70,6 +75,8 @@ PANEL_SETUP_RULES::PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFr
PANEL_SETUP_RULES::~PANEL_SETUP_RULES( )
{
Pgm().GetCommonSettings()->m_Appearance.text_editor_zoom = m_textEditor->GetZoom();
delete m_scintillaTricks;
if( m_helpWindow )
@ -92,6 +99,74 @@ void PANEL_SETUP_RULES::onCharHook( wxKeyEvent& aEvent )
}
void PANEL_SETUP_RULES::OnContextMenu(wxMouseEvent &event)
{
wxMenu menu;
wxString msg;
menu.Append( wxID_UNDO, _( "Undo" ) );
menu.Append( wxID_REDO, _( "Redo" ) );
menu.AppendSeparator();
menu.Append( 1, _( "Cut" ) ); // Don't use wxID_CUT, wxID_COPY, etc. On Mac (at least),
menu.Append( 2, _( "Copy" ) ); // wxWidgets never delivers them to us.
menu.Append( 3, _( "Paste" ) );
menu.Append( 4, _( "Delete" ) );
menu.AppendSeparator();
menu.Append( 5, _( "Select All" ) );
menu.AppendSeparator();
menu.Append( wxID_ZOOM_IN, _( "Zoom In" ) );
menu.Append( wxID_ZOOM_OUT, _( "Zoom Out" ) );
switch( GetPopupMenuSelectionFromUser( menu ) )
{
case wxID_UNDO:
m_textEditor->Undo();
break;
case wxID_REDO:
m_textEditor->Redo();
break;
case 1:
m_textEditor->Cut();
break;
case 2:
m_textEditor->Copy();
break;
case 3:
m_textEditor->Paste();
break;
case 4:
{
long from, to;
m_textEditor->GetSelection( &from, &to );
if( to > from )
m_textEditor->DeleteRange( from, to );
break;
}
case 5:
m_textEditor->SelectAll();
break;
case wxID_ZOOM_IN:
m_textEditor->ZoomIn();
break;
case wxID_ZOOM_OUT:
m_textEditor->ZoomOut();
break;
}
}
void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent )
{
m_Parent->SetModified();
@ -417,6 +492,21 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent )
"Edge connector|"
"NPTH, mechanical";
}
else if( m_pinTypeRegex.Matches( last ) )
{
tokens = "Input|"
"Output|"
"Bidirectional|"
"Tri-state|"
"Passive|"
"Free|"
"Unspecified|"
"Power input|"
"Power output|"
"Open collector|"
"Open emitter|"
"Unconnected";
}
else if( m_fabPropRegex.Matches( last ) )
{
tokens = "None|"

View File

@ -48,6 +48,7 @@ private:
void OnCompile( wxCommandEvent& event ) override;
void OnErrorLinkClicked( wxHtmlLinkEvent& event ) override;
void onCharHook( wxKeyEvent& aEvent );
void OnContextMenu( wxMouseEvent& event ) override;
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
@ -61,6 +62,7 @@ private:
wxRegEx m_netNameRegex;
wxRegEx m_typeRegex;
wxRegEx m_padTypeRegex;
wxRegEx m_pinTypeRegex;
wxRegEx m_fabPropRegex;
HTML_MESSAGE_BOX* m_helpWindow;

View File

@ -99,6 +99,7 @@ PANEL_SETUP_RULES_BASE::PANEL_SETUP_RULES_BASE( wxWindow* parent, wxWindowID id,
// Connect Events
m_syntaxHelp->Connect( wxEVT_COMMAND_HYPERLINK, wxHyperlinkEventHandler( PANEL_SETUP_RULES_BASE::OnSyntaxHelp ), NULL, this );
m_textEditor->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( PANEL_SETUP_RULES_BASE::OnContextMenu ), NULL, this );
m_compileButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_RULES_BASE::OnCompile ), NULL, this );
m_errorsReport->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( PANEL_SETUP_RULES_BASE::OnErrorLinkClicked ), NULL, this );
}
@ -107,6 +108,7 @@ PANEL_SETUP_RULES_BASE::~PANEL_SETUP_RULES_BASE()
{
// Disconnect Events
m_syntaxHelp->Disconnect( wxEVT_COMMAND_HYPERLINK, wxHyperlinkEventHandler( PANEL_SETUP_RULES_BASE::OnSyntaxHelp ), NULL, this );
m_textEditor->Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( PANEL_SETUP_RULES_BASE::OnContextMenu ), NULL, this );
m_compileButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_RULES_BASE::OnCompile ), NULL, this );
m_errorsReport->Disconnect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( PANEL_SETUP_RULES_BASE::OnErrorLinkClicked ), NULL, this );

View File

@ -282,6 +282,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnRightDown">OnContextMenu</event>
</object>
</object>
<object class="sizeritem" expanded="1">

View File

@ -51,6 +51,7 @@ class PANEL_SETUP_RULES_BASE : public wxPanel
// Virtual event handlers, overide them in your derived class
virtual void OnSyntaxHelp( wxHyperlinkEvent& event ) { event.Skip(); }
virtual void OnContextMenu( wxMouseEvent& event ) { event.Skip(); }
virtual void OnCompile( wxCommandEvent& event ) { event.Skip(); }
virtual void OnErrorLinkClicked( wxHtmlLinkEvent& event ) { event.Skip(); }