Fixed issue #1503: Passing full file paths and revisions into diff viewer
[TortoiseGit.git] / src / TortoiseProc / AppUtils.h
blob890bbcc41f431aa96e99e3c5cc474437c69782e7
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.
20 #pragma once
21 #include "HistoryCombo.h"
22 #include "GitRev.h"
23 #include "CommonAppUtils.h"
25 class CTGitPath;
27 enum GIT_POST_CMD
29 GIT_POST_CMD_PUSH,
30 GIT_POST_CMD_DCOMMIT
32 /**
33 * \ingroup TortoiseProc
34 * An utility class with static functions.
36 class CAppUtils : public CCommonAppUtils
38 public:
39 /**
40 * Flags for StartExtDiff function.
42 struct DiffFlags
44 bool bWait;
45 bool bBlame;
46 bool bReadOnly;
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; }
56 CAppUtils(void);
57 ~CAppUtils(void);
59 /**
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);
68 /**
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);
75 /**
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);
81 /**
82 * Starts the external diff application
84 static bool StartExtDiff(
85 const CString& file1, const CString& file2,
86 const CString& sName1, const CString& sName2,
87 const CString& originalFile1, const CString& originalFile2,
88 const git_revnum_t& hash1, const git_revnum_t& hash2, const DiffFlags& flags);
90 /**
91 * Launches the standard text viewer/editor application which is associated
92 * with txt files.
93 * \return TRUE if the program could be started.
95 static BOOL StartTextViewer(CString file);
97 /**
98 * Checks if the given file has a size of less than four, which means
99 * an 'empty' file or just newlines, i.e. an empty diff.
101 static BOOL CheckForEmptyDiff(const CTGitPath& sDiffPath);
104 * Create a font which can is used for log messages, etc
106 static void CreateFontForLogs(CFont& fontToCreate);
109 * Launch the external blame viewer
111 static bool LaunchTortoiseBlame(
112 const CString& sBlameFile, CString Rev, const CString& sParams = CString());
115 * Launch alternative editor
117 static bool LaunchAlternativeEditor(const CString& filename);
120 * Sets the title of a dialog
122 static void SetWindowTitle(HWND hWnd, const CString& urlorpath, const CString& dialogname);
125 * Formats text in a rich edit control (version 2).
126 * text in between * chars is formatted bold
127 * text in between ^ chars is formatted italic
128 * text in between _ chars is underlined
130 static bool FormatTextInRichEditControl(CWnd * pWnd);
131 static bool FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end);
134 * guesses a name of the project from a repository URL
136 static CString GetProjectNameFromURL(CString url);
139 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
141 static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const git_revnum_t& rev1,
142 const CTGitPath & url2, const git_revnum_t& rev2,
144 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
145 bool bAlternateDiff = false,
146 bool bIgnoreAncestry = false,
147 bool blame = false,
148 bool bMerge = false);
150 static bool Export(CString *BashHash=NULL);
151 static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL, bool switch_new_brach=false);
152 static bool Switch(CString initialRefName = CString(), bool autoClose = false);
153 static bool PerformSwitch(CString ref, bool bForce = false, CString sNewBranch = CString(), bool bBranchOverride = false, BOOL bTrack = 2, bool autoClose = false);
155 static bool IgnoreFile(CTGitPathList &filelist,bool IsMask);
156 static bool GitReset(CString *CommitHash,int type=1);
157 static bool ConflictEdit(CTGitPath &file,bool bAlternativeTool=false,bool revertTheirMy=false);
159 static CString GetMergeTempFile(CString str,CTGitPath &merge);
160 static bool StashSave();
161 static bool StashApply(CString ref, bool showChanges = true);
162 static bool StashPop(bool showChanges = true);
164 static bool IsSSHPutty();
166 static bool LaunchRemoteSetting();
168 static bool LaunchPAgent(CString *keyfile=NULL,CString * pRemote=NULL);
170 static CString GetClipboardLink();
171 static CString ChooseRepository(CString *path);
173 static bool SendPatchMail(CTGitPathList &pathlist,bool autoclose=false);
174 static bool SendPatchMail(CString &cmd,CString &formatpatchoutput,bool autoclose=false);
176 static int SaveCommitUnicodeFile(CString &filename, CString &mesage);
178 static int GetLogOutputEncode(CGit *pGit=&g_Git);
180 static bool Fetch(CString remoteName = _T(""), bool allowRebase = false, bool autoClose = false);
181 static bool Push(CString selectLocalBranch = CString(), bool autoClose = false);
182 static bool RequestPull(CString endrevision = _T(""), CString repositoryUrl = _T(""));
184 static bool CreateMultipleDirectory(const CString &dir);
186 static void RemoveTrailSlash(CString &path);
188 static BOOL Commit(CString bugid,BOOL bWholeProject,CString &sLogMsg,
189 CTGitPathList &pathList,
190 CTGitPathList &selectedList,
191 bool bSelectFilesForCommit,
192 bool autoClose = false);
194 static int GetCommitTemplate(CString &temp);
196 static BOOL SVNDCommit();
197 static BOOL Merge(CString *commit =NULL);
198 static void RemoveTempMergeFile(CTGitPath &path);
199 static void EditNote(GitRev *hash);
200 static int GetMsysgitVersion(CString *versionstring=NULL);
201 static void MarkWindowAsUnpinnable(HWND hWnd);
203 static bool BisectStart(CString lastGood, CString firstBad, bool autoClose = false);
205 private:
206 static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);
207 static bool GetMimeType(const CTGitPath& file, CString& mimetype);
209 static bool OpenIgnoreFile(CStdioFile &file, const CString& filename);
211 static void DescribeFile(bool mode, bool base,CString &descript);