Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Dialog return value avoids mistakes reuse reference #393

Merged
merged 3 commits into from
Sep 4, 2024
Merged
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
24 changes: 12 additions & 12 deletions source/creator/io/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,22 @@ string incShowImportDialog(const(TFD_Filter)[] filters, string title, bool multi
op.multiple = multiple;
auto promise = dpFileChooserOpenFile(getWindowHandle(), title, op);
promise.await();
return promise.uriFromPromise().decode;
return promise.uriFromPromise().decode.dup;
} catch (Throwable ex) {

// FALLBACK: If xdg-desktop-portal is not available then try tinyfiledialogs.
c_str filename = tinyfd_openFileDialog(title.toStringz, "", filters, multiple);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file;
return file.dup;
}
return null;
}
} else {
c_str filename = tinyfd_openFileDialog(title.toStringz, "", filters, multiple);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file;
return file.dup;
}
return null;
}
Expand All @@ -109,19 +109,19 @@ string incShowOpenFolderDialog(string title = "Open...") {
op.directory = true;
auto promise = dpFileChooserOpenFile(getWindowHandle(), title, op);
promise.await();
return promise.uriFromPromise().decode;
return promise.uriFromPromise().decode.dup;
} catch (Throwable _) {

// FALLBACK: If xdg-desktop-portal is not available then try tinyfiledialogs.
c_str filename = tinyfd_selectFolderDialog(title.toStringz, null);
if (filename !is null)
return cast(string) filename.fromStringz;
return cast(string) filename.fromStringz.dup;
return null;
}
} else {
c_str filename = tinyfd_selectFolderDialog(title.toStringz, null);
if (filename !is null)
return cast(string) filename.fromStringz;
return cast(string) filename.fromStringz.dup;
return null;
}
}
Expand All @@ -133,22 +133,22 @@ string incShowOpenDialog(const(TFD_Filter)[] filters, string title = "Open...")
op.filters = tfdToFileFilter(filters);
auto promise = dpFileChooserOpenFile(getWindowHandle(), title, op);
promise.await();
return promise.uriFromPromise().decode;
return promise.uriFromPromise().decode.dup;
} catch (Throwable ex) {

// FALLBACK: If xdg-desktop-portal is not available then try tinyfiledialogs.
c_str filename = tinyfd_openFileDialog(title.toStringz, "", filters, false);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file;
return file.dup;
}
return null;
}
} else {
c_str filename = tinyfd_openFileDialog(title.toStringz, "", filters, false);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file;
return file.dup;
}
return null;
}
Expand All @@ -161,22 +161,22 @@ string incShowSaveDialog(const(TFD_Filter)[] filters, string fname, string title
op.filters = tfdToFileFilter(filters);
auto promise = dpFileChooserSaveFile(getWindowHandle(), title, op);
promise.await();
return promise.uriFromPromise().decode;
return promise.uriFromPromise().decode.dup;
} catch (Throwable ex) {

// FALLBACK: If xdg-desktop-portal is not available then try tinyfiledialogs.
c_str filename = tinyfd_saveFileDialog(title.toStringz, fname.toStringz, filters);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file;
return file.dup;
}
return null;
}
} else {
c_str filename = tinyfd_saveFileDialog(title.toStringz, fname.toStringz, filters);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file;
return file.dup;
}
return null;
}
Expand Down
Loading