1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "HistoryCombo.h"
23 #include "CommonAppUtils.h"
33 * \ingroup TortoiseProc
34 * An utility class with static functions.
36 class CAppUtils
: public CCommonAppUtils
40 * Flags for StartExtDiff function.
47 bool bAlternativeTool
; // If true, invert selection of TortoiseMerge vs. external diff tool
49 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
50 DiffFlags
& Wait(bool b
= true) { bWait
= b
; return *this; }
51 DiffFlags
& Blame(bool b
= true) { bBlame
= b
; return *this; }
52 DiffFlags
& ReadOnly(bool b
= true) { bReadOnly
= b
; return *this; }
53 DiffFlags
& AlternativeTool(bool b
= true) { bAlternativeTool
= b
; return *this; }
60 * Launches the external merge program if there is one.
61 * \return TRUE if the program could be started
63 static BOOL
StartExtMerge(
64 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
65 const CString
& basename
= CString(), const CString
& theirname
= CString(), const CString
& yourname
= CString(),
66 const CString
& mergedname
= CString(), bool bReadOnly
= false);
69 * Starts the external patch program (currently always TortoiseMerge)
71 static BOOL
StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
,
72 const CString
& sOriginalDescription
= CString(), const CString
& sPatchedDescription
= CString(),
73 BOOL bReversed
= FALSE
, BOOL bWait
= FALSE
);
76 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
77 * If no app is associated with those file types, the default text editor is used.
79 static BOOL
StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
= FALSE
);
82 * Starts the external diff application
84 static bool StartExtDiff(
85 const CString
& file1
, const CString
& file2
,
86 const CString
& sName1
, const CString
& sName2
, const DiffFlags
& flags
);
89 * Launches the standard text viewer/editor application which is associated
91 * \return TRUE if the program could be started.
93 static BOOL
StartTextViewer(CString file
);
96 * Checks if the given file has a size of less than four, which means
97 * an 'empty' file or just newlines, i.e. an empty diff.
99 static BOOL
CheckForEmptyDiff(const CTGitPath
& sDiffPath
);
102 * Create a font which can is used for log messages, etc
104 static void CreateFontForLogs(CFont
& fontToCreate
);
107 * Launch the external blame viewer
109 static bool LaunchTortoiseBlame(
110 const CString
& sBlameFile
, CString Rev
, const CString
& sParams
= CString());
113 * Launch alternative editor
115 static bool LaunchAlternativeEditor(const CString
& filename
);
118 * Sets the title of a dialog
120 static void SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
);
123 * Formats text in a rich edit control (version 2).
124 * text in between * chars is formatted bold
125 * text in between ^ chars is formatted italic
126 * text in between _ chars is underlined
128 static bool FormatTextInRichEditControl(CWnd
* pWnd
);
129 static bool FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
);
132 * guesses a name of the project from a repository URL
134 static CString
GetProjectNameFromURL(CString url
);
137 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
139 static bool StartShowUnifiedDiff(HWND hWnd
, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
140 const CTGitPath
& url2
, const git_revnum_t
& rev2
,
142 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
143 bool bAlternateDiff
= false,
144 bool bIgnoreAncestry
= false,
146 bool bMerge
= false);
148 static bool Export(CString
*BashHash
=NULL
);
149 static bool CreateBranchTag(bool IsTag
=TRUE
,CString
*CommitHash
=NULL
, bool switch_new_brach
=false);
150 static bool Switch(CString initialRefName
= CString(), bool autoClose
= false);
151 static bool PerformSwitch(CString ref
, bool bForce
= false, CString sNewBranch
= CString(), bool bBranchOverride
= false, BOOL bTrack
= 2, bool autoClose
= false);
153 static bool IgnoreFile(CTGitPathList
&filelist
,bool IsMask
);
154 static bool GitReset(CString
*CommitHash
,int type
=1);
155 static bool ConflictEdit(CTGitPath
&file
,bool bAlternativeTool
=false,bool revertTheirMy
=false);
157 static CString
GetMergeTempFile(CString str
,CTGitPath
&merge
);
158 static bool StashSave();
159 static bool StashApply(CString ref
, bool showChanges
= true);
160 static bool StashPop(bool showChanges
= true);
162 static bool IsSSHPutty();
164 static bool LaunchRemoteSetting();
166 static bool LaunchPAgent(CString
*keyfile
=NULL
,CString
* pRemote
=NULL
);
168 static CString
GetClipboardLink();
169 static CString
ChooseRepository(CString
*path
);
171 static bool SendPatchMail(CTGitPathList
&pathlist
,bool autoclose
=false);
172 static bool SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
=false);
174 static int SaveCommitUnicodeFile(CString
&filename
, CString
&mesage
);
176 static int GetLogOutputEncode(CGit
*pGit
=&g_Git
);
178 static bool Fetch(CString remoteName
= _T(""), bool allowRebase
= false, bool autoClose
= false);
179 static bool Push(CString selectLocalBranch
= CString(), bool autoClose
= false);
180 static bool RequestPull(CString endrevision
= _T(""), CString repositoryUrl
= _T(""));
182 static bool CreateMultipleDirectory(const CString
&dir
);
184 static void RemoveTrailSlash(CString
&path
);
186 static BOOL
Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
187 CTGitPathList
&pathList
,
188 CTGitPathList
&selectedList
,
189 bool bSelectFilesForCommit
,
190 bool autoClose
= false);
192 static int GetCommitTemplate(CString
&temp
);
194 static BOOL
SVNDCommit();
195 static BOOL
Merge(CString
*commit
=NULL
);
196 static void RemoveTempMergeFile(CTGitPath
&path
);
197 static void EditNote(GitRev
*hash
);
198 static int GetMsysgitVersion(CString
*versionstring
=NULL
);
199 static void MarkWindowAsUnpinnable(HWND hWnd
);
201 static bool BisectStart(CString lastGood
, CString firstBad
, bool autoClose
= false);
204 static CString
PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
);
205 static bool GetMimeType(const CTGitPath
& file
, CString
& mimetype
);
207 static bool OpenIgnoreFile(CStdioFile
&file
, const CString
& filename
);
209 static void DescribeFile(bool mode
, bool base
,CString
&descript
);