OSDN Git Service

Add Show Whole Project Checkbox at commitdlg.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / WorkingFile.cpp
1 // TortoiseMerge - a Diff/Patch program\r
2 \r
3 // Copyright (C) 2006-2007 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "StdAfx.h"\r
20 #include "Workingfile.h"\r
21 #include "AppUtils.h"\r
22 #include "PathUtils.h"\r
23 #include "resource.h"\r
24 \r
25 CWorkingFile::CWorkingFile(void)\r
26 {\r
27 }\r
28 \r
29 CWorkingFile::~CWorkingFile(void)\r
30 {\r
31 }\r
32 \r
33 void CWorkingFile::SetFileName(const CString& newFilename)\r
34 {\r
35         m_sFilename = newFilename;\r
36         m_sFilename.Replace('/', '\\');\r
37         m_sDescriptiveName.Empty();\r
38 }\r
39 \r
40 void CWorkingFile::SetDescriptiveName(const CString& newDescName)\r
41 {\r
42         m_sDescriptiveName = newDescName;\r
43 }\r
44 \r
45 CString CWorkingFile::GetDescriptiveName()\r
46 {\r
47         if (m_sDescriptiveName.IsEmpty())\r
48         {\r
49                 CString sDescriptiveName = CPathUtils::GetFileNameFromPath(m_sFilename);\r
50                 if (sDescriptiveName.GetLength() < 20)\r
51                         return sDescriptiveName;\r
52         }\r
53         return m_sDescriptiveName;\r
54 }\r
55 //\r
56 // Make an empty file with this name\r
57 void CWorkingFile::CreateEmptyFile()\r
58 {\r
59         HANDLE hFile = CreateFile(m_sFilename, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\r
60         CloseHandle(hFile);\r
61 }\r
62 \r
63 // Move the details of the specified file to the current one, and then mark the specified file\r
64 // as out of use\r
65 void CWorkingFile::TransferDetailsFrom(CWorkingFile& rightHandFile)\r
66 {\r
67         // We don't do this to files which are already in use\r
68         ASSERT(!InUse());\r
69 \r
70         m_sFilename = rightHandFile.m_sFilename;\r
71         m_sDescriptiveName = rightHandFile.m_sDescriptiveName;\r
72         rightHandFile.SetOutOfUse();\r
73 }\r
74 \r
75 CString CWorkingFile::GetWindowName() const\r
76 {\r
77         CString sErrMsg = _T("");\r
78         // TortoiseMerge allows non-existing files to be used in a merge\r
79         // Inform the user (in a non-intrusive way) if a file is absent\r
80         if (! this->Exists())\r
81         {\r
82                 sErrMsg = CString(MAKEINTRESOURCE(IDS_NOTFOUNDVIEWTITLEINDICATOR));\r
83         }\r
84 \r
85         if(m_sDescriptiveName.IsEmpty())\r
86         {\r
87                 // We don't have a proper name - use the filename part of the path\r
88                 // return the filename part of the path.\r
89                 return CPathUtils::GetFileNameFromPath(m_sFilename) + _T(" ") + sErrMsg;\r
90         }\r
91         else if (sErrMsg.IsEmpty())\r
92         {\r
93                 return m_sDescriptiveName;\r
94         }\r
95         return m_sDescriptiveName + _T(" ") + sErrMsg;\r
96 }\r
97 \r
98 bool CWorkingFile::Exists() const\r
99 {\r
100         return (!!PathFileExists(m_sFilename));\r
101 }\r