forked from nillerusr/source-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtooleditmenubutton.cpp
131 lines (111 loc) · 4.25 KB
/
tooleditmenubutton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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 );
}
}