Skip to content

Commit

Permalink
Add SaveFileDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Sep 6, 2024
1 parent c061a24 commit d03a862
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
20 changes: 20 additions & 0 deletions v2rayN/v2rayN/Common/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,25 @@ public static MessageBoxResult ShowYesNo(string msg)

return true;
}

public static bool? SaveFileDialog(out string fileName, string filter)
{
fileName = string.Empty;

SaveFileDialog fileDialog = new()
{
Filter = filter,
FilterIndex = 2,
RestoreDirectory = true
};
if (fileDialog.ShowDialog() != true)
{
return false;
}

fileName = fileDialog.FileName;

return true;
}
}
}
10 changes: 2 additions & 8 deletions v2rayN/v2rayN/Views/ProfilesView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,11 @@ private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)

case EViewAction.SaveFileDialog:
if (obj is null) return false;
SaveFileDialog fileDialog = new()
{
Filter = "Config|*.json",
FilterIndex = 2,
RestoreDirectory = true
};
if (fileDialog.ShowDialog() != true)
if (UI.SaveFileDialog(out string fileName, "Config|*.json") != true)
{
return false;
}
ViewModel?.Export2ClientConfigResult(fileDialog.FileName, (ProfileItem)obj);
ViewModel?.Export2ClientConfigResult(fileName, (ProfileItem)obj);
break;

case EViewAction.AddServerWindow:
Expand Down

0 comments on commit d03a862

Please sign in to comment.