Support Git svn-clone at clone dialog.
[TortoiseGit.git] / src / TortoiseProc / AppUtils.h
blobf6bc9a1298a2511ced0cb8bedab8d808d6372946
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 /**
26 * \ingroup TortoiseProc
27 * An utility class with static functions.
29 class CAppUtils
31 public:
32 /**
33 * Flags for StartExtDiff function.
35 struct DiffFlags
37 bool bWait;
38 bool bBlame;
39 bool bReadOnly;
40 bool bAlternativeTool; // If true, invert selection of TortoiseMerge vs. external diff tool
42 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
43 DiffFlags& Wait(bool b = true) { bWait = b; return *this; }
44 DiffFlags& Blame(bool b = true) { bBlame = b; return *this; }
45 DiffFlags& ReadOnly(bool b = true) { bReadOnly = b; return *this; }
46 DiffFlags& AlternativeTool(bool b = true) { bAlternativeTool = b; return *this; }
49 CAppUtils(void);
50 ~CAppUtils(void);
52 /**
53 * Launches the external merge program if there is one.
54 * \return TRUE if the program could be started
56 static BOOL StartExtMerge(
57 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
58 const CString& basename = CString(), const CString& theirname = CString(), const CString& yourname = CString(),
59 const CString& mergedname = CString(), bool bReadOnly = false);
61 /**
62 * Starts the external patch program (currently always TortoiseMerge)
64 static BOOL StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir,
65 const CString& sOriginalDescription = CString(), const CString& sPatchedDescription = CString(),
66 BOOL bReversed = FALSE, BOOL bWait = FALSE);
68 /**
69 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
70 * If no app is associated with those file types, the default text editor is used.
72 static BOOL StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait = FALSE);
74 /**
75 * Starts the external diff application
77 static bool StartExtDiff(
78 const CString& file1, const CString& file2,
79 const CString& sName1, const CString& sName2, const DiffFlags& flags);
81 /**
82 * Starts the external diff application for properties
84 static BOOL StartExtDiffProps(const CTGitPath& file1, const CTGitPath& file2,
85 const CString& sName1 = CString(), const CString& sName2 = CString(),
86 BOOL bWait = FALSE, BOOL bReadOnly = FALSE);
88 /**
89 * Launches the standard text viewer/editor application which is associated
90 * with txt files.
91 * \return TRUE if the program could be started.
93 static BOOL StartTextViewer(CString file);
95 /**
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 an external application (usually the diff viewer)
109 static bool LaunchApplication(const CString& sCommandLine, UINT idErrMessageFormat, bool bWaitForStartup);
112 * Launch the external blame viewer
114 static bool LaunchTortoiseBlame(
115 const CString& sBlameFile, CString Rev, const CString& sParams = CString());
118 * Formats text in a rich edit control (version 2).
119 * text in between * chars is formatted bold
120 * text in between ^ chars is formatted italic
121 * text in between _ chars is underlined
123 static bool FormatTextInRichEditControl(CWnd * pWnd);
124 static bool FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end);
126 static bool BrowseRepository(CHistoryCombo& combo, CWnd * pParent, GitRev& rev);
128 static bool FileOpenSave(CString& path, int * filterindex, UINT title, UINT filter, bool bOpen, HWND hwndOwner = NULL);
130 static bool SetListCtrlBackgroundImage(HWND hListCtrl, UINT nID, int width = 128, int height = 128);
133 * guesses a name of the project from a repository URL
135 static CString GetProjectNameFromURL(CString url);
138 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
140 static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const git_revnum_t& rev1,
141 const CTGitPath & url2, const git_revnum_t& rev2,
143 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
144 bool bAlternateDiff = false,
145 bool bIgnoreAncestry = false,
146 bool /* blame */ = false);
149 * Replacement for GitDiff::ShowCompare(), but started as a separate process.
151 static bool StartShowCompare(HWND hWnd, const CTGitPath& url1, const GitRev& rev1,
152 const CTGitPath& url2, const GitRev& rev2,
153 const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
154 bool bAlternateDiff = false, bool ignoreancestry = false,
155 bool blame = false);
157 static bool Export(CString *BashHash=NULL);
158 static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL);
159 static bool Switch(CString *CommitHash);
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);
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);
188 static bool IsSSHPutty();
190 static bool LaunchRemoteSetting();
192 static bool LaunchPAgent(CString *keyfile=NULL,CString * pRemote=NULL);
194 static CString GetClipboardLink();
195 static CString ChooseRepository(CString *path);
197 static bool SendPatchMail(CTGitPathList &pathlist,bool autoclose=false);
199 static int SaveCommitUnicodeFile(CString &filename, CString &mesage);
201 static int GetLogOutputEncode();
203 static bool Push();
205 static bool CreateMultipleDirectory(CString &dir);
207 private:
208 static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);
209 static bool GetMimeType(const CTGitPath& file, CString& mimetype);
211 * Generates a display string showing the relative time between the two given times as COleDateTimes
213 static CString ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo);
214 static CString ExpandRelativeTime( int count, UINT format_1, UINT format_n );
216 static void DescribeFile(bool mode, bool base,CString &descript);