/** * Create App Profile button was clicked, so launch the appropriate form. **/ private void BtnCreateAppProfileClick(object sender, EventArgs e) { // Show Create App Profile form. CreateAppProfile form = new CreateAppProfile(); form.ShowDialog(); // If the user pressed 'Save' the NewAppProfile will be non-null, so let's save it. if (form.NewAppProfile != null) { _globalPreferences.AppProfiles.Add(form.NewAppProfile.AppName, form.NewAppProfile); // Force refresh of ListView with newly added profile. UpdateAppProfileView(); } }
/** * When the user right-clicks an App Profile and chooses Edit, launch the * Create App Profile form with the existing information preloaded. **/ private void CtxMenuEditAppProfileClick(object sender, EventArgs e) { if (lstAppProfiles.SelectedItems.Count != 1) { MessageBox.Show(this, "Please select exactly one App Profile before trying to edit it.", "Error: Too Many or Too Few Selected Profiles", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // Get the AppProfile which corresponds with the selected row ListViewItem selectedItem = lstAppProfiles.SelectedItems[0]; string appName = selectedItem.Text; AppProfile appProfile = _globalPreferences.AppProfiles[appName]; // Launch the Create App Profile form with the existing profile pre-filled CreateAppProfile form = new CreateAppProfile(appProfile); form.ShowDialog(); // Handle the changes, if they were saved (making them non-null). if (form.NewAppProfile != null) { // Remove the profile from Global Preferences keyed by old App Name (in case the name changed) _globalPreferences.AppProfiles.Remove(appName); // Insert the new App Profile to Global Prefs _globalPreferences.AppProfiles.Add(form.NewAppProfile.AppName, form.NewAppProfile); // update Local Preferences if needed if (_localPreferences.LocalAppProfiles.ContainsKey(appName)) { string localFolder = _localPreferences.LocalAppProfiles[appName].LocalFolder; _localPreferences.LocalAppProfiles.Remove(appName); _localPreferences.LocalAppProfiles.Add(form.NewAppProfile.AppName, new LocalAppProfile(form.NewAppProfile, localFolder)); // Since mapped files may have changed, remap them. MoveAndLinkFiles(_localPreferences.LocalAppProfiles[form.NewAppProfile.AppName]); } // Update screen UpdateAppProfileView(); } }