Try reusing the TOOL_DISPATCHER menu hack for libtree previews.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16493
This commit is contained in:
Jeff Young 2024-01-05 14:19:54 +00:00
parent 23f35e1c8b
commit 169ece3b71
5 changed files with 52 additions and 47 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* Copyright (C) 2013-2023 KiCad Developers, see CHANGELOG.txt for contributors.
* Copyright (C) 2013-2024 KiCad Developers, see CHANGELOG.txt for contributors.
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -115,17 +115,16 @@ struct TOOL_DISPATCHER::BUTTON_STATE
return mouseState.Aux2IsDown();
default:
assert( false );
break;
wxFAIL_MSG( wxT( "unknown button" ) );
return false;
}
return false;
}
};
TOOL_DISPATCHER::TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr ) :
m_toolMgr( aToolMgr )
m_toolMgr( aToolMgr ),
m_currentMenu( nullptr )
{
m_sysDragMinX = wxSystemSettings::GetMetric( wxSYS_DRAG_X );
m_sysDragMinY = wxSystemSettings::GetMetric( wxSYS_DRAG_Y );
@ -550,8 +549,6 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
// hotkey. So we keep track of menu highlighting so we can differentiate.
//
static ACTION_MENU* currentMenu;
wxMenuEvent* tmp = dynamic_cast<wxMenuEvent*>( &aEvent );
wxCHECK( tmp, /* void */ );
@ -560,22 +557,22 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
if( type == wxEVT_MENU_OPEN )
{
currentMenu = dynamic_cast<ACTION_MENU*>( menuEvent.GetMenu() );
m_currentMenu = dynamic_cast<ACTION_MENU*>( menuEvent.GetMenu() );
if( currentMenu )
currentMenu->OnMenuEvent( menuEvent );
if( m_currentMenu )
m_currentMenu->OnMenuEvent( menuEvent );
}
else if( type == wxEVT_MENU_HIGHLIGHT )
{
if( currentMenu )
currentMenu->OnMenuEvent( menuEvent );
if( m_currentMenu )
m_currentMenu->OnMenuEvent( menuEvent );
}
else if( type == wxEVT_MENU_CLOSE )
{
if( currentMenu )
currentMenu->OnMenuEvent( menuEvent );
if( m_currentMenu )
m_currentMenu->OnMenuEvent( menuEvent );
currentMenu = nullptr;
m_currentMenu = nullptr;
}
aEvent.Skip();

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
* Copyright (C) 2014-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2014-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -32,6 +32,7 @@
#include <tool/tool_manager.h>
#include <tool/action_manager.h>
#include <tool/actions.h>
#include <tool/tool_dispatcher.h>
#include <widgets/wx_dataviewctrl.h>
#include <wx/settings.h>
#include <wx/sizer.h>
@ -752,7 +753,9 @@ void LIB_TREE::onHoverTimer( wxTimerEvent& aEvent )
{
hidePreview();
if( !m_tree_ctrl->IsShownOnScreen() || m_previewDisabled )
TOOL_DISPATCHER* toolDispatcher = m_adapter->GetToolDispatcher();
if( !m_tree_ctrl->IsShownOnScreen() || m_previewDisabled || toolDispatcher->GetCurrentMenu() )
return;
wxDataViewItem item;

View File

@ -4,7 +4,7 @@
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
* Copyright (C) 2023 CERN
* Copyright (C) 2014-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2014-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -23,6 +23,7 @@
#ifndef LIB_TREE_MODEL_ADAPTER_H
#define LIB_TREE_MODEL_ADAPTER_H
#include <eda_base_frame.h>
#include <lib_id.h>
#include <lib_tree_model.h>
#include <wx/hashmap.h>
@ -259,6 +260,8 @@ public:
virtual bool HasPreview( const wxDataViewItem& aItem ) { return false; }
virtual void ShowPreview( wxWindow* aParent, const wxDataViewItem& aItem ) {}
TOOL_DISPATCHER* GetToolDispatcher() const { return m_parent->GetToolDispatcher(); }
/**
* Return the number of symbols loaded in the tree.
*/

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2020-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
@ -24,8 +24,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __TOOL_DISPATCHER_H
#define __TOOL_DISPATCHER_H
#ifndef TOOL_DISPATCHER_H
#define TOOL_DISPATCHER_H
#include <vector>
#include <wx/event.h>
@ -34,6 +34,7 @@
class TOOL_MANAGER;
class PCB_BASE_FRAME;
class ACTIONS;
class ACTION_MENU;
namespace KIGFX
{
@ -76,24 +77,15 @@ public:
*/
std::optional<TOOL_EVENT> GetToolEvent( wxKeyEvent* aKeyEvent, bool* aSpecialKeyFlag );
ACTION_MENU* GetCurrentMenu() const { return m_currentMenu; }
private:
///< The time threshold for a mouse button press that distinguishes between a single mouse
///< click and a beginning of drag event (expressed in milliseconds).
static const int DragTimeThreshold = 300;
///< The distance threshold for mouse cursor that distinguishes between a single mouse click
///< and a beginning of drag event (expressed in screen pixels).
///< System drag preferences take precedence if available
static const int DragDistanceThreshold = 8;
///< Mininum distance before drag is activated in the X axis
int m_sysDragMinX;
///< Maximum distance before drag is activated in the Y axis
int m_sysDragMinY;
///< Handles mouse related events (click, motion, dragging).
bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
///< Returns the instance of VIEW, used by the application.
KIGFX::VIEW* getView();
///< Saves the state of key modifiers (Alt, Ctrl and so on).
static int decodeModifiers( const wxKeyboardState* aState )
{
@ -111,23 +103,31 @@ private:
return mods;
}
///< Stores all the information regarding a mouse button state.
struct BUTTON_STATE;
private:
///< The time threshold for a mouse button press that distinguishes between a single mouse
///< click and a beginning of drag event (expressed in milliseconds).
static const int DragTimeThreshold = 300;
///< The last mouse cursor position (in world coordinates).
VECTOR2D m_lastMousePos;
///< The distance threshold for mouse cursor that distinguishes between a single mouse click
///< and a beginning of drag event (expressed in screen pixels).
///< System drag preferences take precedence if available
static const int DragDistanceThreshold = 8;
///< The last mouse cursor position (in screen coordinates).
VECTOR2D m_lastMousePosScreen;
int m_sysDragMinX; ///< Mininum distance before drag is activated in the X axis
int m_sysDragMinY; ///< Maximum distance before drag is activated in the Y axis
VECTOR2D m_lastMousePos; ///< The last mouse cursor position (in world coordinates).
VECTOR2D m_lastMousePosScreen; ///< The last mouse cursor position (in screen coordinates).
///< State of mouse buttons.
struct BUTTON_STATE;
std::vector<BUTTON_STATE*> m_buttons;
///< Returns the instance of VIEW, used by the application.
KIGFX::VIEW* getView();
///< Instance of tool manager that cooperates with the dispatcher.
TOOL_MANAGER* m_toolMgr;
///< The menu from the main menubar currently shown (if any; nullptr otherwise)
ACTION_MENU* m_currentMenu;
};
#endif
#endif // TOOL_DISPATCHER_H

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2020-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -54,6 +54,8 @@ public:
*/
TOOL_MANAGER* GetToolManager() const { return m_toolManager; }
TOOL_DISPATCHER* GetToolDispatcher() const { return m_toolDispatcher; }
/**
* Register an action's update conditions with the UI layer to allow the UI to appropriately
* display the state of its controls.