Add Merge command at log context menu
[TortoiseGit.git] / src / TortoiseProc / AppUtils.h
blob086194e9b06595babac766477e93bbcb68399822
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
20 #include "HistoryCombo.h"
21 #include "GitRev.h"
23 class CTGitPath;
25 enum GIT_POST_CMD
27 GIT_POST_CMD_PUSH,
28 GIT_POST_CMD_DCOMMIT
30 /**
31 * \ingroup TortoiseProc
32 * An utility class with static functions.
34 class CAppUtils
36 public:
37 /**
38 * Flags for StartExtDiff function.
40 struct DiffFlags
42 bool bWait;
43 bool bBlame;
44 bool bReadOnly;
45 bool bAlternativeTool; // If true, invert selection of TortoiseMerge vs. external diff tool
47 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
48 DiffFlags& Wait(bool b = true) { bWait = b; return *this; }
49 DiffFlags& Blame(bool b = true) { bBlame = b; return *this; }
50 DiffFlags& ReadOnly(bool b = true) { bReadOnly = b; return *this; }
51 DiffFlags& AlternativeTool(bool b = true) { bAlternativeTool = b; return *this; }
54 CAppUtils(void);
55 ~CAppUtils(void);
57 /**
58 * Launches the external merge program if there is one.
59 * \return TRUE if the program could be started
61 static BOOL StartExtMerge(
62 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
63 const CString& basename = CString(), const CString& theirname = CString(), const CString& yourname = CString(),
64 const CString& mergedname = CString(), bool bReadOnly = false);
66 /**
67 * Starts the external patch program (currently always TortoiseMerge)
69 static BOOL StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir,
70 const CString& sOriginalDescription = CString(), const CString& sPatchedDescription = CString(),
71 BOOL bReversed = FALSE, BOOL bWait = FALSE);
73 /**
74 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
75 * If no app is associated with those file types, the default text editor is used.
77 static BOOL StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait = FALSE);
79 /**
80 * Starts the external diff application
82 static bool StartExtDiff(
83 const CString& file1, const CString& file2,
84 const CString& sName1, const CString& sName2, const DiffFlags& flags);
86 /**
87 * Starts the external diff application for properties
89 static BOOL StartExtDiffProps(const CTGitPath& file1, const CTGitPath& file2,
90 const CString& sName1 = CString(), const CString& sName2 = CString(),
91 BOOL bWait = FALSE, BOOL bReadOnly = FALSE);
93 /**
94 * Launches the standard text viewer/editor application which is associated
95 * with txt files.
96 * \return TRUE if the program could be started.
98 static BOOL StartTextViewer(CString file);
101 * Checks if the given file has a size of less than four, which means
102 * an 'empty' file or just newlines, i.e. an empty diff.
104 static BOOL CheckForEmptyDiff(const CTGitPath& sDiffPath);
107 * Create a font which can is used for log messages, etc
109 static void CreateFontForLogs(CFont& fontToCreate);
112 * Launch an external application (usually the diff viewer)
114 static bool LaunchApplication(const CString& sCommandLine, UINT idErrMessageFormat, bool bWaitForStartup);
117 * Launch the external blame viewer
119 static bool LaunchTortoiseBlame(
120 const CString& sBlameFile, CString Rev, const CString& sParams = CString());
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);
131 static bool BrowseRepository(CHistoryCombo& combo, CWnd * pParent, GitRev& rev);
133 static bool FileOpenSave(CString& path, int * filterindex, UINT title, UINT filter, bool bOpen, HWND hwndOwner = NULL);
135 static bool SetListCtrlBackgroundImage(HWND hListCtrl, UINT nID, int width = 128, int height = 128);
138 * guesses a name of the project from a repository URL
140 static CString GetProjectNameFromURL(CString url);
143 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
145 static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const git_revnum_t& rev1,
146 const CTGitPath & url2, const git_revnum_t& rev2,
148 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
149 bool bAlternateDiff = false,
150 bool bIgnoreAncestry = false,
151 bool /* blame */ = false);
154 * Replacement for GitDiff::ShowCompare(), but started as a separate process.
156 static bool StartShowCompare(HWND hWnd, const CTGitPath& url1, const GitRev& rev1,
157 const CTGitPath& url2, const GitRev& rev2,
158 const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
159 bool bAlternateDiff = false, bool ignoreancestry = false,
160 bool blame = false);
162 static bool Export(CString *BashHash=NULL);
163 static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL);
164 static bool Switch(CString *CommitHash, CString initialRefName = CString());
166 // static bool IgnoreFile(CTGitPath &file, bool IsMask);
167 static bool IgnoreFile(CTGitPathList &filelist,bool IsMask);
168 static bool GitReset(CString *CommitHash,int type=1);
169 static bool ConflictEdit(CTGitPath &file,bool bAlternativeTool=false,bool revertTheirMy=false);
171 * FUNCTION : FormatDateAndTime
172 * DESCRIPTION : Generates a displayable string from a CTime object in
173 * system short or long format or as a relative value
174 * cTime - the time
175 * option - DATE_SHORTDATE or DATE_LONGDATE
176 * bIncluedeTime - whether to show time as well as date
177 * bRelative - if true then relative time is shown if reasonable
178 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
179 * rather than locale
180 * RETURN : CString containing date/time
182 static CString FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime=true,
183 bool bRelative=false );
185 * Converts a given time to a relative display string (relative to current time)
186 * Given time must be in local timezone
188 static CString ToRelativeTimeString(CTime time);
190 static CString GetMergeTempFile(CString str,CTGitPath &merge);
191 static int StashApply(CString ref);
192 static int StashPop();
194 static bool IsSSHPutty();
196 static bool LaunchRemoteSetting();
198 static bool LaunchPAgent(CString *keyfile=NULL,CString * pRemote=NULL);
200 static CString GetClipboardLink();
201 static CString ChooseRepository(CString *path);
203 static bool SendPatchMail(CTGitPathList &pathlist,bool autoclose=false);
204 static bool SendPatchMail(CString &cmd,CString &formatpatchoutput,bool autoclose=false);
206 static int SaveCommitUnicodeFile(CString &filename, CString &mesage);
208 static int GetLogOutputEncode(CGit *pGit=&g_Git);
210 static bool Push();
212 static bool CreateMultipleDirectory(CString &dir);
214 static void RemoveTrailSlash(CString &path);
216 static BOOL Commit(CString bugid,BOOL bWholeProject,CString &sLogMsg,
217 CTGitPathList &pathList,
218 CTGitPathList &selectedList,
219 BOOL bSelectFilesForCommit);
221 static int GetCommitTemplate(CString &temp);
223 static BOOL SVNDCommit();
224 static BOOL Merge(CString *commit =NULL, int mode = 0);
226 private:
227 static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);
228 static bool GetMimeType(const CTGitPath& file, CString& mimetype);
230 * Generates a display string showing the relative time between the two given times as COleDateTimes
232 static CString ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo);
233 static CString ExpandRelativeTime( int count, UINT format_1, UINT format_n );
235 static void DescribeFile(bool mode, bool base,CString &descript);