1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "HistoryCombo.h"
\r
26 * \ingroup TortoiseProc
\r
27 * An utility class with static functions.
\r
33 * Flags for StartExtDiff function.
\r
40 bool bAlternativeTool; // If true, invert selection of TortoiseMerge vs. external diff tool
\r
42 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
\r
43 DiffFlags& Wait(bool b = true) { bWait = b; return *this; }
\r
44 DiffFlags& Blame(bool b = true) { bBlame = b; return *this; }
\r
45 DiffFlags& ReadOnly(bool b = true) { bReadOnly = b; return *this; }
\r
46 DiffFlags& AlternativeTool(bool b = true) { bAlternativeTool = b; return *this; }
\r
53 * Launches the external merge program if there is one.
\r
54 * \return TRUE if the program could be started
\r
56 static BOOL StartExtMerge(
\r
57 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
\r
58 const CString& basename = CString(), const CString& theirname = CString(), const CString& yourname = CString(),
\r
59 const CString& mergedname = CString(), bool bReadOnly = false);
\r
62 * Starts the external patch program (currently always TortoiseMerge)
\r
64 static BOOL StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir,
\r
65 const CString& sOriginalDescription = CString(), const CString& sPatchedDescription = CString(),
\r
66 BOOL bReversed = FALSE, BOOL bWait = FALSE);
\r
69 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
\r
70 * If no app is associated with those file types, the default text editor is used.
\r
72 static BOOL StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait = FALSE);
\r
75 * Starts the external diff application
\r
77 static bool StartExtDiff(
\r
78 const CString& file1, const CString& file2,
\r
79 const CString& sName1, const CString& sName2, const DiffFlags& flags);
\r
82 * Starts the external diff application for properties
\r
84 static BOOL StartExtDiffProps(const CTGitPath& file1, const CTGitPath& file2,
\r
85 const CString& sName1 = CString(), const CString& sName2 = CString(),
\r
86 BOOL bWait = FALSE, BOOL bReadOnly = FALSE);
\r
89 * Launches the standard text viewer/editor application which is associated
\r
91 * \return TRUE if the program could be started.
\r
93 static BOOL StartTextViewer(CString file);
\r
96 * Checks if the given file has a size of less than four, which means
\r
97 * an 'empty' file or just newlines, i.e. an empty diff.
\r
99 static BOOL CheckForEmptyDiff(const CTGitPath& sDiffPath);
\r
102 * Create a font which can is used for log messages, etc
\r
104 static void CreateFontForLogs(CFont& fontToCreate);
\r
107 * Launch an external application (usually the diff viewer)
\r
109 static bool LaunchApplication(const CString& sCommandLine, UINT idErrMessageFormat, bool bWaitForStartup);
\r
112 * Launch the external blame viewer
\r
114 static bool LaunchTortoiseBlame(
\r
115 const CString& sBlameFile, CString Rev, const CString& sParams = CString());
\r
118 * Formats text in a rich edit control (version 2).
\r
119 * text in between * chars is formatted bold
\r
120 * text in between ^ chars is formatted italic
\r
121 * text in between _ chars is underlined
\r
123 static bool FormatTextInRichEditControl(CWnd * pWnd);
\r
124 static bool FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end);
\r
126 static bool BrowseRepository(CHistoryCombo& combo, CWnd * pParent, GitRev& rev);
\r
128 static bool FileOpenSave(CString& path, int * filterindex, UINT title, UINT filter, bool bOpen, HWND hwndOwner = NULL);
\r
130 static bool SetListCtrlBackgroundImage(HWND hListCtrl, UINT nID, int width = 128, int height = 128);
\r
133 * guesses a name of the project from a repository URL
\r
135 static CString GetProjectNameFromURL(CString url);
\r
138 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
\r
140 static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const git_revnum_t& rev1,
\r
141 const CTGitPath & url2, const git_revnum_t& rev2,
\r
143 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
\r
144 bool bAlternateDiff = false,
\r
145 bool bIgnoreAncestry = false,
\r
146 bool /* blame */ = false);
\r
149 * Replacement for GitDiff::ShowCompare(), but started as a separate process.
\r
151 static bool StartShowCompare(HWND hWnd, const CTGitPath& url1, const GitRev& rev1,
\r
152 const CTGitPath& url2, const GitRev& rev2,
\r
153 const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
\r
154 bool bAlternateDiff = false, bool ignoreancestry = false,
\r
155 bool blame = false);
\r
157 static bool Export(CString *BashHash=NULL);
\r
158 static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL);
\r
159 static bool Switch(CString *CommitHash);
\r
161 static bool IgnoreFile(CTGitPath &file, bool IsMask);
\r
162 static bool GitReset(CString *CommitHash,int type=1);
\r
163 static bool ConflictEdit(CTGitPath &file,bool bAlternativeTool=false);
\r
165 * FUNCTION : FormatDateAndTime
\r
166 * DESCRIPTION : Generates a displayable string from a CTime object in
\r
167 * system short or long format dependant on setting of option
\r
168 * as DATE_SHORTDATE or DATE_LONGDATE. bIncludeTime (optional) includes time.
\r
169 * RETURN : CString containing date/time
\r
171 static CString FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime=true,
\r
172 bool bRelative=false );
\r
174 * Converts a given time to a relative display string (relative to current time)
\r
175 * Given time must be in local timezone
\r
176 * If more than a year ago or in the future then normal date/time is shown
\r
178 static CString ToRelativeTimeString(CTime time);
\r
182 static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);
\r
183 static bool GetMimeType(const CTGitPath& file, CString& mimetype);
\r
185 * Generates a display string showing the relative time between the two given times as COleDateTimes
\r
186 * time must be earlier than RelativeTo
\r
187 * If more than a year ago or time > RelativeTo then an empty string is returned
\r
189 static CString ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo);
\r