OSDN Git Service

Try to enable Setting
[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, const CString& sLogFile, const CString& sOriginalFile, const CString& sParams = CString());\r
116         \r
117         /**\r
118          * Resizes all columns in a list control. Considers also icons in columns\r
119          * with no text.\r
120          */\r
121         static void ResizeAllListCtrlCols(CListCtrl * pListCtrl);\r
122 \r
123         /**\r
124          * Formats text in a rich edit control (version 2).\r
125          * text in between * chars is formatted bold\r
126          * text in between ^ chars is formatted italic\r
127          * text in between _ chars is underlined\r
128          */\r
129         static bool FormatTextInRichEditControl(CWnd * pWnd);\r
130         static bool FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end);\r
131 \r
132         static bool BrowseRepository(CHistoryCombo& combo, CWnd * pParent, GitRev& rev);\r
133 \r
134         static bool FileOpenSave(CString& path, int * filterindex, UINT title, UINT filter, bool bOpen, HWND hwndOwner = NULL);\r
135 \r
136         static bool SetListCtrlBackgroundImage(HWND hListCtrl, UINT nID, int width = 128, int height = 128);\r
137 \r
138         /**\r
139          * guesses a name of the project from a repository URL\r
140          */\r
141         static  CString GetProjectNameFromURL(CString url);\r
142 \r
143         /**\r
144          * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.\r
145          */\r
146         static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1,  const git_revnum_t& rev1, \r
147                                                                                                 const CTGitPath & url2, const git_revnum_t& rev2, \r
148 \r
149                                                                                                 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),\r
150                                                                                                 bool bAlternateDiff = false,\r
151                                                                                                 bool bIgnoreAncestry = false,\r
152                                                                                                 bool /* blame */ = false);\r
153 \r
154         /**\r
155          * Replacement for GitDiff::ShowCompare(), but started as a separate process.\r
156          */\r
157         static bool StartShowCompare(HWND hWnd, const CTGitPath& url1, const GitRev& rev1, \r
158                                                                 const CTGitPath& url2, const GitRev& rev2, \r
159                                                                 const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),\r
160                                                                 bool bAlternateDiff = false, bool ignoreancestry = false,\r
161                                                                 bool blame = false);\r
162         \r
163         static bool Export(CString *BashHash=NULL);\r
164         static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL);\r
165         static bool Switch(CString *CommitHash);\r
166 \r
167         static bool IgnoreFile(CTGitPath &file, bool IsMask);\r
168 \r
169 private:\r
170         static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);\r
171         static bool GetMimeType(const CTGitPath& file, CString& mimetype);\r
172 };\r