Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / tools / leveldesign / master / MasterTree.cpp
blobdd9c0b7714db8cb86c3bae492c2b8ce977fd111b
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // MasterTree.cpp : implementation file
20 #include "stdafx.h"
21 #include "master.h"
22 #include "MasterTree.h"
23 #include "Mainfrm.h"
24 #include "nel/misc/types_nl.h"
25 #ifdef NL_NEW
26 #undef new
27 #endif
28 using namespace std;
30 #ifdef _DEBUG
31 #define new DEBUG_NEW
32 #undef THIS_FILE
33 static char THIS_FILE[] = __FILE__;
34 #endif
36 // ---------------------------------------------------------------------------
38 #define IDC_TREE 0x1000
40 // Top level menus
41 #define ID_MENU_CONTINENT_NEW 0x0044
43 #define ID_MENU_SORT_NAME_INC 0x0047
44 #define ID_MENU_SORT_NAME_DEC 0x0048
45 #define ID_MENU_SORT_DATE_INC 0x0049
46 #define ID_MENU_SORT_DATE_DEC 0x0050
48 // Continent menus (a level under the top)
50 #define ID_MENU_CONTINENT_DELETE 0x0064
51 #define ID_MENU_CONTINENT_OPEN 0x0066
52 #define ID_MENU_CONTINENT_PROPERTIES 0x0067
53 #define ID_MENU_CONTINENT_NEW_REGION 0x0068
55 #define ID_MENU_REGION_OPEN 0x0070
56 #define ID_MENU_REGION_RENAME 0x0071
57 #define ID_MENU_REGION_NEW_SUBREGION 0x0072
58 #define ID_MENU_REGION_NEW_PRIM 0x0073
59 #define ID_MENU_REGION_NEW_GEORGES 0x0074
60 #define ID_MENU_REGION_DELETE 0x0075
62 #define ID_MENU_FILE_OPEN 0x0080
63 #define ID_MENU_FILE_RENAME 0x0081
64 #define ID_MENU_FILE_DELETE 0x0082
66 // ---------------------------------------------------------------------------
68 /////////////////////////////////////////////////////////////////////////////
69 // CMasterTreeDlg dialog
70 /////////////////////////////////////////////////////////////////////////////
72 BEGIN_MESSAGE_MAP (CMasterTree, CTreeCtrl)
74 ON_WM_TIMER()
76 ON_NOTIFY_REFLECT(TVN_BEGINDRAG, OnLBeginDrag)
78 ON_WM_MOUSEMOVE()
79 ON_WM_LBUTTONDBLCLK()
80 ON_WM_LBUTTONDOWN()
81 ON_WM_LBUTTONUP()
82 ON_WM_RBUTTONDOWN()
84 ON_COMMAND(ID_MENU_CONTINENT_NEW, OnMenuNewContinent)
86 ON_COMMAND(ID_MENU_CONTINENT_DELETE, OnMenuContinentDelete)
87 ON_COMMAND(ID_MENU_CONTINENT_OPEN, OnMenuContinentOpen)
88 ON_COMMAND(ID_MENU_CONTINENT_PROPERTIES, OnMenuContinentProperties)
89 ON_COMMAND(ID_MENU_CONTINENT_NEW_REGION, OnMenuContinentNewRegion)
91 ON_COMMAND(ID_MENU_REGION_OPEN, OnMenuRegionOpen)
92 ON_COMMAND(ID_MENU_REGION_RENAME, OnMenuRegionRename)
93 ON_COMMAND(ID_MENU_REGION_NEW_PRIM, OnMenuRegionNewPrim)
94 ON_COMMAND(ID_MENU_REGION_NEW_GEORGES, OnMenuRegionNewGeorges)
95 ON_COMMAND(ID_MENU_REGION_DELETE, OnMenuRegionDelete)
96 ON_COMMAND(ID_MENU_REGION_NEW_SUBREGION, OnMenuRegionNewSubRegion)
98 ON_COMMAND(ID_MENU_FILE_OPEN, OnMenuFileOpen)
99 ON_COMMAND(ID_MENU_FILE_RENAME, OnMenuFileRename)
100 ON_COMMAND(ID_MENU_FILE_DELETE, OnMenuFileDelete)
102 END_MESSAGE_MAP()
104 // ---------------------------------------------------------------------------
105 CMasterTree::CMasterTree ()
107 _LDrag = false;
108 _LastItemSelected = NULL;
109 _LastActiveContinent = NULL;
112 // ---------------------------------------------------------------------------
113 void CMasterTree::OnTimer (UINT nIDEvent)
115 if( nIDEvent != m_nTimerID )
117 CTreeCtrl::OnTimer(nIDEvent);
118 return;
121 // Doesn't matter that we didn't initialize m_timerticks
122 m_timerticks++;
124 POINT pt;
125 GetCursorPos (&pt);
126 RECT rect;
127 GetClientRect (&rect);
128 ClientToScreen (&rect);
130 if( pt.y < rect.top + 10 )
132 CImageList::DragShowNolock (FALSE);
133 SendMessage (WM_VSCROLL, SB_LINEUP);
134 CImageList::DragShowNolock (TRUE);
136 else if( pt.y > rect.bottom - 10 )
138 CImageList::DragShowNolock (FALSE);
139 SendMessage (WM_VSCROLL, SB_LINEDOWN);
140 CImageList::DragShowNolock (TRUE);
144 // ---------------------------------------------------------------------------
145 void CMasterTree::OnLBeginDrag (NMHDR* pNMHDR, LRESULT* pResult)
147 NMTREEVIEW *pNMTV = (NMTREEVIEW*)pNMHDR;
148 _DragItem = pNMTV->itemNew.hItem;
149 HTREEITEM hParent = GetParentItem (_DragItem);
150 if (hParent == NULL)
152 *pResult = true;
153 return;
155 _LDrag = true;
156 m_nTimerID = SetTimer (1, 50, NULL);
157 _DragImg = CreateDragImage (_DragItem);
158 _DragImg->BeginDrag (0, CPoint (8, 8));
159 _DragImg->DragEnter (this, ((NM_TREEVIEW *)pNMHDR)->ptDrag);
160 SetCapture ();
161 Invalidate ();
162 *pResult = false;
165 // ---------------------------------------------------------------------------
166 void CMasterTree::OnLButtonDown (UINT nFlags, CPoint point)
168 /*HTREEITEM NewItem = HitTest (point);
170 if (NewItem == NULL)
171 return;
173 CTreeCtrl::OnLButtonDown (nFlags, point);
175 HTREEITEM LastContinent, LastRegion;
176 HTREEITEM NewContinent, NewRegion;
177 LastContinent = getContinent (_LastItemSelected);
178 LastRegion = getRegion (_LastItemSelected);
180 NewContinent = getContinent (NewItem);
181 NewRegion = getRegion (NewItem);
183 if (LastRegion != NewRegion)
185 Expand (LastRegion, TVE_COLLAPSE);
186 Expand (NewRegion, TVE_EXPAND);
189 if (LastContinent != NewContinent)
191 Expand (LastContinent, TVE_COLLAPSE);
192 Expand (NewContinent, TVE_EXPAND);
195 _LastItemSelected = NewItem;
196 Expand (NewItem, TVE_EXPAND);
197 Select (NewItem, TVGN_CARET);*/
199 // ---------------------------------------------------------------------------
200 void CMasterTree::OnLButtonDblClk (UINT nFlags, CPoint point)
202 CTreeCtrl::OnLButtonDblClk (nFlags, point);
204 HTREEITEM hItem = HitTest (point);
206 if (hItem != NULL)
208 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
210 if (isFile(hItem))
212 pDlg->openFile (getPath(hItem));
217 // ---------------------------------------------------------------------------
218 void CMasterTree::OnLButtonUp (UINT nFlags, CPoint point)
220 if (_LDrag)
222 SelectDropTarget (NULL);
223 _DragImg->DragLeave (this);
224 _DragImg->EndDrag ();
225 ReleaseCapture ();
226 KillTimer (m_nTimerID);
227 _LDrag = false;
228 delete _DragImg;
229 Invalidate ();
231 HTREEITEM dragEndItem = HitTest (point);
232 if ((_DragItem == NULL) || (dragEndItem == NULL))
233 return;
235 if (isFile(dragEndItem))
236 return;
238 Select (dragEndItem, TVGN_CARET);
240 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
241 pDlg->copy (getPath(_DragItem), getPath(dragEndItem));
245 // ---------------------------------------------------------------------------
246 void CMasterTree::OnMouseMove (UINT nFlags, CPoint point)
248 if (_LDrag)
250 _DragImg->DragMove (point);
251 _DragImg->DragShowNolock (FALSE);
253 UINT Flags;
254 HTREEITEM hItem = HitTest (point, &Flags);
255 HTREEITEM hParent = GetParentItem (hItem) ;
257 if ((_DragItem == NULL) || (hItem == NULL))
258 return;
260 if (!isFile(hItem))
261 SelectDropTarget (hItem);
263 _DragImg->DragShowNolock (TRUE);
267 // ---------------------------------------------------------------------------
268 void CMasterTree::OnRButtonDown (UINT nFlags, CPoint point)
270 UINT uFlags;
271 HTREEITEM hItem = HitTest (point, &uFlags);
272 HTREEITEM hParent = GetParentItem (hItem);
273 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
275 CRect r;
276 this->GetWindowRect (r);
278 CMenu *pMenu = new CMenu;
279 pMenu->CreatePopupMenu ();
281 if (hItem == NULL)
283 pMenu->AppendMenu (MF_STRING, ID_MENU_CONTINENT_NEW, "&New Continent");
284 pMenu->AppendMenu (MF_SEPARATOR);
285 pMenu->AppendMenu (MF_STRING, ID_MENU_SORT_NAME_DEC, "Sort By Name (A-Z)");
286 pMenu->AppendMenu (MF_STRING, ID_MENU_SORT_NAME_INC, "Sort By Name (Z-A)");
287 pMenu->AppendMenu (MF_STRING, ID_MENU_SORT_DATE_INC, "Sort By Date (New-Old)");
288 pMenu->AppendMenu (MF_STRING, ID_MENU_SORT_DATE_DEC, "Sort By Date (Old-New)");
290 else if (TVHT_ONITEM & uFlags)
292 Select (hItem, TVGN_CARET);
294 // System roots == continents
295 if (hParent == NULL)
297 pMenu->AppendMenu (MF_STRING, ID_MENU_CONTINENT_OPEN, "&Open");
298 pMenu->AppendMenu (MF_STRING, ID_MENU_CONTINENT_PROPERTIES, "&Properties");
299 pMenu->AppendMenu (MF_STRING, ID_MENU_CONTINENT_NEW_REGION, "New &Region");
300 pMenu->AppendMenu (MF_STRING, ID_MENU_CONTINENT_DELETE, "&Delete");
302 // Under the continents == regions and sub-regions
303 else
305 if (!isFile (hItem))
307 pMenu->AppendMenu (MF_STRING, ID_MENU_REGION_OPEN, "&Open");
308 pMenu->AppendMenu (MF_STRING, ID_MENU_REGION_RENAME, "&Rename");
309 pMenu->AppendMenu (MF_STRING, ID_MENU_REGION_NEW_SUBREGION, "New &SubRegion");
310 pMenu->AppendMenu (MF_STRING, ID_MENU_REGION_NEW_GEORGES, "New &Form");
311 pMenu->AppendMenu (MF_STRING, ID_MENU_REGION_NEW_PRIM, "New &Patatoid");
312 pMenu->AppendMenu (MF_STRING, ID_MENU_REGION_DELETE, "&Delete");
314 else
316 pMenu->AppendMenu (MF_STRING, ID_MENU_FILE_OPEN, "&Open");
317 pMenu->AppendMenu (MF_STRING, ID_MENU_FILE_RENAME, "&Rename");
318 pMenu->AppendMenu (MF_STRING, ID_MENU_FILE_DELETE, "&Delete");
322 pMenu->TrackPopupMenu (TPM_LEFTALIGN | TPM_LEFTBUTTON,
323 r.left+point.x, r.top+point.y, this);
326 // ---------------------------------------------------------------------------
327 void CMasterTree::OnMenuNewContinent ()
329 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
330 pDlg->continentNew ();
333 // ---------------------------------------------------------------------------
334 void CMasterTree::OnMenuContinentDelete ()
336 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
337 pDlg->continentDelete ((LPCSTR)GetItemText(GetSelectedItem()));
340 // ---------------------------------------------------------------------------
341 void CMasterTree::OnMenuContinentOpen ()
343 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent ();
344 HTREEITEM hItem = GetSelectedItem ();
345 HTREEITEM hParent = GetParentItem (hItem);
347 if (_LastActiveContinent != NULL)
348 SetItem (_LastActiveContinent, TVIF_STATE, NULL, 0, 0, 0, TVIS_BOLD, 0);
349 SetItem (hItem, TVIF_STATE, NULL, 0, 0, TVIS_BOLD, TVIS_BOLD, 0);
350 _LastActiveContinent = hItem;
351 pDlg->continentOpen (string((LPCSTR)GetItemText(hItem)));
354 // ---------------------------------------------------------------------------
355 void CMasterTree::OnMenuContinentProperties ()
357 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
358 pDlg->continentProperties ((LPCSTR)GetItemText(GetSelectedItem()));
361 // ---------------------------------------------------------------------------
362 void CMasterTree::OnMenuContinentNewRegion ()
364 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
365 pDlg->continentNewRegion ((LPCSTR)GetItemText(GetSelectedItem()));
368 // ---------------------------------------------------------------------------
369 void CMasterTree::OnMenuRegionOpen ()
371 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
372 HTREEITEM ht = GetSelectedItem();
373 pDlg->regionOpen (getPath(ht));
376 // ---------------------------------------------------------------------------
377 void CMasterTree::OnMenuRegionRename ()
379 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
380 HTREEITEM ht = GetSelectedItem();
381 pDlg->regionRename (getPath(ht));
384 // ---------------------------------------------------------------------------
385 void CMasterTree::OnMenuRegionNewSubRegion ()
387 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
388 HTREEITEM ht = GetSelectedItem();
389 pDlg->regionNewSubRegion (getPath(ht));
392 // ---------------------------------------------------------------------------
393 void CMasterTree::OnMenuRegionNewPrim ()
395 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
396 HTREEITEM ht = GetSelectedItem();
397 pDlg->regionNewPrim (getPath(ht));
400 // ---------------------------------------------------------------------------
401 void CMasterTree::OnMenuRegionNewGeorges ()
403 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
404 HTREEITEM ht = GetSelectedItem();
405 pDlg->regionNewGeorges (getPath(ht));
408 // ---------------------------------------------------------------------------
409 void CMasterTree::OnMenuRegionDelete ()
411 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
412 HTREEITEM ht = GetSelectedItem();
413 pDlg->regionDelete (getPath(ht));
416 // ---------------------------------------------------------------------------
417 void CMasterTree::OnMenuFileOpen ()
419 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
420 HTREEITEM hItem = GetSelectedItem();
421 bool bFile = isFile (hItem);
422 if (!bFile) return;
423 pDlg->fileOpen (getPath(hItem));
426 // ---------------------------------------------------------------------------
427 void CMasterTree::OnMenuFileRename ()
429 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
430 HTREEITEM hItem = GetSelectedItem();
431 bool bFile = isFile (hItem);
432 if (!bFile) return;
433 pDlg->fileRename (getPath(hItem));
436 // ---------------------------------------------------------------------------
437 void CMasterTree::OnMenuFileDelete ()
439 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
440 HTREEITEM hItem = GetSelectedItem();
441 bool bFile = isFile (hItem);
442 if (!bFile) return;
443 pDlg->fileDelete (getPath(hItem));
446 // ---------------------------------------------------------------------------
447 string CMasterTree::getCurrentPath ()
449 return getPath(GetSelectedItem());
452 // TOOLS
454 // ---------------------------------------------------------------------------
455 string CMasterTree::getPath (HTREEITEM ht)
457 string sTmp = "";
459 while (ht != NULL)
461 sTmp = string("\\") + (LPCSTR)GetItemText(ht) + sTmp;
462 ht = GetParentItem(ht);
465 return sTmp;
468 // ---------------------------------------------------------------------------
469 HTREEITEM CMasterTree::getContinent (HTREEITEM ht)
471 if (ht == NULL) return NULL;
472 if (GetParentItem(ht) == NULL) return NULL;
473 while (GetParentItem(GetParentItem(ht)) != NULL)
474 ht = GetParentItem(ht);
475 if (isFile(ht)) return NULL;
476 return ht;
479 // ---------------------------------------------------------------------------
480 HTREEITEM CMasterTree::getRegion (HTREEITEM ht)
482 if (ht == NULL) return NULL;
483 if (GetParentItem(ht) == NULL) return NULL;
484 if (GetParentItem(GetParentItem(ht)) == NULL) return NULL;
485 while (GetParentItem(GetParentItem(GetParentItem(ht))) != NULL)
486 ht = GetParentItem(ht);
487 if (isFile(ht)) return NULL;
488 return ht;
491 // ---------------------------------------------------------------------------
492 bool CMasterTree::isFile (HTREEITEM ht)
494 CMasterTreeDlg *pDlg = (CMasterTreeDlg*)GetParent();
495 map<HTREEITEM,string>::iterator it = pDlg->_Files.find (ht);
496 if (it != pDlg->_Files.end())
497 return true;
498 else
499 return false;
503 /////////////////////////////////////////////////////////////////////////////
504 // CMasterTreeDlg dialog
505 /////////////////////////////////////////////////////////////////////////////
507 BEGIN_MESSAGE_MAP(CMasterTreeDlg, CDialog)
508 //{{AFX_MSG_MAP(CMasterTreeDlg)
509 ON_WM_SIZE()
510 ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE, OnExpanding)
511 //ON_NOTIFY(NM_DBLCLK, IDC_TREE, OnLDblClkTree)
512 ON_WM_CREATE()
513 ON_WM_CLOSE()
514 //}}AFX_MSG_MAP
515 END_MESSAGE_MAP()
519 // ---------------------------------------------------------------------------
520 CMasterTreeDlg::CMasterTreeDlg ()
522 _Tree = NULL;
523 ContinentSortBy = 1; // 0/1 - by name
524 TrashSortBy = 1; // 2/3 - by date
525 BackupSortBy = 2;
528 // ---------------------------------------------------------------------------
529 FILETIME getFileTime (const string &fname)
531 WIN32_FIND_DATA FindFileData;
532 HANDLE hFind;
533 FILETIME ret = { 0xFFFFFFFF, 0xFFFFFFFF };
535 hFind = FindFirstFile (fname.c_str(), &FindFileData);
537 if (hFind != INVALID_HANDLE_VALUE)
539 ret = FindFileData.ftLastWriteTime;
540 FindClose (hFind);
542 return ret;
545 // ---------------------------------------------------------------------------
546 void CMasterTreeDlg::parseAdd (HTREEITEM itRoot, const string &path, char SortType, int DirDepth)
548 WIN32_FIND_DATA findData;
549 HANDLE hFind;
550 CTreeCtrl *pTree = (CTreeCtrl*)GetDlgItem(IDC_TREE);
551 vector<string> SortTable;
552 sint32 i, j;
554 char sCurDir[MAX_PATH];
555 GetCurrentDirectory (MAX_PATH, sCurDir);
557 if (!SetCurrentDirectory (path.c_str()))
559 SetCurrentDirectory (sCurDir);
560 return;
563 hFind = FindFirstFile ("*.*", &findData);
564 if (hFind != INVALID_HANDLE_VALUE)
568 // Look if the name is a system directory
569 bool bFound = false;
570 for (uint32 i = 0; i < MAX_SYS_DIR; ++i)
571 if (stricmp (findData.cFileName, gSysDir[i]) == 0)
573 bFound = true;
574 break;
576 if (!bFound) // No ok lets add it
578 SortTable.push_back (findData.cFileName);
581 while (FindNextFile(hFind, &findData) != 0);
582 FindClose (hFind);
585 if (SortTable.size() == 0)
587 SetCurrentDirectory (sCurDir);
588 return;
591 if (SortType == 0) // Sort By Name increasing (z-a)
593 for (i = 0; i < (sint32)SortTable.size()-1; ++i)
594 for (j = i+1; j < (sint32)SortTable.size(); ++j)
595 if (strcmp(SortTable[i].c_str(), SortTable[j].c_str()) < 0)
597 string tmp = SortTable[i];
598 SortTable[i] = SortTable[j];
599 SortTable[j] = tmp;
602 if (SortType == 1) // Sort By Name decreasing (a-z)
604 for (i = 0; i < (sint32)SortTable.size()-1; ++i)
605 for (j = i+1; j < (sint32)SortTable.size(); ++j)
606 if (strcmp(SortTable[i].c_str(), SortTable[j].c_str()) > 0)
608 string tmp = SortTable[i];
609 SortTable[i] = SortTable[j];
610 SortTable[j] = tmp;
613 if (SortType == 2) // Sort By Date increasing
615 for (i = 0; i < (sint32)SortTable.size()-1; ++i)
617 FILETIME timeI = getFileTime (SortTable[i]);
618 for (j = i+1; j < (sint32)SortTable.size(); ++j)
620 FILETIME timeJ = getFileTime (SortTable[j]);
621 if ((timeI.dwHighDateTime < timeJ.dwHighDateTime) ||
623 (timeI.dwHighDateTime == timeJ.dwHighDateTime) &&
624 (timeI.dwLowDateTime < timeJ.dwLowDateTime)
627 string tmp = SortTable[i];
628 SortTable[i] = SortTable[j];
629 SortTable[j] = tmp;
630 timeI = timeJ;
636 if (SortType == 3) // Sort By Date decreasing
638 for (i = 0; i < (sint32)SortTable.size()-1; ++i)
640 FILETIME timeI = getFileTime (SortTable[i]);
641 for (j = i+1; j < (sint32)SortTable.size(); ++j)
643 FILETIME timeJ = getFileTime (SortTable[j]);
644 if ((timeI.dwHighDateTime > timeJ.dwHighDateTime) ||
646 (timeI.dwHighDateTime == timeJ.dwHighDateTime) &&
647 (timeI.dwLowDateTime > timeJ.dwLowDateTime)
650 string tmp = SortTable[i];
651 SortTable[i] = SortTable[j];
652 SortTable[j] = tmp;
653 timeI = timeJ;
659 // Put directories first !
660 vector<string> SortTable2;
661 for (i = 0; i < (sint32)SortTable.size(); ++i)
663 if (GetFileAttributes(SortTable[i].c_str())&FILE_ATTRIBUTE_DIRECTORY)
664 SortTable2.push_back(SortTable[i]);
666 for (i = 0; i < (sint32)SortTable.size(); ++i)
668 if (!(GetFileAttributes(SortTable[i].c_str())&FILE_ATTRIBUTE_DIRECTORY))
669 SortTable2.push_back(SortTable[i]);
671 SortTable = SortTable2;
673 // Recurse
674 for (i = 0; i < (sint32)SortTable.size(); ++i)
676 if (GetFileAttributes(SortTable[i].c_str())&FILE_ATTRIBUTE_DIRECTORY)
678 HTREEITEM item;
680 if (DirDepth == 0)
681 item = pTree->InsertItem (SortTable[i].c_str(), 2, 2, itRoot);
682 else
683 item = pTree->InsertItem (SortTable[i].c_str(), 0, 0, itRoot);
684 string newPath = path;
685 if (newPath[newPath.size()-1] != '\\')
686 newPath += "\\";
687 newPath += SortTable[i].c_str();
688 parseAdd (item, newPath, SortType, DirDepth+1);
690 else
692 // Look if the name is a valid filename (look at the extension)
693 bool bFound = false;
694 for (uint32 j = 0; j < MAX_INVALID_EXT; ++j)
695 if (strlen(SortTable[i].c_str()) > strlen(gInvalidExt[j]))
696 if (stricmp(&SortTable[i].c_str()[strlen(SortTable[i].c_str())-strlen(gInvalidExt[j])], gInvalidExt[j]) == 0)
698 bFound = true;
699 break;
701 // If the extension is an invalid one -> Do not display file
702 if (!bFound)
704 HTREEITEM item = pTree->InsertItem (SortTable[i].c_str(), 1, 1, itRoot);
705 string sTemp = path;
706 if (sTemp[sTemp.size()-1] != '\\')
707 sTemp += "\\";
708 sTemp += SortTable[i].c_str();
709 _Files.insert(map<HTREEITEM,string>::value_type(item, sTemp));
714 SetCurrentDirectory (sCurDir);
717 // ---------------------------------------------------------------------------
718 HTREEITEM CMasterTreeDlg::activate (const std::string &name, HTREEITEM parent)
720 // Extract the eltName
721 string eltName;
722 string resName;
723 uint32 i = 0;
724 if (name.size() == 0) return NULL;
725 if (name[i] == '\\') ++i;
726 for (; i < name.size(); ++i)
728 if (name[i] == '\\') break;
729 eltName += name[i];
731 ++i;
732 for (; i < name.size(); ++i)
734 resName += name[i];
737 CTreeCtrl *pTree = (CTreeCtrl*)GetDlgItem (IDC_TREE);
738 HTREEITEM hChildItem = pTree->GetChildItem (parent);
739 bool bFound = false;
740 while (hChildItem != NULL)
742 if (eltName == (LPCSTR)pTree->GetItemText(hChildItem))
744 pTree->SetItem (hChildItem, TVIF_STATE, NULL, 0, 0, TVIS_BOLD, TVIS_BOLD, 0);
745 pTree->Expand (hChildItem, TVE_EXPAND);
746 activate (resName, hChildItem);
747 bFound = true;
748 break;
751 hChildItem = pTree->GetNextItem (hChildItem, TVGN_NEXT);
753 if (bFound)
754 return hChildItem;
755 else
756 return NULL;
759 // ---------------------------------------------------------------------------
760 void CMasterTreeDlg::update (const std::string& ContinentsPath)
762 CMasterTree *pTree = (CMasterTree*)GetDlgItem (IDC_TREE);
763 string sCurPath = pTree->getCurrentPath();
764 _Files.clear();
765 pTree->DeleteAllItems ();
766 // Parse all the path
767 char sCurDir[MAX_PATH];
768 GetCurrentDirectory (MAX_PATH, sCurDir);
769 parseAdd (TVI_ROOT, ContinentsPath, ContinentSortBy);
770 SetCurrentDirectory (sCurDir);
771 // Hilight active Continent
772 CMainFrame *pMF = (CMainFrame *)GetParent ();
773 activate (sCurPath, TVI_ROOT);
776 // ---------------------------------------------------------------------------
777 void CMasterTreeDlg::DoDataExchange (CDataExchange* pDX)
779 CDialog::DoDataExchange (pDX);
780 //{{AFX_DATA_MAP(CMasterTreeDlg)
781 // NOTE: the ClassWizard will add DDX and DDV calls here
782 //}}AFX_DATA_MAP
785 // ---------------------------------------------------------------------------
786 BOOL CMasterTreeDlg::OnInitDialog()
788 CDialog::OnInitDialog();
790 _Tree = new CMasterTree;
791 RECT r;
792 r.left = r.top = 10;
793 r.right = r.bottom = 40;
794 _Tree->Create (WS_VISIBLE|WS_BORDER, r, this, IDC_TREE);
795 // Load image list
796 CImageList *pImgList = new CImageList;
797 pImgList->Create (16, 16, ILC_MASK, 0, 5);
798 pImgList->Add (AfxGetApp()->LoadIcon(IDI_FOLDER));
799 pImgList->Add (AfxGetApp()->LoadIcon(IDI_FILE));
800 pImgList->Add (AfxGetApp()->LoadIcon(IDI_CONTINENTS));
801 pImgList->Add (AfxGetApp()->LoadIcon(IDI_BACKUP));
802 pImgList->Add (AfxGetApp()->LoadIcon(IDI_TRASH));
804 _Tree->SetImageList (pImgList, TVSIL_NORMAL);
805 return true;
808 // ---------------------------------------------------------------------------
809 void CMasterTreeDlg::OnSize (UINT nType, int cx, int cy)
811 if (_Tree)
812 _Tree->SetWindowPos (&wndTop, 0, 0, cx-20, cy-20, SWP_NOMOVE);
815 // ---------------------------------------------------------------------------
816 void CMasterTreeDlg::OnExpanding (LPNMHDR pnmhdr, LRESULT *pLResult)
818 /*CTreeCtrl *pTree = (CTreeCtrl*)GetDlgItem (IDC_TREE);
819 NMTREEVIEW *pnmtv = (LPNMTREEVIEW) pnmhdr;
821 if ((pnmtv->itemNew.state & TVIS_EXPANDED) != 0)
823 // We want to collapse this item -> forbid it
824 *pLResult = true;
828 // ---------------------------------------------------------------------------
829 void CMasterTreeDlg::openFile (const std::string &fname)
831 CMainFrame *pMF = (CMainFrame *)GetParent();
832 pMF->openFile (fname.c_str());
835 // ---------------------------------------------------------------------------
836 void CMasterTreeDlg::openDir (const std::string &fname)
838 CMainFrame *pMF = (CMainFrame *)GetParent();
839 pMF->openDir (fname.c_str());
842 // ---------------------------------------------------------------------------
843 void CMasterTreeDlg::continentNew ()
845 CMainFrame *pMF = (CMainFrame *)GetParent();
846 pMF->continentNew ();
849 // ---------------------------------------------------------------------------
850 void CMasterTreeDlg::continentDelete (const string &contName)
852 CMainFrame *pMF = (CMainFrame*)GetParent();
853 pMF->continentDelete (contName);
856 // ---------------------------------------------------------------------------
857 void CMasterTreeDlg::continentProperties (const string &contName)
859 CMainFrame *pMF = (CMainFrame *)GetParent();
860 pMF->continentProperties (contName);
863 // ---------------------------------------------------------------------------
864 void CMasterTreeDlg::continentNewRegion (const string &contName)
866 CMainFrame *pMF = (CMainFrame *)GetParent();
867 pMF->continentNewRegion (contName);
870 // ---------------------------------------------------------------------------
871 void CMasterTreeDlg::continentOpen (const string &contName)
873 CMainFrame *pMF = (CMainFrame *)GetParent();
874 pMF->continentOpen (contName);
877 // ---------------------------------------------------------------------------
878 void CMasterTreeDlg::regionOpen (const string &path)
880 CMainFrame *pMF = (CMainFrame *)GetParent();
881 pMF->regionOpen (path);
884 // ---------------------------------------------------------------------------
885 void CMasterTreeDlg::regionRename (const string &path)
887 CMainFrame *pMF = (CMainFrame *)GetParent();
888 pMF->regionRename (path);
891 // ---------------------------------------------------------------------------
892 void CMasterTreeDlg::regionNewPrim (const string &path)
894 CMainFrame *pMF = (CMainFrame *)GetParent();
895 pMF->regionNewPrim (path);
898 // ---------------------------------------------------------------------------
899 void CMasterTreeDlg::regionNewGeorges (const string &path)
901 CMainFrame *pMF = (CMainFrame *)GetParent();
902 pMF->regionNewGeorges (path);
905 // ---------------------------------------------------------------------------
906 void CMasterTreeDlg::regionNewSubRegion (const std::string &path)
908 CMainFrame *pMF = (CMainFrame *)GetParent();
909 pMF->regionNewSubRegion (path);
912 // ---------------------------------------------------------------------------
913 void CMasterTreeDlg::regionDelete (const std::string &path)
915 CMainFrame *pMF = (CMainFrame *)GetParent();
916 pMF->regionDelete (path);
919 // ---------------------------------------------------------------------------
920 void CMasterTreeDlg::fileOpen (const std::string &sFileFullName)
922 CMainFrame *pMF = (CMainFrame *)GetParent();
923 pMF->fileOpen (sFileFullName);
926 // ---------------------------------------------------------------------------
927 void CMasterTreeDlg::fileRename (const std::string &sFileFullName)
929 CMainFrame *pMF = (CMainFrame *)GetParent();
930 pMF->fileRename (sFileFullName);
933 // ---------------------------------------------------------------------------
934 void CMasterTreeDlg::fileDelete (const std::string &sFileFullName)
936 CMainFrame *pMF = (CMainFrame *)GetParent();
937 pMF->fileDelete (sFileFullName);
940 // ---------------------------------------------------------------------------
941 void CMasterTreeDlg::copy (const std::string &pathSrc, const std::string &pathDst)
943 CMainFrame *pMF = (CMainFrame *)GetParent();
944 pMF->copy (pathSrc, pathDst);
947 // ---------------------------------------------------------------------------
949 void CMasterTreeDlg::OnLDblClkTree(NMHDR* pNMHDR, LRESULT* pResult)
951 CTreeCtrl *pTree = (CTreeCtrl*)GetDlgItem (IDC_TREE);
952 NMTREEVIEW *pnmtv = (LPNMTREEVIEW) pNMHDR;
953 HTREEITEM hItem = pTree->GetSelectedItem();
954 HTREEITEM hParent = pTree->GetParentItem (hItem);
956 *pResult = 0;
957 if (hItem != NULL)
959 map<HTREEITEM,string>::iterator it = _Files.find (hItem);
961 if (it != _Files.end())
963 // Double click on a file open the corresponding editor
964 openAnyFile (it->second.c_str());
965 return;
968 if ((hParent != NULL) && (pTree->GetParentItem (hParent) == NULL))
970 // Double click on a Continent open all editors
971 // Parse all files and open them in the good editor
972 HTREEITEM hChildItem = pTree->GetChildItem (hItem);
974 while (hChildItem != NULL)
976 it = _Files.find (hChildItem);
977 if (it != _Files.end())
979 openAnyFile (it->second.c_str());
981 hChildItem = pTree->GetNextItem (hChildItem, TVGN_NEXT);
983 return;
989 // ---------------------------------------------------------------------------
990 void CMasterTreeDlg::OnCancel ()
994 // ---------------------------------------------------------------------------
995 void CMasterTreeDlg::OnOK ()