Correctly show progress label text
[TortoiseGit.git] / src / TortoiseProc / ProgressCommands / RemoteProgressCommand.h
blob9eecc3e24adf028656567c9e492a8c9477119ec6
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2014 - TortoiseGit
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 #include "stdafx.h"
20 #include "GitProgressList.h"
21 #include "../TortoiseShell/resource.h"
22 #include "AppUtils.h"
24 class RemoteProgressCommand : public ProgressCommand
26 protected:
27 CTGitPath m_url;
28 CString m_RefSpec;
29 CString m_remote;
31 static int RemoteProgressCallback(const char* str, int len, void* data)
33 ((CGitProgressList*)data)->SetProgressLabelText(CUnicodeUtils::GetUnicode(CStringA(str, len)));
34 return 0;
36 static int RemoteCompletionCallback(git_remote_completion_type /*type*/, void* /*data*/)
38 // this method is unused by libgit2 so far
39 // TODO: "m_pAnimate->Stop();" and "m_pAnimate->ShowWindow(SW_HIDE);", cleanup possible in GitProgressList::Notify
40 return 0;
42 static int RemoteUpdatetipsCallback(const char* refname, const git_oid* oldOid, const git_oid* newOid, void* data)
44 ((CGitProgressList*)data)->AddNotify(new RefUpdateNotificationData(refname, oldOid, newOid));
45 return 0;
48 class RefUpdateNotificationData : public CGitProgressList::NotificationData
50 public:
51 RefUpdateNotificationData(const char* refname, const git_oid* oldOid, const git_oid* newOid)
52 : NotificationData()
54 CString str = CUnicodeUtils::GetUnicode(refname);
55 m_NewHash = newOid->id;
56 m_OldHash = oldOid->id;
57 sActionColumnText.LoadString(IDS_GITACTION_UPDATE_REF);
58 sPathColumnText.Format(_T("%s\t %s -> %s"), str, m_OldHash.ToString().Left(g_Git.GetShortHASHLength()), m_NewHash.ToString().Left(g_Git.GetShortHASHLength()));
60 virtual void GetContextMenu(CIconMenu& popup, CGitProgressList::ContextMenuActionList& actions)
62 actions.push_back([&]()
64 CString cmd = _T("/command:log");
65 cmd += _T(" /path:\"") + g_Git.m_CurrentDir + _T("\"");
66 if (!m_OldHash.IsEmpty())
67 cmd += _T(" /startrev:") + m_OldHash.ToString();
68 if (!m_NewHash.IsEmpty())
69 cmd += _T(" /endrev:") + m_NewHash.ToString();
70 CAppUtils::RunTortoiseGitProc(cmd);
71 });
72 popup.AppendMenuIcon(actions.size(), IDS_MENULOG, IDI_LOG);
74 protected:
75 CGitHash m_OldHash;
76 CGitHash m_NewHash;
79 public:
80 void SetUrl(const CString& url) { m_url.SetFromUnknown(url); }
81 void SetRefSpec(CString spec){ m_RefSpec = spec; }
82 void SetRemote(const CString& remote) { m_remote = remote; }
85 class CSmartAnimation
87 CAnimateCtrl* m_pAnimate;
89 public:
90 CSmartAnimation(CAnimateCtrl* pAnimate)
92 m_pAnimate = pAnimate;
93 if (m_pAnimate)
95 m_pAnimate->ShowWindow(SW_SHOW);
96 m_pAnimate->Play(0, INT_MAX, INT_MAX);
99 ~CSmartAnimation()
101 if (m_pAnimate)
103 m_pAnimate->Stop();
104 m_pAnimate->ShowWindow(SW_HIDE);