Skip to content

Commit 6a1834d

Browse files
committed
Gtk.Application.Quit not needed
1 parent 36ab371 commit 6a1834d

File tree

5 files changed

+78
-119
lines changed

5 files changed

+78
-119
lines changed

AssetRipper.NativeDialogs/ConfirmationDialog.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,23 @@ public Options(string message, Type type = Type.OkCancel)
116116
if (Gtk.Global.IsSupported)
117117
{
118118
bool? result;
119-
Gtk.Application.Init(); // spins a main loop
120-
try
121-
{
122-
using Gtk.MessageDialog md = new(
123-
null,
124-
Gtk.DialogFlags.Modal,
125-
Gtk.MessageType.Info,
126-
options.Type == Type.OkCancel ? Gtk.ButtonsType.OkCancel : Gtk.ButtonsType.YesNo,
127-
options.Message
128-
);
129-
int response = md.Run();
130-
result = response switch
131-
{
132-
(int)Gtk.ResponseType.Ok or (int)Gtk.ResponseType.Yes => true,
133-
(int)Gtk.ResponseType.Cancel or (int)Gtk.ResponseType.No => false,
134-
_ => throw new($"Unexpected response type: {response}"),
135-
};
136-
}
137-
finally
119+
Gtk.Application.Init();
120+
121+
using Gtk.MessageDialog md = new(
122+
null,
123+
Gtk.DialogFlags.Modal,
124+
Gtk.MessageType.Info,
125+
options.Type == Type.OkCancel ? Gtk.ButtonsType.OkCancel : Gtk.ButtonsType.YesNo,
126+
options.Message
127+
);
128+
129+
int response = md.Run();
130+
result = response switch
138131
{
139-
//Gtk.Application.Quit(); // stops the main loop
140-
}
132+
(int)Gtk.ResponseType.Ok or (int)Gtk.ResponseType.Yes => true,
133+
(int)Gtk.ResponseType.Cancel or (int)Gtk.ResponseType.No => false,
134+
_ => throw new($"Unexpected response type: {response}"),
135+
};
141136

142137
return Task.FromResult(result);
143138
}

