mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 18:25:58 +00:00
[MSPAINT] Refactor about Recent Files (#5163)
Define MAX_RECENT_FILES macro as 4. Remove strFile1, ..., strFile4 settings and add strFiles[MAX_RECENT_FILES] for Most Recently Used (MRU) files. CORE-18867
This commit is contained in:
parent
a81f229065
commit
41c30182d4
4 changed files with 88 additions and 95 deletions
|
@ -115,10 +115,12 @@ void RegistrySettings::Load(INT nCmdShow)
|
|||
CRegKey files;
|
||||
if (files.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List"), KEY_READ) == ERROR_SUCCESS)
|
||||
{
|
||||
ReadString(files, _T("File1"), strFile1);
|
||||
ReadString(files, _T("File2"), strFile2);
|
||||
ReadString(files, _T("File3"), strFile3);
|
||||
ReadString(files, _T("File4"), strFile4);
|
||||
TCHAR szName[64];
|
||||
for (INT i = 0; i < MAX_RECENT_FILES; ++i)
|
||||
{
|
||||
wsprintf(szName, _T("File%u"), i + 1);
|
||||
ReadString(files, szName, strFiles[i]);
|
||||
}
|
||||
}
|
||||
|
||||
CRegKey text;
|
||||
|
@ -167,14 +169,12 @@ void RegistrySettings::Store()
|
|||
CRegKey files;
|
||||
if (files.Create(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List")) == ERROR_SUCCESS)
|
||||
{
|
||||
if (!strFile1.IsEmpty())
|
||||
files.SetStringValue(_T("File1"), strFile1);
|
||||
if (!strFile2.IsEmpty())
|
||||
files.SetStringValue(_T("File2"), strFile2);
|
||||
if (!strFile3.IsEmpty())
|
||||
files.SetStringValue(_T("File3"), strFile3);
|
||||
if (!strFile4.IsEmpty())
|
||||
files.SetStringValue(_T("File4"), strFile4);
|
||||
TCHAR szName[64];
|
||||
for (INT iFile = 0; iFile < MAX_RECENT_FILES; ++iFile)
|
||||
{
|
||||
wsprintf(szName, _T("File%u"), iFile + 1);
|
||||
files.SetStringValue(szName, strFiles[iFile]);
|
||||
}
|
||||
}
|
||||
|
||||
CRegKey text;
|
||||
|
@ -194,39 +194,30 @@ void RegistrySettings::Store()
|
|||
|
||||
void RegistrySettings::SetMostRecentFile(LPCTSTR szPathName)
|
||||
{
|
||||
// Register the file to the user's 'Recent' folder
|
||||
if (szPathName && szPathName[0])
|
||||
SHAddToRecentDocs(SHARD_PATHW, szPathName);
|
||||
|
||||
if (strFile1 == szPathName)
|
||||
// If szPathName is present in strFiles, move it to the top of the list
|
||||
for (INT i = MAX_RECENT_FILES - 1, iFound = -1; i > 0; --i)
|
||||
{
|
||||
// do nothing
|
||||
if (iFound < 0 && strFiles[i].CompareNoCase(szPathName) == 0)
|
||||
iFound = i;
|
||||
|
||||
if (iFound >= 0)
|
||||
{
|
||||
CString tmp = strFiles[i];
|
||||
strFiles[i] = strFiles[i - 1];
|
||||
strFiles[i - 1] = tmp;
|
||||
}
|
||||
}
|
||||
else if (strFile2 == szPathName)
|
||||
|
||||
// If szPathName is not the first item in strFiles, insert it at the top of the list
|
||||
if (strFiles[0].CompareNoCase(szPathName) != 0)
|
||||
{
|
||||
CString strTemp = strFile2;
|
||||
strFile2 = strFile1;
|
||||
strFile1 = strTemp;
|
||||
}
|
||||
else if (strFile3 == szPathName)
|
||||
{
|
||||
CString strTemp = strFile3;
|
||||
strFile3 = strFile2;
|
||||
strFile2 = strFile1;
|
||||
strFile1 = strTemp;
|
||||
}
|
||||
else if (strFile4 == szPathName)
|
||||
{
|
||||
CString strTemp = strFile4;
|
||||
strFile4 = strFile3;
|
||||
strFile3 = strFile2;
|
||||
strFile2 = strFile1;
|
||||
strFile1 = strTemp;
|
||||
}
|
||||
else
|
||||
{
|
||||
strFile4 = strFile3;
|
||||
strFile3 = strFile2;
|
||||
strFile2 = strFile1;
|
||||
strFile1 = szPathName;
|
||||
for (INT i = MAX_RECENT_FILES - 1; i > 0; --i)
|
||||
strFiles[i] = strFiles[i - 1];
|
||||
|
||||
strFiles[0] = szPathName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define MAX_RECENT_FILES 4
|
||||
|
||||
class RegistrySettings
|
||||
{
|
||||
private:
|
||||
|
@ -27,10 +29,7 @@ public:
|
|||
DWORD UnitSetting;
|
||||
WINDOWPLACEMENT WindowPlacement;
|
||||
|
||||
CString strFile1;
|
||||
CString strFile2;
|
||||
CString strFile3;
|
||||
CString strFile4;
|
||||
CString strFiles[MAX_RECENT_FILES];
|
||||
|
||||
CString strFontName;
|
||||
DWORD PointSize;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
#include <assert.h>
|
||||
|
||||
typedef HWND (WINAPI *FN_HtmlHelpW)(HWND, LPCWSTR, UINT, DWORD_PTR);
|
||||
|
||||
|
@ -310,53 +311,63 @@ LRESULT CMainWindow::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan
|
|||
return 0;
|
||||
}
|
||||
|
||||
void CMainWindow::ProcessFileMenu(HMENU hPopupMenu)
|
||||
{
|
||||
LPCTSTR dotext = PathFindExtensionW(filepathname);
|
||||
BOOL isBMP = FALSE;
|
||||
if (_tcsicmp(dotext, _T(".bmp")) == 0 ||
|
||||
_tcsicmp(dotext, _T(".dib")) == 0 ||
|
||||
_tcsicmp(dotext, _T(".rle")) == 0)
|
||||
{
|
||||
isBMP = TRUE;
|
||||
}
|
||||
|
||||
EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERPLANE, ENABLED_IF(isAFile && isBMP));
|
||||
EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERCENTERED, ENABLED_IF(isAFile && isBMP));
|
||||
EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERSTRETCHED, ENABLED_IF(isAFile && isBMP));
|
||||
|
||||
for (INT iItem = 0; iItem < MAX_RECENT_FILES; ++iItem)
|
||||
RemoveMenu(hPopupMenu, IDM_FILE1 + iItem, MF_BYCOMMAND);
|
||||
|
||||
if (registrySettings.strFiles[0].IsEmpty())
|
||||
return;
|
||||
|
||||
RemoveMenu(hPopupMenu, IDM_FILEMOSTRECENTLYUSEDFILE, MF_BYCOMMAND);
|
||||
|
||||
INT cMenuItems = GetMenuItemCount(hPopupMenu);
|
||||
|
||||
for (INT iItem = 0; iItem < MAX_RECENT_FILES; ++iItem)
|
||||
{
|
||||
CString& strFile = registrySettings.strFiles[iItem];
|
||||
if (strFile.IsEmpty())
|
||||
break;
|
||||
|
||||
// Condense the lengthy pathname by using '...'
|
||||
#define MAX_RECENT_PATHNAME_DISPLAY 30
|
||||
CPath pathFile(strFile);
|
||||
pathFile.CompactPathEx(MAX_RECENT_PATHNAME_DISPLAY);
|
||||
assert(_tcslen((LPCTSTR)pathFile) <= MAX_RECENT_PATHNAME_DISPLAY);
|
||||
|
||||
// Add an accelerator (by '&') to the item number for quick access
|
||||
TCHAR szText[4 + MAX_RECENT_PATHNAME_DISPLAY + 1];
|
||||
wsprintf(szText, _T("&%u %s"), iItem + 1, (LPCTSTR)pathFile);
|
||||
|
||||
INT iMenuItem = (cMenuItems - 2) + iItem;
|
||||
InsertMenu(hPopupMenu, iMenuItem, MF_BYPOSITION | MF_STRING, IDM_FILE1 + iItem, szText);
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT CMainWindow::OnInitMenuPopup(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||
{
|
||||
HMENU menu = GetMenu();
|
||||
BOOL trueSelection =
|
||||
(::IsWindowVisible(selectionWindow) &&
|
||||
((toolsModel.GetActiveTool() == TOOL_FREESEL) || (toolsModel.GetActiveTool() == TOOL_RECTSEL)));
|
||||
BOOL isBMP;
|
||||
|
||||
switch (lParam)
|
||||
{
|
||||
case 0: /* File menu */
|
||||
if ((HMENU)wParam != GetSubMenu(menu, 0))
|
||||
break;
|
||||
|
||||
isBMP = _wcsicmp(PathFindExtensionW(filepathname), L".bmp") == 0;
|
||||
EnableMenuItem(menu, IDM_FILEASWALLPAPERPLANE, ENABLED_IF(isAFile && isBMP));
|
||||
EnableMenuItem(menu, IDM_FILEASWALLPAPERCENTERED, ENABLED_IF(isAFile && isBMP));
|
||||
EnableMenuItem(menu, IDM_FILEASWALLPAPERSTRETCHED, ENABLED_IF(isAFile && isBMP));
|
||||
|
||||
RemoveMenu(menu, IDM_FILE1, MF_BYCOMMAND);
|
||||
RemoveMenu(menu, IDM_FILE2, MF_BYCOMMAND);
|
||||
RemoveMenu(menu, IDM_FILE3, MF_BYCOMMAND);
|
||||
RemoveMenu(menu, IDM_FILE4, MF_BYCOMMAND);
|
||||
if (!registrySettings.strFile1.IsEmpty())
|
||||
{
|
||||
RemoveMenu(menu, IDM_FILEMOSTRECENTLYUSEDFILE, MF_BYCOMMAND);
|
||||
CPath pathFile1(registrySettings.strFile1);
|
||||
pathFile1.CompactPathEx(30);
|
||||
if (!registrySettings.strFile2.IsEmpty())
|
||||
{
|
||||
CPath pathFile2(registrySettings.strFile2);
|
||||
pathFile2.CompactPathEx(30);
|
||||
if (!registrySettings.strFile3.IsEmpty())
|
||||
{
|
||||
CPath pathFile3(registrySettings.strFile3);
|
||||
pathFile3.CompactPathEx(30);
|
||||
if (!registrySettings.strFile4.IsEmpty())
|
||||
{
|
||||
CPath pathFile4(registrySettings.strFile4);
|
||||
pathFile4.CompactPathEx(30);
|
||||
InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE4, _T("4 ") + pathFile4);
|
||||
}
|
||||
InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE3, _T("3 ") + pathFile3);
|
||||
}
|
||||
InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE2, _T("2 ") + pathFile2);
|
||||
}
|
||||
InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE1, _T("1 ") + pathFile1);
|
||||
}
|
||||
ProcessFileMenu((HMENU)wParam);
|
||||
break;
|
||||
case 1: /* Edit menu */
|
||||
EnableMenuItem(menu, IDM_EDITUNDO, ENABLED_IF(imageModel.HasUndoSteps()));
|
||||
|
@ -545,23 +556,13 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
|
|||
RegistrySettings::SetWallpaper(filepathname, RegistrySettings::STRETCHED);
|
||||
break;
|
||||
case IDM_FILE1:
|
||||
{
|
||||
ConfirmSave() && DoLoadImageFile(m_hWnd, registrySettings.strFile1, TRUE);
|
||||
break;
|
||||
}
|
||||
case IDM_FILE2:
|
||||
{
|
||||
ConfirmSave() && DoLoadImageFile(m_hWnd, registrySettings.strFile2, TRUE);
|
||||
break;
|
||||
}
|
||||
case IDM_FILE3:
|
||||
{
|
||||
ConfirmSave() && DoLoadImageFile(m_hWnd, registrySettings.strFile3, TRUE);
|
||||
break;
|
||||
}
|
||||
case IDM_FILE4:
|
||||
{
|
||||
ConfirmSave() && DoLoadImageFile(m_hWnd, registrySettings.strFile4, TRUE);
|
||||
INT iFile = LOWORD(wParam) - IDM_FILE1;
|
||||
if (ConfirmSave())
|
||||
DoLoadImageFile(m_hWnd, registrySettings.strFiles[iFile], TRUE);
|
||||
break;
|
||||
}
|
||||
case IDM_EDITUNDO:
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
MESSAGE_HANDLER(WM_MOUSEWHEEL, OnMouseWheel)
|
||||
END_MSG_MAP()
|
||||
|
||||
private:
|
||||
LRESULT OnDropFiles(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||
LRESULT OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||
LRESULT OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||
|
@ -44,4 +45,5 @@ public:
|
|||
void saveImage(BOOL overwrite);
|
||||
void InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window);
|
||||
BOOL ConfirmSave();
|
||||
void ProcessFileMenu(HMENU hPopupMenu);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue