]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/radiant/EntKeyFindReplace.cpp
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / tools / radiant / EntKeyFindReplace.cpp
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
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.
13
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.
18
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/>.
21
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.
23
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.
25
26 ===========================================================================
27 */
28
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31
32 //#include "stdafx.h"
33 #include "radiant.h"
34 #include "GetString.h"  // for ErrorBox() etc
35 #include "qe3.h"
36
37 #include "EntKeyFindReplace.h"
38 //#include "oddbits.h"
39 /*
40 #include "stdafx.h"
41 #include "Radiant.h"
42 #include "ZWnd.h"
43 #include "qe3.h"
44 #include "zclip.h"
45 */
46
47 #ifdef _DEBUG
48 #define new DEBUG_NEW
49 #undef THIS_FILE
50 static char THIS_FILE[] = __FILE__;
51 #endif
52
53 /////////////////////////////////////////////////////////////////////////////
54 // CEntKeyFindReplace dialog
55
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)
64 {
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;
71
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;
79         //}}AFX_DATA_INIT
80 }
81
82
83 void CEntKeyFindReplace::DoDataExchange(CDataExchange* pDX)
84 {
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);
93         //}}AFX_DATA_MAP
94 }
95
96
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)
103         //}}AFX_MSG_MAP
104 END_MESSAGE_MAP()
105
106 /////////////////////////////////////////////////////////////////////////////
107 // CEntKeyFindReplace message handlers
108
109 void CEntKeyFindReplace::OnCancel() 
110 {       
111         CDialog::OnCancel();
112 }
113
114 void CEntKeyFindReplace::OnReplace() 
115 {
116         // quick check, if no key value is specified then there's not much to do...
117         //
118         UpdateData(DIALOG_TO_DATA);
119         if (m_strFindKey.IsEmpty())
120         {
121                 ErrorBox("Empty FIND <key>!\n\n(This is only permitted for FIND, not replace, for safety reasons)");
122         }
123         else
124         {
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)))
126                 {
127                         // another check, if they're trying to do a replace with a missing replace key, it'll just delete found keys...
128                         //
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)))
130                         {
131                                 if (GetYesNo("Sure?"))
132                                 {
133                                         CopyFields();
134                                         EndDialog(ID_RET_REPLACE);
135                                 }
136                         }
137                 }
138         }
139 }
140
141 void CEntKeyFindReplace::OnFind()
142 {
143         // quick check, if no key value is specified then there's not much to do...
144         //
145         UpdateData(DIALOG_TO_DATA);
146
147         if (m_strFindKey.IsEmpty() && m_strFindValue.IsEmpty())
148         {
149                 ErrorBox("Empty FIND fields!");
150         }
151         else
152         {       
153 //              if (m_strFindKey.IsEmpty() && m_bSelectAllMatchingEnts)
154 //              {
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?"))
156 //                      {
157 //                              CopyFields();
158 //                              EndDialog(ID_RET_FIND);
159 //                      }
160 //              }
161 //              else
162                 {
163                         CopyFields();
164                         EndDialog(ID_RET_FIND);
165                 }
166         }
167 }
168
169 void CEntKeyFindReplace::CopyFields()
170 {
171         UpdateData(DIALOG_TO_DATA);
172
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;
179 }
180
181
182 void CEntKeyFindReplace::OnKeycopy() 
183 {
184         UpdateData(DIALOG_TO_DATA);
185
186         m_strReplaceKey = m_strFindKey;
187
188         UpdateData(DATA_TO_DIALOG);     
189 }
190
191 void CEntKeyFindReplace::OnValuecopy() 
192 {
193         UpdateData(DIALOG_TO_DATA);
194
195         m_strReplaceValue = m_strFindValue;
196
197         UpdateData(DATA_TO_DIALOG);     
198 }
199