mirror of
https://github.com/obsqrbtz/clrsync.git
synced 2026-04-08 20:19:04 +03:00
fix: gtk dialogs freezing
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
namespace clrsync::core
|
namespace clrsync::core
|
||||||
{
|
{
|
||||||
|
|
||||||
const std::string GIT_SEMVER = "0.1.5+git.g0acb364";
|
const std::string GIT_SEMVER = "0.1.5+git.g4c0502d";
|
||||||
|
|
||||||
const std::string version_string();
|
const std::string version_string();
|
||||||
} // namespace clrsync::core
|
} // namespace clrsync::core
|
||||||
|
|||||||
@@ -229,36 +229,38 @@ std::string open_file_dialog(const std::string& title,
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget* dialog = gtk_file_chooser_dialog_new(
|
GtkFileChooserNative *native = gtk_file_chooser_native_new(
|
||||||
title.c_str(),
|
title.c_str(),
|
||||||
nullptr,
|
nullptr,
|
||||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
"Cancel", GTK_RESPONSE_CANCEL,
|
"_Open",
|
||||||
"Open", GTK_RESPONSE_ACCEPT,
|
"_Cancel");
|
||||||
nullptr);
|
|
||||||
|
|
||||||
|
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
|
||||||
|
|
||||||
if (!initial_path.empty()) {
|
if (!initial_path.empty()) {
|
||||||
std::filesystem::path p(initial_path);
|
std::filesystem::path p(initial_path);
|
||||||
if (std::filesystem::exists(p)) {
|
if (std::filesystem::exists(p)) {
|
||||||
if (std::filesystem::is_directory(p)) {
|
if (std::filesystem::is_directory(p)) {
|
||||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), initial_path.c_str());
|
gtk_file_chooser_set_current_folder(chooser, initial_path.c_str());
|
||||||
} else {
|
} else {
|
||||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), p.parent_path().c_str());
|
gtk_file_chooser_set_current_folder(chooser, p.parent_path().c_str());
|
||||||
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), p.filename().c_str());
|
gtk_file_chooser_set_current_name(chooser, p.filename().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(native)) == GTK_RESPONSE_ACCEPT) {
|
||||||
char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
char* filename = gtk_file_chooser_get_filename(chooser);
|
||||||
if (filename) {
|
if (filename) {
|
||||||
result = filename;
|
result = filename;
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_widget_destroy(dialog);
|
g_object_unref(native);
|
||||||
|
while (gtk_events_pending()) gtk_main_iteration();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,34 +271,35 @@ std::string save_file_dialog(const std::string& title,
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget* dialog = gtk_file_chooser_dialog_new(
|
GtkFileChooserNative *native = gtk_file_chooser_native_new(
|
||||||
title.c_str(),
|
title.c_str(),
|
||||||
nullptr,
|
nullptr,
|
||||||
GTK_FILE_CHOOSER_ACTION_SAVE,
|
GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||||
"Cancel", GTK_RESPONSE_CANCEL,
|
"_Save",
|
||||||
"Save", GTK_RESPONSE_ACCEPT,
|
"_Cancel");
|
||||||
nullptr);
|
|
||||||
|
|
||||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
|
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
|
||||||
|
gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
|
||||||
|
|
||||||
if (!initial_path.empty()) {
|
if (!initial_path.empty()) {
|
||||||
std::filesystem::path p(initial_path);
|
std::filesystem::path p(initial_path);
|
||||||
if (std::filesystem::exists(p.parent_path())) {
|
if (std::filesystem::exists(p.parent_path())) {
|
||||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), p.parent_path().c_str());
|
gtk_file_chooser_set_current_folder(chooser, p.parent_path().c_str());
|
||||||
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), p.filename().c_str());
|
gtk_file_chooser_set_current_name(chooser, p.filename().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(native)) == GTK_RESPONSE_ACCEPT) {
|
||||||
char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
char* filename = gtk_file_chooser_get_filename(chooser);
|
||||||
if (filename) {
|
if (filename) {
|
||||||
result = filename;
|
result = filename;
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_widget_destroy(dialog);
|
g_object_unref(native);
|
||||||
|
while (gtk_events_pending()) gtk_main_iteration();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,28 +309,30 @@ std::string select_folder_dialog(const std::string& title,
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget* dialog = gtk_file_chooser_dialog_new(
|
GtkFileChooserNative *native = gtk_file_chooser_native_new(
|
||||||
title.c_str(),
|
title.c_str(),
|
||||||
nullptr,
|
nullptr,
|
||||||
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||||
"Cancel", GTK_RESPONSE_CANCEL,
|
"_Select",
|
||||||
"Select", GTK_RESPONSE_ACCEPT,
|
"_Cancel");
|
||||||
nullptr);
|
|
||||||
|
|
||||||
|
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
|
||||||
|
|
||||||
if (!initial_path.empty() && std::filesystem::exists(initial_path)) {
|
if (!initial_path.empty() && std::filesystem::exists(initial_path)) {
|
||||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), initial_path.c_str());
|
gtk_file_chooser_set_current_folder(chooser, initial_path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(native)) == GTK_RESPONSE_ACCEPT) {
|
||||||
char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
char* filename = gtk_file_chooser_get_filename(chooser);
|
||||||
if (filename) {
|
if (filename) {
|
||||||
result = filename;
|
result = filename;
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_widget_destroy(dialog);
|
g_object_unref(native);
|
||||||
|
while (gtk_events_pending()) gtk_main_iteration();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user