Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
// Copyright (C) 2011 Fog Creek Software//// This program is free software: you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation, either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program. If not, see <http://www.gnu.org/licenses/>.#include "stdafx.h"#include "THgShell_h.h"#include "TortoiseHgKeyboard.h"
#include "TortoiseUtils.h"
+#include "StringUtils.h"#include "RunDialog.h"
#include "GlobalData.h"
// Each Windows Explorer window is launched in a separate thread. Therefore, use thread// local storage so that each thread can have its own hook.CTlsPtr<CTortoiseHgKeyboard>CTortoiseHgKeyboard::g_pObject;STDMETHODIMPCTortoiseHgKeyboard::SetSite(IUnknown*pUnkSite){if(g_pObject==NULL){ATLASSERT(m_hHook==NULL);g_pObject=this;m_hHook=::SetWindowsHookEx(WH_KEYBOARD,HookProc,NULL,::GetCurrentThreadId());}elseif(pUnkSite==NULL&&g_pObject==this){::UnhookWindowsHookEx(m_hHook);m_hHook=NULL;g_pObject=NULL;}returnIObjectWithSiteImpl<CTortoiseHgKeyboard>::SetSite(pUnkSite);}LRESULTCALLBACKCTortoiseHgKeyboard::HookProc(intcode,WPARAMwParam,LPARAMlParam){ATLASSERT(g_pObject!=NULL);ATLASSERT(g_pObject->m_hHook!=NULL);// Ignore repeated key messages when the user holds a key down, as well as calls when// a key is released.if(!(lParam&0x80000000L)&&!(lParam&0x40000000L)){// Get the state of the Alt, Control, and Shift keys.WORDwFlags=0;if(::GetKeyState(VK_MENU)&0x8000)wFlags|=KSF_ALT;if(::GetKeyState(VK_CONTROL)&0x8000)wFlags|=KSF_CONTROL;if(::GetKeyState(VK_SHIFT)&0x8000)wFlags|=KSF_SHIFT;// Look for a matching keyboard shortcut.for(inti=0;i<KeyShortcutListCount;i++){if(KeyShortcutList[i].wKey==wParam&&KeyShortcutList[i].wFlags==wFlags){// Get the selected files and the current directory.CAtlList<CString>listFiles;g_pObject->GetSelectedFiles(listFiles);CStringstrFolder;g_pObject->GetFolder(strFolder);// Run the command corresponding to the shortcut.RunDialog(g_pObject->GetExplorerWindow(),KeyShortcutList[i].strName,listFiles,strFolder);}}}return::CallNextHookEx(g_pObject->m_hHook,code,wParam,lParam);}boolCTortoiseHgKeyboard::GetActiveShellView(IShellView**ppSV){CComQIPtr<IWebBrowser2>spWB=m_spUnkSite;if(spWB==NULL)returnfalse;CComPtr<IDispatch>spApp;if(FAILED(spWB->get_Application(&spApp)))returnfalse;CComQIPtr<IServiceProvider>spSP=spApp;if(spSP==NULL)returnfalse;CComPtr<IShellBrowser>spSB;if(FAILED(spSP->QueryService(SID_STopLevelBrowser,IID_IShellBrowser,(void**)&spSB))){returnfalse;}returnSUCCEEDED(spSB->QueryActiveShellView(ppSV));}boolCTortoiseHgKeyboard::GetSelectedFiles(CAtlList<CString>&listFiles){// Get the active shell view object.CComPtr<IShellView>spSV;if(!GetActiveShellView(&spSV))returnfalse;// Obtain the current selection as an IDataObject.CComPtr<IDataObject>spDO;if(FAILED(spSV->GetItemObject(SVGIO_SELECTION,IID_IDataObject,(void**)&spDO))){returnfalse;}// Obtain a drop handle from the IDataObject.FORMATETCfmt={CF_HDROP,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL};STGMEDIUMstg;stg.tymed=TYMED_HGLOBAL;if(FAILED(spDO->GetData(&fmt,&stg)))returnfalse;// Enumerate through the files and add each one to the list.HDROPhDrop=(HDROP)::GlobalLock(stg.hGlobal);UINTuNumFiles=::DragQueryFile(hDrop,(UINT)-1,NULL,0);for(UINTi=0;i<uNumFiles;i++){TCHARszPath[MAX_PATH];::DragQueryFile(hDrop,i,szPath,MAX_PATH);listFiles.AddTail(szPath);}::GlobalUnlock(stg.hGlobal);::ReleaseStgMedium(&stg);returntrue;}#define FILE_PREFIX "file:///"#define FILE_PREFIX_LENGTH (sizeof(FILE_PREFIX) / sizeof(TCHAR) - 1)boolCTortoiseHgKeyboard::GetFolder(CString&strFolder){// Get the URL of the current location.CComQIPtr<IWebBrowser2>spWB=m_spUnkSite;if(spWB==NULL)returnfalse;BSTRbstrURL;if(FAILED(spWB->get_LocationURL(&bstrURL)))returnfalse; strFolder = bstrURL;
::SysFreeString(bstrURL);
+ // Unescape the URL.+ LPTSTR lpszFolder = strFolder.LockBuffer();+ ::UrlUnescape(lpszFolder, NULL, NULL, URL_UNESCAPE_INPLACE);+ strFolder.UnlockBuffer();+ // Check if it's a file URL and extract the path.
if (StartsWith(strFolder, FILE_PREFIX))
{
strFolder=strFolder.Mid(FILE_PREFIX_LENGTH);}returntrue;}HWNDCTortoiseHgKeyboard::GetExplorerWindow(){CComQIPtr<IWebBrowser2>spWB=m_spUnkSite;if(spWB==NULL)returnNULL;SHANDLE_PTRhWnd;if(FAILED(spWB->get_HWND(&hWnd)))returnNULL;return(HWND)hWnd;}CTortoiseHgKeyboard::CTortoiseHgKeyboard():m_hHook(NULL){}
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.