2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
34 #include "GetString.h" // for ErrorBox() etc
37 #include "EntKeyFindReplace.h"
38 //#include "oddbits.h"
50 static char THIS_FILE[] = __FILE__;
53 /////////////////////////////////////////////////////////////////////////////
54 // CEntKeyFindReplace dialog
56 CEntKeyFindReplace::CEntKeyFindReplace( CString* p_strFindKey,
57 CString* p_strFindValue,
58 CString* p_strReplaceKey,
59 CString* p_strReplaceValue,
60 bool* p_bWholeStringMatchOnly,
61 bool* p_bSelectAllMatchingEnts,
62 CWnd* pParent /*=NULL*/)
63 : CDialog(CEntKeyFindReplace::IDD, pParent)
65 m_pStrFindKey = p_strFindKey;
66 m_pStrFindValue = p_strFindValue;
67 m_pStrReplaceKey = p_strReplaceKey;
68 m_pStrReplaceValue = p_strReplaceValue;
69 m_pbWholeStringMatchOnly = p_bWholeStringMatchOnly;
70 m_pbSelectAllMatchingEnts= p_bSelectAllMatchingEnts;
72 //{{AFX_DATA_INIT(CEntKeyFindReplace)
73 m_strFindKey = *m_pStrFindKey;
74 m_strFindValue = *m_pStrFindValue;
75 m_strReplaceKey = *m_pStrReplaceKey;
76 m_strReplaceValue = *m_pStrReplaceValue;
77 m_bWholeStringMatchOnly = *m_pbWholeStringMatchOnly;
78 m_bSelectAllMatchingEnts = *m_pbSelectAllMatchingEnts;
83 void CEntKeyFindReplace::DoDataExchange(CDataExchange* pDX)
85 CDialog::DoDataExchange(pDX);
86 //{{AFX_DATA_MAP(CEntKeyFindReplace)
87 DDX_Text(pDX, IDC_EDIT_FIND_KEY, m_strFindKey);
88 DDX_Text(pDX, IDC_EDIT_FIND_VALUE, m_strFindValue);
89 DDX_Text(pDX, IDC_EDIT_REPLACE_KEY, m_strReplaceKey);
90 DDX_Text(pDX, IDC_EDIT_REPLACE_VALUE, m_strReplaceValue);
91 DDX_Check(pDX, IDC_CHECK_FIND_WHOLESTRINGMATCHONLY, m_bWholeStringMatchOnly);
92 DDX_Check(pDX, IDC_CHECK_SELECTALLMATCHING, m_bSelectAllMatchingEnts);
97 BEGIN_MESSAGE_MAP(CEntKeyFindReplace, CDialog)
98 //{{AFX_MSG_MAP(CEntKeyFindReplace)
99 ON_BN_CLICKED(IDC_REPLACE, OnReplace)
100 ON_BN_CLICKED(IDC_FIND, OnFind)
101 ON_BN_CLICKED(IDC_KEYCOPY, OnKeycopy)
102 ON_BN_CLICKED(IDC_VALUECOPY, OnValuecopy)
106 /////////////////////////////////////////////////////////////////////////////
107 // CEntKeyFindReplace message handlers
109 void CEntKeyFindReplace::OnCancel()
114 void CEntKeyFindReplace::OnReplace()
116 // quick check, if no key value is specified then there's not much to do...
118 UpdateData(DIALOG_TO_DATA);
119 if (m_strFindKey.IsEmpty())
121 ErrorBox("Empty FIND <key>!\n\n(This is only permitted for FIND, not replace, for safety reasons)");
125 if (!m_strFindValue.IsEmpty() || GetYesNo(va("Empty FIND <value> means replace any existing ( & non-blank ) <value> for <key> \"%s\"\n\nProceed?",(LPCSTR)m_strFindKey)))
127 // another check, if they're trying to do a replace with a missing replace key, it'll just delete found keys...
129 if ((!m_strReplaceKey.IsEmpty() && !m_strReplaceValue.IsEmpty()) || GetYesNo(va("Empty REPLACE <key> or <value> fields will just delete all occurence of <key> \"%s\"\n\nProceed?",m_strFindKey)))
131 if (GetYesNo("Sure?"))
134 EndDialog(ID_RET_REPLACE);
141 void CEntKeyFindReplace::OnFind()
143 // quick check, if no key value is specified then there's not much to do...
145 UpdateData(DIALOG_TO_DATA);
147 if (m_strFindKey.IsEmpty() && m_strFindValue.IsEmpty())
149 ErrorBox("Empty FIND fields!");
153 // if (m_strFindKey.IsEmpty() && m_bSelectAllMatchingEnts)
155 // if (GetYesNo("Warning! Having a blank FIND <key> and ticking \"Select all matching ents\" can take a LONG time to do (and is probably a wrong choice anyway?)\n\nProceed?"))
158 // EndDialog(ID_RET_FIND);
164 EndDialog(ID_RET_FIND);
169 void CEntKeyFindReplace::CopyFields()
171 UpdateData(DIALOG_TO_DATA);
173 *m_pStrFindKey = m_strFindKey;
174 *m_pStrFindValue = m_strFindValue;
175 *m_pStrReplaceKey = m_strReplaceKey;
176 *m_pStrReplaceValue = m_strReplaceValue;
177 *m_pbWholeStringMatchOnly = m_bWholeStringMatchOnly != 0;
178 *m_pbSelectAllMatchingEnts = m_bSelectAllMatchingEnts != 0;
182 void CEntKeyFindReplace::OnKeycopy()
184 UpdateData(DIALOG_TO_DATA);
186 m_strReplaceKey = m_strFindKey;
188 UpdateData(DATA_TO_DIALOG);
191 void CEntKeyFindReplace::OnValuecopy()
193 UpdateData(DIALOG_TO_DATA);
195 m_strReplaceValue = m_strFindValue;
197 UpdateData(DATA_TO_DIALOG);