better check when to enable statistics button
[TortoiseGit.git] / src / TortoiseProc / AppUtils.h
blob5b00b102924ddf2ec0d941686ddde857a85475b5
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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"
24 class CTGitPath;
26 enum GIT_POST_CMD
28 GIT_POST_CMD_PUSH,
29 GIT_POST_CMD_DCOMMIT
31 /**
32 * \ingroup TortoiseProc
33 * An utility class with static functions.
35 class CAppUtils
37 public:
38 /**
39 * Flags for StartExtDiff function.
41 struct DiffFlags
43 bool bWait;
44 bool bBlame;
45 bool bReadOnly;
46 bool bAlternativeTool; // If true, invert selection of TortoiseMerge vs. external diff tool
48 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
49 DiffFlags& Wait(bool b = true) { bWait = b; return *this; }
50 DiffFlags& Blame(bool b = true) { bBlame = b; return *this; }
51 DiffFlags& ReadOnly(bool b = true) { bReadOnly = b; return *this; }
52 DiffFlags& AlternativeTool(bool b = true) { bAlternativeTool = b; return *this; }
55 CAppUtils(void);
56 ~CAppUtils(void);
58 /**
59 * Launches the external merge program if there is one.
60 * \return TRUE if the program could be started
62 static BOOL StartExtMerge(
63 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
64 const CString& basename = CString(), const CString& theirname = CString(), const CString& yourname = CString(),
65 const CString& mergedname = CString(), bool bReadOnly = false);
67 /**
68 * Starts the external patch program (currently always TortoiseMerge)
70 static BOOL StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir,
71 const CString& sOriginalDescription = CString(), const CString& sPatchedDescription = CString(),
72 BOOL bReversed = FALSE, BOOL bWait = FALSE);
74 /**
75 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
76 * If no app is associated with those file types, the default text editor is used.
78 static BOOL StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait = FALSE);
80 /**
81 * Starts the external diff application
83 static bool StartExtDiff(
84 const CString& file1, const CString& file2,
85 const CString& sName1, const CString& sName2, const DiffFlags& flags);
87 /**
88 * Starts the external diff application for properties
90 static BOOL StartExtDiffProps(const CTGitPath& file1, const CTGitPath& file2,
91 const CString& sName1 = CString(), const CString& sName2 = CString(),
92 BOOL bWait = FALSE, BOOL bReadOnly = FALSE);
94 /**
95 * Launches the standard text viewer/editor application which is associated
96 * with txt files.
97 * \return TRUE if the program could be started.
99 static BOOL StartTextViewer(CString file);
102 * Checks if the given file has a size of less than four, which means
103 * an 'empty' file or just newlines, i.e. an empty diff.
105 static BOOL CheckForEmptyDiff(const CTGitPath& sDiffPath);
108 * Create a font which can is used for log messages, etc
110 static void CreateFontForLogs(CFont& fontToCreate);
113 * Launch an external application (usually the diff viewer)
115 static bool LaunchApplication(const CString& sCommandLine, UINT idErrMessageFormat, bool bWaitForStartup);
118 * Launch the external blame viewer
120 static bool LaunchTortoiseBlame(
121 const CString& sBlameFile, CString Rev, const CString& sParams = CString());
124 * Launch alternative editor
126 static bool LaunchAlternativeEditor(const CString& filename);
129 * Sets the title of a dialog
131 static void SetWindowTitle(HWND hWnd, const CString& urlorpath, const CString& dialogname);
134 * Formats text in a rich edit control (version 2).
135 * text in between * chars is formatted bold
136 * text in between ^ chars is formatted italic
137 * text in between _ chars is underlined
139 static bool FormatTextInRichEditControl(CWnd * pWnd);
140 static bool FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end);
142 static bool FileOpenSave(CString& path, int * filterindex, UINT title, UINT filter, bool bOpen, HWND hwndOwner = NULL);
144 static bool SetListCtrlBackgroundImage(HWND hListCtrl, UINT nID, int width = 128, int height = 128);
147 * guesses a name of the project from a repository URL
149 static CString GetProjectNameFromURL(CString url);
152 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
154 static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const git_revnum_t& rev1,
155 const CTGitPath & url2, const git_revnum_t& rev2,
157 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
158 bool bAlternateDiff = false,
159 bool bIgnoreAncestry = false,
160 bool blame = false,
161 bool bMerge = false);
163 static bool Export(CString *BashHash=NULL);
164 static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL, bool switch_new_brach=false);
165 static bool Switch(CString *CommitHash, CString initialRefName = CString(), bool autoClose = false);
166 static bool PerformSwitch(CString ref, bool bForce = false, CString sNewBranch = CString(), bool bBranchOverride = false, bool bTrack = false, bool autoClose = false);
168 // static bool IgnoreFile(CTGitPath &file, bool IsMask);
169 static bool IgnoreFile(CTGitPathList &filelist,bool IsMask);
170 static bool GitReset(CString *CommitHash,int type=1);
171 static bool ConflictEdit(CTGitPath &file,bool bAlternativeTool=false,bool revertTheirMy=false);
173 * FUNCTION : FormatDateAndTime
174 * DESCRIPTION : Generates a displayable string from a CTime object in
175 * system short or long format or as a relative value
176 * cTime - the time
177 * option - DATE_SHORTDATE or DATE_LONGDATE
178 * bIncluedeTime - whether to show time as well as date
179 * bRelative - if true then relative time is shown if reasonable
180 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
181 * rather than locale
182 * RETURN : CString containing date/time
184 static CString FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime=true,
185 bool bRelative=false );
187 * Converts a given time to a relative display string (relative to current time)
188 * Given time must be in local timezone
190 static CString ToRelativeTimeString(CTime time);
192 static CString GetMergeTempFile(CString str,CTGitPath &merge);
193 static bool StashSave();
194 static int StashApply(CString ref, bool showChanges = true);
195 static int StashPop(bool showChanges = true);
197 static bool IsSSHPutty();
199 static bool LaunchRemoteSetting();
201 static bool LaunchPAgent(CString *keyfile=NULL,CString * pRemote=NULL);
203 static CString GetClipboardLink();
204 static CString ChooseRepository(CString *path);
206 static bool SendPatchMail(CTGitPathList &pathlist,bool autoclose=false);
207 static bool SendPatchMail(CString &cmd,CString &formatpatchoutput,bool autoclose=false);
209 static int SaveCommitUnicodeFile(CString &filename, CString &mesage);
211 static int GetLogOutputEncode(CGit *pGit=&g_Git);
213 static bool Fetch(CString remoteName = _T(""), bool allowRebase = false, bool autoClose = false);
214 static bool Push(CString selectLocalBranch = CString(), bool autoClose = false);
215 static bool RequestPull(CString endrevision = _T(""), CString repositoryUrl = _T(""));
217 static bool CreateMultipleDirectory(const CString &dir);
219 static void RemoveTrailSlash(CString &path);
221 static BOOL Commit(CString bugid,BOOL bWholeProject,CString &sLogMsg,
222 CTGitPathList &pathList,
223 CTGitPathList &selectedList,
224 bool bSelectFilesForCommit,
225 bool autoClose = false);
227 static int GetCommitTemplate(CString &temp);
229 static BOOL SVNDCommit();
230 static BOOL Merge(CString *commit =NULL);
231 static void RemoveTempMergeFile(CTGitPath &path);
232 static void EditNote(GitRev *hash);
233 static int GetMsysgitVersion(CString *versionstring=NULL);
234 static void MarkWindowAsUnpinnable(HWND hWnd);
236 private:
237 static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);
238 static bool GetMimeType(const CTGitPath& file, CString& mimetype);
240 * Generates a display string showing the relative time between the two given times as COleDateTimes
242 static CString ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo);
243 static CString ExpandRelativeTime( int count, UINT format_1, UINT format_n );
245 static void DescribeFile(bool mode, bool base,CString &descript);