Use wxWidgets IDs for cut/copy/paste.

This allows them to work in places like search boxes in standard file
dialogs.  If wxWidgets doesn't find the standard IDs in our menus
then it won't enable them.
This commit is contained in:
Jeff Young 2022-08-06 21:28:48 +01:00
parent 05785ac6b9
commit 5c9aed62aa
5 changed files with 48 additions and 5 deletions

View File

@ -466,8 +466,14 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent )
} }
// Check if there is a TOOL_ACTION for the given ID // Check if there is a TOOL_ACTION for the given ID
if( m_selected >= TOOL_ACTION::GetBaseUIId() ) // Note that we also have to check the standard wxWidgets' cut/copy/paste IDs because
// we can't use our own IDs there without losing cut/copy/paste in places like search
// boxes in standard file dialogs.
if( m_selected == wxID_CUT || m_selected == wxID_COPY || m_selected == wxID_PASTE
|| m_selected >= TOOL_ACTION::GetBaseUIId() )
{
evt = findToolAction( m_selected ); evt = findToolAction( m_selected );
}
if( !evt ) if( !evt )
{ {

View File

@ -151,19 +151,19 @@ TOOL_ACTION ACTIONS::cut( "common.Interactive.cut",
AS_GLOBAL, AS_GLOBAL,
MD_CTRL + 'X', LEGACY_HK_NAME( "Cut" ), MD_CTRL + 'X', LEGACY_HK_NAME( "Cut" ),
_( "Cut" ), _( "Cut selected item(s) to clipboard" ), _( "Cut" ), _( "Cut selected item(s) to clipboard" ),
BITMAPS::cut ); BITMAPS::cut, AF_NONE, (void*) wxID_CUT );
TOOL_ACTION ACTIONS::copy( "common.Interactive.copy", TOOL_ACTION ACTIONS::copy( "common.Interactive.copy",
AS_GLOBAL, AS_GLOBAL,
MD_CTRL + 'C', LEGACY_HK_NAME( "Copy" ), MD_CTRL + 'C', LEGACY_HK_NAME( "Copy" ),
_( "Copy" ), _( "Copy selected item(s) to clipboard" ), _( "Copy" ), _( "Copy selected item(s) to clipboard" ),
BITMAPS::copy ); BITMAPS::copy, AF_NONE, (void*) wxID_COPY );
TOOL_ACTION ACTIONS::paste( "common.Interactive.paste", TOOL_ACTION ACTIONS::paste( "common.Interactive.paste",
AS_GLOBAL, AS_GLOBAL,
MD_CTRL + 'V', LEGACY_HK_NAME( "Paste" ), MD_CTRL + 'V', LEGACY_HK_NAME( "Paste" ),
_( "Paste" ), _( "Paste item(s) from clipboard" ), _( "Paste" ), _( "Paste item(s) from clipboard" ),
BITMAPS::paste ); BITMAPS::paste, AF_NONE, (void*) wxID_PASTE );
TOOL_ACTION ACTIONS::selectAll( "common.Interactive.selectAll", TOOL_ACTION ACTIONS::selectAll( "common.Interactive.selectAll",
AS_GLOBAL, AS_GLOBAL,

View File

@ -127,7 +127,20 @@ public:
* *
* @return The unique ID number for use in the user interface system. * @return The unique ID number for use in the user interface system.
*/ */
int GetUIId() const { return m_id + ACTION_BASE_UI_ID; } int GetUIId() const
{
// Hack for wxWidgets' use in stuff like search controls in standard file dialogs. If
// it doesn't find these specific IDs somewhere in the menus then it won't enable
// cut/copy/paste.
if( m_param == (void*) wxID_CUT )
return wxID_CUT;
else if( m_param == (void*) wxID_COPY )
return wxID_COPY;
else if( m_param == (void*) wxID_PASTE )
return wxID_PASTE;
return m_id + ACTION_BASE_UI_ID;
}
/* /*
* Get the base value used to offset the user interface IDs for the actions. * Get the base value used to offset the user interface IDs for the actions.

View File

@ -257,14 +257,24 @@ void KICAD_MANAGER_FRAME::setupUIConditions()
return m_active_project; return m_active_project;
}; };
#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
ACTION_CONDITIONS activeProjectCond; ACTION_CONDITIONS activeProjectCond;
activeProjectCond.Enable( activeProject ); activeProjectCond.Enable( activeProject );
manager->SetConditions( ACTIONS::saveAs, activeProjectCond ); manager->SetConditions( ACTIONS::saveAs, activeProjectCond );
manager->SetConditions( KICAD_MANAGER_ACTIONS::closeProject, activeProjectCond ); manager->SetConditions( KICAD_MANAGER_ACTIONS::closeProject, activeProjectCond );
// These are just here for text boxes, search boxes, etc. in places such as the standard
// file dialogs.
manager->SetConditions( ACTIONS::cut, ENABLE( SELECTION_CONDITIONS::ShowNever ) );
manager->SetConditions( ACTIONS::copy, ENABLE( SELECTION_CONDITIONS::ShowNever ) );
manager->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::ShowNever ) );
// TODO: Switch this to an action // TODO: Switch this to an action
RegisterUIUpdateHandler( ID_SAVE_AND_ZIP_FILES, activeProjectCond ); RegisterUIUpdateHandler( ID_SAVE_AND_ZIP_FILES, activeProjectCond );
#undef ENABLE
} }

View File

@ -129,6 +129,19 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
fileMenu->AppendSeparator(); fileMenu->AppendSeparator();
fileMenu->AddQuitOrClose( nullptr, "KiCad" ); fileMenu->AddQuitOrClose( nullptr, "KiCad" );
//-- Edit menu -----------------------------------------------------------
//
ACTION_MENU* editMenu = new ACTION_MENU( false, controlTool );
/*
* While we don't presently use these, they need to be here so that cut/copy/paste work
* in things like search boxes in file open dialogs.
*/
editMenu->Add( ACTIONS::cut );
editMenu->Add( ACTIONS::copy );
editMenu->Add( ACTIONS::paste );
//-- View menu ----------------------------------------------------------- //-- View menu -----------------------------------------------------------
// //
ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool ); ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
@ -198,6 +211,7 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
//-- Menubar ------------------------------------------------------------- //-- Menubar -------------------------------------------------------------
// //
menuBar->Append( fileMenu, _( "&File" ) ); menuBar->Append( fileMenu, _( "&File" ) );
menuBar->Append( editMenu, _( "&Edit" ) );
menuBar->Append( viewMenu, _( "&View" ) ); menuBar->Append( viewMenu, _( "&View" ) );
menuBar->Append( toolsMenu, _( "&Tools" ) ); menuBar->Append( toolsMenu, _( "&Tools" ) );
menuBar->Append( prefsMenu, _( "&Preferences" ) ); menuBar->Append( prefsMenu, _( "&Preferences" ) );