source: dev/trunk/abdev/ProjectEditor/FileTree.cpp@ 192

Last change on this file since 192 was 3, checked in by dai_9181, 18 years ago
File size: 5.7 KB
Line 
1#include "common.h"
2
3CFileTree *pobj_FileTree;
4
5WNDPROC OldFileTreeViewProc;
6
7BOOL CALLBACK DlgProject_FileProperty(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
8 extern PROJECTINFO ProjectInfo;
9 HTREEITEM hTreeItem;
10 int i;
11 char temporary[MAX_PATH];
12 HANDLE hFile;
13 FILETIME LastWriteTime,LocalTime;
14 SYSTEMTIME SystemTime;
15
16 switch(message){
17 case WM_INITDIALOG:
18 SetPosCenter(hwnd);
19
20 hTreeItem=TreeView_GetSelection(pobj_FileTree->hTree);
21
22 char *path;
23 path=ProjectInfo.pobj_DBFileInfo->GetPath(hTreeItem);
24
25 //絶対パス、相対パスを表示
26 lstrcpy(temporary,path);
27 GetFullPath(temporary,ProjectInfo.dir);
28 SetDlgItemText(hwnd,IDC_USING_FILE,temporary);
29 SetDlgItemText(hwnd,IDC_DEFINED_FILE,path);
30
31 //最終更新日時を表示
32 hFile=CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
33 if(hFile==INVALID_HANDLE_VALUE){
34 //"エラー"
35 lstrcpy(temporary,STRING_ERROR);
36 }
37 else{
38 GetFileTime(hFile,NULL,NULL,&LastWriteTime);
39 FileTimeToLocalFileTime(&LastWriteTime,&LocalTime);
40 FileTimeToSystemTime(&LocalTime,&SystemTime);
41 if(SystemTime.wHour>=12){
42 //"午後 "
43 lstrcpy(temporary,STRING_AFTERNOON);
44 lstrcat(temporary," ");
45 SystemTime.wHour-=12;
46 }
47 else{
48 //"午前 "
49 lstrcpy(temporary,STRING_MORNING);
50 lstrcat(temporary," ");
51 }
52 sprintf(temporary+5,"%02d:%02d:%02d %04d/%02d/%02d",
53 SystemTime.wHour,SystemTime.wMinute,SystemTime.wSecond,
54 SystemTime.wYear,SystemTime.wMonth,SystemTime.wDay);
55 CloseHandle(hFile);
56 }
57 SetDlgItemText(hwnd,IDC_UPDATE_TIME,temporary);
58
59
60 //////////////
61 // 形式を表示
62 //////////////
63 i=GetFileExtension(path);
64
65 //"Basic プログラム"
66 if(i==FT_BASICPROGRAM) lstrcpy(temporary,STRING_FILETYPE_BASICPROGRAM);
67 //"サブ プログラム"
68 else if(i==FT_SUBPROGRAM) lstrcpy(temporary,STRING_FILETYPE_SUBPROGRAM);
69 //"テキスト ドキュメント"
70 else if(i==FT_TEXT) lstrcpy(temporary,STRING_FILETYPE_TEXT);
71 //"判別できません"
72 else lstrcpy(temporary,STRING_FILETYPE_UNKNOWN);
73
74 SetDlgItemText(hwnd,IDC_FILETYPE,temporary);
75
76 break;
77 case WM_COMMAND:
78 switch(LOWORD(wParam)){
79 case IDOK:
80 EndDialog(hwnd,0);
81 return 1;
82 case IDCANCEL:
83 EndDialog(hwnd,0);
84 return 1;
85 }
86 break;
87 }
88 return 0;
89}
90
91LRESULT CALLBACK FileTreeViewProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
92 HTREEITEM hTreeItem;
93 char temporary[MAX_PATH];
94 char *path;
95 switch(message){
96 case WM_COMMAND:
97 switch(LOWORD(wParam)){
98 case IDM_FILETREE_INSERT:
99 //"プロジェクトへ挿入するファイルを指定して下さい"
100 extern LPSTR DefFileFilter;
101 if(!GetFilePathDialog(hOwner,temporary,DefFileFilter,STRING_FILEOPENTITLE_INSERTEDPROJECT,1)) break;
102 Project_File_Insert(temporary);
103 break;
104 case IDM_FILETREE_OPEN:
105 hTreeItem=TreeView_GetSelection(hwnd);
106
107 path=ProjectInfo.pobj_DBFileInfo->GetPath(hTreeItem);
108 if(!path) break;
109
110 lstrcpy(temporary,path);
111 GetFullPath(temporary,ProjectInfo.dir);
112 OpenFileWithExtension(temporary);
113 break;
114 case IDM_FILETREE_DELETE:
115 hTreeItem=TreeView_GetSelection(hwnd);
116 Project_File_Delete(hTreeItem);
117 break;
118 case IDM_FILETREE_PROPERTY:
119 DialogBox(hResInst,MAKEINTRESOURCE(IDD_PROJECT_FILEPROPERTY),hOwner,DlgProject_FileProperty);
120 break;
121 }
122 return 0;
123 case WM_CHAR:
124 if(wParam==VK_RETURN){
125 SendMessage(hwnd,WM_COMMAND,IDM_FILETREE_OPEN,0);
126 //デフォルトのメッセージ処理をするとビープ音がしてしまうので避ける
127 return 0;
128 }
129 break;
130 case WM_KEYDOWN:
131 if(wParam==VK_DELETE){
132 SendMessage(hwnd,WM_COMMAND,IDM_FILETREE_DELETE,0);
133 }
134 break;
135 case WM_LBUTTONDBLCLK:
136 SendMessage(hwnd,WM_COMMAND,IDM_FILETREE_OPEN,0);
137 break;
138 }
139 return CallWindowProc(OldFileTreeViewProc,hwnd,message,wParam,lParam);
140}
141
142CFileTree::CFileTree(HWND hParent){
143 hTree=CreateWindowEx(WS_EX_CLIENTEDGE,WC_TREEVIEW,"",
144 WS_CHILD|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT|TVS_SHOWSELALWAYS,
145 0,0,0,0,
146 hParent,0,hInst,0);
147 OldFileTreeViewProc=(WNDPROC)GetWindowLong(hTree,GWL_WNDPROC);
148 SetWindowLong(hTree,GWL_WNDPROC,(long)FileTreeViewProc);
149
150 //イメージリスト読み込み、設定
151 hImageList=ImageList_Create(16,16,ILC_COLOR24|ILC_MASK,3,0);
152 ImageList_AddIcon(hImageList,LoadIcon(hResInst,MAKEINTRESOURCE(IDI_FOLDER_CLOSE)));
153 ImageList_AddIcon(hImageList,LoadIcon(hResInst,MAKEINTRESOURCE(IDI_FOLDER_OPEN)));
154 ImageList_AddIcon(hImageList,LoadIcon(hResInst,MAKEINTRESOURCE(IDI_TEXTDOCUMENT)));
155 TreeView_SetImageList(hTree,hImageList,TVSIL_NORMAL);
156}
157CFileTree::~CFileTree(){
158 DestroyWindow(hTree);
159 ImageList_Destroy(hImageList);
160}
161
162void CFileTree::ContextMenu(POINT *pPos){
163 //右クリックによるメニューを表示
164 TV_HITTESTINFO tvHitTestInfo;
165 tvHitTestInfo.pt=*pPos;
166 ScreenToClient(hTree,&tvHitTestInfo.pt);
167
168 HTREEITEM hTreeItem;
169 hTreeItem=TreeView_HitTest(hTree,&tvHitTestInfo);
170 if(hTreeItem){
171 TreeView_SelectItem(hTree,hTreeItem);
172
173 extern HMENU hFileTreeMenuBase;
174 if(TreeView_GetRoot(hTree)==hTreeItem)
175 TrackPopupMenu(GetSubMenu(hFileTreeMenuBase,0),TPM_LEFTALIGN,pPos->x,pPos->y,0,hTree,0);
176 else TrackPopupMenu(GetSubMenu(hFileTreeMenuBase,1),TPM_LEFTALIGN,pPos->x,pPos->y,0,hTree,0);
177 }
178}
179
180HTREEITEM CFileTree::insert(char *str){
181 //////////////////////
182 //ツリービューに追加
183
184 TV_INSERTSTRUCT tv;
185 tv.hInsertAfter=TVI_SORT;
186 tv.item.mask=TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
187 tv.item.iImage=2;
188 tv.item.iSelectedImage=2;
189 tv.hParent=TreeView_GetRoot(hTree);
190 tv.item.pszText=str;
191
192 return TreeView_InsertItem(hTree,&tv);
193}
194
195void CFileTree::resize(int x,int y,int cx,int cy){
196 MoveWindow(hTree,x,y,cx,cy,1);
197}
Note: See TracBrowser for help on using the repository browser.