2 * PROJECT: ReactOS browseui
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Custom MRU AutoComplete List
5 * COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org)
10 CACLCustomMRU::CACLCustomMRU()
15 CACLCustomMRU::~CACLCustomMRU()
21 void CACLCustomMRU::PersistMRU()
23 WCHAR Key
[2] = { 0, 0 };
31 m_Key
.SetStringValue(L
"MRUList", m_MRUList
);
32 for (int Index
= 0; Index
< m_MRUList
.GetLength(); ++Index
)
35 m_Key
.SetStringValue(Key
, m_MRUData
[Index
]);
40 // *** IACLCustomMRU methods ***
41 HRESULT STDMETHODCALLTYPE
CACLCustomMRU::Initialize(LPCWSTR pwszMRURegKey
, DWORD dwMax
)
43 LSTATUS Status
= m_Key
.Create(HKEY_CURRENT_USER
, pwszMRURegKey
);
44 if (Status
!= ERROR_SUCCESS
)
45 return HRESULT_FROM_WIN32(Status
);
47 m_MRUData
.RemoveAll();
48 dwMax
= max(0, dwMax
);
49 dwMax
= min(29, dwMax
);
51 m_MRUData
.Add(CStringW());
54 ULONG nChars
= _countof(MRUList
);
56 Status
= m_Key
.QueryStringValue(L
"MRUList", MRUList
, &nChars
);
57 if (Status
!= ERROR_SUCCESS
)
60 if (nChars
> 0 && MRUList
[nChars
-1] == '\0')
63 if (nChars
> (ULONG
)m_MRUData
.GetSize())
66 for (ULONG n
= 0; n
< nChars
; ++n
)
68 if (MRUList
[n
] >= 'a' && MRUList
[n
] <= '}' && m_MRUList
.Find(MRUList
[n
]) < 0)
70 WCHAR Key
[2] = { MRUList
[n
], NULL
};
71 WCHAR Value
[MAX_PATH
* 2];
72 ULONG nValueChars
= _countof(Value
);
74 m_MRUList
+= MRUList
[n
];
75 int Index
= MRUList
[n
] - 'a';
77 if (Index
< m_MRUData
.GetSize())
79 Status
= m_Key
.QueryStringValue(Key
, Value
, &nValueChars
);
80 if (Status
== ERROR_SUCCESS
)
82 m_MRUData
[Index
] = CStringW(Value
, nValueChars
);
91 HRESULT STDMETHODCALLTYPE
CACLCustomMRU::AddMRUString(LPCWSTR pwszEntry
)
93 ATLASSERT(m_MRUData
.GetSize() <= m_MRUList
.GetLength());
97 CStringW NewElement
= pwszEntry
;
98 WCHAR Key
[2] = { 0, 0 };
99 int Index
= m_MRUData
.Find(NewElement
);
102 /* Move the key to the front */
103 Key
[0] = Index
+ 'a';
104 m_MRUList
.Replace(Key
, L
"");
105 m_MRUList
= Key
+ m_MRUList
;
109 int TotalLen
= m_MRUList
.GetLength();
110 if (m_MRUData
.GetSize() == TotalLen
)
112 /* Find oldest element, move that to the front */
113 Key
[0] = m_MRUList
[TotalLen
-1];
114 m_MRUList
= Key
+ m_MRUList
.Left(TotalLen
-1);
115 Index
= Key
[0] - 'a';
119 /* Find the first empty entry */
120 for (Index
= 0; Index
< m_MRUData
.GetSize(); ++Index
)
122 if (m_MRUData
[Index
].IsEmpty())
125 Key
[0] = Index
+ 'a';
126 m_MRUList
= Key
+ m_MRUList
;
128 m_MRUData
[Index
] = NewElement
;