Hi YannDuran,
Before getting the mru list, you need to click Test Sub Command
to trigger the event at the first time. After that the mru list will auto refresh when you go to Extensions > Test Menu > Sub Menu.
By the way, since the policy, we cannot share the sample through our onedrive at the moment, I paste the codes here:
private TestCommand(AsyncPackage package, OleMenuCommandService commandService)
{
....
this.InitMRUMenu(commandService);
}
private int baseMRUID = (int)TopLevelMenuPackage.cmdidMRUList;
private ArrayList mruList;
private void InitializeMRUList()
{
if (null == this.mruList)
{
this.mruList = new ArrayList();
if (null != this.mruList)
{
string vsExePath = AppDomain.CurrentDomain.BaseDirectory + "devenv.exe";
string mruPath = @"MRUItems\{" + VSConstants.MruList.Projects + @"}\Items";
ExternalSettingsManager ext = ExternalSettingsManager.CreateForApplication(vsExePath);
SettingsStore store = ext.GetReadOnlySettingsStore(SettingsScope.UserSettings);
foreach (string name in store.GetPropertyNames(mruPath))
{
string value = store.GetString(mruPath, name);
string[] subValue = value.Split('|');
this.mruList.Add(subValue[0]);
}
}
}
}
private void InitMRUMenu(OleMenuCommandService mcs)
{
InitializeMRUList();
for (int i = 0; i < this.mruList.Count; i++)
{
var cmdID = new CommandID(
new Guid(TopLevelMenuPackage.guidTopLevelMenuPackageCmdSet), this.baseMRUID + i);
var mc = new OleMenuCommand(
new EventHandler(OnMRUExec), cmdID);
mc.BeforeQueryStatus += new EventHandler(OnMRUQueryStatus);
mcs.AddCommand(mc);
}
}
private void OnMRUQueryStatus(object sender, EventArgs e)
{
OleMenuCommand menuCommand = sender as OleMenuCommand;
if (null != menuCommand)
{
int MRUItemIndex = menuCommand.CommandID.ID - this.baseMRUID;
if (MRUItemIndex >= 0 && MRUItemIndex < this.mruList.Count)
{
menuCommand.Text = this.mruList[MRUItemIndex] as string;
}
}
}
private void OnMRUExec(object sender, EventArgs e)
{
var menuCommand = sender as OleMenuCommand;
if (null != menuCommand)
{
int MRUItemIndex = menuCommand.CommandID.ID - this.baseMRUID;
if (MRUItemIndex >= 0 && MRUItemIndex < this.mruList.Count)
{
string selection = this.mruList[MRUItemIndex] as string;
for (int i = MRUItemIndex; i > 0; i--)
{
this.mruList[i] = this.mruList[i - 1];
}
this.mruList[0] = selection;
System.Windows.Forms.MessageBox.Show(
string.Format(CultureInfo.CurrentCulture,
"Selected {0}", selection));
}
}
}
Hope it could help you.
Best Regards,
Dylan