19#include <owl/window.rh>
20#include <owl/editfile.rh>
25#include <owl/rcntfile.rh>
50uint TRecentFiles::MruMessage = 0;
71TRecentFiles__ReadMaxNum(
bool useRegistry, const
tstring& mruName,
74 const auto getMaxCount = [&]() ->
int
80 return static_cast<int>(
static_cast<uint32>(*v));
96 int namelen,
bool useRegistry,
bool keepFullNameInMenu)
100 AddedSeparator(false),
101 UseRegistry(useRegistry),
104 keepFullNameInMenu(keepFullNameInMenu)
106 int filestosave = std::min(numSavedFiles,
static_cast<int>(
MaxMenuItems));
113 MruName =
TFileName(iniName).Canonical();
116 filestosave = TRecentFiles__ReadMaxNum(UseRegistry, MruName, filestosave);
138 if(numItems > MaxFilesToSave){
140 for(
int i = 0; i < MaxFilesToSave && i < numItems; i++)
141 items[i] = MruNames[i];
144 MaxFilesToSave = numItems;
169 for (
int i = ::GetMenuItemCount(menu) - 1; i >= 0; i--)
170 if (::GetMenuItemID(menu, i) ==
id)
191 int menuPos =
GetMenuPos(hMenu, CM_MRU_FIRST + 0);
192 return menuPos != -1;
203 if (::GetMenuItemID(hMenu, exitPos - 1) == 0 && AddedSeparator) {
204 AddedSeparator =
false;
205 if (LastHMenu == hMenu)
206 ::RemoveMenu(hMenu, exitPos - 1, MF_BYPOSITION);
215 ::RemoveMenu(hMenu, i, MF_BYCOMMAND);
234 int numItemsAdded = 0;
238 for (i = 0; i < MruCount; i++) {
247 curname =
TFileName(curname).Squeezed(MaxDispLen, keepFullNameInMenu);
250 wsprintf(menuItemBuffer,
_T(
"%d&%d %s"), (i+1)/10, (i+1)%10, curname.c_str());
252 wsprintf(menuItemBuffer,
_T(
"&%d %s"), (i+1), curname.c_str());
254 menu.
InsertMenu(exitPos + i, MF_BYPOSITION | MF_STRING, CM_MRU_FIRST + i, menuItemBuffer);
257 if (numItemsAdded > 0) {
258 if (AddedSeparator ==
false) {
260 AddedSeparator =
true;
261 menuItemBuffer[0] = 0;
262 ::InsertMenu(hMenu, exitPos + numItemsAdded, MF_BYPOSITION|MF_SEPARATOR, 0, menuItemBuffer);
289 if (
id < 0 || MruCount <=
id)
302 if (
id < 0 || MruCount <=
id)
305 if(
::_tcslen(menuText.c_str()) > (
size_t)maxTextLen){
306 _tcsncpy(text, menuText.c_str(), maxTextLen-1);
307 text[maxTextLen] =
_T(
'\0');
310 ::_tcscpy(text, menuText.c_str());
341 if (index < 0 || MruCount <= index)
344 if (index != MruCount - 1) {
347 for(
int i = index; i < MruCount - 1; i++)
348 MruNames[i] = MruNames[i+1];
353 MruNames[MruCount-1] =
_T(
"");
364 if (MaxFilesToSave <= 0)
367 if (sFullFilePath.empty())
369 if(MruCount < MaxFilesToSave)
374 for (
int i = MruCount - 2; i >= 0; i--)
375 MruNames[i+1] = MruNames[i];
380 MruNames[0] = sFullFilePath;
399 for (
int i = 0; i < MruCount; i++) {
400 if(MruNames[i] == filename)
414 WARN(!k,
_T(
"Registry key is missing for MRU: HKEY_CURRENT_USER\\") << MruName);
416 const auto c = k->GetValue(
CountKey);
419 MruCount = std::min(
static_cast<int>(
static_cast<uint32>(*c)), MaxFilesToSave);
420 for (
auto i = 0; i != MruCount; ++i)
430 TAPointer<tchar> srcKeyBuffer(
new tchar[80]);
432 TProfile profile(
Section, MruName.c_str());
433 MruCount = profile.GetInt(
CountKey, 0);
434 if (MruCount > MaxFilesToSave)
435 MruCount = MaxFilesToSave;
436 for (
int i = 0; i < MruCount; i++){
439 MruNames[i] = (
tchar*)menuText;
452 [[maybe_unused]]
const auto r = c.DeleteKey(MruName);
453 CHECK(r == ERROR_SUCCESS || r == ERROR_FILE_NOT_FOUND || r == ERROR_PATH_NOT_FOUND);
454 auto k = TRegKey{c, MruName};
CHECK(k.GetHandle());
456 for (
auto i = 0; i != MruCount; ++i)
461 TAPointer<tchar> dstKeyBuffer(
new tchar[80]);
462 TProfile profile(
Section, MruName.c_str());
463 profile.WriteInt(
CountKey, MruCount);
464 for (
int i = 0; i < MruCount; i++){
466 profile.WriteString(dstKeyBuffer, MruNames[i].GetParts(
FullFileName));
#define WARN(condition, message)
Pointer to an array of type T.
Derived from TModule and TMsgThread and virtually derived from TEventHandler, TApplication acts as an...
TFrameWindow * GetMainWindow()
Return the current main window.
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
virtual void Enable(bool enable=true)
Enables or disables the command sender.
TEventHandler is a base class from which you can derive classes that handle messages.
The TFileName class constructs filenames.
TFileName()
Constructs an empty filename.
@ Device
Logical device or sharename.
@ Path
Directory path to the file.
@ File
Filename part without the extension.
@ CurrentDir
Current working directory if any.
Derived from TWindow, TFrameWindow controls such window-specific behavior as keyboard navigation and ...
An instance of TProfile encapsulates a setting within a system file, often referred to as a profile o...
int GetInt(LPCTSTR key, int defaultInt=0)
Looks up and returns the integer value associated with the given string, key.
TRecentFiles implements a most-recent files list, designed to be mixed in with TApplication.
void CeExit(TCommandEnabler &ce)
Reads information in the TProfile to display the menu choices.
void SaveMenuChoice(LPCTSTR text)
Saves the menu choice into the profile.
void InsertMruItemsToMenu(HMENU hMenu)
Reads external information and adds the MRU items into the menu.
int GetMenuPos(HMENU hMenu, uint id)
Searches the menu to find the position of a menu item.
int GetExitMenuPos(HMENU hMenu)
Retrieves the menu position of the CM_EXIT menu item. Returns -1 if not found.
bool GetMenuText(int id, TCHAR *text, int maxTextLen)
Retrieves the text of the choice based on the ID.
void RemoveMruIndex(int index)
Removes the MRU item at index. Shuffles the items below index up.
virtual ~TRecentFiles()
Deletes the allocated profile.
void SetMaxMruItems(int maxValue)
Sets the maximum number of items that can be saved with this MRU.
void CmFile(uint id)
Responds to a menu item selection.
bool ExistMruItem(LPCTSTR text)
Returns true if there are any items in the MRU list that match the text.
int GetMruItemIndex(LPCTSTR text)
Returns the index of the MRU item containing text. Returns -1 if not found.
TRecentFiles(const tstring &iniOrKeyName, int numSavedFiles=MaxMenuItems, int namelen=30, bool useRegistry=false, bool keepFullNameInMenu=true)
Constructor to initialize the external storage and the maximum number of items to save in the most-re...
void RemoveMruItemsFromMenu(HMENU hMenu)
Removes the MRU items from the menu.
void RemoveMenuChoice(LPCTSTR text)
bool MruItemsInsertedIntoMenu(HMENU hMenu)
Returns true if the menu has any MRU items in it.
void AddMruItem(LPCTSTR text)
Adds an item to the top of the MRU list.
static auto GetCurrentUser() -> TRegKey &
Special predefined root key defining the preferences of the current user (HKEY_CURRENT_USER).
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition of class TFrameWindow.
Object Windows Library (OWLNext Core).
EV_COMMAND_AND_ID(CM_MRU_FIRST+0, CmFile)
const tchar * MaxCountKey
EV_COMMAND_ENABLE(CM_FILENEW, CeFileNew)
auto to_tstring(const T &v) -> tstring
const tchar * MenuItemDefault
#define TYPESAFE_DOWNCAST(object, toClass)
Various types of smart pointer templatized classes.
Definition of TProfile class.
Definition of TRecentFiles class.
#define MruFileMessage
Derived classes should catch the following registered message to know when an item in the recent list...
General Registry access & registration implementation TRegKey, TRegValue, TRegKeyIterator,...