Add support for Ctrl+A in BrowseRefsDlg and RepositoryBrowser
[TortoiseGit.git] / src / TortoiseProc / AppUtils.h
blob5d128d815514a65d359d545d29e4d7db1b4dfd4d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2020 - 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 "GitRevLoglist.h"
22 #include "CommonAppUtils.h"
24 class CTGitPath;
25 struct git_credential;
26 struct git_indexer_progress;
27 class CIgnoreFile;
28 class ProjectProperties;
30 /**
31 * \ingroup TortoiseProc
32 * An utility class with static functions.
34 class CAppUtils : public CCommonAppUtils
36 public:
37 /**
38 * Flags for StartExtDiff function.
40 struct DiffFlags
42 bool bWait;
43 bool bReadOnly;
44 bool bAlternativeTool; // If true, invert selection of TortoiseGitMerge vs. external diff tool
46 DiffFlags(): bWait(false), bReadOnly(false), bAlternativeTool(false) {}
47 DiffFlags& Wait(bool b = true) { bWait = b; return *this; }
48 DiffFlags& ReadOnly(bool b = true) { bReadOnly = b; return *this; }
49 DiffFlags& AlternativeTool(bool b = true) { bAlternativeTool = b; return *this; }
52 CAppUtils() = delete;
54 public:
55 /**
56 * Launches the external merge program if there is one.
57 * \return TRUE if the program could be started
59 static BOOL StartExtMerge(bool bAlternativeTool,
60 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
61 const CString& basename = CString(), const CString& theirname = CString(), const CString& yourname = CString(),
62 const CString& mergedname = CString(), bool bReadOnly = false, HWND resolveMsgHwnd = nullptr, bool bDeleteBaseTheirsMineOnClose = false);
64 /**
65 * Starts the external patch program (currently always TortoiseGitMerge)
67 static BOOL StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir,
68 const CString& sOriginalDescription = CString(), const CString& sPatchedDescription = CString(),
69 BOOL bReversed = FALSE, BOOL bWait = FALSE);
71 /**
72 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
73 * If no app is associated with those file types, the default text editor is used.
75 static BOOL StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait = FALSE, bool bAlternativeTool = false);
77 /**
78 * Sets up all the default diff and merge scripts.
79 * \param force if true, overwrite all existing entries
80 * \param either "Diff", "Merge" or an empty string
82 static bool SetupDiffScripts(bool force, const CString& type);
84 /**
85 * Starts the external diff application
87 static bool StartExtDiff(
88 const CString& file1, const CString& file2,
89 const CString& sName1, const CString& sName2,
90 const CString& originalFile1, const CString& originalFile2,
91 const CGitHash& hash1, const CGitHash& hash2, const DiffFlags& flags, int jumpToLine = 0);
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 * Launch the external blame viewer
109 static bool LaunchTortoiseBlame(
110 const CString& sBlameFile, const CString& Rev, const CString& sParams = CString());
113 * Launch alternative editor
115 static bool LaunchAlternativeEditor(const CString& filename, bool uac = false);
118 * Sets the title of a dialog
120 static void SetWindowTitle(HWND hWnd, const CString& urlorpath, const CString& dialogname);
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, wchar_t stylechar, int& start, int& end);
131 * implements URL searching with the same logic as CSciEdit::StyleURLs
133 static std::vector<CHARRANGE> FindURLMatches(const CString& msg);
134 static BOOL StyleURLs(const CString& msg, CWnd* pWnd);
137 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
139 static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const CString& rev1,
140 const CTGitPath& url2, const CString& rev2,
142 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
143 bool bAlternateDiff = false,
144 bool bIgnoreAncestry = false,
145 bool blame = false,
146 bool bMerge = false,
147 bool bCompact = false,
148 bool bNoPrefix = false);
150 static bool Export(HWND hWnd, const CString* BashHash = nullptr, const CTGitPath* orgPath = nullptr);
151 static bool UpdateBranchDescription(const CString& branch, CString description);
152 static bool CreateBranchTag(HWND hWnd, bool isTag = true, const CString* ref = nullptr, bool switchNewBranch = false, LPCWSTR name = nullptr);
153 static bool Switch(HWND hWnd, const CString& initialRefName = CString());
154 static bool PerformSwitch(HWND hWnd, const CString& ref, bool bForce = false, const CString& sNewBranch = CString(), bool bBranchOverride = false, BOOL bTrack = 2, bool bMerge = false);
156 static bool IgnoreFile(HWND hWnd, const CTGitPathList& filelist, bool IsMask);
157 static bool GitReset(HWND hWnd, const CString& ref, int type = 1);
158 static bool ConflictEdit(HWND hWnd, CTGitPath& file, bool bAlternativeTool = false, bool revertTheirMy = false, HWND resolveMsgHwnd = nullptr);
159 static void GetConflictTitles(CString* baseText, CString& mineText, CGitHash* mineHash, CString& theirsText, CGitHash* theirsHash, bool rebaseActive);
161 static CString GetMergeTempFile(const CString& str, const CTGitPath& merge, bool returnAbsolutePath = true);
162 static bool StashSave(HWND hWnd, const CString& msg = CString(), bool showPull = false, bool pullShowPush = false, bool showMerge = false, const CString& mergeRev = CString());
163 static bool StashApply(HWND hWnd, CString ref, bool showChanges = true);
164 /** Execute "stash pop"
165 * showChanges
166 * 0: only show info on error (and allow to diff on error)
167 * 1: allow to open diff dialog on error or success
168 * 2: only show error or success message
170 static bool StashPop(HWND hWnd, int showChanges = 1);
172 static bool IsSSHPutty();
174 static bool LaunchRemoteSetting();
176 static bool LaunchPAgent(HWND hWnd, const CString* keyfile = nullptr, const CString* pRemote = nullptr);
178 static bool ShellOpen(const CString& file, HWND hwnd = nullptr);
179 static bool ShowOpenWithDialog(const CString& file, HWND hwnd = nullptr);
181 static CString GetClipboardLink(const CString& skipGitPrefix = L"", int paramsCount = 0);
182 static CString ChooseRepository(HWND hWnd, const CString* path);
184 static bool SendPatchMail(HWND hWnd, CTGitPathList& pathlist);
185 static bool SendPatchMail(HWND hWnd, const CString& cmd, const CString& formatpatchoutput);
187 static int SaveCommitUnicodeFile(const CString& filename, CString& mesage);
188 static bool MessageContainsConflictHints(HWND hWnd, const CString& message);
190 static int GetLogOutputEncode(CGit *pGit=&g_Git);
192 static bool Pull(HWND hWnd, bool showPush = false, bool showStashPop = false);
193 // rebase = 1: ask user what to do, rebase = 2: run autorebase
194 static bool RebaseAfterFetch(HWND hWnd, const CString& upstream = L"", int rebase = 0, bool preserveMerges = false);
195 static bool Fetch(HWND hWnd, const CString& remoteName = L"", bool allRemotes = false);
196 static bool DoPush(HWND hWnd, bool autoloadKey, bool tags, bool allRemotes, bool allBranches, bool force, bool forceWithLease, const CString& localBranch, const CString& remote, const CString& remoteBranch, bool setUpstream, int recurseSubmodules, const CString& pushOption);
197 static bool Push(HWND hWnd, const CString& selectLocalBranch = CString());
198 static bool RequestPull(HWND hWnd, const CString& endrevision = L"", const CString& repositoryUrl = L"");
200 static void RemoveTrailSlash(CString &path);
202 static bool CheckUserData(HWND hWnd);
204 static BOOL Commit(HWND hWnd, const CString& bugid, BOOL bWholeProject, CString& sLogMsg,
205 CTGitPathList &pathList,
206 bool bSelectFilesForCommit);
208 static BOOL SVNDCommit(HWND hWnd);
209 static BOOL Merge(HWND hWnd, const CString* commit = nullptr, bool showStashPop = false);
210 static BOOL MergeAbort(HWND hWnd);
211 static void RemoveTempMergeFile(const CTGitPath& path, bool pathIsRelative = true);
212 static void EditNote(HWND hWnd, GitRevLoglist* rev, ProjectProperties* projectProperties);
213 static int GetMsysgitVersion(HWND hWnd);
214 static bool IsGitVersionNewerOrEqual(HWND hWnd, unsigned __int8 major, unsigned __int8 minor, unsigned __int8 patchlevel = 0, unsigned __int8 build = 0);
215 static void MarkWindowAsUnpinnable(HWND hWnd);
217 static bool BisectStart(HWND hWnd, const CString& lastGood, const CString& firstBad);
218 static bool BisectOperation(HWND hWnd, const CString& op, const CString& ref = L"");
220 static int Git2GetUserPassword(git_credential** out, const char* url, const char* username_from_url, unsigned int allowed_types, void* payload);
222 static int Git2CertificateCheck(git_cert *cert, int valid, const char* host, void *payload);
224 static int ExploreTo(HWND hwnd, CString path);
226 static bool DeleteRef(CWnd* parent, const CString& ref);
228 static void SetupBareRepoIcon(const CString& path);
230 enum resolve_with {
231 RESOLVE_WITH_CURRENT,
232 RESOLVE_WITH_MINE,
233 RESOLVE_WITH_THEIRS,
236 static int ResolveConflict(HWND hWnd, CTGitPath& path, resolve_with resolveWith);
238 static bool IsTGitRebaseActive(HWND hWnd);
240 private:
241 static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);
243 static bool OpenIgnoreFile(HWND hWnd, CIgnoreFile& file, const CString& filename);
245 static void DescribeConflictFile(bool mode, bool base,CString &descript);