ProfileDialog.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Gtk;
  2. using System;
  3. using GUI = Gtk.Builder.ObjectAttribute;
  4. namespace Ryujinx.Ui.Widgets
  5. {
  6. public class ProfileDialog : Dialog
  7. {
  8. public string FileName { get; private set; }
  9. #pragma warning disable CS0649, IDE0044
  10. [GUI] Entry _profileEntry;
  11. [GUI] Label _errorMessage;
  12. #pragma warning restore CS0649, IDE0044
  13. public ProfileDialog() : this(new Builder("Ryujinx.Ui.Widgets.ProfileDialog.glade")) { }
  14. private ProfileDialog(Builder builder) : base(builder.GetObject("_profileDialog").Handle)
  15. {
  16. builder.Autoconnect(this);
  17. }
  18. private void OkToggle_Activated(object sender, EventArgs args)
  19. {
  20. ((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true);
  21. bool validFileName = true;
  22. foreach (char invalidChar in System.IO.Path.GetInvalidFileNameChars())
  23. {
  24. if (_profileEntry.Text.Contains(invalidChar))
  25. {
  26. validFileName = false;
  27. }
  28. }
  29. if (validFileName && !string.IsNullOrEmpty(_profileEntry.Text))
  30. {
  31. FileName = $"{_profileEntry.Text}.json";
  32. Respond(ResponseType.Ok);
  33. }
  34. else
  35. {
  36. _errorMessage.Text = "The file name contains invalid characters. Please try again.";
  37. }
  38. }
  39. private void CancelToggle_Activated(object sender, EventArgs args)
  40. {
  41. Respond(ResponseType.Cancel);
  42. }
  43. }
  44. }