private void RenameProfileButton_Click(object sender, RoutedEventArgs e) { System.Diagnostics.Debug.Assert(this.ProfilesListView.SelectedItem != null); var selectedItem = (this.ProfilesListView.SelectedItem as ProfileItem); string newProfileName = InputWindow.ShowDialog(this, "What is the new profile's name?", "New Profile..."); newProfileName = this.PurifyFileName(newProfileName); if (String.IsNullOrWhiteSpace(newProfileName)) { return; } string newProfilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Profiles", newProfileName); try { if (System.IO.Directory.Exists(newProfilePath)) { MessageBox.Show("Profile \"" + newProfileName + "\" already existed. Try another.", "Failure", MessageBoxButton.OK, MessageBoxImage.Warning); } System.IO.Directory.Move(selectedItem.Directory, newProfilePath); selectedItem.ReplaceFrom(new ProfileItem(new System.IO.DirectoryInfo(newProfilePath))); this.On_ProgProfilesListView_SelectionChanged(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void NewProfileButton_Click(object sender, RoutedEventArgs e) { string newProfileName = InputWindow.ShowDialog(this, "What is the new profile's name?", "New Profile..."); newProfileName = this.PurifyFileName(newProfileName); if (String.IsNullOrWhiteSpace(newProfileName)) { return; } string newProfilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Profiles", newProfileName); try { if (System.IO.Directory.Exists(newProfilePath)) { MessageBox.Show("Profile \"" + newProfileName + "\" already existed. Try another.", "Failure", MessageBoxButton.OK, MessageBoxImage.Warning); } var directoryInfo = System.IO.Directory.CreateDirectory(newProfilePath); this.ProfilesListView.Items.Add(new ProfileItem(directoryInfo)); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void NewProfileButton_Click(object sender, RoutedEventArgs e) { string newProfileName = InputWindow.ShowDialog(this, "请设定一个配置文件名称", "新建配置文件"); newProfileName = this.PurifyFileName(newProfileName); if (String.IsNullOrWhiteSpace(newProfileName)) { return; } string newProfilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Profiles", newProfileName); try { if (System.IO.Directory.Exists(newProfilePath)) { MessageBox.Show("配置文件 \"" + newProfileName + "\" 已存在。 请尝试别的名称。", "失败", MessageBoxButton.OK, MessageBoxImage.Warning); } var directoryInfo = System.IO.Directory.CreateDirectory(newProfilePath); this.ProfilesListView.Items.Add(new ProfileItem(directoryInfo)); } catch (Exception ex) { MessageBox.Show(ex.Message, "严重错误", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static string ShowDialog(Window Owner, string Text, string Caption) { var dialog = new InputWindow() { Owner = Owner, Title = Caption }; dialog.TextBlock.Text = Text; bool result = (bool)dialog.ShowDialog(); return(result ? dialog.TextBox.Text : String.Empty); }