diff --git a/Mirivoice/ViewModels/MainViewModel.cs b/Mirivoice/ViewModels/MainViewModel.cs index 98a4cb5..cbbd0c2 100644 --- a/Mirivoice/ViewModels/MainViewModel.cs +++ b/Mirivoice/ViewModels/MainViewModel.cs @@ -212,32 +212,35 @@ public async Task OnOpenButtonClick() public async Task OpenProject(string path) { - if (File.Exists(path)) + await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(async () => { - Log.Information($"Opening project: {path}"); - var yamlUtf8Bytes = System.Text.Encoding.UTF8.GetBytes(MainManager.Instance.ReadTxtFile(path)); - Mrp mrp = YamlSerializer.Deserialize(yamlUtf8Bytes); - try + if (File.Exists(path)) { - await mrp.Load(this); - project = mrp; - CurrentProjectPath = path; - RecentFiles.AddRecentFile(CurrentProjectPath, this); - OnPropertyChanged(nameof(RecentMenuCollection)); - MainManager.Instance.cmd.ProjectOpened(); - OnPropertyChanged(nameof(Title)); + Log.Information($"Opening project: {path}"); + var yamlUtf8Bytes = System.Text.Encoding.UTF8.GetBytes(MainManager.Instance.ReadTxtFile(path)); + Mrp mrp = YamlSerializer.Deserialize(yamlUtf8Bytes); + try + { + await mrp.Load(this); + project = mrp; + CurrentProjectPath = path; + RecentFiles.AddRecentFile(CurrentProjectPath, this); + OnPropertyChanged(nameof(RecentMenuCollection)); + MainManager.Instance.cmd.ProjectOpened(); + OnPropertyChanged(nameof(Title)); + } + catch (Exception e) + { + Log.Error($"[Failed to load project]{e.ToString}: {e.Message} \n>> traceback: \n\t{e.StackTrace}"); + var res = await ShowConfirmWindow("app.openFailed"); + } + } - catch (Exception e) + else { - Log.Error($"[Failed to load project]{e.ToString}: {e.Message} \n>> traceback: \n\t{e.StackTrace}"); - var res = await ShowConfirmWindow("app.openFailed"); + var res = await ShowConfirmWindow("menu.files.recent.openFailed"); } - - } - else - { - var res = await ShowConfirmWindow("menu.files.recent.openFailed"); - } + }); } public ObservableCollection MResultsCollection { get; set; } = new ObservableCollection(); @@ -594,7 +597,20 @@ public async void OnExportAudioSelectedClick() string path = file.Path.LocalPath; try { - MainManager.Instance.AudioM.PlayAllCacheFiles(1, true, false, System.IO.Path.GetFileNameWithoutExtension(path), System.IO.Path.GetDirectoryName(path), false, true); + int currentLineBoxIndex; + if (CurrentLineBox == null) + { + if (LineBoxCollection.Count == 0) + { + return; + } + return; + } + else + { + currentLineBoxIndex = Int32.Parse(CurrentLineBox.viewModel.LineNo); + } + MainManager.Instance.AudioM.PlayAllCacheFiles(currentLineBoxIndex, true, true, System.IO.Path.GetFileNameWithoutExtension(path), System.IO.Path.GetDirectoryName(path), false, true); } catch (Exception e) {