AssetRipper.NativeDialogs/MessageDialog.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,16 @@ private static Task MessageLinux(Options options)
8383
{
8484
if (Gtk.Global.IsSupported)
8585
{
86-
Gtk.Application.Init(); // spins a main loop
87-
try
88-
{
89-
using Gtk.MessageDialog md = new(
90-
null,
91-
Gtk.DialogFlags.Modal,
92-
Gtk.MessageType.Info,
93-
Gtk.ButtonsType.Ok,
94-
options.Message
95-
);
96-
md.Run();
97-
}
98-
finally
99-
{
100-
//Gtk.Application.Quit(); // stops the main loop
101-
}
86+
Gtk.Application.Init();
87+
88+
using Gtk.MessageDialog md = new(
89+
null,
90+
Gtk.DialogFlags.Modal,
91+
Gtk.MessageType.Info,
92+
Gtk.ButtonsType.Ok,
93+
options.Message
94+
);
95+
md.Run();
10296

10397
return Task.CompletedTask;
10498
}

AssetRipper.NativeDialogs/OpenFileDialog.cs

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,19 @@ public static class OpenFileDialog
7474
if (Gtk.Global.IsSupported)
7575
{
7676
string? result;
77-
Gtk.Application.Init(); // spins a main loop
78-
try
79-
{
80-
using Gtk.FileChooserNative dlg = new(
81-
"Open a file", null,
82-
Gtk.FileChooserAction.Open, "Open", "Cancel");
77+
Gtk.Application.Init();
8378

84-
if (dlg.Run() == (int)Gtk.ResponseType.Accept)
85-
{
86-
result = dlg.Filename;
87-
}
88-
else
89-
{
90-
result = null; // User canceled the dialog
91-
}
79+
using Gtk.FileChooserNative dlg = new(
80+
"Open a file", null,
81+
Gtk.FileChooserAction.Open, "Open", "Cancel");
82+
83+
if (dlg.Run() == (int)Gtk.ResponseType.Accept)
84+
{
85+
result = dlg.Filename;
9286
}
93-
finally
87+
else
9488
{
95-
//Gtk.Application.Quit(); // stops the main loop
89+
result = null; // User canceled the dialog
9690
}
9791

9892
return Task.FromResult(result);
@@ -203,27 +197,21 @@ public static class OpenFileDialog
203197
if (Gtk.Global.IsSupported)
204198
{
205199
string[]? result;
206-
Gtk.Application.Init(); // spins a main loop
207-
try
208-
{
209-
using Gtk.FileChooserNative dlg = new(
210-
"Open files", null,
211-
Gtk.FileChooserAction.Open, "Open", "Cancel");
200+
Gtk.Application.Init();
212201

213-
dlg.SelectMultiple = true; // Allow multiple folder selection
202+
using Gtk.FileChooserNative dlg = new(
203+
"Open files", null,
204+
Gtk.FileChooserAction.Open, "Open", "Cancel");
214205

215-
if (dlg.Run() == (int)Gtk.ResponseType.Accept)
216-
{
217-
result = dlg.Filenames;
218-
}
219-
else
220-
{
221-
result = null; // User canceled the dialog
222-
}
206+
dlg.SelectMultiple = true; // Allow multiple folder selection
207+
208+
if (dlg.Run() == (int)Gtk.ResponseType.Accept)
209+
{
210+
result = dlg.Filenames;
223211
}
224-
finally
212+
else
225213
{
226-
//Gtk.Application.Quit(); // stops the main loop
214+
result = null; // User canceled the dialog
227215
}
228216

229217
return Task.FromResult(result);

AssetRipper.NativeDialogs/OpenFolderDialog.cs

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,19 @@ public static class OpenFolderDialog
123123
if (Gtk.Global.IsSupported)
124124
{
125125
string? result;
126-
Gtk.Application.Init(); // spins a main loop
127-
try
128-
{
129-
using Gtk.FileChooserNative dlg = new(
130-
"Open a folder", null,
131-
Gtk.FileChooserAction.SelectFolder, "Open", "Cancel");
126+
Gtk.Application.Init();
132127

133-
if (dlg.Run() == (int)Gtk.ResponseType.Accept)
134-
{
135-
result = dlg.Filename;
136-
}
137-
else
138-
{
139-
result = null; // User canceled the dialog
140-
}
128+
using Gtk.FileChooserNative dlg = new(
129+
"Open a folder", null,
130+
Gtk.FileChooserAction.SelectFolder, "Open", "Cancel");
131+
132+
if (dlg.Run() == (int)Gtk.ResponseType.Accept)
133+
{
134+
result = dlg.Filename;
141135
}
142-
finally
136+
else
143137
{
144-
//Gtk.Application.Quit(); // stops the main loop
138+
result = null; // User canceled the dialog
145139
}
146140

147141
return Task.FromResult(result);
@@ -212,27 +206,21 @@ public static class OpenFolderDialog
212206
if (Gtk.Global.IsSupported)
213207
{
214208
string[]? result;
215-
Gtk.Application.Init(); // spins a main loop
216-
try
217-
{
218-
using Gtk.FileChooserNative dlg = new(
219-
"Open folders", null,
220-
Gtk.FileChooserAction.SelectFolder, "Open", "Cancel");
209+
Gtk.Application.Init();
221210

222-
dlg.SelectMultiple = true; // Allow multiple folder selection
211+
using Gtk.FileChooserNative dlg = new(
212+
"Open folders", null,
213+
Gtk.FileChooserAction.SelectFolder, "Open", "Cancel");
223214

224-
if (dlg.Run() == (int)Gtk.ResponseType.Accept)
225-
{
226-
result = dlg.Filenames;
227-
}
228-
else
229-
{
230-
result = null; // User canceled the dialog
231-
}
215+
dlg.SelectMultiple = true; // Allow multiple folder selection
216+
217+
if (dlg.Run() == (int)Gtk.ResponseType.Accept)
218+
{
219+
result = dlg.Filenames;
232220
}
233-
finally
221+
else
234222
{
235-
//Gtk.Application.Quit(); // stops the main loop
223+
result = null; // User canceled the dialog
236224
}
237225

238226
return Task.FromResult(result);

AssetRipper.NativeDialogs/SaveFileDialog.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,19 @@ public static class SaveFileDialog
7676
if (Gtk.Global.IsSupported)
7777
{
7878
string? result;
79-
Gtk.Application.Init(); // spins a main loop
80-
try
81-
{
82-
using Gtk.FileChooserNative dlg = new(
83-
"Save a file", null,
84-
Gtk.FileChooserAction.Save, "Save", "Cancel");
79+
Gtk.Application.Init();
8580

86-
if (dlg.Run() == (int)Gtk.ResponseType.Accept)
87-
{
88-
result = dlg.File?.Path;
89-
}
90-
else
91-
{
92-
result = null; // User canceled the dialog
93-
}
81+
using Gtk.FileChooserNative dlg = new(
82+
"Save a file", null,
83+
Gtk.FileChooserAction.Save, "Save", "Cancel");
84+
85+
if (dlg.Run() == (int)Gtk.ResponseType.Accept)
86+
{
87+
result = dlg.File?.Path;
9488
}
95-
finally
89+
else
9690
{
97-
//Gtk.Application.Quit(); // stops the main loop
91+
result = null; // User canceled the dialog
9892
}
9993

10094
return Task.FromResult(result);

0 commit comments

Comments
 (0)