From 9d8f4b1727297df6ce6240afc09d1a8bb0460280 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 20 Sep 2021 15:01:34 +0800 Subject: [PATCH] Add more features * Support full shortcut. * Fix the crash when open invalid TAS documents. * Support frag file to open. --- BallanceTASEditor/App.xaml.cs | 3 +- BallanceTASEditor/Core/ConfigManager.cs | 1 + BallanceTASEditor/MainWindow.xaml | 50 +++++++++++---- BallanceTASEditor/MainWindow.xaml.cs | 84 ++++++++++++++++++------- BallanceTASEditor/UI/Util.cs | 1 - 5 files changed, 100 insertions(+), 39 deletions(-) diff --git a/BallanceTASEditor/App.xaml.cs b/BallanceTASEditor/App.xaml.cs index 63a8110..7742efa 100644 --- a/BallanceTASEditor/App.xaml.cs +++ b/BallanceTASEditor/App.xaml.cs @@ -31,7 +31,8 @@ namespace BallanceTASEditor { GlobalVariable.configManager = new Core.ConfigManager("ballance-tas-editor.cfg", new Dictionary() { {Core.ConfigManager.CfgNode_Language, CultureInfo.CurrentCulture.ThreeLetterWindowsLanguageName}, {Core.ConfigManager.CfgNode_ItemCount, "15"}, - {Core.ConfigManager.CfgNode_IsHorizonLayout, "True"} + {Core.ConfigManager.CfgNode_IsHorizonLayout, "True"}, + {Core.ConfigManager.CfgNode_IsOverwrittenPaste, "False"} }); // init i18n diff --git a/BallanceTASEditor/Core/ConfigManager.cs b/BallanceTASEditor/Core/ConfigManager.cs index 2b7d382..b4728bb 100644 --- a/BallanceTASEditor/Core/ConfigManager.cs +++ b/BallanceTASEditor/Core/ConfigManager.cs @@ -23,6 +23,7 @@ namespace BallanceTASEditor.Core { public static readonly string CfgNode_Language = "Language"; public static readonly string CfgNode_ItemCount = "ItemCount"; public static readonly string CfgNode_IsHorizonLayout = "IsHorizonLayout"; + public static readonly string CfgNode_IsOverwrittenPaste = "IsOverwrittenPaste"; Dictionary Read() { if (!File.Exists(Path.Combine(Environment.CurrentDirectory, _fileName))) diff --git a/BallanceTASEditor/MainWindow.xaml b/BallanceTASEditor/MainWindow.xaml index fa3fcd8..d0047a2 100644 --- a/BallanceTASEditor/MainWindow.xaml +++ b/BallanceTASEditor/MainWindow.xaml @@ -16,6 +16,10 @@ + + + + @@ -23,6 +27,10 @@ + + + + @@ -30,6 +38,10 @@ + + + + @@ -52,6 +64,7 @@ + @@ -59,9 +72,20 @@ - + + + + + + + + + + + + - + @@ -105,20 +129,20 @@ - - + + - - - - + + + + - - - + + + - - + + diff --git a/BallanceTASEditor/MainWindow.xaml.cs b/BallanceTASEditor/MainWindow.xaml.cs index 06c725f..1984243 100644 --- a/BallanceTASEditor/MainWindow.xaml.cs +++ b/BallanceTASEditor/MainWindow.xaml.cs @@ -40,10 +40,18 @@ namespace BallanceTASEditor { private void funcCommand_Menu_File_Save(object sender, ExecutedRoutedEventArgs e) => funcMenu_File_Save(sender, e); private void funcCommand_Menu_Display_Undo(object sender, ExecutedRoutedEventArgs e) => funcMenu_Display_Undo(sender, e); private void funcCommand_Menu_Display_Redo(object sender, ExecutedRoutedEventArgs e) => funcMenu_Display_Redo(sender, e); + private void funcCommand_DataMenu_Cut(object sender, ExecutedRoutedEventArgs e) => funcDataMenu_Cut(sender, e); + private void funcCommand_DataMenu_Copy(object sender, ExecutedRoutedEventArgs e) => funcDataMenu_Copy(sender, e); + private void funcCommand_DataMenu_DeleteAfter(object sender, ExecutedRoutedEventArgs e) => funcDataMenu_DeleteAfter(sender, e); + private void funcCommand_DataMenu_DeleteBefore(object sender, ExecutedRoutedEventArgs e) => funcDataMenu_DeleteBefore(sender, e); private void funcCanExeCmd_Menu_File_Open(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = uiMenu_File_Open.IsEnabled; private void funcCanExeCmd_Menu_File_Save(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = uiMenu_File_Save.IsEnabled; private void funcCanExeCmd_Menu_Display_Undo(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = uiMenu_Display_Undo.IsEnabled; private void funcCanExeCmd_Menu_Display_Redo(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = uiMenu_Display_Redo.IsEnabled; + private void funcCanExeCmd_DataMenu_Cut(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = mViewer != null && uiDataMenu_Cut.IsEnabled; + private void funcCanExeCmd_DataMenu_Copy(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = mViewer != null && uiDataMenu_Copy.IsEnabled; + private void funcCanExeCmd_DataMenu_DeleteAfter(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = mViewer != null && uiDataMenu_DeleteAfter.IsEnabled; + private void funcCanExeCmd_DataMenu_DeleteBefore(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = mViewer != null && uiDataMenu_DeleteBefore.IsEnabled; // =========================== menu #region window menu @@ -53,23 +61,13 @@ namespace BallanceTASEditor { } private void funcMenu_Help_About(object sender, RoutedEventArgs e) { - MessageBox.Show("Under MIT License\nVersion: 1.0 alpha\nyyc12345.", "Ballance TAS Editor"); + MessageBox.Show("Under MIT License\nVersion: 1.0 beta\nyyc12345.", "Ballance TAS Editor", MessageBoxButton.OK, MessageBoxImage.Information); } private void funcMenu_File_Open(object sender, RoutedEventArgs e) { var file = DialogUtil.OpenFileDialog(); if (file == "") return; - mFile = new TASFile(file); - mViewer = new TASViewer(mFile, mSlider, mFlow); - - mViewer.UpdateDataUI += RefreshDataUI; - mViewer.UpdateSelection += RefreshSelection; - mViewer.UpdateToolMode += RefreshToolMode; - - RefreshUI(true); - - mViewer.ChangeToolMode(ToolMode.Cursor); - mViewer.ChangeOverwrittenMode(uiMenu_Display_OverwrittenPaste.IsChecked); + OpenFile(file); } private void funcMenu_File_Save(object sender, RoutedEventArgs e) { @@ -118,49 +116,49 @@ namespace BallanceTASEditor { #endregion - #region menu operation + #region datamenu operation - private void uiDataMenu_Set_Click(object sender, RoutedEventArgs e) { + private void funcDataMenu_Set(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.Set); } - private void uiDataMenu_Unset_Click(object sender, RoutedEventArgs e) { + private void funcDataMenu_Unset(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.Unset); } - private void uiDataMenu_Cut_Click(object sender, RoutedEventArgs e) { + private void funcDataMenu_Cut(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.Cut); } - private void uiDataMenu_Copy_Click(object sender, RoutedEventArgs e) { + private void funcDataMenu_Copy(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.Copy); } - private void uiDataMenu_PasteAfter_Click(object sender, RoutedEventArgs e) { + private void funcDataMenu_PasteAfter(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.PasteAfter); } - private void uiDataMenu_PasteBefore_Click(object sender, RoutedEventArgs e) { + private void funcDataMenu_PasteBefore(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.PasteBefore); } - private void uiDataMenu_Delete_Click(object sender, RoutedEventArgs e) { + private void funcDataMenu_Delete(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.Delete); } - private void uiDataMenu_DeleteAfter_Click(object sender, RoutedEventArgs e) { + private void funcDataMenu_DeleteAfter(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.DeleteAfter); } - private void uiDataMenu_DeleteBefore_Click(object sender, RoutedEventArgs e) { + private void funcDataMenu_DeleteBefore(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.DeleteBefore); } - private void uiDataMenu_AddAfter_Click(object sender, RoutedEventArgs e) { + private void funcDataMenu_AddAfter(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.AddAfter); } - private void uiDataMenu_AddBefore_Click(object sender, RoutedEventArgs e) { + private void funcDataMenu_AddBefore(object sender, RoutedEventArgs e) { mViewer.ProcessOperation(OperationEnum.AddBefore); } @@ -251,8 +249,46 @@ namespace BallanceTASEditor { } } + // drop file to open + private void funcDrop_Drop(object sender, DragEventArgs e) { + string fileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); + OpenFile(fileName); + } + + private void funcDrop_DragEnter(object sender, DragEventArgs e) { + // only accept one file + if (e.Data.GetDataPresent(DataFormats.FileDrop)) { + var arr = (System.Array)e.Data.GetData(DataFormats.FileDrop); + if (arr.Length != 1) e.Effects = DragDropEffects.None; + else e.Effects = DragDropEffects.Link; + } + else e.Effects = DragDropEffects.None; + } + + #endregion + private void OpenFile(string file) { + try { + mFile = new TASFile(file); + } catch { + MessageBox.Show("Fail to open file. This file might not a legal TAS file.", "Ballance TAS Editor", MessageBoxButton.OK, MessageBoxImage.Error); + mFile = null; + return; + } + + mViewer = new TASViewer(mFile, mSlider, mFlow); + + mViewer.UpdateDataUI += RefreshDataUI; + mViewer.UpdateSelection += RefreshSelection; + mViewer.UpdateToolMode += RefreshToolMode; + + RefreshUI(true); + + mViewer.ChangeToolMode(ToolMode.Cursor); + mViewer.ChangeOverwrittenMode(uiMenu_Display_OverwrittenPaste.IsChecked); + } + private void RefreshToolMode(ToolMode mode) { switch (mode) { case ToolMode.Cursor: diff --git a/BallanceTASEditor/UI/Util.cs b/BallanceTASEditor/UI/Util.cs index ca2aab7..fe713c7 100644 --- a/BallanceTASEditor/UI/Util.cs +++ b/BallanceTASEditor/UI/Util.cs @@ -6,7 +6,6 @@ using System.Text; namespace BallanceTASEditor.UI { - public enum ToolMode { Cursor, Fill,