Fix for issue #278 - continued

Because kdialog can't select multiple directories, run the GTK chooser
when BROWSE_MULTI_DIRECTORY is used.
This commit is contained in:
ManoloFLTK 2021-12-07 12:57:39 +01:00
parent 663b93a807
commit 630517049f
2 changed files with 26 additions and 5 deletions

View File

@ -914,14 +914,14 @@ Fl_Native_File_Chooser::Fl_Native_File_Chooser(int val) {
platform_fnfc = NULL;
if (Fl::option(Fl::OPTION_FNFC_USES_GTK)) {
const char *desktop = getenv("XDG_CURRENT_DESKTOP");
if (desktop && strcmp(desktop, "KDE") == 0) {
if (desktop && strcmp(desktop, "KDE") == 0 && val != BROWSE_MULTI_DIRECTORY) {
if (!Fl_Kdialog_Native_File_Chooser_Driver::have_looked_for_kdialog) {
// First Time here, try to find kdialog
FILE *pipe = popen("kdialog -v 2> /dev/null", "r");
if (pipe) {
char line[100] = "";
fgets(line, sizeof(line), pipe);
if (strlen(line) > 0) Fl_Kdialog_Native_File_Chooser_Driver::did_find_kdialog = true;
char *p, line[100] = "";
p = fgets(line, sizeof(line), pipe);
if (p && strlen(line) > 0) Fl_Kdialog_Native_File_Chooser_Driver::did_find_kdialog = true;
pclose(pipe);
}
Fl_Kdialog_Native_File_Chooser_Driver::have_looked_for_kdialog = true;

View File

@ -51,8 +51,29 @@ int Fl_Kdialog_Native_File_Chooser_Driver::show() {
Fl::flush(); // to close menus if necessary
const char *option;
switch (_btype) {
case Fl_Native_File_Chooser::BROWSE_MULTI_DIRECTORY: {
// BROWSE_MULTI_DIRECTORY is not supported by kdialog, run GTK chooser instead
Fl_Native_File_Chooser fnfc(Fl_Native_File_Chooser::BROWSE_MULTI_DIRECTORY);
fnfc.title( title() );
fnfc.directory(directory());
fnfc.preset_file(preset_file());
fnfc.filter(filter());
fnfc.options(options());
int retval = fnfc.show();
for (int i = 0; i < _tpathnames; i++) delete[] _pathnames[i];
delete[] _pathnames; _pathnames = NULL;
_tpathnames = fnfc.count();
if (_tpathnames && retval == 0) {
_pathnames = new char*[_tpathnames];
for (int i = 0; i < _tpathnames; i++) {
_pathnames[i] = new char[strlen(fnfc.filename(i))+1];
strcpy(_pathnames[i], fnfc.filename(i));
}
}
return retval;
}
break;
case Fl_Native_File_Chooser::BROWSE_DIRECTORY:
case Fl_Native_File_Chooser::BROWSE_MULTI_DIRECTORY: // not supported
option = "--getexistingdirectory";
break;