/// <summary> /// プロファイルリストに追加 /// </summary> /// <param name="pf"></param> /// <param name="index">上書きではない場合、リストのどの位置に追加するか(-1指定で末尾に追加)</param> private void AddToUserProfileList(UserProfileInfo newUserProfileInfo, int index) { if (UserProfileList.Any(pl => pl.RelativePath == newUserProfileInfo.RelativePath)) { // 上書き UserProfileInfo oldProfileInfo = UserProfileList.FirstOrDefault(pl => pl.RelativePath == newUserProfileInfo.RelativePath); if (oldProfileInfo != null) { index = UserProfileList.IndexOf(oldProfileInfo); UserProfileList.RemoveAt(index); UserProfileList.Insert(index, newUserProfileInfo); newUserProfileInfo.SaveProfileToXmlFile(); } } else { // 追加 if (index > -1) { UserProfileList.Insert(index, newUserProfileInfo); } else { UserProfileList.Add(newUserProfileInfo); } newUserProfileInfo.SaveProfileToXmlFile(); } }
private void ProfileList_Delete_Click(object sender, RoutedEventArgs e) { int index = ProfileListBox.SelectedIndex; if (index < 0 || index > ProfileListBox.Items.Count - 1) { return; } UserProfileInfo upi = setting.UserProfileList[index]; MessageBoxResult result = MessageBoxEx.Show(this, "プロファイル「" + upi.Profile.Name + "」を削除してもよろしいですか?", "確認", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { MainWindow.Current.RemoveUserProfileInfo(upi); ProfileListBox.Items.RemoveAt(index); if (index < ProfileListBox.Items.Count - 1) { ProfileListBox.SelectedIndex = index; } else if (ProfileListBox.Items.Count > 0) { ProfileListBox.SelectedIndex = ProfileListBox.Items.Count - 1; } UpdateNumberingItemTextAll(); } }
private void InsertUserProfileInfoToListBox(UserProfileInfo newUpi, int index) { ListBoxItem newItem = new ListBoxItem(); newItem.ToolTip = newUpi.Profile.CreateProfileToolTip(); ToolTipService.SetShowDuration(newItem, 1000000); newItem.Content = newUpi.Profile.Name; ProfileListBox.Items.Insert(index, newItem); UpdateNumberingItemTextAll(); }
public void RemoveUserProfileInfo(UserProfileInfo upi) { Setting.UserProfileList.Remove(upi); string xmlDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName + "\\Profile"; string xmlPath = xmlDir + "\\" + upi.RelativePath; if (File.Exists(xmlPath)) { File.Delete(xmlPath); } }
private void ProfileList_New_Click(object sender, RoutedEventArgs e) { int cntPrev = setting.UserProfileList.Count; MainWindow.Current.ShowProfileEditDialog(ProfileEditDialogMode.New, null); if (setting.UserProfileList.Count > cntPrev) { UserProfileInfo newUpi = setting.UserProfileList[setting.UserProfileList.Count - 1]; InsertUserProfileInfoToListBox(newUpi, ProfileListBox.Items.Count); ProfileListBox.SelectedIndex = ProfileListBox.Items.Count - 1; ProfileListBox.ScrollIntoView(ProfileListBox.Items[ProfileListBox.Items.Count - 1]); } }
private void ProfileList_Copy_Click(object sender, RoutedEventArgs e) { int index = ProfileListBox.SelectedIndex; if (index < 0 || index > ProfileListBox.Items.Count - 1) { return; } UserProfileInfo newUpi = MainWindow.Current.CopyUserProfileInfo(setting.UserProfileList[index]); setting.UserProfileList.Insert(index + 1, newUpi); InsertUserProfileInfoToListBox(newUpi, index + 1); }
private void UpdateListBoxItem(int index) { if (index < 0 || index > setting.UserProfileList.Count - 1) { return; } UserProfileInfo upi = setting.UserProfileList[index]; ListBoxItem newItem = new ListBoxItem(); newItem.ToolTip = upi.Profile.CreateProfileToolTip(); ToolTipService.SetShowDuration(newItem, 1000000); newItem.Content = CreateNumberingItemText(index + 1, upi.Profile.Name); ProfileListBox.Items[index] = newItem; }
public void ShowProfileEditDialog(ProfileEditDialogMode mode, UserProfileInfo targetUseProfileInfo) { if (ProfileEditDialog == null) { ProfileEditDialog = new ProfileEditDialog(); ProfileEditDialog.Owner = this; } ProfileEditDialog.Mode = mode; ProfileEditDialog.UserProfileList = Setting.UserProfileList; // 表示前にメインウインドウのウインドウ情報、ページ情報保存 UpdateTempProfile(); // モードに依る挙動 string message = ""; if (mode == ProfileEditDialogMode.New || targetUseProfileInfo == null) { ProfileEditDialog.Title = "プロファイルの作成"; message = "現在の状態・設定をプロファイルとして保存することが出来ます。\r\nプロファイルに含める項目にチェックを入れて下さい。"; ProfileEditDialog.SetControlValue(Setting.TempProfile); } else if (mode == ProfileEditDialogMode.Edit) { ProfileEditDialog.Title = "プロファイルの編集 (" + targetUseProfileInfo.Profile.Name + ")"; message = null; ProfileEditDialog.EditingUserProfileInfo = targetUseProfileInfo; // コントロールの値は、TempProfileに統合したものを表示 Profile pf = Setting.TempProfile.Clone().Marge(targetUseProfileInfo.Profile); pf.Name = targetUseProfileInfo.Profile.Name; ProfileEditDialog.SetControlValue(pf); } ProfileEditDialog.Label_Message.Content = message; // 初期位置は、メインウインドウの中心に Util.SetWindowCenterOnWindow(this, ProfileEditDialog); // プロファイル編集ダイアログ表示 ProfileEditDialog.ShowDialog(); ProfileEditDialog.MainScrollViewer.ScrollToTop(); }
private void ProfileList_Down_Click(object sender, RoutedEventArgs e) { int index = ProfileListBox.SelectedIndex; if (index >= ProfileListBox.Items.Count - 1 || index < 0) { return; } UserProfileInfo upi = setting.UserProfileList[index]; setting.UserProfileList.RemoveAt(index); setting.UserProfileList.Insert(index + 1, upi); ListBoxItem lbi = ProfileListBox.Items[index] as ListBoxItem; ProfileListBox.Items.RemoveAt(index); ProfileListBox.Items.Insert(index + 1, lbi); ProfileListBox.SelectedIndex = index + 1; UpdateNumberingItemTextAll(); }
public UserProfileInfo CopyUserProfileInfo(UserProfileInfo upi) { string xmlDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName + "\\Profile"; // コピー先の相対パスを決める string srcRelativePathWithoutExt = System.IO.Path.GetFileNameWithoutExtension(upi.RelativePath); string newRelativePath = srcRelativePathWithoutExt + "_コピー.xml"; int cnt = 2; while (File.Exists(xmlDir + "\\" + newRelativePath)) { newRelativePath = srcRelativePathWithoutExt + "_コピー(" + cnt + ").xml"; cnt++; if (cnt >= int.MaxValue) { return(null); } } // Profileのコピー Profile newProfile = upi.Profile.Clone(); string newProfileName = System.IO.Path.GetFileName(newRelativePath); newProfileName = System.IO.Path.GetFileNameWithoutExtension(newProfileName); newProfile.Name = newProfileName; // UserProfileInfoのコピー UserProfileInfo newUpi = new UserProfileInfo(newRelativePath); newUpi.Profile = newProfile; // Profileのコピーをxmlに保存 newUpi.SaveProfileToXmlFile(); return(newUpi); }
private void Footer_OK_Click(object sender, RoutedEventArgs e) { // 1つ以上チェックが入っているか if (this.Descendants <CheckBox>().ToList().All(x => !(bool)x.IsChecked)) { MessageBoxEx.Show(this, "プロファイルを作成するには、1つ以上の項目にチェックを入れて下さい", "エラー", MessageBoxButton.OK, MessageBoxImage.Warning); return; } // ファイル名に使用できない文字をアンダーバーに書き換え Footer_ProfileName.Text = Util.ValidFileName(Footer_ProfileName.Text); Profile newProfile = CreateProfile(); UserProfileInfo newUserProfileInfo = new UserProfileInfo(newProfile.Name + ".xml"); newUserProfileInfo.Profile = newProfile; // プロファイル名重複確認 bool conflict = false; if (UserProfileList.Any(pl => pl.RelativePath == newUserProfileInfo.RelativePath)) { switch (Mode) { case ProfileEditDialogMode.New: conflict = true; break; case ProfileEditDialogMode.Edit: if (EditingUserProfileInfo.RelativePath == newUserProfileInfo.RelativePath) { conflict = false; } else { conflict = true; } break; } } if (conflict) { MessageBoxResult result = MessageBoxEx.Show(this, "プロファイル名「" + newProfile.Name + "」は既に存在しています。上書きしてよろしいですか?", "上書き確認", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.No) { return; } } // プロファイル追加or上書き if (Mode == ProfileEditDialogMode.New) { AddToUserProfileList(newUserProfileInfo, -1); } else if (Mode == ProfileEditDialogMode.Edit) { // 編集前のプロファイルを削除 int editingProfileIndex = UserProfileList.IndexOf(EditingUserProfileInfo); MainWindow.Current.RemoveUserProfileInfo(EditingUserProfileInfo); AddToUserProfileList(newUserProfileInfo, editingProfileIndex); } this.Close(); }
// プロファイルメニュー内、コンテキストメニュー作成 private ContextMenu CreateProfileContextMenu(UserProfileInfo upi) { ContextMenu contextMenu = new ContextMenu(); MenuItem cmi1 = new MenuItem(); MenuItem cmi2 = new MenuItem(); MenuItem cmi3 = new MenuItem(); MenuItem cmi4 = new MenuItem(); MenuItem cmi5 = new MenuItem(); Separator sep1 = new Separator(); cmi1.Header = "編集"; cmi2.Header = "コピー"; cmi3.Header = "削除"; cmi4.Header = "上へ"; cmi5.Header = "下へ"; Action updateMenu = () => { MenuItem_Profile_SubmenuOpened(this, new RoutedEventArgs(null, MenuItem_Profile)); }; // 編集 cmi1.Click += (se, ev) => { MenuItem mi = ((ev.Source as MenuItem).Parent as ContextMenu).PlacementTarget as MenuItem; if (mi == null) { return; } ShowProfileEditDialog(ProfileEditDialogMode.Edit, upi); }; // コピー cmi2.Click += (se, ev) => { MenuItem mi = ((ev.Source as MenuItem).Parent as ContextMenu).PlacementTarget as MenuItem; if (mi == null) { return; } int idx = Setting.UserProfileList.IndexOf(upi); UserProfileInfo newUpi = CopyUserProfileInfo(upi); Setting.UserProfileList.Insert(idx + 1, newUpi); MenuItem_Profile.IsSubmenuOpen = false; MenuItem_Profile.IsSubmenuOpen = true; }; // 削除 cmi3.Click += (se, ev) => { MenuItem mi = ((ev.Source as MenuItem).Parent as ContextMenu).PlacementTarget as MenuItem; if (mi == null) { return; } MessageBoxResult result = MessageBoxEx.Show(this, "プロファイル「" + upi.Profile.Name + "」を削除してもよろしいですか?", "確認", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { RemoveUserProfileInfo(upi); } ToolbarWrapper.Visibility = Visibility.Visible; MenuItem_Profile.IsSubmenuOpen = true; }; // 上へ cmi4.Click += (se, ev) => { MenuItem mi = ((ev.Source as MenuItem).Parent as ContextMenu).PlacementTarget as MenuItem; if (mi == null) { return; } int index = Setting.UserProfileList.IndexOf(upi); if (index <= 0) { return; } Setting.UserProfileList.RemoveAt(index); Setting.UserProfileList.Insert(index - 1, upi); updateMenu.Invoke(); }; // 下へ cmi5.Click += (se, ev) => { MenuItem mi = ((ev.Source as MenuItem).Parent as ContextMenu).PlacementTarget as MenuItem; if (mi == null) { return; } int index = Setting.UserProfileList.IndexOf(upi); if (index == Setting.UserProfileList.Count - 1) { return; } Setting.UserProfileList.RemoveAt(index); Setting.UserProfileList.Insert(index + 1, upi); updateMenu.Invoke(); }; contextMenu.Items.Add(cmi1); contextMenu.Items.Add(cmi2); contextMenu.Items.Add(cmi3); contextMenu.Items.Add(sep1); contextMenu.Items.Add(cmi4); contextMenu.Items.Add(cmi5); return(contextMenu); }
// プロファイルメニュー開いた時 private void MenuItem_Profile_SubmenuOpened(object sender, RoutedEventArgs e) { // Xmlからプロファイルをロード string xmlDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName + "\\Profile"; if (Directory.Exists(xmlDir)) { string[] xmls = Directory.GetFiles(xmlDir); foreach (string xml in xmls) { if (System.IO.Path.GetExtension(xml) == ".xml") { // UserProfileListにあるなら、メンバとしてプロファイルを追加、ないなら新たにUserProfileInfoを作成して追加 string relativePath = xml.Replace(xmlDir + "\\", ""); UserProfileInfo upi = Setting.UserProfileList.FirstOrDefault(pl => pl.RelativePath == relativePath); if (upi != null) { if (upi.Profile == null) { Profile pf = UserProfileInfo.LoadProfileFromXmlFile(xml); upi.Profile = pf; } } else { UserProfileInfo newUpi = new UserProfileInfo(relativePath); Profile pf = UserProfileInfo.LoadProfileFromXmlFile(xml); newUpi.Profile = pf; Setting.UserProfileList.Add(newUpi); } } } } // xmlファイルからロード出来なかった、UserProfileInfoを全て削除 Setting.UserProfileList.RemoveAll(pl => pl.Profile == null); // イベントの発生元チェック(子要素からのイベントなら無視) MenuItem miSrc = e.OriginalSource as MenuItem; if (miSrc == null || miSrc.Name != MenuItem_Profile.Name) { return; } // プロファイル追加前に削除 const int basicManuCnt = 1; while (MenuItem_Profile.Items.Count > basicManuCnt) { MenuItem_Profile.Items.RemoveAt(basicManuCnt); } // プリセットプロファイル追加 if (Setting.UsePresetProfile) { MenuItem_Profile.Items.Add(new Separator()); foreach (Profile ppf in PresetProfile.Items) { MenuItem mi = new MenuItem(); mi.Header = ppf.Name; if (ppf.Name == "デフォルト") { mi.ToolTip = "デフォルト"; } else { mi.ToolTip = ppf.CreateProfileToolTip(); } ToolTipService.SetShowDuration(mi, 1000000); mi.Click += (se, ev) => { LoadUserProfile(ppf); }; MenuItem_Profile.Items.Add(mi); } } // セパレータ追加 if (Setting.UserProfileList.Count > 0) { MenuItem_Profile.Items.Add(new Separator()); } // プロファイル追加 int num = 1; foreach (UserProfileInfo upi in Setting.UserProfileList) { MenuItem mi = new MenuItem(); mi.Header = string.Format("{0:00}", num) + ": " + upi.Profile.Name.Replace("_", "__"); mi.ToolTip = upi.Profile.CreateProfileToolTip(); ToolTipService.SetShowDuration(mi, 1000000); mi.Click += (se, ev) => { LoadUserProfile(upi.Profile); }; mi.ContextMenu = CreateProfileContextMenu(upi); MenuItem_Profile.Items.Add(mi); num++; } // リストを編集... を追加 MenuItem_Profile.Items.Add(new Separator()); MenuItem ms = new MenuItem(); ms.Header = "リストを編集..."; ms.Click += (se, ev) => { ShowProfileListEditDialog(); }; MenuItem_Profile.Items.Add(ms); }