mirror of
https://github.com/reactos/reactos.git
synced 2026-09-26 20:20:12 +08:00
[MMC_NEW] Implement the recent files list properly and pretty print the menu items
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#define BTN_HELP 5
|
||||
#define BTN_ACTIONS_PANE 6
|
||||
|
||||
#define MAX_RECENT_FILES 4
|
||||
|
||||
class CMainWnd :
|
||||
public CWindowImpl<CMainWnd>
|
||||
{
|
||||
@@ -46,7 +48,7 @@ private:
|
||||
|
||||
CSnapin *m_RootNode;
|
||||
|
||||
CAtlList<CAtlString> m_RecentFilesList;
|
||||
CAtlList<CRecentFileEntry *> m_RecentFilesList;
|
||||
|
||||
public:
|
||||
CWindow m_MDIClient;
|
||||
|
||||
@@ -8,6 +8,7 @@ list(APPEND CPP_SOURCE
|
||||
CConsoleWnd.cpp
|
||||
CMainWnd.cpp
|
||||
COptionsDialog.cpp
|
||||
CRecentFileEntry.cpp
|
||||
CSnapin.cpp
|
||||
CSnapinCacheEntry.cpp
|
||||
mscfile.cpp
|
||||
|
||||
62
base/applications/mmc_new/CRecentFileEntry.cpp
Normal file
62
base/applications/mmc_new/CRecentFileEntry.cpp
Normal file
@@ -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 <debug.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
base/applications/mmc_new/CRecentFileEntry.h
Normal file
24
base/applications/mmc_new/CRecentFileEntry.h
Normal file
@@ -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; }
|
||||
};
|
||||
@@ -48,6 +48,7 @@ typedef enum _DOCUMENT_MODE
|
||||
|
||||
#include "mscfile.h"
|
||||
|
||||
#include "CRecentFileEntry.h"
|
||||
#include "CSnapinCacheEntry.h"
|
||||
#include "CSnapin.h"
|
||||
#include "CConsoleWnd.h"
|
||||
|
||||
Reference in New Issue
Block a user