From 3bf9df6b2785fa6d951086978a3e66f49427166a Mon Sep 17 00:00:00 2001 From: FluorescentCIAAfricanAmerican <0934gj3049fk@protonmail.com> Date: Wed, 22 Apr 2020 12:56:21 -0400 Subject: 1 --- tools/toolutils/tooleditmenubutton.cpp | 131 +++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 tools/toolutils/tooleditmenubutton.cpp (limited to 'tools/toolutils/tooleditmenubutton.cpp') diff --git a/tools/toolutils/tooleditmenubutton.cpp b/tools/toolutils/tooleditmenubutton.cpp new file mode 100644 index 0000000..99e64a3 --- /dev/null +++ b/tools/toolutils/tooleditmenubutton.cpp @@ -0,0 +1,131 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Standard edit menu for tools +// +//============================================================================= + +#include "toolutils/tooleditmenubutton.h" +#include "toolutils/toolmenubutton.h" +#include "tier1/KeyValues.h" +#include "toolutils/enginetools_int.h" +#include "datamodel/idatamodel.h" +#include "vgui_controls/menu.h" +#include "vgui/ilocalize.h" +#include "tier2/tier2.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +//----------------------------------------------------------------------------- +// +// The Edit menu +// +//----------------------------------------------------------------------------- +class CToolEditMenuButton : public CToolMenuButton +{ + DECLARE_CLASS_SIMPLE( CToolEditMenuButton, CToolMenuButton ); +public: + CToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget ); + virtual void OnShowMenu( vgui::Menu *menu ); +}; + + +//----------------------------------------------------------------------------- +// Global function to create the file menu +//----------------------------------------------------------------------------- +CToolMenuButton* CreateToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget ) +{ + return new CToolEditMenuButton( parent, panelName, text, pActionTarget ); +} + + +//----------------------------------------------------------------------------- +// Constructor +//----------------------------------------------------------------------------- +CToolEditMenuButton::CToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget ) + : BaseClass( parent, panelName, text, pActionSignalTarget ) +{ + AddMenuItem( "undo", "#ToolEditUndo", new KeyValues ( "Command", "command", "OnUndo" ), pActionSignalTarget, NULL, "undo" ); + AddMenuItem( "redo", "#ToolEditRedo", new KeyValues ( "Command", "command", "OnRedo" ), pActionSignalTarget, NULL, "redo" ); + AddSeparator(); + AddMenuItem( "describe", "#ToolEditDescribeUndo", new KeyValues ( "Command", "command", "OnDescribeUndo" ), pActionSignalTarget); + AddMenuItem( "wipeundo", "#ToolEditWipeUndo", new KeyValues ( "Command", "command", "OnWipeUndo" ), pActionSignalTarget); + AddSeparator(); + AddMenuItem( "editkeybindings", "#BxEditKeyBindings", new KeyValues( "OnEditKeyBindings" ), pActionSignalTarget, NULL, "editkeybindings" ); + + SetMenu(m_pMenu); +} + +void CToolEditMenuButton::OnShowMenu( vgui::Menu *menu ) +{ + BaseClass::OnShowMenu( menu ); + + // Update the menu + char sz[ 512 ]; + + int id; + id = m_Items.Find( "undo" ); + if ( g_pDataModel->CanUndo() ) + { + m_pMenu->SetItemEnabled( id, true ); + + wchar_t *fmt = g_pVGuiLocalize->Find( "ToolEditUndoStr" ); + if ( fmt ) + { + wchar_t desc[ 256 ]; + g_pVGuiLocalize->ConvertANSIToUnicode( g_pDataModel->GetUndoDesc(), desc, sizeof( desc ) ); + + wchar_t buf[ 512 ]; + g_pVGuiLocalize->ConstructString( buf, sizeof( buf ), fmt, 1, desc ); + + m_pMenu->UpdateMenuItem( id, buf, new KeyValues( "Command", "command", "OnUndo" ) ); + } + else + { + m_pMenu->UpdateMenuItem( id, "#ToolEditUndo", new KeyValues( "Command", "command", "OnUndo" ) ); + } + } + else + { + m_pMenu->SetItemEnabled( id, false ); + m_pMenu->UpdateMenuItem( id, "#ToolEditUndo", new KeyValues( "Command", "command", "OnUndo" ) ); + } + + id = m_Items.Find( "redo" ); + if ( g_pDataModel->CanRedo() ) + { + m_pMenu->SetItemEnabled( id, true ); + + wchar_t *fmt = g_pVGuiLocalize->Find( "ToolEditRedoStr" ); + if ( fmt ) + { + wchar_t desc[ 256 ]; + g_pVGuiLocalize->ConvertANSIToUnicode( g_pDataModel->GetRedoDesc(), desc, sizeof( desc ) ); + + wchar_t buf[ 512 ]; + g_pVGuiLocalize->ConstructString( buf, sizeof( buf ), fmt, 1, desc ); + + m_pMenu->UpdateMenuItem( id, buf, new KeyValues( "Command", "command", "OnRedo" ) ); + } + else + { + m_pMenu->UpdateMenuItem( id, sz, new KeyValues( "Command", "command", "OnRedo" ) ); + } + } + else + { + m_pMenu->SetItemEnabled( id, false ); + m_pMenu->UpdateMenuItem( id, "#ToolEditRedo", new KeyValues( "Command", "command", "OnRedo" ) ); + } + + id = m_Items.Find( "describe" ); + if ( g_pDataModel->CanUndo() ) + { + m_pMenu->SetItemEnabled( id, true ); + } + else + { + m_pMenu->SetItemEnabled( id, false ); + } +} -- cgit v1.2.3