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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Core Movie Maker UI API
//
//=============================================================================
#include "toolutils/recentfilelist.h"
#include "vgui_controls/menu.h"
#include "iregistry.h"
#include "tier1/KeyValues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Adds a file to the list of recent files
//-----------------------------------------------------------------------------
void CRecentFileList::Add( const char *pFileName, const char *pFileFormat )
{
RecentFileInfo_t info;
info.m_pFileName = pFileName;
int idx = m_RecentFiles.Find( info );
if ( idx != m_RecentFiles.InvalidIndex() )
{
// Remove from current slot so it gets added to head (most recent) below...
m_RecentFiles.Remove( idx );
}
while ( m_RecentFiles.Count() >= MAX_RECENT_FILES )
{
// Oldest is at last slot
m_RecentFiles.Remove( m_RecentFiles.Count() - 1 );
}
int i = m_RecentFiles.AddToHead( );
m_RecentFiles[i].m_pFileName = pFileName;
m_RecentFiles[i].m_pFileFormat = pFileFormat;
}
//-----------------------------------------------------------------------------
// Removes all files from the list
//-----------------------------------------------------------------------------
void CRecentFileList::Clear()
{
m_RecentFiles.RemoveAll();
}
//-----------------------------------------------------------------------------
// Returns true if there's no files in the file list
//-----------------------------------------------------------------------------
bool CRecentFileList::IsEmpty() const
{
return m_RecentFiles.Count() == 0;
}
//-----------------------------------------------------------------------------
// Gets the file in a particular slot
//-----------------------------------------------------------------------------
const char *CRecentFileList::GetFile( int slot ) const
{
if ( slot < 0 || slot >= m_RecentFiles.Count() )
return NULL;
return m_RecentFiles[slot].m_pFileName;
}
//-----------------------------------------------------------------------------
// Gets the file in a particular slot
//-----------------------------------------------------------------------------
const char *CRecentFileList::GetFileFormat( int slot ) const
{
if ( slot < 0 || slot >= m_RecentFiles.Count() )
return NULL;
return m_RecentFiles[slot].m_pFileFormat;
}
//-----------------------------------------------------------------------------
// Loads the file list from the registry
//-----------------------------------------------------------------------------
void CRecentFileList::LoadFromRegistry( const char *pToolKeyName )
{
Clear();
// Iterate in reverse order so most recent files goes to top
for ( int i = MAX_RECENT_FILES; i >= 0; --i )
{
char sz[ 128 ];
char szType[ 128 ];
Q_snprintf( sz, sizeof( sz ), "%s\\history%02i", pToolKeyName, i );
Q_snprintf( szType, sizeof( szType ), "%s\\history_fileformat%02i", pToolKeyName, i );
// NOTE: Can't call registry->ReadString twice in a row!
char pFileName[MAX_PATH];
Q_strncpy( pFileName, registry->ReadString( sz, "" ), sizeof(pFileName) );
if ( pFileName && pFileName[ 0 ] )
{
const char *valType = registry->ReadString( szType, "" );
const char *pFormat = (valType && valType[0]) ? valType : "dmx";
Add( pFileName, pFormat );
}
}
}
//-----------------------------------------------------------------------------
// Saves file list into the registry
//-----------------------------------------------------------------------------
void CRecentFileList::SaveToRegistry( const char *pToolKeyName ) const
{
char sz[ 128 ];
int i, c;
c = m_RecentFiles.Count();
for ( i = 0 ; i < c; ++i )
{
Q_snprintf( sz, sizeof( sz ), "%s\\history%02i", pToolKeyName, i );
registry->WriteString( sz, m_RecentFiles[i].m_pFileName );
Q_snprintf( sz, sizeof( sz ), "%s\\history_fileformat%02i", pToolKeyName, i );
registry->WriteString( sz, m_RecentFiles[i].m_pFileFormat );
}
// Clear out all other registry settings
for ( ; i < MAX_RECENT_FILES; ++i )
{
Q_snprintf( sz, sizeof( sz ), "%s\\history%02i", pToolKeyName, i );
registry->WriteString( sz, "" );
Q_snprintf( sz, sizeof( sz ), "%s\\history_fileformat%02i", pToolKeyName, i );
registry->WriteString( sz, "" );
}
}
//-----------------------------------------------------------------------------
// Adds the list of files to a particular menu
//-----------------------------------------------------------------------------
void CRecentFileList::AddToMenu( vgui::Menu *menu, vgui::Panel *pActionTarget, const char *pCommandName ) const
{
int i, c;
c = m_RecentFiles.Count();
for ( i = 0 ; i < c; ++i )
{
char sz[ 32 ];
Q_snprintf( sz, sizeof( sz ), "%s%02i", pCommandName, i );
char const *fn = m_RecentFiles[i].m_pFileName;
menu->AddMenuItem( fn, new KeyValues( "Command", "command", sz ), pActionTarget );
}
}
|