1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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
22 #include "MasterTree.h"
24 #include "nel/misc/types_nl.h"
33 static char THIS_FILE
[] = __FILE__
;
36 // ---------------------------------------------------------------------------
38 #define IDC_TREE 0x1000
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
)
76 ON_NOTIFY_REFLECT(TVN_BEGINDRAG
, OnLBeginDrag
)
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
)
104 // ---------------------------------------------------------------------------
105 CMasterTree::CMasterTree ()
108 _LastItemSelected
= NULL
;
109 _LastActiveContinent
= NULL
;
112 // ---------------------------------------------------------------------------
113 void CMasterTree::OnTimer (UINT nIDEvent
)
115 if( nIDEvent
!= m_nTimerID
)
117 CTreeCtrl::OnTimer(nIDEvent
);
121 // Doesn't matter that we didn't initialize m_timerticks
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
);
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
);
165 // ---------------------------------------------------------------------------
166 void CMasterTree::OnLButtonDown (UINT nFlags
, CPoint point
)
168 /*HTREEITEM NewItem = HitTest (point);
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
);
208 CMasterTreeDlg
*pDlg
= (CMasterTreeDlg
*)GetParent();
212 pDlg
->openFile (getPath(hItem
));
217 // ---------------------------------------------------------------------------
218 void CMasterTree::OnLButtonUp (UINT nFlags
, CPoint point
)
222 SelectDropTarget (NULL
);
223 _DragImg
->DragLeave (this);
224 _DragImg
->EndDrag ();
226 KillTimer (m_nTimerID
);
231 HTREEITEM dragEndItem
= HitTest (point
);
232 if ((_DragItem
== NULL
) || (dragEndItem
== NULL
))
235 if (isFile(dragEndItem
))
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
)
250 _DragImg
->DragMove (point
);
251 _DragImg
->DragShowNolock (FALSE
);
254 HTREEITEM hItem
= HitTest (point
, &Flags
);
255 HTREEITEM hParent
= GetParentItem (hItem
) ;
257 if ((_DragItem
== NULL
) || (hItem
== NULL
))
261 SelectDropTarget (hItem
);
263 _DragImg
->DragShowNolock (TRUE
);
267 // ---------------------------------------------------------------------------
268 void CMasterTree::OnRButtonDown (UINT nFlags
, CPoint point
)
271 HTREEITEM hItem
= HitTest (point
, &uFlags
);
272 HTREEITEM hParent
= GetParentItem (hItem
);
273 CMasterTreeDlg
*pDlg
= (CMasterTreeDlg
*)GetParent();
276 this->GetWindowRect (r
);
278 CMenu
*pMenu
= new CMenu
;
279 pMenu
->CreatePopupMenu ();
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
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
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");
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
);
423 pDlg
->fileOpen (getPath(hItem
));
426 // ---------------------------------------------------------------------------
427 void CMasterTree::OnMenuFileRename ()
429 CMasterTreeDlg
*pDlg
= (CMasterTreeDlg
*)GetParent();
430 HTREEITEM hItem
= GetSelectedItem();
431 bool bFile
= isFile (hItem
);
433 pDlg
->fileRename (getPath(hItem
));
436 // ---------------------------------------------------------------------------
437 void CMasterTree::OnMenuFileDelete ()
439 CMasterTreeDlg
*pDlg
= (CMasterTreeDlg
*)GetParent();
440 HTREEITEM hItem
= GetSelectedItem();
441 bool bFile
= isFile (hItem
);
443 pDlg
->fileDelete (getPath(hItem
));
446 // ---------------------------------------------------------------------------
447 string
CMasterTree::getCurrentPath ()
449 return getPath(GetSelectedItem());
454 // ---------------------------------------------------------------------------
455 string
CMasterTree::getPath (HTREEITEM ht
)
461 sTmp
= string("\\") + (LPCSTR
)GetItemText(ht
) + sTmp
;
462 ht
= GetParentItem(ht
);
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
;
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
;
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())
503 /////////////////////////////////////////////////////////////////////////////
504 // CMasterTreeDlg dialog
505 /////////////////////////////////////////////////////////////////////////////
507 BEGIN_MESSAGE_MAP(CMasterTreeDlg
, CDialog
)
508 //{{AFX_MSG_MAP(CMasterTreeDlg)
510 ON_NOTIFY(TVN_ITEMEXPANDING
, IDC_TREE
, OnExpanding
)
511 //ON_NOTIFY(NM_DBLCLK, IDC_TREE, OnLDblClkTree)
519 // ---------------------------------------------------------------------------
520 CMasterTreeDlg::CMasterTreeDlg ()
523 ContinentSortBy
= 1; // 0/1 - by name
524 TrashSortBy
= 1; // 2/3 - by date
528 // ---------------------------------------------------------------------------
529 FILETIME
getFileTime (const string
&fname
)
531 WIN32_FIND_DATA FindFileData
;
533 FILETIME ret
= { 0xFFFFFFFF, 0xFFFFFFFF };
535 hFind
= FindFirstFile (fname
.c_str(), &FindFileData
);
537 if (hFind
!= INVALID_HANDLE_VALUE
)
539 ret
= FindFileData
.ftLastWriteTime
;
545 // ---------------------------------------------------------------------------
546 void CMasterTreeDlg::parseAdd (HTREEITEM itRoot
, const string
&path
, char SortType
, int DirDepth
)
548 WIN32_FIND_DATA findData
;
550 CTreeCtrl
*pTree
= (CTreeCtrl
*)GetDlgItem(IDC_TREE
);
551 vector
<string
> SortTable
;
554 char sCurDir
[MAX_PATH
];
555 GetCurrentDirectory (MAX_PATH
, sCurDir
);
557 if (!SetCurrentDirectory (path
.c_str()))
559 SetCurrentDirectory (sCurDir
);
563 hFind
= FindFirstFile ("*.*", &findData
);
564 if (hFind
!= INVALID_HANDLE_VALUE
)
568 // Look if the name is a system directory
570 for (uint32 i
= 0; i
< MAX_SYS_DIR
; ++i
)
571 if (stricmp (findData
.cFileName
, gSysDir
[i
]) == 0)
576 if (!bFound
) // No ok lets add it
578 SortTable
.push_back (findData
.cFileName
);
581 while (FindNextFile(hFind
, &findData
) != 0);
585 if (SortTable
.size() == 0)
587 SetCurrentDirectory (sCurDir
);
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
];
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
];
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
];
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
];
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
;
674 for (i
= 0; i
< (sint32
)SortTable
.size(); ++i
)
676 if (GetFileAttributes(SortTable
[i
].c_str())&FILE_ATTRIBUTE_DIRECTORY
)
681 item
= pTree
->InsertItem (SortTable
[i
].c_str(), 2, 2, itRoot
);
683 item
= pTree
->InsertItem (SortTable
[i
].c_str(), 0, 0, itRoot
);
684 string newPath
= path
;
685 if (newPath
[newPath
.size()-1] != '\\')
687 newPath
+= SortTable
[i
].c_str();
688 parseAdd (item
, newPath
, SortType
, DirDepth
+1);
692 // Look if the name is a valid filename (look at the extension)
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)
701 // If the extension is an invalid one -> Do not display file
704 HTREEITEM item
= pTree
->InsertItem (SortTable
[i
].c_str(), 1, 1, itRoot
);
706 if (sTemp
[sTemp
.size()-1] != '\\')
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
724 if (name
.size() == 0) return NULL
;
725 if (name
[i
] == '\\') ++i
;
726 for (; i
< name
.size(); ++i
)
728 if (name
[i
] == '\\') break;
732 for (; i
< name
.size(); ++i
)
737 CTreeCtrl
*pTree
= (CTreeCtrl
*)GetDlgItem (IDC_TREE
);
738 HTREEITEM hChildItem
= pTree
->GetChildItem (parent
);
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
);
751 hChildItem
= pTree
->GetNextItem (hChildItem
, TVGN_NEXT
);
759 // ---------------------------------------------------------------------------
760 void CMasterTreeDlg::update (const std::string
& ContinentsPath
)
762 CMasterTree
*pTree
= (CMasterTree
*)GetDlgItem (IDC_TREE
);
763 string sCurPath
= pTree
->getCurrentPath();
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
785 // ---------------------------------------------------------------------------
786 BOOL
CMasterTreeDlg::OnInitDialog()
788 CDialog::OnInitDialog();
790 _Tree
= new CMasterTree
;
793 r
.right
= r
.bottom
= 40;
794 _Tree
->Create (WS_VISIBLE
|WS_BORDER
, r
, this, IDC_TREE
);
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
);
808 // ---------------------------------------------------------------------------
809 void CMasterTreeDlg::OnSize (UINT nType
, int cx
, int cy
)
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
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);
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());
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);
989 // ---------------------------------------------------------------------------
990 void CMasterTreeDlg::OnCancel ()
994 // ---------------------------------------------------------------------------
995 void CMasterTreeDlg::OnOK ()