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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
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.
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.
===========================================================================
*/
#include "tools/edit_gui_common.h"
#include "qe3.h"
#include "Radiant.h"
#include "EditViewDlg.h"
// CEditViewDlg dialog
IMPLEMENT_DYNAMIC(CEditViewDlg, CDialog)
CEditViewDlg::CEditViewDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEditViewDlg::IDD, pParent)
{
findDlg = NULL;
}
CEditViewDlg::~CEditViewDlg() {
}
void CEditViewDlg::DoDataExchange(CDataExchange* pDX) {
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT_INFO, editInfo);
}
static UINT FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
BEGIN_MESSAGE_MAP(CEditViewDlg, CDialog)
ON_WM_SIZE()
ON_BN_CLICKED(IDC_BUTTON_OPEN, OnBnClickedButtonOpen)
ON_BN_CLICKED(IDC_BUTTON_SAVE, OnBnClickedButtonSave)
ON_WM_DESTROY()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON_GOTO, OnBnClickedButtonGoto)
ON_REGISTERED_MESSAGE(FindDialogMessage, OnFindDialogMessage)
END_MESSAGE_MAP()
// CEditViewDlg message handlers
void CEditViewDlg::OnSize(UINT nType, int cx, int cy) {
CDialog::OnSize(nType, cx, cy);
if (GetSafeHwnd() == NULL) {
return;
}
CRect rect, crect;
GetClientRect(rect);
CWnd *wnd = GetDlgItem(IDC_BUTTON_OPEN);
if (wnd == NULL || (wnd && wnd->GetSafeHwnd() == NULL)) {
return;
}
wnd->GetWindowRect(crect);
wnd->SetWindowPos(NULL, 4, 4, crect.Width(), crect.Height(), SWP_SHOWWINDOW);
wnd = GetDlgItem(IDC_BUTTON_SAVE);
int left = 8 + crect.Width();
wnd->SetWindowPos(NULL, left, 4, crect.Width(), crect.Height(), SWP_SHOWWINDOW);
wnd = GetDlgItem(IDOK);
wnd->SetWindowPos(NULL, rect.Width() - crect.Width() - 4, 4, crect.Width(), crect.Height(), SWP_SHOWWINDOW);
editInfo.SetWindowPos(NULL, 4, 8 + crect.Height(), rect.Width() - 8, rect.Height() - crect.Height() * 2 - 16, SWP_SHOWWINDOW);
wnd = GetDlgItem(IDC_BUTTON_GOTO);
wnd->SetWindowPos(NULL, 4, rect.Height() - 4 - crect.Height(), crect.Width(), crect.Height(), SWP_SHOWWINDOW);
wnd = GetDlgItem(IDC_EDIT_GOTO);
wnd->SetWindowPos(NULL, 8 + crect.Width(), rect.Height() - 3 - crect.Height(), crect.Width() + 8, crect.Height() - 3, SWP_SHOWWINDOW);
wnd = GetDlgItem(IDC_STATIC_LINE);
wnd->SetWindowPos(NULL, 30 + crect.Width() * 2, rect.Height() - crect.Height(), crect.Width() * 2, crect.Height(), SWP_SHOWWINDOW);
wnd = GetDlgItem(IDC_EDIT_LINE);
wnd->SetWindowPos(NULL, 40 + crect.Width() * 3, rect.Height() - crect.Height(), crect.Width() + 8, crect.Height(), SWP_SHOWWINDOW);
}
void CEditViewDlg::ShowFindDlg() {
if (findDlg) {
return;
}
findDlg = new CFindReplaceDialog();
findDlg->Create(TRUE, findStr, NULL, FR_DOWN, this);
}
void CEditViewDlg::OnBnClickedButtonOpen() {
CPreviewDlg *dlg = NULL;
dlg = ((mode == MATERIALS) ? CEntityDlg::ShowMaterialChooser() : CEntityDlg::ShowGuiChooser());
if (dlg) {
if (mode == MATERIALS) {
const idMaterial *mat = declManager->FindMaterial(dlg->mediaName);
SetMaterialInfo(mat->GetName(), mat->GetFileName(), mat->GetLineNum());
} else {
SetGuiInfo(dlg->mediaName);
}
}
}
void CEditViewDlg::OnBnClickedButtonSave() {
if (fileName.Length()) {
CString text;
editInfo.GetWindowText(text);
fileSystem->WriteFile(fileName, text.GetBuffer(0), text.GetLength(), "fs_devpath");
if (mode == MATERIALS) {
declManager->Reload( false );
} else {
uiManager->Reload(false);
}
}
}
void CEditViewDlg::UpdateEditPreview() {
if (GetSafeHwnd() && editInfo.GetSafeHwnd()) {
editInfo.SetWindowText(editText);
editInfo.LineScroll(line);
int cindex = editInfo.LineIndex(line);
int len = editInfo.LineLength(line);
editInfo.SetSel(cindex, cindex);
mediaPreview.SetMode((mode == MATERIALS) ? CMediaPreviewDlg::MATERIALS : CMediaPreviewDlg::GUIS);
mediaPreview.SetMedia((mode == MATERIALS) ? matName : fileName);
SetWindowText(va("Editing %s in file <%s>", (mode == MATERIALS) ? matName.c_str() : fileName.c_str(), fileName.c_str()));
editInfo.SetFocus();
}
}
BOOL CEditViewDlg::OnInitDialog() {
CDialog::OnInitDialog();
mediaPreview.Create(IDD_DIALOG_EDITPREVIEW, this);
mediaPreview.ShowWindow(SW_SHOW);
CRect rct;
LONG lSize = sizeof(rct);
if (LoadRegistryInfo("Radiant::EditViewWindow", &rct, &lSize)) {
SetWindowPos(NULL, rct.left, rct.top, rct.Width(), rct.Height(), SWP_SHOWWINDOW);
}
editInfo.SetTabStops();
editInfo.SetLimitText(1024 * 1024);
UpdateEditPreview();
SetTimer(1, 250, NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CEditViewDlg::OnDestroy() {
if (GetSafeHwnd()) {
CRect rct;
GetWindowRect(rct);
SaveRegistryInfo("Radiant::EditViewWindow", &rct, sizeof(rct));
}
CDialog::OnDestroy();
}
void CEditViewDlg::SetMaterialInfo(const char *name, const char *file, int _line) {
idStr str;
void *buf;
fileName = "";
matName = "";
line = 0;
str = fileSystem->OSPathToRelativePath( file );
int size = fileSystem->ReadFile( str, &buf );
if (size > 0) {
fileName = str;
matName = name;
line = _line - 1;
if (line < 0) {
line = 0;
}
editText = (char*)buf;
fileSystem->FreeFile(buf);
}
UpdateEditPreview();
}
void CEditViewDlg::SetGuiInfo(const char *name) {
fileName = "";
line = 0;
void *buf;
int size = fileSystem->ReadFile(name, &buf, NULL);
if (size > 0) {
fileName = name;
editText = (char*)buf;
fileSystem->FreeFile(buf);
}
UpdateEditPreview();
}
void CEditViewDlg::OnTimer(UINT nIDEvent) {
CDialog::OnTimer(nIDEvent);
CWnd *wnd = GetDlgItem(IDC_EDIT_LINE);
if (wnd) {
int start, end;
editInfo.GetSel(start, end);
wnd->SetWindowText(va("%i",editInfo.LineFromChar(start)));
}
}
void CEditViewDlg::OnBnClickedButtonGoto() {
CWnd *wnd = GetDlgItem(IDC_EDIT_GOTO);
if (wnd) {
CString str;
wnd->GetWindowText(str);
if (str.GetLength()) {
int l = atoi(str);
editInfo.SetSel(0, 0);
editInfo.LineScroll(l);
int cindex = editInfo.LineIndex(l);
int len = editInfo.LineLength(l);
editInfo.SetSel(cindex, cindex);
editInfo.RedrawWindow();
editInfo.SetFocus();
}
}
}
BOOL CEditViewDlg::PreTranslateMessage(MSG* pMsg) {
if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 's' || pMsg->wParam == 'S') && GetAsyncKeyState(VK_CONTROL) & 0x8000) {
OnBnClickedButtonSave();
return TRUE;
}
if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 'o' || pMsg->wParam == 'O') && GetAsyncKeyState(VK_CONTROL) & 0x8000) {
OnBnClickedButtonOpen();
return TRUE;
}
if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 'f' || pMsg->wParam == 'F') && GetAsyncKeyState(VK_CONTROL) & 0x8000) {
ShowFindDlg();
return TRUE;
}
if (pMsg->hwnd == editInfo.GetSafeHwnd() && (pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_TAB)) {
// get the char index of the caret position
int nPos = LOWORD(editInfo.CharFromPos(editInfo.GetCaretPos()));
// select zero chars
editInfo.SetSel(nPos, nPos);
// then replace that selection with a TAB
editInfo.ReplaceSel("\t", TRUE);
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
LRESULT CEditViewDlg::OnFindDialogMessage(WPARAM wParam, LPARAM lParam) {
if (findDlg == NULL) {
return 0;
}
if (findDlg->IsTerminating()) {
findDlg = NULL;
return 0;
}
// If the FR_FINDNEXT flag is set,
// call the application-defined search routine
// to search for the requested string.
if(findDlg->FindNext()) {
//read data from dialog
findStr = findDlg->GetFindString().GetBuffer(0);
CString str;
editInfo.GetWindowText(str);
editText = str;
int start, end;
editInfo.GetSel(start, end);
start = editText.Find(findStr, false, end);
if (start >= 0) {
editInfo.SetSel(start, start + findStr.Length());
editInfo.Invalidate();
editInfo.RedrawWindow();
}
}
return 0;
}
|