[ros-diffs] [rharabien] 54964: [SHELL32] - If there is no default menu item, make Open With menu item the default, rename it to Open and disallow it to be submenu. See issue #6801 for more details.

rharabien at svn.reactos.org rharabien at svn.reactos.org
Sat Jan 14 17:50:33 UTC 2012


Author: rharabien
Date: Sat Jan 14 17:50:33 2012
New Revision: 54964

URL: http://svn.reactos.org/svn/reactos?rev=54964&view=rev
Log:
[SHELL32]
- If there is no default menu item, make Open With menu item the default, rename it to Open and disallow it to be submenu.
See issue #6801 for more details.

Modified:
    trunk/reactos/dll/win32/shell32/openwithmenu.cpp

Modified: trunk/reactos/dll/win32/shell32/openwithmenu.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/openwithmenu.cpp?rev=54964&r1=54963&r2=54964&view=diff
==============================================================================
--- trunk/reactos/dll/win32/shell32/openwithmenu.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/openwithmenu.cpp [iso-8859-1] Sat Jan 14 17:50:33 2012
@@ -1160,44 +1160,47 @@
     UINT idCmdLast,
     UINT uFlags)
 {
-    MENUITEMINFOW mii;
-    WCHAR wszBuf[100];
-    INT DefaultPos;
-
     TRACE("hMenu %p indexMenu %u idFirst %u idLast %u uFlags %u\n", hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
 
-    if (!LoadStringW(shell32_hInstance, IDS_OPEN_WITH, wszBuf, _countof(wszBuf)))
+    INT DefaultPos = GetMenuDefaultItem(hMenu, TRUE, 0);
+
+    WCHAR wszName[100];
+    UINT NameId = (DefaultPos == -1 ? IDS_OPEN : IDS_OPEN_WITH);
+    if (!LoadStringW(shell32_hInstance, NameId, wszName, _countof(wszName)))
     {
         ERR("Failed to load string\n");
         return E_FAIL;
     }
 
-    /* Init cmd id */
+    /* Init first cmd id and submenu */
     m_idCmdFirst = m_idCmdLast = idCmdFirst;
-
-    /* Load applications list */
-    m_pAppList->Load();
-    m_pAppList->LoadRecommended(m_wszPath);
-
-    /* Create submenu only if the is some choice */
-    if (m_pAppList->GetRecommendedCount() > 1)
-    {
-        m_hSubMenu = CreatePopupMenu();
-
-        for(unsigned i = 0; i < m_pAppList->GetCount(); ++i)
-        {
-            COpenWithList::SApp *pApp = m_pAppList->GetList() + i;
-            if (pApp->bRecommended)
-                AddApp(pApp);
-        }
-
-        AddChooseProgramItem();
-    }
-    else
-        m_hSubMenu = NULL;
-
-    DefaultPos = GetMenuDefaultItem(hMenu, TRUE, 0);
-
+    m_hSubMenu = NULL;
+
+    /* If we are going to be default item, we shouldn't be submenu */
+    if (DefaultPos != -1)
+    {
+        /* Load applications list */
+        m_pAppList->Load();
+        m_pAppList->LoadRecommended(m_wszPath);
+        
+        /* Create submenu only if there is more than one application and menu has a default item */
+        if (m_pAppList->GetRecommendedCount() > 1)
+        {
+            m_hSubMenu = CreatePopupMenu();
+
+            for(UINT i = 0; i < m_pAppList->GetCount(); ++i)
+            {
+                COpenWithList::SApp *pApp = m_pAppList->GetList() + i;
+                if (pApp->bRecommended)
+                    AddApp(pApp);
+            }
+
+            AddChooseProgramItem();
+        }
+    }
+
+    /* Insert menu item */
+    MENUITEMINFOW mii;
     ZeroMemory(&mii, sizeof(mii));
     mii.cbSize = sizeof(mii);
     mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
@@ -1211,14 +1214,15 @@
         mii.wID = m_idCmdLast;
 
     mii.fType = MFT_STRING;
-    mii.dwTypeData = (LPWSTR)wszBuf;
-    mii.cch = wcslen(wszBuf);
+    mii.dwTypeData = (LPWSTR)wszName;
+    mii.cch = wcslen(wszName);
 
     mii.fState = MFS_ENABLED;
     if (DefaultPos == -1)
         mii.fState |= MFS_DEFAULT;
 
-    InsertMenuItemW(hMenu, DefaultPos + 1, TRUE, &mii);
+    if (!InsertMenuItemW(hMenu, DefaultPos + 1, TRUE, &mii))
+        return E_FAIL;
 
     return MAKE_HRESULT(SEVERITY_SUCCESS, 0, m_idCmdLast - m_idCmdFirst + 1);
 }




More information about the Ros-diffs mailing list