Changeset e214839bf369…
Parent fa3706bd1bdc…
by
Changes to one file · Browse files at e214839bf369 Showing diff from parent fa3706bd1bdc Diff from another changeset...
|
|
@@ -4,16 +4,19 @@ #include "StringUtils.h"
#include "Dirstatecache.h"
#include "Thgstatus.h"
+#include "Winstat.h"
-typedef struct {
+struct MenuDescription
+{
std::string name;
std::string menuText;
std::string helpText;
std::string iconName;
UINT idCmd;
-} MenuDescription;
+};
-MenuDescription menuDescList[] = {
+MenuDescription menuDescList[] =
+{
{"commit", "Commit...",
"Commit changes in repository",
"menucommit.ico", 0},
@@ -82,7 +85,8 @@};
/* These enumerations must match the order of menuDescList */
-enum menuDescListEntries {
+enum menuDescListEntries
+{
Commit, Init, Clone, Status, Shelve, Add, Revert, Remove, Rename,
Log, Synch, Serve, Update, Recover, Thgstatus, Userconf, Repoconf,
About, Datamine, VDiff,
@@ -90,8 +94,9 @@ Separator, EndOfList
};
-menuDescListEntries RepoNoFilesMenu[] = {
- Commit, Status, Shelve, VDiff, Separator,
+menuDescListEntries RepoNoFilesMenu[] =
+{
+ Commit, Status, Shelve, VDiff, Separator,
Log, Separator,
Update, Separator,
Synch, Clone, Recover, Serve, Thgstatus, Separator,
@@ -99,13 +104,15 @@ About, EndOfList
};
-menuDescListEntries RepoFilesMenu[] = {
+menuDescListEntries RepoFilesMenu[] =
+{
Commit, Status, VDiff, Add, Revert, Rename, Remove, Separator,
Log, Datamine, Separator,
About, EndOfList
};
-menuDescListEntries NoRepoMenu[] = {
+menuDescListEntries NoRepoMenu[] =
+{
Clone, Init, Userconf, Thgstatus, Separator,
About, EndOfList
};
@@ -116,17 +123,20 @@MenuDescriptionMap MenuDescMap;
MenuIdCmdMap MenuIdMap;
+
void AddMenuList(UINT idCmd, const std::string& name)
-{
+{
TDEBUG_TRACE("AddMenuList: idCmd = " << idCmd << " name = " << name);
MenuIdMap[idCmd] = MenuDescMap[name];
}
+
void GetCMenuTranslation(
- const std::string& lang,
- const std::string& name,
- std::string& menuText,
- std::string& helpText)
+ const std::string& lang,
+ const std::string& name,
+ std::string& menuText,
+ std::string& helpText
+)
{
std::string subkey = "Software\\TortoiseHg\\CMenu\\";
subkey += lang;
@@ -155,6 +165,7 @@ helpText = reinterpret_cast<const char*>(&Data);
}
+
void InitMenuMaps()
{
if (MenuDescMap.empty())
@@ -163,7 +174,7 @@ GetRegistryConfig("CMenuLang", lang);
std::size_t sz = sizeof(menuDescList) / sizeof(MenuDescription);
- for (std::size_t i=0; i < sz; i++)
+ for (std::size_t i = 0; i < sz; i++)
{
MenuDescription md = menuDescList[i];
TDEBUG_TRACE("InitMenuMaps: adding " << md.name);
@@ -179,13 +190,15 @@ MenuIdMap.clear();
}
-void InsertMenuItemWithIcon(HMENU hMenu, UINT indexMenu, UINT idCmd,
- const std::string& menuText, const std::string& iconName)
+
+void InsertMenuItemWithIcon(
+ HMENU hMenu, UINT indexMenu, UINT idCmd,
+ const std::string& menuText, const std::string& iconName)
{
- MENUITEMINFO mi;
- mi.cbSize = sizeof(mi);
- mi.dwTypeData = const_cast<char*> (menuText.c_str());
- mi.cch = static_cast<UINT> (menuText.length());
+ MENUITEMINFO mi;
+ mi.cbSize = sizeof(mi);
+ mi.dwTypeData = const_cast<char*>(menuText.c_str());
+ mi.cch = static_cast<UINT>(menuText.length());
mi.wID = idCmd;
mi.fType = MFT_STRING;
@@ -198,21 +211,23 @@ }
else
{
- TDEBUG_TRACE(" InsertMenuItemWithIcon: can't find " + iconName);
+ TDEBUG_TRACE(" InsertMenuItemWithIcon: can't find " + iconName);
mi.fMask = MIIM_TYPE | MIIM_ID;
}
InsertMenuItem(hMenu, indexMenu, TRUE, &mi);
}
-void InsertSubMenuItemWithIcon(HMENU hMenu, HMENU hSubMenu, UINT indexMenu, UINT idCmd,
- const std::string& menuText, const std::string& iconName)
+
+void InsertSubMenuItemWithIcon(
+ HMENU hMenu, HMENU hSubMenu, UINT indexMenu, UINT idCmd,
+ const std::string& menuText, const std::string& iconName)
{
MENUITEMINFO mi;
mi.cbSize = sizeof(mi);
mi.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_ID;
mi.fType = MFT_STRING;
- mi.dwTypeData = const_cast<char*> (menuText.c_str());
- mi.cch = static_cast<UINT> (menuText.length());
+ mi.dwTypeData = const_cast<char*>(menuText.c_str());
+ mi.cch = static_cast<UINT>(menuText.length());
mi.wID = idCmd;
mi.hSubMenu = hSubMenu;
HICON h = GetTortoiseIcon(iconName);
@@ -225,13 +240,15 @@ }
else
{
- TDEBUG_TRACE(" InsertSubMenuItemWithIcon: can't find " + iconName);
+ TDEBUG_TRACE(" InsertSubMenuItemWithIcon: can't find " + iconName);
}
InsertMenuItem(hMenu, indexMenu, TRUE, &mi);
}
-void InsertMenuItemByName(HMENU hMenu, const std::string& name, UINT indexMenu,
- UINT idCmd, UINT idCmdFirst, const std::string& prefix)
+
+void InsertMenuItemByName(
+ HMENU hMenu, const std::string& name, UINT indexMenu,
+ UINT idCmd, UINT idCmdFirst, const std::string& prefix)
{
TDEBUG_TRACE("InsertMenuItemByName: name = " << name);
MenuDescriptionMap::iterator iter = MenuDescMap.find(name);
@@ -243,34 +260,36 @@
MenuDescription md = iter->second;
AddMenuList(idCmd - idCmdFirst, name);
- InsertMenuItemWithIcon(hMenu, indexMenu, idCmd, prefix + md.menuText, md.iconName);
+ InsertMenuItemWithIcon(
+ hMenu, indexMenu, idCmd, prefix + md.menuText, md.iconName);
}
-// IContextMenu
+
+// IContextMenu
STDMETHODIMP
-CShellExt::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst,
- UINT idCmdLast, UINT uFlags)
+CShellExt::QueryContextMenu(
+ HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
{
TDEBUG_TRACE("CShellExt::QueryContextMenu");
InitMenuMaps();
-
+
UINT idCmd = idCmdFirst;
- BOOL bAppendItems = TRUE;
+ BOOL bAppendItems = TRUE;
- if((uFlags & 0x000F) == CMF_NORMAL)
- bAppendItems = TRUE;
- else if (uFlags & CMF_VERBSONLY)
- bAppendItems = TRUE;
- else if (uFlags & CMF_EXPLORE)
- bAppendItems = TRUE;
- else
- bAppendItems = FALSE;
+ if ((uFlags & 0x000F) == CMF_NORMAL)
+ bAppendItems = TRUE;
+ else if (uFlags & CMF_VERBSONLY)
+ bAppendItems = TRUE;
+ else if (uFlags & CMF_EXPLORE)
+ bAppendItems = TRUE;
+ else
+ bAppendItems = FALSE;
if (!bAppendItems)
return NOERROR;
const std::size_t sz = sizeof(menuDescList) / sizeof(MenuDescription);
- bool promoted[ sz ];
+ bool promoted[sz];
memset(&promoted, 0, sizeof(promoted));
std::string cval = "commit"; // default value if key not found
@@ -279,7 +298,7 @@ size_t found;
do
{
- if( cval.empty() )
+ if (cval.empty())
break;
found = cval.find_first_of(',');
@@ -293,9 +312,9 @@ cval = cval.substr(found+1);
}
- for( UINT i = 0; i < sz; i++ )
+ for (UINT i = 0; i < sz; i++)
{
- if( !key.compare(menuDescList[i].name) )
+ if (!key.compare(menuDescList[i].name))
{
promoted[i] = true;
break;
@@ -338,40 +357,51 @@ InsertMenu(hMenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);
menuDescListEntries *walk;
- for( walk = entries; *walk != EndOfList; walk++ )
+ for (walk = entries; *walk != EndOfList; walk++)
{
UINT idx = (UINT) *walk;
- if( promoted[idx] )
- InsertMenuItemByName(hMenu, menuDescList[idx].name, indexMenu++, idCmd++, idCmdFirst, "HG ");
+ if (promoted[idx])
+ {
+ InsertMenuItemByName(
+ hMenu, menuDescList[idx].name, indexMenu++,
+ idCmd++, idCmdFirst, "HG "
+ );
+ }
}
- HMENU hSubMenu = CreatePopupMenu();
+ const HMENU hSubMenu = CreatePopupMenu();
if (hSubMenu)
{
UINT indexSubMenu = 0;
bool isSeparator = true;
- for( walk = entries; *walk != EndOfList; walk++ )
+ for (walk = entries; *walk != EndOfList; walk++)
{
- if( *walk == Separator)
+ if (*walk == Separator)
{
if (!isSeparator)
{
- InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);
+ InsertMenu(
+ hSubMenu, indexSubMenu++,
+ MF_SEPARATOR | MF_BYPOSITION, 0, NULL
+ );
isSeparator = true;
}
}
else
{
UINT idx = (UINT) *walk;
- if( !promoted[idx] )
+ if (!promoted[idx])
{
- InsertMenuItemByName(hSubMenu, menuDescList[idx].name, indexSubMenu++, idCmd++, idCmdFirst, "");
+ InsertMenuItemByName(
+ hSubMenu, menuDescList[idx].name,
+ indexSubMenu++, idCmd++, idCmdFirst, ""
+ );
isSeparator = false;
}
}
}
- if (isSeparator && indexSubMenu>0)
- RemoveMenu(hSubMenu, indexSubMenu-1, MF_BYPOSITION);
+ if (isSeparator && indexSubMenu > 0)
+ RemoveMenu(hSubMenu, indexSubMenu - 1, MF_BYPOSITION);
}
TDEBUG_TRACE(" CShellExt::QueryContextMenu: adding main THG menu");
@@ -383,6 +413,7 @@ return ResultFromShort(idCmd - idCmdFirst);
}
+
STDMETHODIMP
CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
{
@@ -394,36 +425,46 @@ UINT idCmd = LOWORD(lpcmi->lpVerb);
TDEBUG_TRACE("CShellExt::InvokeCommand: idCmd = " << idCmd);
MenuIdCmdMap::iterator iter = MenuIdMap.find(idCmd);
- if(iter != MenuIdMap.end())
+ if (iter != MenuIdMap.end())
{
DoHgtk(iter->second.name);
hr = NOERROR;
}
else
{
- TDEBUG_TRACE("CShellExt::InvokeCommand: action not found for idCmd " << idCmd);
+ TDEBUG_TRACE(
+ "CShellExt::InvokeCommand: action not found for idCmd "
+ << idCmd
+ );
}
}
return hr;
}
+
STDMETHODIMP
-CShellExt::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved,
- LPSTR pszName, UINT cchMax)
+CShellExt::GetCommandString(
+ UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved,
+ LPSTR pszName, UINT cchMax)
{
- *pszName = 0;
- char *psz;
+ *pszName = 0;
+ char *psz;
- TDEBUG_TRACE("CShellExt::GetCommandString: idCmd = " << idCmd << ", uFlags = " << uFlags);
+ TDEBUG_TRACE(
+ "CShellExt::GetCommandString: idCmd = " << idCmd
+ << ", uFlags = " << uFlags
+ );
MenuIdCmdMap::iterator iter = MenuIdMap.find(static_cast<UINT>(idCmd));
if (iter != MenuIdMap.end())
{
- TDEBUG_TRACE("CShellExt::GetCommandString: name = " << iter->second.name);
+ TDEBUG_TRACE(
+ "CShellExt::GetCommandString: name = " << iter->second.name);
psz = (char*)iter->second.helpText.c_str();
}
else
{
- TDEBUG_TRACE("CShellExt::GetCommandString: can't find idCmd " << idCmd);
+ TDEBUG_TRACE(
+ "CShellExt::GetCommandString: can't find idCmd " << idCmd);
psz = "";
}
@@ -438,13 +479,18 @@ return NOERROR;
}
-STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
+
+STDMETHODIMP
+CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT res;
return HandleMenuMsg2(uMsg, wParam, lParam, &res);
}
-STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
+
+STDMETHODIMP
+CShellExt::HandleMenuMsg2(
+ UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
TDEBUG_ENTER("CShellExt::HandleMenuMsg2");
// A great tutorial on owner drawn menus in shell extension can be found
@@ -458,29 +504,34 @@ switch (uMsg)
{
case WM_MEASUREITEM:
- {
- MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
- if (lpmis==NULL)
- break;
- lpmis->itemWidth += 2;
- if(lpmis->itemHeight < 16)
- lpmis->itemHeight = 16;
- *pResult = TRUE;
- }
- break;
+ {
+ MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
+ if (lpmis==NULL)
+ break;
+ lpmis->itemWidth += 2;
+ if(lpmis->itemHeight < 16)
+ lpmis->itemHeight = 16;
+ *pResult = TRUE;
+ }
+ break;
+
case WM_DRAWITEM:
- {
- DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
- if (!lpdis || (lpdis->CtlType != ODT_MENU) || !lpdis->itemData)
- break; //not for a menu
- DrawIconEx(lpdis->hDC,
- lpdis->rcItem.left - 16,
- lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
- (HICON) lpdis->itemData, 16, 16,
- 0, 0, DI_NORMAL);
- *pResult = TRUE;
- }
- break;
+ {
+ DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
+ if (!lpdis || (lpdis->CtlType != ODT_MENU) || !lpdis->itemData)
+ break; //not for a menu
+ DrawIconEx(
+ lpdis->hDC,
+ lpdis->rcItem.left - 16,
+ lpdis->rcItem.top
+ + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
+ (HICON) lpdis->itemData, 16, 16,
+ 0, 0, DI_NORMAL
+ );
+ *pResult = TRUE;
+ }
+ break;
+
default:
return NOERROR;
}
@@ -488,7 +539,6 @@ return NOERROR;
}
-#include "Winstat.h"
void CShellExt::DoHgtk(const std::string &cmd)
{
@@ -508,7 +558,7 @@ FindClose(hfind);
hgcmd = Quote(hgcmd) + " " + cmd;
-
+
std::string cwd;
if (!myFolder.empty())
{
@@ -524,22 +574,27 @@ {
cwd = IsDirectory(myFiles[0])? myFiles[0] : DirName(myFiles[0]);
- std::string tempfile = GetTemporaryFile();
+ const std::string tempfile = GetTemporaryFile();
SECURITY_ATTRIBUTES sa;
memset(&sa, 0, sizeof(sa));
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
TDEBUG_TRACE("DoHgtk: temp file = " << tempfile);
- HANDLE tempfileHandle = CreateFileA(tempfile.c_str(), GENERIC_WRITE,
- FILE_SHARE_READ, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
-
- for (std::vector<std::string>::size_type i=0; i<myFiles.size(); i++)
+ HANDLE tempfileHandle = CreateFileA(
+ tempfile.c_str(), GENERIC_WRITE,
+ FILE_SHARE_READ, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
+ );
+
+ typedef std::vector<std::string>::size_type ST;
+ for (ST i = 0; i < myFiles.size(); i++)
{
DWORD dwWritten;
TDEBUG_TRACE("DoHgtk: temp file adding " << myFiles[i]);
- WriteFile(tempfileHandle, myFiles[i].c_str(),
- static_cast<DWORD>(myFiles[i].size()), &dwWritten, 0);
+ WriteFile(
+ tempfileHandle, myFiles[i].c_str(),
+ static_cast<DWORD>(myFiles[i].size()), &dwWritten, 0
+ );
WriteFile(tempfileHandle, "\n", 1, &dwWritten, 0);
}
CloseHandle(tempfileHandle);
|
Loading...