|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionAnyone who has used Visual Studio to create more than one project or solution has used the "Start Page" to see the most recently used (MRU) projects or solutions. If you are like me, you often have more than one Visual Studio instance opened and have been frustrated by the fact that the list never seems to be "right". In addition I find myself often creating "temporary" projects to test a new idea and don't want to see these projects on my MRU Project List. I have seen two articles on CodeProject discussing the "Start Page", but neither gave me an easy way to edit or maintain this list. The Stagner article speaks of maintaining the list by editing the registry, which in the end is all my tool does, but I wanted an interface to maintain the list.
BackgroundVisual Studio stores the MRU Projects in the registry under the path HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\XX\ProjectMRUList where XX is the version number of Visual Studio.
There is a string value for each recent file named File1, File2, File3, etc. with a value of the full path to the file. Visual Studio updates this list on close, which is the root of some of my problems. Multiple versions of Visual Studio do not communicate about their open projects, nor do they read the current state of the registry and attempt to merge them. On close, Studio clears this key and re-writes out the list as it knows it. My scenario is as follows:
Important NoteSince Visual Studio clears and rewrites the list on close, you must have all instances of Visual Studio before using this tool. Using the codeThere is no real magic in this code; one listbox, six buttons and some Registry code. Since we are using the Registry, we need to include the using Microsoft.Win32;
On the form load we open the key in a writable mode: private void MainForm_Load(object sender, System.EventArgs e) {
// Open a writable RegKey
m_ProjectMRUKey = Registry.CurrentUser.OpenSubKey(PROJECT_MRU_PATH, true);
}
Loading and daving methods: /// <SUMMARY>
/// Loads (Reads) Registry Values into ListBox
/// </SUMMARY>
private void btnLoad_Click(object sender, System.EventArgs e) {
lstBoxMain.Items.Clear();
foreach (string key in m_ProjectMRUKey.GetValueNames()) {
lstBoxMain.Items.Add(m_ProjectMRUKey.GetValue(key));
}
}
/// <SUMMARY>
/// Save (Writes) Registry Values from ListBox
/// </SUMMARY>
private void btnSave_Click(object sender, System.EventArgs e) {
foreach (string key in m_ProjectMRUKey.GetValueNames())
m_ProjectMRUKey.DeleteValue(key);
for(int i=0; i < lstBoxMain.Items.Count; ++i) {
m_ProjectMRUKey.SetValue("File" + (i+1), lstBoxMain.Items[i]);
}
//Flush the object to force it to write the files to the Registry
m_ProjectMRUKey.Flush();
}
Form closing - Close the Registry key: private void MainForm_Closed(object sender, System.EventArgs e) {
//Close and flush the registry value on close
m_ProjectMRUKey.Close();
}
The rest of the code deals with maintaining the Final ThoughtsAs the radio cliché goes, "I'm a long time listener first time caller to CodeProject". I hope this simple article is useful to those who take the time to read it. I use this tool all the time and have found it very helpful. Depending on how my experience with this article goes, I will hopefully be back to lend more tips and tricks to the coding community. I look forward to your comments and / or questions. History
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||