Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Standard edit menu for tools
  4. //
  5. //=============================================================================
  6. #include "toolutils/tooleditmenubutton.h"
  7. #include "toolutils/toolmenubutton.h"
  8. #include "tier1/KeyValues.h"
  9. #include "toolutils/enginetools_int.h"
  10. #include "datamodel/idatamodel.h"
  11. #include "vgui_controls/menu.h"
  12. #include "vgui/ilocalize.h"
  13. #include "tier2/tier2.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. //-----------------------------------------------------------------------------
  17. //
  18. // The Edit menu
  19. //
  20. //-----------------------------------------------------------------------------
  21. class CToolEditMenuButton : public CToolMenuButton
  22. {
  23. DECLARE_CLASS_SIMPLE( CToolEditMenuButton, CToolMenuButton );
  24. public:
  25. CToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget );
  26. virtual void OnShowMenu( vgui::Menu *menu );
  27. };
  28. //-----------------------------------------------------------------------------
  29. // Global function to create the file menu
  30. //-----------------------------------------------------------------------------
  31. CToolMenuButton* CreateToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget )
  32. {
  33. return new CToolEditMenuButton( parent, panelName, text, pActionTarget );
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Constructor
  37. //-----------------------------------------------------------------------------
  38. CToolEditMenuButton::CToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget )
  39. : BaseClass( parent, panelName, text, pActionSignalTarget )
  40. {
  41. AddMenuItem( "undo", "#ToolEditUndo", new KeyValues ( "Command", "command", "OnUndo" ), pActionSignalTarget, NULL, "undo" );
  42. AddMenuItem( "redo", "#ToolEditRedo", new KeyValues ( "Command", "command", "OnRedo" ), pActionSignalTarget, NULL, "redo" );
  43. AddSeparator();
  44. AddMenuItem( "describe", "#ToolEditDescribeUndo", new KeyValues ( "Command", "command", "OnDescribeUndo" ), pActionSignalTarget);
  45. AddMenuItem( "wipeundo", "#ToolEditWipeUndo", new KeyValues ( "Command", "command", "OnWipeUndo" ), pActionSignalTarget);
  46. AddSeparator();
  47. AddMenuItem( "editkeybindings", "#BxEditKeyBindings", new KeyValues( "OnEditKeyBindings" ), pActionSignalTarget, NULL, "editkeybindings" );
  48. SetMenu(m_pMenu);
  49. }
  50. void CToolEditMenuButton::OnShowMenu( vgui::Menu *menu )
  51. {
  52. BaseClass::OnShowMenu( menu );
  53. // Update the menu
  54. char sz[ 512 ];
  55. int id;
  56. id = m_Items.Find( "undo" );
  57. if ( g_pDataModel->CanUndo() )
  58. {
  59. m_pMenu->SetItemEnabled( id, true );
  60. wchar_t *fmt = g_pVGuiLocalize->Find( "ToolEditUndoStr" );
  61. if ( fmt )
  62. {
  63. wchar_t desc[ 256 ];
  64. g_pVGuiLocalize->ConvertANSIToUnicode( g_pDataModel->GetUndoDesc(), desc, sizeof( desc ) );
  65. wchar_t buf[ 512 ];
  66. g_pVGuiLocalize->ConstructString( buf, sizeof( buf ), fmt, 1, desc );
  67. m_pMenu->UpdateMenuItem( id, buf, new KeyValues( "Command", "command", "OnUndo" ) );
  68. }
  69. else
  70. {
  71. m_pMenu->UpdateMenuItem( id, "#ToolEditUndo", new KeyValues( "Command", "command", "OnUndo" ) );
  72. }
  73. }
  74. else
  75. {
  76. m_pMenu->SetItemEnabled( id, false );
  77. m_pMenu->UpdateMenuItem( id, "#ToolEditUndo", new KeyValues( "Command", "command", "OnUndo" ) );
  78. }
  79. id = m_Items.Find( "redo" );
  80. if ( g_pDataModel->CanRedo() )
  81. {
  82. m_pMenu->SetItemEnabled( id, true );
  83. wchar_t *fmt = g_pVGuiLocalize->Find( "ToolEditRedoStr" );
  84. if ( fmt )
  85. {
  86. wchar_t desc[ 256 ];
  87. g_pVGuiLocalize->ConvertANSIToUnicode( g_pDataModel->GetRedoDesc(), desc, sizeof( desc ) );
  88. wchar_t buf[ 512 ];
  89. g_pVGuiLocalize->ConstructString( buf, sizeof( buf ), fmt, 1, desc );
  90. m_pMenu->UpdateMenuItem( id, buf, new KeyValues( "Command", "command", "OnRedo" ) );
  91. }
  92. else
  93. {
  94. m_pMenu->UpdateMenuItem( id, sz, new KeyValues( "Command", "command", "OnRedo" ) );
  95. }
  96. }
  97. else
  98. {
  99. m_pMenu->SetItemEnabled( id, false );
  100. m_pMenu->UpdateMenuItem( id, "#ToolEditRedo", new KeyValues( "Command", "command", "OnRedo" ) );
  101. }
  102. id = m_Items.Find( "describe" );
  103. if ( g_pDataModel->CanUndo() )
  104. {
  105. m_pMenu->SetItemEnabled( id, true );
  106. }
  107. else
  108. {
  109. m_pMenu->SetItemEnabled( id, false );
  110. }
  111. }