OSDN Git Service

.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / AppUtils.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - 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 #pragma once\r
20 #include "HistoryCombo.h"\r
21 #include "GitRev.h"\r
22 \r
23 class CTGitPath;\r
24 \r
25 /**\r
26  * \ingroup TortoiseProc\r
27  * An utility class with static functions.\r
28  */\r
29 class CAppUtils\r
30 {\r
31 public:\r
32         /**\r
33         * Flags for StartExtDiff function.\r
34         */\r
35         struct DiffFlags\r
36         {\r
37                 bool bWait;\r
38                 bool bBlame;\r
39                 bool bReadOnly;\r
40                 bool bAlternativeTool; // If true, invert selection of TortoiseMerge vs. external diff tool\r
41 \r
42                 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false)     {}\r
43                 DiffFlags& Wait(bool b = true) { bWait = b; return *this; }\r
44                 DiffFlags& Blame(bool b = true) { bBlame = b; return *this; }\r
45                 DiffFlags& ReadOnly(bool b = true) { bReadOnly = b; return *this; }\r
46                 DiffFlags& AlternativeTool(bool b = true) { bAlternativeTool = b; return *this; }\r
47         };\r
48 \r
49         CAppUtils(void);\r
50         ~CAppUtils(void);\r
51 \r
52         /**\r
53          * Launches the external merge program if there is one.\r
54          * \return TRUE if the program could be started\r
55          */\r
56         static BOOL StartExtMerge(\r
57                 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,\r
58                 const CString& basename = CString(), const CString& theirname = CString(), const CString& yourname = CString(),\r
59                 const CString& mergedname = CString(), bool bReadOnly = false);\r
60 \r
61         /**\r
62          * Starts the external patch program (currently always TortoiseMerge)\r
63          */\r
64         static BOOL StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir, \r
65                         const CString& sOriginalDescription = CString(), const CString& sPatchedDescription = CString(), \r
66                         BOOL bReversed = FALSE, BOOL bWait = FALSE);\r
67 \r
68         /**\r
69          * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).\r
70          * If no app is associated with those file types, the default text editor is used.\r
71          */\r
72         static BOOL StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait = FALSE);\r
73 \r
74         /**\r
75          * Starts the external diff application\r
76          */\r
77         static bool StartExtDiff(\r
78                 const CString& file1, const CString& file2, \r
79                 const CString& sName1, const CString& sName2, const DiffFlags& flags);\r
80 \r
81         /**\r
82          * Starts the external diff application for properties\r
83          */\r
84         static BOOL StartExtDiffProps(const CTGitPath& file1, const CTGitPath& file2, \r
85                         const CString& sName1 = CString(), const CString& sName2 = CString(),\r
86                         BOOL bWait = FALSE, BOOL bReadOnly = FALSE);\r
87 \r
88         /**\r
89          * Launches the standard text viewer/editor application which is associated\r
90          * with txt files.\r
91          * \return TRUE if the program could be started.\r
92          */\r
93         static BOOL StartTextViewer(CString file);\r
94 \r
95         /**\r
96          * Checks if the given file has a size of less than four, which means\r
97          * an 'empty' file or just newlines, i.e. an empty diff.\r
98          */\r
99         static BOOL CheckForEmptyDiff(const CTGitPath& sDiffPath);\r
100 \r
101         /**\r
102          * Create a font which can is used for log messages, etc\r
103          */\r
104         static void CreateFontForLogs(CFont& fontToCreate);\r
105 \r
106         /**\r
107         * Launch an external application (usually the diff viewer)\r
108         */\r
109         static bool LaunchApplication(const CString& sCommandLine, UINT idErrMessageFormat, bool bWaitForStartup);\r
110 \r
111         /**\r
112         * Launch the external blame viewer\r
113         */\r
114         static bool LaunchTortoiseBlame(\r
115                 const CString& sBlameFile, CString Rev, const CString& sParams = CString());\r
116         \r
117         /**\r
118          * Formats text in a rich edit control (version 2).\r
119          * text in between * chars is formatted bold\r
120          * text in between ^ chars is formatted italic\r
121          * text in between _ chars is underlined\r
122          */\r
123         static bool FormatTextInRichEditControl(CWnd * pWnd);\r
124         static bool FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end);\r
125 \r
126         static bool BrowseRepository(CHistoryCombo& combo, CWnd * pParent, GitRev& rev);\r
127 \r
128         static bool FileOpenSave(CString& path, int * filterindex, UINT title, UINT filter, bool bOpen, HWND hwndOwner = NULL);\r
129 \r
130         static bool SetListCtrlBackgroundImage(HWND hListCtrl, UINT nID, int width = 128, int height = 128);\r
131 \r
132         /**\r
133          * guesses a name of the project from a repository URL\r
134          */\r
135         static  CString GetProjectNameFromURL(CString url);\r
136 \r
137         /**\r
138          * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.\r
139          */\r
140         static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1,  const git_revnum_t& rev1, \r
141                                                                                                 const CTGitPath & url2, const git_revnum_t& rev2, \r
142 \r
143                                                                                                 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),\r
144                                                                                                 bool bAlternateDiff = false,\r
145                                                                                                 bool bIgnoreAncestry = false,\r
146                                                                                                 bool /* blame */ = false);\r
147 \r
148         /**\r
149          * Replacement for GitDiff::ShowCompare(), but started as a separate process.\r
150          */\r
151         static bool StartShowCompare(HWND hWnd, const CTGitPath& url1, const GitRev& rev1, \r
152                                                                 const CTGitPath& url2, const GitRev& rev2, \r
153                                                                 const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),\r
154                                                                 bool bAlternateDiff = false, bool ignoreancestry = false,\r
155                                                                 bool blame = false);\r
156         \r
157         static bool Export(CString *BashHash=NULL);\r
158         static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL);\r
159         static bool Switch(CString *CommitHash);\r
160 \r
161 //      static bool IgnoreFile(CTGitPath &file, bool IsMask);\r
162         static bool IgnoreFile(CTGitPathList &filelist,bool IsMask);\r
163         static bool GitReset(CString *CommitHash,int type=1);\r
164         static bool ConflictEdit(CTGitPath &file,bool bAlternativeTool=false);\r
165         /**\r
166          * FUNCTION    :   FormatDateAndTime\r
167          * DESCRIPTION :   Generates a displayable string from a CTime object in\r
168          *                 system short or long format  or as a relative value\r
169          *                                 cTime - the time\r
170          *                                 option - DATE_SHORTDATE or DATE_LONGDATE\r
171          *                                 bIncluedeTime - whether to show time as well as date\r
172          *                                 bRelative - if true then relative time is shown if reasonable \r
173          *                                 If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format\r
174          *                                 rather than locale\r
175          * RETURN      :   CString containing date/time\r
176          */\r
177         static CString FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime=true,\r
178                 bool bRelative=false );\r
179         /**\r
180          *      Converts a given time to a relative display string (relative to current time)\r
181          *      Given time must be in local timezone\r
182          */\r
183         static CString ToRelativeTimeString(CTime time);\r
184 \r
185         \r
186 private:\r
187         static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);\r
188         static bool GetMimeType(const CTGitPath& file, CString& mimetype);\r
189         /**\r
190          *      Generates a display string showing the relative time between the two given times as COleDateTimes\r
191          */\r
192         static CString ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo);\r
193         static CString ExpandRelativeTime( int count, UINT format_1, UINT format_n );\r
194 };\r