From 41f37613ec6a14fb8b3357e2dc0323116bf8439b Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Tue, 13 Dec 2022 18:37:48 +0100 Subject: =?UTF-8?q?Derive=20Fl=5FZenity=5FNative=5FFile=5FChooser=5FDriver?= =?UTF-8?q?=20from=20Fl=5FKdialog=5FNative=5F=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add Fl::option(OPTION_FNFC_USES_ZENITY) --- src/Fl_Native_File_Chooser_Kdialog.cxx | 54 +++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'src/Fl_Native_File_Chooser_Kdialog.cxx') diff --git a/src/Fl_Native_File_Chooser_Kdialog.cxx b/src/Fl_Native_File_Chooser_Kdialog.cxx index 3e86b021e..b61bed43e 100644 --- a/src/Fl_Native_File_Chooser_Kdialog.cxx +++ b/src/Fl_Native_File_Chooser_Kdialog.cxx @@ -67,31 +67,9 @@ static int fnfc_dispatch(int /*event*/, Fl_Window* /*win*/) { } -int Fl_Kdialog_Native_File_Chooser_Driver::show() { +char *Fl_Kdialog_Native_File_Chooser_Driver::build_command() { 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: option = "--getexistingdirectory"; break; @@ -126,6 +104,34 @@ int Fl_Kdialog_Native_File_Chooser_Driver::show() { " \"%s\" ", _parsedfilt); } strcat(command, "2> /dev/null"); // get rid of stderr output + return command; +} + + +int Fl_Kdialog_Native_File_Chooser_Driver::show() { + if (_btype == 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; + } + + char *command = build_command(); //puts(command); FILE *pipe = popen(command, "r"); fnfc_pipe_struct data; @@ -243,7 +249,7 @@ void Fl_Kdialog_Native_File_Chooser_Driver::filter(const char *f) { while (part) { char *p = parse_filter(part); _parsedfilt = strapp(_parsedfilt, p); - _parsedfilt = strapp(_parsedfilt, "\\n"); + _parsedfilt = strapp(_parsedfilt, "\n"); delete[] p; _nfilters++; part = strtok_r(NULL, "\n", &ptr); -- cgit v1.2.3