some code cleanup
[TortoiseGit.git] / src / TortoiseProc / AppUtils.h
blob26dfcc8a65e20b45be21dddbb0baa5351d988e52
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 * Launch alternative editor
125 static bool LaunchAlternativeEditor(const CString& filename);
128 * Formats text in a rich edit control (version 2).
129 * text in between * chars is formatted bold
130 * text in between ^ chars is formatted italic
131 * text in between _ chars is underlined
133 static bool FormatTextInRichEditControl(CWnd * pWnd);
134 static bool FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end);
136 static bool FileOpenSave(CString& path, int * filterindex, UINT title, UINT filter, bool bOpen, HWND hwndOwner = NULL);
138 static bool SetListCtrlBackgroundImage(HWND hListCtrl, UINT nID, int width = 128, int height = 128);
141 * guesses a name of the project from a repository URL
143 static CString GetProjectNameFromURL(CString url);
146 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
148 static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const git_revnum_t& rev1,
149 const CTGitPath & url2, const git_revnum_t& rev2,
151 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
152 bool bAlternateDiff = false,
153 bool bIgnoreAncestry = false,
154 bool blame = false,
155 bool bMerge = false);
157 static bool Export(CString *BashHash=NULL);
158 static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL, bool switch_new_brach=false);
159 static bool Switch(CString *CommitHash, CString initialRefName = CString());
161 // static bool IgnoreFile(CTGitPath &file, bool IsMask);
162 static bool IgnoreFile(CTGitPathList &filelist,bool IsMask);
163 static bool GitReset(CString *CommitHash,int type=1);
164 static bool ConflictEdit(CTGitPath &file,bool bAlternativeTool=false,bool revertTheirMy=false);
166 * FUNCTION : FormatDateAndTime
167 * DESCRIPTION : Generates a displayable string from a CTime object in
168 * system short or long format or as a relative value
169 * cTime - the time
170 * option - DATE_SHORTDATE or DATE_LONGDATE
171 * bIncluedeTime - whether to show time as well as date
172 * bRelative - if true then relative time is shown if reasonable
173 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
174 * rather than locale
175 * RETURN : CString containing date/time
177 static CString FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime=true,
178 bool bRelative=false );
180 * Converts a given time to a relative display string (relative to current time)
181 * Given time must be in local timezone
183 static CString ToRelativeTimeString(CTime time);
185 static CString GetMergeTempFile(CString str,CTGitPath &merge);
186 static int StashApply(CString ref);
187 static int StashPop();
189 static bool IsSSHPutty();
191 static bool LaunchRemoteSetting();
193 static bool LaunchPAgent(CString *keyfile=NULL,CString * pRemote=NULL);
195 static CString GetClipboardLink();
196 static CString ChooseRepository(CString *path);
198 static bool SendPatchMail(CTGitPathList &pathlist,bool autoclose=false);
199 static bool SendPatchMail(CString &cmd,CString &formatpatchoutput,bool autoclose=false);
201 static int SaveCommitUnicodeFile(CString &filename, CString &mesage);
203 static int GetLogOutputEncode(CGit *pGit=&g_Git);
205 static bool Push(bool autoClose = false);
206 static bool RequestPull(CString endrevision = _T(""), CString repositoryUrl = _T(""));
208 static bool CreateMultipleDirectory(CString &dir);
210 static void RemoveTrailSlash(CString &path);
212 static BOOL Commit(CString bugid,BOOL bWholeProject,CString &sLogMsg,
213 CTGitPathList &pathList,
214 CTGitPathList &selectedList,
215 bool bSelectFilesForCommit);
217 static int GetCommitTemplate(CString &temp);
219 static BOOL SVNDCommit();
220 static BOOL Merge(CString *commit =NULL);
221 static void RemoveTempMergeFile(CTGitPath &path);
222 static void EditNote(GitRev *hash);
223 static int GetMsysgitVersion(CString *versionstring=NULL);
225 private:
226 static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);
227 static bool GetMimeType(const CTGitPath& file, CString& mimetype);
229 * Generates a display string showing the relative time between the two given times as COleDateTimes
231 static CString ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo);
232 static CString ExpandRelativeTime( int count, UINT format_1, UINT format_n );
234 static void DescribeFile(bool mode, bool base,CString &descript);