OSDN Git Service

Lycheeにリネーム。
[tpi/lychee.git] / src / frontend / functions.cpp
1 /*******************************************************************************\r
2   TPI - flexible but useless plug-in framework.\r
3   Copyright (C) 2002-2009 Silky\r
4 \r
5   This library is free software; you can redistribute it and/or modify it under\r
6   the terms of the GNU Lesser General Public License as published by the Free\r
7   Software Foundation; either version 2.1 of the License, or (at your option)\r
8   any later version.\r
9 \r
10   This library is distributed in the hope that it will be useful, but WITHOUT\r
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
12   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License\r
13   for more details.\r
14 \r
15   You should have received a copy of the GNU Lesser General Public License along\r
16   with this library; if not, write to the Free Software Foundation, Inc.,\r
17   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
18 \r
19   $Id: functions.cpp,v 1.17 2009/09/02 11:18:49 sirakaba Exp $\r
20 *******************************************************************************/\r
21 \r
22 //******************************************************************************\r
23 //    \83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý\r
24 //******************************************************************************\r
25 \r
26 #include "frontend.h"\r
27 #include "frm_main.h"\r
28 #include "dlg_make.h"\r
29 #include "functions.h"\r
30 \r
31 //******************************************************************************\r
32 //    \83R\83\93\83g\83\8d\81[\83\8b\8f\88\97\9d\8cn\8aÖ\90\94\r
33 //******************************************************************************\r
34 \r
35 bool TreeView_CheckNewerItem(wxTreeCtrl * tree_ctrl, wxTreeItemId idParent, const wxString & szDirPath, bool bReallyMake)\r
36 {\r
37         // \8dÅ\8f\89\82Ì\8eq\83A\83C\83e\83\80\82ð\8eæ\93¾\81B\r
38         wxTreeItemIdValue idv;\r
39         wxTreeItemId idChild = tree_ctrl->GetFirstChild(idParent, idv);\r
40         wxChar cSep = wxFileName::GetPathSeparator();\r
41         while (idChild.IsOk())\r
42         {\r
43                 // \83A\83C\83e\83\80\82Æ\96¼\91O\82ª\93¯\82\82È\82çOK\81B\r
44                 if (tree_ctrl->GetItemText(idChild) == szDirPath.BeforeFirst(cSep))\r
45                 {\r
46                         // \82±\82ê\88È\89º\82Ì\8aK\91w\82ª\96³\82¢\8fê\8d\87\81B\r
47                         if (szDirPath.Find(cSep) == wxNOT_FOUND)\r
48                         {\r
49                                 return bReallyMake;\r
50                         }\r
51 \r
52                         // \82Ü\82¾\8aK\91w\82ª\97L\82é\8fê\8d\87\81A\8dÄ\8bA\81B\r
53                         return TreeView_CheckNewerItem(tree_ctrl, idChild, szDirPath.AfterFirst(cSep), bReallyMake);\r
54                 }\r
55 \r
56                 idChild = tree_ctrl->GetNextSibling(idChild);\r
57         }\r
58 \r
59         // \91Î\8fÛ\82ª\96³\82¢\8fê\8d\87\82É\82Í\8dì\90¬\81B\r
60         if (! szDirPath.IsEmpty())\r
61         {\r
62                 if (! bReallyMake)\r
63                 {\r
64                         // \8am\94F\82·\82é\82¾\82¯\82È\82ç\82±\82±\82Å\8fI\97¹\81B\r
65                         return true;\r
66                 }\r
67 \r
68                 // 2\8aK\91w\88È\8fã\90[\82¢\8fê\8d\87\82É\82à\91Î\89\9e\81B\r
69                 wxString szTemp = szDirPath;\r
70                 wxTreeItemId idTemp = idParent;\r
71                 do\r
72                 {\r
73                         // \93W\8aJ\82µ\82Ä\82©\82ç\8dì\90¬\81B\r
74                         idTemp = tree_ctrl->AppendItem(idTemp, szTemp.BeforeFirst(cSep), 0, 1);\r
75                         szTemp = szTemp.AfterFirst(cSep);\r
76                 }\r
77                 while (szTemp.Find(cSep) != wxNOT_FOUND);\r
78 \r
79                 // \8dÅ\8cã\82É\8bó\82Å\82È\82¢\8fê\8d\87\82É\82Í\82à\82¤1\8aK\91w\8dì\90¬\81B\r
80                 if (! szTemp.IsEmpty())\r
81                 {\r
82                         tree_ctrl->AppendItem(idTemp, szTemp, 0, 1);\r
83                 }\r
84         }\r
85 \r
86         return false;\r
87 }\r
88 \r
89 wxString TreeView_GetItemPath(wxTreeCtrl * tree_ctrl, wxTreeItemId idItem)\r
90 {\r
91         wxString szItemName, szNodePath = wxEmptyString;\r
92         wxChar cSep = wxFileName::GetPathSeparator();\r
93 \r
94         // \83A\83C\83e\83\80\82Ì\96¼\91O\82ð\8eæ\93¾\81B\r
95         while ((szItemName = tree_ctrl->GetItemText(idItem)))\r
96         {\r
97                 if (szItemName == wxT("-----"))\r
98                 {\r
99                         break;\r
100                 }\r
101 \r
102                 // \83p\83X\82É\92Ç\89Á\81B\r
103                 szNodePath = szItemName + cSep + szNodePath;\r
104 \r
105                 // \90e\83A\83C\83e\83\80\82É\91k\82é\81B\r
106                 idItem = tree_ctrl->GetItemParent(idItem);\r
107                 if (idItem == tree_ctrl->GetRootItem())\r
108                 {\r
109                         // \82±\82±\82É\82­\82é\82Ì\82Í\8f\91\8cÉ\93à\91S\95\\8e¦\8e\9e\81B\r
110                         szNodePath = wxT("*");\r
111                         break;\r
112                 }\r
113         }\r
114 \r
115         return (szNodePath.Find(cSep) == wxNOT_FOUND) ? szNodePath : szNodePath.BeforeLast(cSep);\r
116 }\r
117 \r
118 //******************************************************************************\r
119 //    \8f\94\8f\88\97\9d\8aÖ\90\94\r
120 //******************************************************************************\r
121 \r
122 // \83f\83B\83\8c\83N\83g\83\8a\82ð\90V\8bK\82É\8dì\90¬\81B\r
123 wxFileName MakeDirPath(wxFileName fnPath, wxString szBase, bool bAct)\r
124 {\r
125         // \82Æ\82è\82 \82¦\82¸\8dì\82Á\82Ä\82Ý\82é\81B\r
126         wxFileName fnDir = fnPath;\r
127         fnDir.AppendDir(szBase);\r
128         if (! fnDir.DirExists() && ! ::wxFileExists(fnDir.GetPath()))\r
129         {\r
130                 if (! bAct || fnDir.Mkdir())\r
131                 {\r
132                         return fnDir;\r
133                 }\r
134         }\r
135 \r
136         // \83_\83\81\82È\82ç"_%d"\82ð\95t\89Á\82µ\82Ä\8e\8e\8ds\81B\r
137         for (int i = 0; i < 255; i++)\r
138         {\r
139                 fnDir = fnPath;\r
140                 fnDir.AppendDir(szBase + wxString::Format(wxT("_%d"), i));\r
141                 if (! fnDir.DirExists() && ! ::wxFileExists(fnDir.GetPath()))\r
142                 {\r
143                         if (! bAct || fnDir.Mkdir())\r
144                         {\r
145                                 return fnDir;\r
146                         }\r
147                 }\r
148         }\r
149 \r
150         // \83G\83\89\81[\8fI\97¹\81B\r
151         fnDir.Clear();\r
152         return fnDir;\r
153 }\r
154 \r
155 wxArrayString MakeTargetFileList(MainFrame * frm, bool fOnlyOneFile)\r
156 {\r
157         wxArrayString as;\r
158         const int nState = frm->list_ctrl->GetSelectedItemCount() == 0 ? wxLIST_STATE_DONTCARE : wxLIST_STATE_SELECTED;\r
159         long nId = frm->list_ctrl->GetNextItem(-1, wxLIST_NEXT_ALL, nState);\r
160         while (nId != -1)\r
161         {\r
162                 as.Add(frm->list_ctrl->showFileInfo[nId].szStoredName);\r
163                 if (fOnlyOneFile)\r
164                 {\r
165                         break;\r
166                 }\r
167                 nId = frm->list_ctrl->GetNextItem(nId, wxLIST_NEXT_ALL, nState);\r
168         }\r
169 \r
170         return as;\r
171 }\r
172 \r
173 bool WillMakeDirByArcName(MainFrame * frm, MakeDialog * mk)\r
174 {\r
175         if (mk->chDirMake->GetSelection() != 2)\r
176         {\r
177                 return mk->chDirMake->GetSelection() == 1;\r
178         }\r
179 \r
180         // \83\8b\81[\83g\82É\83f\83B\83\8c\83N\83g\83\8a\82Æ\83t\83@\83C\83\8b\8d\87\82í\82¹\82Ä2\8cÂ\88È\8fã\82 \82é\82Æ\82«\81A\83f\83B\83\8c\83N\83g\83\8a\82ð\8dì\90¬\81B\r
181         wxTreeItemId tiArcRoot = frm->tree_ctrl->GetLastChild(frm->tree_ctrl->GetRootItem());\r
182         switch (frm->tree_ctrl->GetChildrenCount(tiArcRoot, false))\r
183         {\r
184         case 0:\r
185         {\r
186                 // \83f\83B\83\8c\83N\83g\83\8a\82ª\82È\82¢\82Ì\82Å\81A\83\8b\81[\83g\82É\83t\83@\83C\83\8b\82ª2\8cÂ\88È\8fã\82 \82é\82©\82Ç\82¤\82©\82ð\94»\92è\81B\r
187                 bool fFlag = false;\r
188                 for (size_t i = 0; i < frm->fileinfo.GetCount(); i++)\r
189                 {\r
190                         if (frm->fileinfo[i].fnFileName.GetPath().IsEmpty())\r
191                         {\r
192                                 // \83t\83@\83C\83\8b\82Í\83\8b\81[\83g\82É\82 \82é\81B\r
193                                 if (fFlag)\r
194                                 {\r
195                                         return true;\r
196                                 }\r
197 \r
198                                 fFlag = true;\r
199                         }\r
200                 }\r
201                 break;\r
202         }\r
203         case 1:\r
204                 // \83f\83B\83\8c\83N\83g\83\8a\82ª1\8cÂ\82È\82Ì\82Å\81A\83\8b\81[\83g\82É\83t\83@\83C\83\8b\82ª\82È\82¢\82©\82Ç\82¤\82©\82ð\94»\92è\81B\r
205                 for (size_t i = 0; i < frm->fileinfo.GetCount(); i++)\r
206                 {\r
207                         // \83f\83B\83\8c\83N\83g\83\8a\83\81\83\93\83o\82ª\8ai\94[\82³\82ê\82Ä\82¢\82é\8fê\8d\87\82É\82Í\81A\82»\82Ì\96¼\91O\82ª\83c\83\8a\81[\83r\83\85\81[\82Ì\83A\83C\83e\83\80\96¼\82É\88ê\92v\82µ\82½\8fê\8d\87\82Í\83J\83E\83\93\83g\82µ\82È\82¢\81B\r
208                         if (frm->fileinfo[i].fnFileName.GetPath().IsEmpty() && frm->fileinfo[i].fnFileName.GetFullName() != frm->tree_ctrl->GetItemText(frm->tree_ctrl->GetLastChild(tiArcRoot)))\r
209                         {\r
210                                 return true;\r
211                         }\r
212                 }\r
213                 break;\r
214         default:\r
215                 // \83f\83B\83\8c\83N\83g\83\8a\82¾\82¯\82Å2\8cÂ\88È\8fã\82 \82é\82Ì\82Å\81A\8e©\93®\93I\82É\93W\8aJ\90æ\83f\83B\83\8c\83N\83g\83\8a\82ð\8dì\90¬\81B\r
216                 return true;\r
217         }\r
218 \r
219         return false;\r
220 }\r
221 \r
222 wxString GetFileTypeName(wxFileName fn)\r
223 {\r
224         wxString szExt = fn.GetExt().MakeUpper();\r
225         wxString sz = szExt + (szExt.IsEmpty() ? wxT("file") : wxT(" file"));\r
226         wxFileType * ftFile = wxTheMimeTypesManager->GetFileTypeFromExtension(szExt);\r
227         if (ftFile)\r
228         {\r
229                 ftFile->GetDescription(& sz);\r
230         }\r
231         return sz;\r
232 }\r
233 \r
234 wxIcon GetFileTypeIcon(wxFileName fn)\r
235 {\r
236         wxIcon icon;\r
237         wxIconLocation ilFile;\r
238         wxFileType * ftFile = wxTheMimeTypesManager->GetFileTypeFromExtension(fn.GetExt());\r
239         if (ftFile && ftFile->GetIcon(& ilFile))\r
240         {\r
241                 if (! ::wxFileExists(ilFile.GetFileName()))\r
242                 {\r
243                         icon.CopyFromBitmap(wxBitmap((ilFile.GetFileName() == wxT("%1") || ilFile.GetFileName() == wxT("\"%1\"")) ? FE_DIR_S_ICO wxT("exe.png") : FE_DIR_S_ICO wxT("file.png"), wxBITMAP_TYPE_ANY));\r
244                 }\r
245                 else\r
246                 {\r
247                         icon = wxIcon(ilFile);\r
248                 }\r
249         }\r
250         else\r
251         {\r
252                 icon.CopyFromBitmap(wxBitmap(FE_DIR_S_ICO wxT("file.png"), wxBITMAP_TYPE_ANY));\r
253         }\r
254         return icon;\r
255 }\r