From cd2bd23c37d466de490e8fc1cd4fdd210e74e82d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 6 May 2019 21:37:54 +0100 Subject: [PATCH] Fix a bunch of issues with hotkeys, IDs and event processing. Fixes: lp:1827894 * https://bugs.launchpad.net/kicad/+bug/1827894 --- common/tool/tool_event.cpp | 14 ++++++++++++++ eeschema/eeschema_id.h | 25 ++++--------------------- eeschema/hotkeys.cpp | 19 +++++++++++-------- eeschema/hotkeys.h | 2 -- eeschema/libedit/lib_edit_frame.cpp | 4 +--- eeschema/menubar.cpp | 2 +- eeschema/sch_draw_panel.cpp | 4 ++++ eeschema/sch_edit_frame.cpp | 2 +- eeschema/toolbars_sch_editor.cpp | 2 +- eeschema/tools/sch_actions.cpp | 8 +++++++- eeschema/tools/sch_drawing_tool.cpp | 6 +++--- eeschema/tools/sch_edit_tool.cpp | 6 ++++++ eeschema/tools/sch_move_tool.cpp | 2 +- include/hotkeys_basic.h | 2 ++ include/id.h | 1 + include/tool/tool_event.h | 17 ++++------------- pagelayout_editor/hotkeys.h | 4 +--- pcbnew/hotkeys.cpp | 1 - pcbnew/hotkeys.h | 2 -- 19 files changed, 62 insertions(+), 61 deletions(-) diff --git a/common/tool/tool_event.cpp b/common/tool/tool_event.cpp index a23161c59c..630942e43b 100644 --- a/common/tool/tool_event.cpp +++ b/common/tool/tool_event.cpp @@ -162,6 +162,20 @@ const std::string TOOL_EVENT_LIST::Format() const } +bool TOOL_EVENT::IsClick( int aButtonMask ) const +{ + return IsAction( &ACTIONS::cursorClick ) + || ( m_actions == TA_MOUSE_CLICK && ( m_mouseButtons & aButtonMask ) == aButtonMask ); +} + + +bool TOOL_EVENT::IsDblClick( int aButtonMask ) const +{ + return IsAction( &ACTIONS::cursorDblClick ) + || ( m_actions == TA_MOUSE_DBLCLICK && ( m_mouseButtons & aButtonMask ) == aButtonMask ); +} + + bool TOOL_EVT_UTILS::IsCancelInteractive( const TOOL_EVENT& aEvt ) { return aEvt.IsAction( &ACTIONS::cancelInteractive ) diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index 9c48adf528..ca2feb2330 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -68,6 +68,7 @@ enum id_eeschema_frm /* Schematic editor horizontal toolbar IDs */ ID_HIERARCHY, + ID_SCH_LEAVE_SHEET, ID_TO_LIBVIEW, ID_GET_ANNOTATE, ID_GET_ERC, @@ -127,31 +128,12 @@ enum id_eeschema_frm ID_TB_OPTIONS_HIDDEN_PINS, ID_TB_OPTIONS_BUS_WIRES_ORIENT, - /* Schematic editor context menu IDs. */ - ID_POPUP_START_RANGE, - ID_POPUP_SCH_BREAK_WIRE, - ID_POPUP_SCH_BEGIN_WIRE, - ID_POPUP_SCH_BEGIN_BUS, - ID_POPUP_SCH_BEGIN_LINES, - ID_POPUP_SCH_RESIZE_SHEET, - ID_POPUP_SCH_CLEANUP_SHEET, - ID_POPUP_IMPORT_HLABEL_TO_SHEETPIN, - ID_POPUP_SCH_EDIT_CONVERT_CMP, - ID_POPUP_SCH_ENTER_SHEET, - ID_POPUP_SCH_LEAVE_SHEET, - ID_POPUP_SCH_SELECT_ON_PCB, - ID_POPUP_SCH_ADD_JUNCTION, - ID_POPUP_SCH_ADD_LABEL, - ID_POPUP_SCH_ADD_GLABEL, - ID_POPUP_SCH_ADD_HLABEL, - ID_POPUP_END_RANGE, - // Dynamically bound in AddMenusForBus() ID_POPUP_SCH_UNFOLD_BUS, ID_POPUP_SCH_UNFOLD_BUS_END = ID_POPUP_SCH_UNFOLD_BUS + 64, - ID_POPUP_SCH_DISPLAYDOC_CMP, - ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, + ID_SCH_DISPLAYDOC_CMP, + ID_SCH_CALL_LIBEDIT_AND_LOAD_CMP, // Unit select context menus command IDs. ID_POPUP_SCH_SELECT_UNIT_CMP, @@ -180,6 +162,7 @@ enum id_eeschema_frm ID_SCH_DELETE, ID_SCH_END_LINE_WIRE_OR_BUS, ID_SCH_UNFOLD_BUS, + ID_SCH_RESIZE_SHEET, ID_AUTOPLACE_FIELDS, diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index aca4fe782c..2b6c8c6e92 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -24,6 +24,7 @@ */ #include +#include #include #include #include @@ -117,11 +118,13 @@ static EDA_HOTKEY HkHelp( _HKI( "List Hotkeys" ), HK_HELP, GR_KB_CTRL + WXK_F1 ) static EDA_HOTKEY HkPreferences( _HKI( "Preferences" ), HK_PREFERENCES, GR_KB_CTRL + ',', (int) wxID_PREFERENCES ); static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ), HK_RESET_LOCAL_COORD, ' ' ); static EDA_HOTKEY HkLeaveSheet( _HKI( "Leave Sheet" ), HK_LEAVE_SHEET, GR_KB_ALT + WXK_BACK, - ID_POPUP_SCH_LEAVE_SHEET ); + ID_SCH_LEAVE_SHEET ); // mouse click command: -static EDA_HOTKEY HkMouseLeftClick( _HKI( "Mouse Left Click" ), HK_LEFT_CLICK, WXK_RETURN, 0 ); -static EDA_HOTKEY HkMouseLeftDClick( _HKI( "Mouse Left Double Click" ), HK_LEFT_DCLICK, WXK_END, 0 ); +static EDA_HOTKEY HkMouseLeftClick( _HKI( "Mouse Left Click" ), HK_LEFT_CLICK, WXK_RETURN, + ID_MOUSE_CLICK ); +static EDA_HOTKEY HkMouseLeftDClick( _HKI( "Mouse Left Double Click" ), HK_LEFT_DCLICK, WXK_END, + ID_MOUSE_DOUBLECLICK ); // Schematic editor static EDA_HOTKEY HkBeginWire( _HKI( "Begin Wire" ), HK_BEGIN_WIRE, 'W', ID_WIRE_BUTT ); @@ -160,17 +163,17 @@ static EDA_HOTKEY HkEdit( _HKI( "Edit Item" ), HK_EDIT, 'E', ID_SCH_EDIT_ITEM ); static EDA_HOTKEY HkEditComponentValue( _HKI( "Edit Symbol Value" ), HK_EDIT_COMPONENT_VALUE, 'V', ID_SCH_EDIT_COMPONENT_VALUE ); static EDA_HOTKEY HkEditComponentReference( _HKI( "Edit Symbol Reference" ), - HK_EDIT_COMPONENT_REFERENCE, 'U', - ID_SCH_EDIT_COMPONENT_REFERENCE ); + HK_EDIT_COMPONENT_REFERENCE, 'U', + ID_SCH_EDIT_COMPONENT_REFERENCE ); static EDA_HOTKEY HkEditComponentFootprint( _HKI( "Edit Symbol Footprint" ), HK_EDIT_COMPONENT_FOOTPRINT, 'F', ID_SCH_EDIT_COMPONENT_FOOTPRINT ); static EDA_HOTKEY HkShowComponentDatasheet( _HKI( "Show Symbol Datasheet" ), - HK_SHOW_COMPONENT_DATASHEET, 'D', - ID_POPUP_SCH_DISPLAYDOC_CMP ); + HK_SHOW_COMPONENT_DATASHEET, 'D', + ID_SCH_DISPLAYDOC_CMP ); static EDA_HOTKEY HkEditComponentWithLibedit( _HKI( "Edit with Symbol Editor" ), HK_EDIT_COMPONENT_WITH_LIBEDIT, 'E' + GR_KB_CTRL, - ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP ); + ID_SCH_CALL_LIBEDIT_AND_LOAD_CMP ); static EDA_HOTKEY HkMove( _HKI( "Move Schematic Item" ), HK_MOVE, 'M', ID_SCH_MOVE ); diff --git a/eeschema/hotkeys.h b/eeschema/hotkeys.h index d07ae0a81c..51f85148eb 100644 --- a/eeschema/hotkeys.h +++ b/eeschema/hotkeys.h @@ -75,8 +75,6 @@ enum hotkey_id_command { HK_ADD_GRAPHIC_TEXT, HK_ADD_GRAPHIC_POLYLINE, HK_ADD_NOCONN_FLAG, - HK_LEFT_CLICK, - HK_LEFT_DCLICK, HK_LEAVE_SHEET, HK_DELETE_NODE, HK_AUTOPLACE_FIELDS, diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index e3a07b0721..2879a62377 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -341,11 +341,9 @@ void LIB_EDIT_FRAME::setupTools() // Run the selection tool, it is supposed to be always active // JEY TODO: not ready for modern toolset event processing yet.... -#if 0 - m_toolManager->InvokeTool( "eeschema.InteractiveSelection" ); + //m_toolManager->InvokeTool( "eeschema.InteractiveSelection" ); GetCanvas()->SetEventDispatcher( m_toolDispatcher ); -#endif } diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index 53da4516e1..7f4b026a33 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -142,7 +142,7 @@ void prepareViewMenu( wxMenu* aParentMenu ) text = AddHotkeyName( _( "&Leave Sheet" ), g_Schematic_Hotkeys_Descr, HK_LEAVE_SHEET ); AddMenuItem( aParentMenu, - ID_POPUP_SCH_LEAVE_SHEET, text, + ID_SCH_LEAVE_SHEET, text, _( "Return to parent schematic sheet" ), KiBitmap( leave_sheet_xpm ) ); diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index d4d1273a07..7f0e713322 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -269,6 +269,10 @@ void SCH_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) if( !screen ) return; + // JEY TODO: this whole routine can go once libEdit is moved over to modern toolset + if( dynamic_cast( m_parent ) ) + return; + /* Adjust value to filter mouse displacement before consider the drag * mouse is really a drag command, not just a movement while click */ diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index baf677c92e..148942e10e 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -295,7 +295,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) SCH_EDIT_FRAME::OnUpdateSelectTool ) EVT_UPDATE_UI( ID_SAVE_PROJECT, SCH_EDIT_FRAME::OnUpdateSave ) EVT_UPDATE_UI( ID_UPDATE_ONE_SHEET, SCH_EDIT_FRAME::OnUpdateSaveSheet ) - EVT_UPDATE_UI( ID_POPUP_SCH_LEAVE_SHEET, SCH_EDIT_FRAME::OnUpdateHierarchySheet ) + EVT_UPDATE_UI( ID_SCH_LEAVE_SHEET, SCH_EDIT_FRAME::OnUpdateHierarchySheet ) EVT_UPDATE_UI( ID_REMAP_SYMBOLS, SCH_EDIT_FRAME::OnUpdateRemapSymbols ) EVT_UPDATE_UI( ID_MENU_CANVAS_CAIRO, SCH_EDIT_FRAME::OnUpdateSwitchCanvas ) EVT_UPDATE_UI( ID_MENU_CANVAS_OPENGL, SCH_EDIT_FRAME::OnUpdateSwitchCanvas ) diff --git a/eeschema/toolbars_sch_editor.cpp b/eeschema/toolbars_sch_editor.cpp index 01d9366f0d..fc42317bc3 100644 --- a/eeschema/toolbars_sch_editor.cpp +++ b/eeschema/toolbars_sch_editor.cpp @@ -132,7 +132,7 @@ void SCH_EDIT_FRAME::ReCreateHToolbar() _( "Navigate schematic hierarchy" ) ); - m_mainToolBar->AddTool( ID_POPUP_SCH_LEAVE_SHEET, wxEmptyString, + m_mainToolBar->AddTool( ID_SCH_LEAVE_SHEET, wxEmptyString, KiScaledBitmap( leave_sheet_xpm, this ), _( "Leave sheet" ) ); KiScaledSeparator( m_mainToolBar, this ); diff --git a/eeschema/tools/sch_actions.cpp b/eeschema/tools/sch_actions.cpp index 7786f1d90c..6ca626a2f9 100644 --- a/eeschema/tools/sch_actions.cpp +++ b/eeschema/tools/sch_actions.cpp @@ -196,7 +196,7 @@ OPT SCH_ACTIONS::TranslateLegacyId( int aId ) case ID_AUTOPLACE_FIELDS: return SCH_ACTIONS::autoplaceFields.MakeEvent(); - case ID_POPUP_SCH_LEAVE_SHEET: + case ID_SCH_LEAVE_SHEET: return SCH_ACTIONS::leaveSheet.MakeEvent(); case ID_HOTKEY_SELECT_NODE: @@ -207,6 +207,12 @@ OPT SCH_ACTIONS::TranslateLegacyId( int aId ) case ID_SCH_UNFOLD_BUS: return SCH_ACTIONS::unfoldBus.MakeEvent(); + + case ID_MOUSE_CLICK: + return SCH_ACTIONS::cursorClick.MakeEvent(); + + case ID_MOUSE_DOUBLECLICK: + return SCH_ACTIONS::cursorDblClick.MakeEvent(); } return OPT(); diff --git a/eeschema/tools/sch_drawing_tool.cpp b/eeschema/tools/sch_drawing_tool.cpp index ebfd4816ad..1ee6a97961 100644 --- a/eeschema/tools/sch_drawing_tool.cpp +++ b/eeschema/tools/sch_drawing_tool.cpp @@ -780,7 +780,7 @@ int SCH_DRAWING_TOOL::ResizeSheet( const TOOL_EVENT& aEvent ) { SCH_SHEET* sheet = (SCH_SHEET*) selection.Front(); - m_frame->SetToolID( ID_POPUP_SCH_RESIZE_SHEET, wxCURSOR_PENCIL, _( "Resize sheet" ) ); + m_frame->SetToolID( ID_SCH_RESIZE_SHEET, wxCURSOR_PENCIL, _( "Resize sheet" ) ); doDrawSheet( sheet ); } @@ -818,7 +818,7 @@ int SCH_DRAWING_TOOL::doDrawSheet( SCH_SHEET *aSheet ) m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true ); m_view->ClearPreview(); - if( m_frame->GetToolId() == ID_POPUP_SCH_RESIZE_SHEET ) + if( m_frame->GetToolId() == ID_SCH_RESIZE_SHEET ) { m_frame->RollbackSchematicFromUndo(); // resize sheet is a single-shot command, when we're done we're done @@ -871,7 +871,7 @@ int SCH_DRAWING_TOOL::doDrawSheet( SCH_SHEET *aSheet ) aSheet = nullptr; - if( m_frame->GetToolId() == ID_POPUP_SCH_RESIZE_SHEET ) + if( m_frame->GetToolId() == ID_SCH_RESIZE_SHEET ) break; // resize sheet is a single-shot command; when we're done we're done } } diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 44fcd57bf0..4e67307932 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -399,6 +399,9 @@ bool SCH_EDIT_TOOL::Init() drawingTool->GetToolMenu().AddSubMenu( symUnitMenu2 ); drawMenu.AddMenu( symUnitMenu2.get(), false, SCH_CONDITIONS::SingleMultiUnitSymbol, 1 ); + drawMenu.AddItem( SCH_ACTIONS::editWithSymbolEditor, + singleComponentCondition && SCH_CONDITIONS::Idle, 200 ); + drawMenu.AddItem( SCH_ACTIONS::toShapeSlash, entryCondition, 200 ); drawMenu.AddItem( SCH_ACTIONS::toShapeBackslash, entryCondition, 200 ); drawMenu.AddItem( SCH_ACTIONS::toLabel, anyTextTool && SCH_CONDITIONS::Idle, 200 ); @@ -432,6 +435,9 @@ bool SCH_EDIT_TOOL::Init() m_selectionTool->GetToolMenu().AddSubMenu( symUnitMenu3 ); selToolMenu.AddMenu( symUnitMenu3.get(), false, SCH_CONDITIONS::SingleMultiUnitSymbol, 1 ); + selToolMenu.AddItem( SCH_ACTIONS::editWithSymbolEditor, + singleComponentCondition && SCH_CONDITIONS::Idle, 200 ); + selToolMenu.AddItem( SCH_ACTIONS::toShapeSlash, entryCondition, 200 ); selToolMenu.AddItem( SCH_ACTIONS::toShapeBackslash, entryCondition, 200 ); selToolMenu.AddItem( SCH_ACTIONS::toLabel, toLabelCondition, 200 ); diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index 78a2956a44..140910edea 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -417,7 +417,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) selection.ClearReferencePoint(); for( auto item : selection ) - item->ClearFlags( IS_MOVED ); + item->ClearFlags( item->GetEditFlags() ); if( unselect ) m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true ); diff --git a/include/hotkeys_basic.h b/include/hotkeys_basic.h index ee0616105b..6257179bcf 100644 --- a/include/hotkeys_basic.h +++ b/include/hotkeys_basic.h @@ -284,6 +284,8 @@ enum common_hotkey_id_command { HK_ZOOM_CENTER, HK_ZOOM_AUTO, HK_ZOOM_SELECTION, + HK_LEFT_CLICK, + HK_LEFT_DCLICK, HK_PREFERENCES, HK_TOGGLE_CURSOR, HK_MEASURE_TOOL, diff --git a/include/id.h b/include/id.h index 8f03626c97..196ea60cf8 100644 --- a/include/id.h +++ b/include/id.h @@ -258,6 +258,7 @@ enum main_id ID_PAN_LEFT, ID_PAN_RIGHT, + ID_MOUSE_CLICK, ID_MOUSE_DOUBLECLICK, ID_GET_NETLIST, diff --git a/include/tool/tool_event.h b/include/tool/tool_event.h index 7b47c3af1c..b2134e61bb 100644 --- a/include/tool/tool_event.h +++ b/include/tool/tool_event.h @@ -30,7 +30,6 @@ #include #include - #include #ifdef WX_COMPATIBILITY @@ -274,26 +273,18 @@ public: return m_mouseButtons; } - bool IsClick( int aButtonMask = BUT_ANY ) const - { - return ( m_actions == TA_MOUSE_CLICK ) - && ( ( m_mouseButtons & aButtonMask ) == aButtonMask ); - } + bool IsClick( int aButtonMask = BUT_ANY ) const; - bool IsDblClick( int aButtonMask = BUT_ANY ) const - { - return ( m_actions == TA_MOUSE_DBLCLICK ) - && ( ( m_mouseButtons & aButtonMask ) == aButtonMask ); - } + bool IsDblClick( int aButtonMask = BUT_ANY ) const; bool IsDrag( int aButtonMask = BUT_ANY ) const { - return ( m_actions == TA_MOUSE_DRAG ) && ( ( m_mouseButtons & aButtonMask ) == aButtonMask ); + return m_actions == TA_MOUSE_DRAG && ( m_mouseButtons & aButtonMask ) == aButtonMask; } bool IsMouseUp( int aButtonMask = BUT_ANY ) const { - return ( m_actions == TA_MOUSE_UP ) && ( ( m_mouseButtons & aButtonMask ) == aButtonMask ); + return m_actions == TA_MOUSE_UP && ( m_mouseButtons & aButtonMask ) == aButtonMask; } bool IsMotion() const diff --git a/pagelayout_editor/hotkeys.h b/pagelayout_editor/hotkeys.h index b07ecfd8b9..404051eb19 100644 --- a/pagelayout_editor/hotkeys.h +++ b/pagelayout_editor/hotkeys.h @@ -40,9 +40,7 @@ enum hotkey_id_command { HK_MOVE_START_POINT, HK_MOVE_END_POINT, HK_PLACE_ITEM, - HK_DELETE_ITEM, - HK_LEFT_CLICK, - HK_LEFT_DCLICK + HK_DELETE_ITEM }; // List of hotkey descriptors for PlEditor. diff --git a/pcbnew/hotkeys.cpp b/pcbnew/hotkeys.cpp index 7823ea5a90..ded0868393 100644 --- a/pcbnew/hotkeys.cpp +++ b/pcbnew/hotkeys.cpp @@ -32,7 +32,6 @@ #include #include #include - #include // Remark: the hotkey message info is used as keyword in hotkey config files and diff --git a/pcbnew/hotkeys.h b/pcbnew/hotkeys.h index aff28b6780..cda79b37b5 100644 --- a/pcbnew/hotkeys.h +++ b/pcbnew/hotkeys.h @@ -116,8 +116,6 @@ enum hotkey_id_command { HK_CANVAS_LEGACY, HK_CANVAS_OPENGL, HK_CANVAS_CAIRO, - HK_LEFT_CLICK, - HK_LEFT_DCLICK, HK_ZONE_FILL_OR_REFILL, HK_ZONE_REMOVE_FILLED, HK_INC_LAYER_ALPHA,