00001 using System.Windows;
00002 using System.Windows.Controls;
00003 using CodePlex.MicrosoftProject.mpFx;
00004 using Microsoft.MCS.Projects.MopsBrowser;
00005
00006 namespace Mcs.Epm.MpFx.Browser.Controls.Login
00007 {
00008
00009
00010
00011 public partial class ProfileManagerWindow
00012 {
00013 private readonly ProjectProfiles _ProjectProfiles;
00014
00015 public ProfileManagerWindow(ProjectProfiles projectProfiles, string startupProfile)
00016 {
00017 InitializeComponent();
00018
00019 _ProjectProfiles = projectProfiles;
00020
00021 addProfileButton.IsEnabled = true;
00022 deleteProfileButton.IsEnabled = false;
00023 saveProfileButton.IsEnabled = false;
00024
00025 _StartProfile = startupProfile;
00026 }
00027
00028 public string ProfileName
00029 {
00030 get
00031 {
00032 if (profileList.SelectedValue == null)
00033 {
00034 return string.Empty;
00035 }
00036 return profileList.SelectedValue.ToString();
00037 }
00038 }
00039
00040 private void profileList_SelectionChanged(object sender, SelectionChangedEventArgs e)
00041 {
00042 if (profileList.SelectedIndex == -1)
00043 {
00044 deleteProfileButton.IsEnabled = false;
00045 saveProfileButton.IsEnabled = false;
00046 }
00047 else
00048 {
00049 ProjectProfiles.ProjectProfile currentProfile =
00050 _ProjectProfiles.FindByName(profileList.SelectedValue.ToString());
00051
00052 if (currentProfile == null)
00053 {
00054 return;
00055 }
00056
00057 if (currentProfile.IsWinProjProfile)
00058 {
00059 deleteProfileButton.IsEnabled = false;
00060 saveProfileButton.IsEnabled = false;
00061
00062 }
00063 else
00064 {
00065 deleteProfileButton.IsEnabled = true;
00066 saveProfileButton.IsEnabled = true;
00067 }
00068
00069 profileNameTextBox.Text = currentProfile.Name;
00070 urtTextBox.Text = currentProfile.Url;
00071 userNameTextBox.Text = currentProfile.UserName;
00072 }
00073 }
00074
00075 private void SaveProfileButton_Loaded(object sender, RoutedEventArgs e)
00076 {
00077 foreach (ProjectProfiles.ProjectProfile profile in _ProjectProfiles.Profiles)
00078 {
00079 profileList.Items.Add(profile.Name);
00080 }
00081
00082 if (string.IsNullOrEmpty(_StartProfile))
00083 {
00084 SelectFirstProfile();
00085 }
00086 else
00087 {
00088 profileList.Items.MoveCurrentTo(_StartProfile);
00089 }
00090 }
00091
00092 private string _StartProfile { get; set; }
00093
00094 private void saveProfileButton_Click(object sender, RoutedEventArgs e)
00095 {
00096 SaveProfile();
00097 }
00098
00099 private bool SaveProfile()
00100 {
00101 ProjectProfiles.ProjectProfile currentProfile = null;
00102
00103 if (profileList.SelectedValue != null)
00104 {
00105 currentProfile = _ProjectProfiles.FindByName(profileList.SelectedValue.ToString());
00106 }
00107
00108 if (currentProfile == null)
00109 {
00110 if (_ProjectProfiles.FindByName(profileNameTextBox.Text) != null)
00111 {
00112 Global.ShowMessageBox(this,
00113 "profileAlreadyExists",
00114 MessageBoxButton.OK,
00115 MessageBoxImage.Error, MessageBoxOptions.None);
00116 return false;
00117 }
00118
00119 currentProfile = new ProjectProfiles.ProjectProfile(profileNameTextBox.Text,
00120 urtTextBox.Text,
00121 userNameTextBox.Text,
00122 false);
00123 _ProjectProfiles.Profiles.Add(currentProfile);
00124 }
00125 else
00126 {
00127 string currentProfileName = profileList.SelectedValue.ToString();
00128
00129 currentProfile.Name = profileNameTextBox.Text;
00130 currentProfile.UserName = userNameTextBox.Text;
00131 currentProfile.Url = urtTextBox.Text;
00132
00133 _ProjectProfiles.Replace(currentProfileName, currentProfile);
00134 profileList.Items.Remove(profileList.SelectedItem);
00135 }
00136
00137 profileList.SelectedIndex = profileList.Items.Add(currentProfile.Name);
00138 return true;
00139 }
00140
00141 private void addProfileButton_Click(object sender, RoutedEventArgs e)
00142 {
00143 profileNameTextBox.Text = string.Empty;
00144 userNameTextBox.Text = string.Empty;
00145 urtTextBox.Text = string.Empty;
00146 profileList.SelectedIndex = -1;
00147 saveProfileButton.IsEnabled = true;
00148 deleteProfileButton.IsEnabled = true;
00149 profileNameTextBox.Focus();
00150 }
00151
00152 private void deleteProfileButton_Click(object sender, RoutedEventArgs e)
00153 {
00154 ProjectProfiles.ProjectProfile currentProfile =
00155 _ProjectProfiles.FindByName(profileList.SelectedValue.ToString());
00156
00157 if (currentProfile != null)
00158 {
00159 _ProjectProfiles.Profiles.Remove(currentProfile);
00160 }
00161
00162 profileList.Items.Remove(profileList.SelectedItem);
00163
00164 SelectFirstProfile();
00165 }
00166
00167 private void SelectFirstProfile()
00168 {
00169 if (profileList.Items.Count > 0)
00170 {
00171 profileList.SelectedIndex = 0;
00172 }
00173 }
00174
00175 private void okButton_Click(object sender, RoutedEventArgs e)
00176 {
00177 if (profileNameTextBox.Text != string.Empty)
00178 {
00179 if (!SaveProfile())
00180 {
00181 return;
00182 }
00183 }
00184
00185 _ProjectProfiles.Save();
00186 DialogResult = true;
00187 Close();
00188 }
00189 }
00190 }