From 9dc3ca87209fd8ebabd96c8ea95d439c13e7fdf8 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Tue, 22 Sep 2026 23:40:34 +0200 Subject: [PATCH] [MMC_NEW] Implement the recent files list properly and pretty print the menu items --- base/applications/mmc_new/CMainWnd.cpp | 39 +++++++----- base/applications/mmc_new/CMainWnd.h | 4 +- base/applications/mmc_new/CMakeLists.txt | 1 + .../applications/mmc_new/CRecentFileEntry.cpp | 62 +++++++++++++++++++ base/applications/mmc_new/CRecentFileEntry.h | 24 +++++++ base/applications/mmc_new/precomp.h | 1 + 6 files changed, 115 insertions(+), 16 deletions(-) create mode 100644 base/applications/mmc_new/CRecentFileEntry.cpp create mode 100644 base/applications/mmc_new/CRecentFileEntry.h diff --git a/base/applications/mmc_new/CMainWnd.cpp b/base/applications/mmc_new/CMainWnd.cpp index b7eeb00570c..bd7d802fa77 100644 --- a/base/applications/mmc_new/CMainWnd.cpp +++ b/base/applications/mmc_new/CMainWnd.cpp @@ -642,15 +642,15 @@ CMainWnd::UpdateRecentFilesMenu() { RemoveMenu(hMenu, IDM_FILE_RECENT1 + i, MF_BYCOMMAND); - CAtlString ValueData = m_RecentFilesList.GetNext(pos); - - mi.dwTypeData = ValueData.GetString(); + CRecentFileEntry *ValueData = m_RecentFilesList.GetNext(pos); + ValueName.Format(L"%d %s", i + 1, ValueData->DisplayName().GetString()); + mi.dwTypeData = ValueName.GetString(); InsertMenuItemW(hMenu, IDM_FILE_EXIT, FALSE, &mi); mi.wID++; i++; - if (i >= 4) + if (i >= MAX_RECENT_FILES) break; } @@ -672,7 +672,7 @@ CMainWnd::LoadRecentFiles() CAtlString valueName; CAtlString fileName; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_RECENT_FILES; i++) { valueName.Format(L"File%u", i + 1); pathLength = _countof(pathBuf); @@ -682,7 +682,7 @@ CMainWnd::LoadRecentFiles() if (err == ERROR_SUCCESS) { CAtlString fileName(pathBuf); - m_RecentFilesList.AddTail(fileName); + m_RecentFilesList.AddTail(new CRecentFileEntry(fileName)); } } @@ -695,11 +695,20 @@ CMainWnd::LoadRecentFiles() VOID CMainWnd::AddToRecentFiles(CAtlString &FileName) { - POSITION pos = m_RecentFilesList.Find(FileName); + POSITION pos = m_RecentFilesList.GetHeadPosition(); + while (pos != NULL) + { + CRecentFileEntry *ValueData = m_RecentFilesList.GetAt(pos); + if (ValueData->FileName() == FileName) + break; + + m_RecentFilesList.GetNext(pos); + } + if (pos == NULL) { /* Insert at top */ - m_RecentFilesList.AddHead(FileName); + m_RecentFilesList.AddHead(new CRecentFileEntry(FileName)); if (m_RecentFilesList.GetCount() > 4) m_RecentFilesList.RemoveTail(); } @@ -707,25 +716,25 @@ CMainWnd::AddToRecentFiles(CAtlString &FileName) { /* Move to top */ /* m_RecentFilesList.MoveToHead(pos); */ - CAtlString str = m_RecentFilesList.GetAt(pos); + CRecentFileEntry *ValueData = m_RecentFilesList.GetAt(pos); m_RecentFilesList.RemoveAt(pos); - m_RecentFilesList.AddHead(str); + m_RecentFilesList.AddHead(ValueData); } /* Update the registry key */ CRegKey RecentFilesKey; if (ERROR_SUCCESS == RecentFilesKey.Create(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\MMC_NEW\\Recent Files List")) { - INT count = 1; + INT count = 0; CAtlString ValueName; pos = m_RecentFilesList.GetHeadPosition(); while (pos != NULL) { - CAtlString ValueData = m_RecentFilesList.GetNext(pos); - ValueName.Format(L"File%u", count); - RecentFilesKey.SetStringValue(ValueName, ValueData); + CRecentFileEntry *ValueData = m_RecentFilesList.GetNext(pos); + ValueName.Format(L"File%u", count + 1); + RecentFilesKey.SetStringValue(ValueName, ValueData->FileName().GetString()); count++; - if (count >= 5) + if (count >= MAX_RECENT_FILES) break; } diff --git a/base/applications/mmc_new/CMainWnd.h b/base/applications/mmc_new/CMainWnd.h index 9bed5de4b49..65acb22c17e 100644 --- a/base/applications/mmc_new/CMainWnd.h +++ b/base/applications/mmc_new/CMainWnd.h @@ -18,6 +18,8 @@ #define BTN_HELP 5 #define BTN_ACTIONS_PANE 6 +#define MAX_RECENT_FILES 4 + class CMainWnd : public CWindowImpl { @@ -46,7 +48,7 @@ private: CSnapin *m_RootNode; - CAtlList m_RecentFilesList; + CAtlList m_RecentFilesList; public: CWindow m_MDIClient; diff --git a/base/applications/mmc_new/CMakeLists.txt b/base/applications/mmc_new/CMakeLists.txt index 3c7ef25cf33..e29d017803a 100644 --- a/base/applications/mmc_new/CMakeLists.txt +++ b/base/applications/mmc_new/CMakeLists.txt @@ -8,6 +8,7 @@ list(APPEND CPP_SOURCE CConsoleWnd.cpp CMainWnd.cpp COptionsDialog.cpp + CRecentFileEntry.cpp CSnapin.cpp CSnapinCacheEntry.cpp mscfile.cpp diff --git a/base/applications/mmc_new/CRecentFileEntry.cpp b/base/applications/mmc_new/CRecentFileEntry.cpp new file mode 100644 index 00000000000..33a4431e61e --- /dev/null +++ b/base/applications/mmc_new/CRecentFileEntry.cpp @@ -0,0 +1,62 @@ +/* + * PROJECT: ReactOS Management Console + * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) + * PURPOSE: Recent file entry class + * COPYRIGHT: Copyright 2026 Eric Kohl (eric.kohl@reactos.org) + */ + +#include "precomp.h" + +#define NDEBUG +#include + +CRecentFileEntry::CRecentFileEntry(const CAtlString& FileName) +{ + m_FileName = FileName; + BuildDisplayName(); +} + +CRecentFileEntry::~CRecentFileEntry() +{ + delete m_FileName; + delete m_DisplayName; +} + +void +CRecentFileEntry::BuildDisplayName() +{ + WCHAR SystemDirectory[MAX_PATH]; + UINT Length; + + Length = ::GetSystemDirectoryW(SystemDirectory, MAX_PATH); + + if (_wcsnicmp(m_FileName.GetString(), SystemDirectory, Length) == 0) + { + m_DisplayName = m_FileName.Mid(Length + 1); + } + else + { + PWSTR pBackslash1 = NULL, pBackslash2 = NULL, pBackslash3 = NULL; + + pBackslash1 = wcschr(m_FileName.GetString(), L'\\'); + + if (pBackslash1) + pBackslash2 = wcschr(pBackslash1 + 1, L'\\'); + + if (pBackslash2) + pBackslash3 = wcsrchr(m_FileName.GetString(), L'\\'); + + if (pBackslash1 && pBackslash2 && pBackslash3 && (pBackslash2 != pBackslash3)) + { + int Length = pBackslash2 - m_FileName.GetString(); + CAtlString str(m_FileName.Left(Length + 1)); + str.Append(L"..."); + str.Append(pBackslash3); + m_DisplayName = str; + } + else + { + m_DisplayName = m_FileName; + } + } +} diff --git a/base/applications/mmc_new/CRecentFileEntry.h b/base/applications/mmc_new/CRecentFileEntry.h new file mode 100644 index 00000000000..62119a29c85 --- /dev/null +++ b/base/applications/mmc_new/CRecentFileEntry.h @@ -0,0 +1,24 @@ +/* + * PROJECT: ReactOS Management Console + * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) + * PURPOSE: Recent file entry class + * COPYRIGHT: Copyright 2026 Eric Kohl (eric.kohl@reactos.org) + */ + +#pragma once + +class CRecentFileEntry +{ +private: + CAtlString m_FileName; + CAtlString m_DisplayName; + + void BuildDisplayName(); + +public: + CRecentFileEntry(const CAtlString& FileName); + ~CRecentFileEntry(); + + const CAtlString& FileName() const { return m_FileName; } + const CAtlString& DisplayName() const { return m_DisplayName; } +}; diff --git a/base/applications/mmc_new/precomp.h b/base/applications/mmc_new/precomp.h index b8d6424c3bb..5e6e880b7e9 100644 --- a/base/applications/mmc_new/precomp.h +++ b/base/applications/mmc_new/precomp.h @@ -48,6 +48,7 @@ typedef enum _DOCUMENT_MODE #include "mscfile.h" +#include "CRecentFileEntry.h" #include "CSnapinCacheEntry.h" #include "CSnapin.h" #include "CConsoleWnd.h"