Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ OpenUtau aims to be an open source editing environment for UTAU community, with
<system:String x:Key="dialogs.voicecolorremapping">Voice color remapping</system:String>
<system:String x:Key="dialogs.voicecolorremapping.error">This singer has no voice color</system:String>
<system:String x:Key="dialogs.voicecolorremapping.caption">Applies to all notes in this track:</system:String>
<system:String x:Key="dialogs.projectimport.caption">Project Import</system:String>
<system:String x:Key="dialogs.projectimport.message">Files to import:</system:String>
<system:String x:Key="dialogs.projectimport.asproject">Import as Project</system:String>
<system:String x:Key="dialogs.projectimport.astracks">Import as Tracks</system:String>

<system:String x:Key="errors.caption">Error</system:String>
<system:String x:Key="errors.details">Error Details</system:String>
Expand Down
97 changes: 76 additions & 21 deletions OpenUtau/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -885,29 +885,83 @@ async void OnDrop(object? sender, DragEventArgs args) {
//If multiple project/audio files are dropped, open/import them all.
if (ProjectExts.Contains(FirstExt) || AudioExts.Contains(FirstExt)) {
var projectFiles = supportedFiles.Where(file => ProjectExts.Contains(Path.GetExtension(file).ToLower())).ToArray();
viewModel.Page = 1;
if (projectFiles.Length > 0) {
try {
var loadedProjects = Formats.ReadProjects(files);
// Imports tempo for new projects, otherwise asks the user.
bool importTempo = DocManager.Inst.Project.parts.Count == 0;
if (!importTempo && loadedProjects[0].tempos.Count > 0) {
var tempoString = string.Join("\n",
loadedProjects[0].tempos
.Select(tempo => $"position: {tempo.position}, tempo: {tempo.bpm}")
);
// Ask the user
var result = await MessageBox.Show(
this,
ThemeManager.GetString("dialogs.importtracks.importtempo") + "\n" + tempoString,
ThemeManager.GetString("dialogs.importtracks.caption"),
MessageBox.MessageBoxButtons.YesNo);
importTempo = result == MessageBox.MessageBoxResult.Yes;
bool openAsProject = true;

if (viewModel.Page == 1) {
bool cancelled = true;
var openAs = new MessageBox() {
Title = ThemeManager.GetString("dialogs.projectimport.caption"),
Text = {
Text = $"{ThemeManager.GetString("dialogs.projectimport.message")}\n{string.Join("\n", projectFiles)}"
}
};

var btnAsProject = new Button() {
Content = ThemeManager.GetString("dialogs.projectimport.asproject")
};
btnAsProject.Click += async (s, e) => {
await AskIfSaveAndContinue();
cancelled = false;
openAsProject = true;
openAs.Close();
};
openAs.Buttons.Children.Add(btnAsProject);

var btnAsTracks = new Button() {
Content = ThemeManager.GetString("dialogs.projectimport.astracks")
};
btnAsTracks.Click += (s, e) => {
cancelled = false;
openAsProject = false;
openAs.Close();
};
openAs.Buttons.Children.Add(btnAsTracks);

var tcs = new TaskCompletionSource();
openAs.Closed += delegate {
if (cancelled) {
return;
}
tcs.SetResult();
};
openAs.Show();

await tcs.Task;
}

if (openAsProject) {
try {
viewModel.OpenProject(projectFiles);
} catch (Exception e) {
Log.Error(e, $"Failed to open files {string.Join("\n", projectFiles)}");
_ = await MessageBox.ShowError(this,
new MessageCustomizableException($"Failed to open files {string.Join("\n", projectFiles)}",
$"<translate:errors.failed.openfile>:\n{string.Join("\n", projectFiles)}", e));
}
} else {
try {
var loadedProjects = Formats.ReadProjects(projectFiles);
// Imports tempo for new projects, otherwise asks the user.
bool importTempo = DocManager.Inst.Project.parts.Count == 0;
if (!importTempo && loadedProjects[0].tempos.Count > 0) {
var tempoString = string.Join("\n",
loadedProjects[0].tempos
.Select(tempo => $"position: {tempo.position}, tempo: {tempo.bpm}")
);
// Ask the user
var result = await MessageBox.Show(
this,
ThemeManager.GetString("dialogs.importtracks.importtempo") + "\n" + tempoString,
ThemeManager.GetString("dialogs.importtracks.caption"),
MessageBox.MessageBoxButtons.YesNo);
importTempo = result == MessageBox.MessageBoxResult.Yes;
}
viewModel.ImportTracks(loadedProjects, importTempo);
} catch (Exception e) {
Log.Error(e, "Failed to import project");
_ = await MessageBox.ShowError(this, new MessageCustomizableException("Failed to import files", "<translate:errors.failed.importfiles>", e));
}
viewModel.ImportTracks(loadedProjects, importTempo);
} catch (Exception e) {
Log.Error(e, "Failed to import project");
_ = await MessageBox.ShowError(this, new MessageCustomizableException("Failed to import files", "<translate:errors.failed.importfiles>", e));
}
}
var audioFiles = supportedFiles.Where(file => AudioExts.Contains(Path.GetExtension(file).ToLower())).ToArray();
Expand All @@ -919,6 +973,7 @@ async void OnDrop(object? sender, DragEventArgs args) {
_ = await MessageBox.ShowError(this, new MessageCustomizableException("Failed to import audio", "<translate:errors.failed.importaudio>", e));
}
}
viewModel.Page = 1;
return;
}
// Otherwise, only one installer file is handled at a time.
Expand Down
Loading