kopia lustrzana https://github.com/jamescoxon/dl-fldigi
file-chooser
* Update to Native File Chooser usage.
* Passes corrected parameters ... OS X very pedantic on
parameter format
pull/2/head
rodzic
990492bf50
commit
25fcf8d1b5
|
|
@ -5,7 +5,6 @@ src/main.cxx
|
|||
src/dialogs/fl_digi.cxx
|
||||
src/dialogs/font_browser.cxx
|
||||
src/dialogs/Viewer.cxx
|
||||
src/fileselector/FL/Fl_Native_File_Chooser_FLTK.H
|
||||
src/globals/globals.cxx
|
||||
src/logbook/adif_io.cxx
|
||||
src/logbook/logbook.cxx
|
||||
|
|
|
|||
4533
po/fldigi.pot
4533
po/fldigi.pot
Plik diff jest za duży
Load Diff
|
|
@ -264,8 +264,8 @@ fldigi_SOURCES += \
|
|||
feld/feld.cxx \
|
||||
feld/feldfonts.cxx \
|
||||
fft/fft.cxx \
|
||||
fileselector/FL/Fl_Native_File_Chooser.H \
|
||||
fileselector/Fl_Native_File_Chooser.cxx \
|
||||
fileselector/FL/Native_File_Chooser.H \
|
||||
fileselector/Native_File_Chooser.cxx \
|
||||
fileselector/fileselect.cxx \
|
||||
filters/fftfilt.cxx \
|
||||
filters/filters.cxx \
|
||||
|
|
@ -544,12 +544,12 @@ fldigi_SOURCES += \
|
|||
EXTRA_fldigi_SOURCES += \
|
||||
blank/blank.cxx \
|
||||
blank/blank.h \
|
||||
fileselector/FL/Fl_Native_File_Chooser_FLTK.H \
|
||||
fileselector/FL/MAC_chooser.h \
|
||||
fileselector/FL/Fl_Native_File_Chooser_WIN32.H \
|
||||
fileselector/Fl_Native_File_Chooser_FLTK.cxx \
|
||||
fileselector/MAC_chooser.cxx \
|
||||
fileselector/Fl_Native_File_Chooser_WIN32.cxx \
|
||||
fileselector/FL/Native_File_Chooser_FLTK.H \
|
||||
fileselector/FL/Native_File_Chooser_MAC.H \
|
||||
fileselector/FL/Native_File_Chooser_WIN32.H \
|
||||
fileselector/Native_File_Chooser_FLTK.cxx \
|
||||
fileselector/Native_File_Chooser_WIN32.cxx \
|
||||
fileselector/Native_File_Chooser_MAC.cxx \
|
||||
fileselector/flnfc_common.cxx \
|
||||
fileselector/fileselect_1_1.cxx \
|
||||
fileselector/fileselect_1_3.cxx \
|
||||
|
|
@ -622,8 +622,8 @@ flarq_SOURCES += \
|
|||
include/table.h \
|
||||
include/util.h \
|
||||
combo/combo.cxx \
|
||||
fileselector/FL/Fl_Native_File_Chooser.H \
|
||||
fileselector/Fl_Native_File_Chooser.cxx \
|
||||
fileselector/FL/Native_File_Chooser.H \
|
||||
fileselector/Native_File_Chooser.cxx \
|
||||
fileselector/fileselect.cxx \
|
||||
logbook/table.cxx \
|
||||
misc/ascii.cxx \
|
||||
|
|
|
|||
Plik diff jest za duży
Load Diff
|
|
@ -1,138 +0,0 @@
|
|||
//
|
||||
// Fl_Native_File_Chooser_MAC.H -- FLTK native OS file chooser widget
|
||||
//
|
||||
// Copyright 2004 by Greg Ercolano.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// USA.
|
||||
//
|
||||
// 10 20 30 40 50 60 70
|
||||
// | | | | | | |
|
||||
// 4567890123456789012345678901234567890123456789012345678901234567890123456789
|
||||
|
||||
// OSX-SPECIFIC NATIVE BROWSER
|
||||
#ifdef __APPLE_CC__
|
||||
#include <Carbon/Carbon.h>
|
||||
#else
|
||||
#include <Carbon.h>
|
||||
#endif
|
||||
|
||||
#include <FL/filename.H>
|
||||
#define MAXFILTERS 80
|
||||
|
||||
class Fl_Native_File_Chooser {
|
||||
public:
|
||||
enum Type {
|
||||
BROWSE_FILE = 0,
|
||||
BROWSE_DIRECTORY,
|
||||
BROWSE_MULTI_FILE,
|
||||
BROWSE_MULTI_DIRECTORY,
|
||||
BROWSE_SAVE_FILE,
|
||||
BROWSE_SAVE_DIRECTORY
|
||||
};
|
||||
enum Option {
|
||||
NO_OPTIONS = 0x0000, // no options enabled
|
||||
SAVEAS_CONFIRM = 0x0001, // Show native 'Save As' overwrite
|
||||
// confirm dialog (if supported)
|
||||
NEW_FOLDER = 0x0002, // Show 'New Folder' icon
|
||||
// (if supported)
|
||||
PREVIEW = 0x0004, // enable preview mode
|
||||
};
|
||||
protected:
|
||||
NavDialogCreationOptions _opts; // file navigation options
|
||||
private:
|
||||
int _btype; // kind-of browser to show()
|
||||
int _options; // general options
|
||||
NavDialogRef _ref; // file navigation reference
|
||||
NavActionState _keepstate; // holds button permissions
|
||||
NavMenuItemSpec _tempitem; // Popup menu selection
|
||||
char **_pathnames; // array of pathnames
|
||||
int _tpathnames; // total pathnames
|
||||
char *_directory; // default pathname to use
|
||||
char *_title; // title for window
|
||||
char *_preset_file; // the 'save as' filename
|
||||
|
||||
char *_filter; // user-side search filter, eg:
|
||||
// C Files\t*.[ch]\nText Files\t*.txt"
|
||||
|
||||
char *_filt_names; // filter names (tab delimited)
|
||||
// eg. "C Files\tText Files"
|
||||
|
||||
char *_filt_patt[MAXFILTERS];
|
||||
// array of filter patterns, eg:
|
||||
// _filt_patt[0]="*.{cxx,h}"
|
||||
// _filt_patt[1]="*.txt"
|
||||
|
||||
int _filt_total; // parse_filter() # of filters loaded
|
||||
int _filt_value; // index of the selected filter
|
||||
char *_errmsg; // error message
|
||||
|
||||
// PRIVATE CLASS TO HANDLE NAVIGATION DIALOG REPLY STRUCT
|
||||
// Class-ified, mainly to ensure proper cleanup.
|
||||
//
|
||||
class NavReply {
|
||||
int _valid_reply;
|
||||
NavReplyRecord _reply;
|
||||
public:
|
||||
NavReply();
|
||||
~NavReply();
|
||||
int get_reply(NavDialogRef& ref);
|
||||
int get_saveas_basename(char *s, int slen);
|
||||
int get_dirname(char *s, int slen);
|
||||
int get_pathnames(char **&pathnames, int& tpathnames);
|
||||
};
|
||||
|
||||
// Private methods
|
||||
void errmsg(const char *msg);
|
||||
void clear_pathnames();
|
||||
void set_single_pathname(const char *s);
|
||||
int get_saveas_basename(NavDialogRef& ref);
|
||||
int get_pathnames(NavDialogRef& ref);
|
||||
static void event_handler(NavEventCallbackMessage callBackSelector,
|
||||
NavCBRecPtr cbparm, void *data);
|
||||
|
||||
void clear_filters();
|
||||
void add_filter(const char *, const char *);
|
||||
void parse_filter(const char *from);
|
||||
static Boolean filter_proc_cb(AEDesc *, void *, void *, NavFilterModes);
|
||||
Boolean filter_proc_cb2(AEDesc*, void*, void*, NavFilterModes);
|
||||
int post();
|
||||
|
||||
public:
|
||||
Fl_Native_File_Chooser(int val = BROWSE_FILE);
|
||||
~Fl_Native_File_Chooser();
|
||||
|
||||
// Public methods
|
||||
void type(int);
|
||||
int type() const;
|
||||
void options(int);
|
||||
int options() const;
|
||||
int count() const;
|
||||
const char *filename() const;
|
||||
const char *filename(int i) const;
|
||||
void directory(const char *);
|
||||
const char *directory() const;
|
||||
void title(const char *);
|
||||
const char *title() const;
|
||||
const char *filter() const;
|
||||
void filter(const char *);
|
||||
void filter_value(int i) { _filt_value = i; }
|
||||
int filter_value() { return(_filt_value); }
|
||||
int filters() { return(_filt_total); }
|
||||
void preset_file(const char *);
|
||||
const char *preset_file();
|
||||
const char *errmsg() const;
|
||||
int show();
|
||||
};
|
||||
|
|
@ -26,25 +26,17 @@
|
|||
|
||||
// Use Windows' chooser
|
||||
#if defined(__WIN32__) || defined(__CYGWIN__)
|
||||
#include "Fl_Native_File_Chooser_WIN32.cxx"
|
||||
#include "Native_File_Chooser_WIN32.cxx"
|
||||
#endif
|
||||
|
||||
// Use Apple's chooser
|
||||
#ifdef __APPLE__
|
||||
#include "MAC_chooser.cxx"
|
||||
#include "Native_File_Chooser_MAC.cxx"
|
||||
#endif
|
||||
|
||||
// All else falls back to FLTK's own chooser
|
||||
#if ! defined(__APPLE__) && !defined(_WIN32) && !defined(__CYGWIN__)
|
||||
#include "Fl_Native_File_Chooser_FLTK.cxx"
|
||||
#include "Native_File_Chooser_FLTK.cxx"
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
// Use Apple's chooser
|
||||
#ifdef __APPLE__
|
||||
#include "MAC_chooser.cxx"
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -26,32 +26,13 @@
|
|||
// 4567890123456789012345678901234567890123456789012345678901234567890123456789
|
||||
//
|
||||
|
||||
#define FLTK1
|
||||
|
||||
#ifdef FLTK1
|
||||
//
|
||||
// FLTK1
|
||||
//
|
||||
#include <FL/Fl_Native_File_Chooser.H>
|
||||
#include "FL/Native_File_Chooser.H"
|
||||
#define FNFC_CLASS Fl_Native_File_Chooser
|
||||
#define FNFC_CTOR Fl_Native_File_Chooser
|
||||
#define FLTK_CHOOSER_SINGLE Fl_File_Chooser::SINGLE
|
||||
#define FLTK_CHOOSER_DIRECTORY Fl_File_Chooser::DIRECTORY
|
||||
#define FLTK_CHOOSER_MULTI Fl_File_Chooser::MULTI
|
||||
#define FLTK_CHOOSER_CREATE Fl_File_Chooser::CREATE
|
||||
#else
|
||||
//
|
||||
// FLTK2
|
||||
//
|
||||
#include <fltk/NativeFileChooser.h>
|
||||
#include <fltk/run.h>
|
||||
#define FNFC_CTOR NativeFileChooser
|
||||
#define FNFC_CLASS fltk::FNFC_CTOR
|
||||
#define FLTK_CHOOSER_SINGLE fltk::FileChooser::SINGLE
|
||||
#define FLTK_CHOOSER_DIRECTORY fltk::FileChooser::DIRECTORY
|
||||
#define FLTK_CHOOSER_MULTI fltk::FileChooser::MULTI
|
||||
#define FLTK_CHOOSER_CREATE fltk::FileChooser::CREATE
|
||||
#endif
|
||||
|
||||
#include "flnfc_common.cxx"
|
||||
#include <sys/stat.h>
|
||||
|
|
@ -34,24 +34,9 @@
|
|||
#include <stdio.h> // debugging
|
||||
#include "flnfc_common.cxx" // strnew/strfree/strapp/chrcat
|
||||
|
||||
#define FLTK1
|
||||
|
||||
#ifdef FLTK1
|
||||
//
|
||||
// FLTK1
|
||||
//
|
||||
#include <FL/Fl_Native_File_Chooser.H>
|
||||
#include "FL/Native_File_Chooser.H"
|
||||
#define FNFC_CLASS Fl_Native_File_Chooser
|
||||
#define FNFC_CTOR Fl_Native_File_Chooser
|
||||
#else
|
||||
//
|
||||
// FLTK2
|
||||
//
|
||||
#include <fltk/NativeFileChooser.h>
|
||||
#include <fltk/run.h>
|
||||
#define FNFC_CTOR NativeFileChooser
|
||||
#define FNFC_CLASS fltk::FNFC_CTOR
|
||||
#endif
|
||||
|
||||
#define LCURLY_CHR '{'
|
||||
#define RCURLY_CHR '}'
|
||||
|
|
@ -23,186 +23,8 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include <libgen.h>
|
||||
|
||||
#include "fileselect.h"
|
||||
#include "icons.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <FL/fl_ask.H>
|
||||
#include "FL/Fl_Native_File_Chooser.H"
|
||||
|
||||
#if FSEL_THREAD
|
||||
# include <FL/Fl.H>
|
||||
# include <semaphore.h>
|
||||
# include "threads.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
FSEL* FSEL::inst = 0;
|
||||
static std::string filename;
|
||||
#if FSEL_THREAD
|
||||
static pthread_t fsel_thread;
|
||||
sem_t fsel_sem;
|
||||
#endif
|
||||
|
||||
void FSEL::create(void)
|
||||
{
|
||||
if (inst)
|
||||
return;
|
||||
#if FSEL_THREAD
|
||||
if (sem_init(&fsel_sem, 0, 0) == -1) {
|
||||
LOG_PERROR("sem_init");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
inst = new FSEL;
|
||||
}
|
||||
|
||||
void FSEL::destroy(void)
|
||||
{
|
||||
#if FSEL_THREAD
|
||||
sem_destroy(&fsel_sem);
|
||||
#endif
|
||||
delete inst;
|
||||
inst = 0;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
FSEL::FSEL()
|
||||
: chooser(new MAC_chooser) { }
|
||||
FSEL::~FSEL() { delete chooser; }
|
||||
#if (FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR < 3) || (FLARQ_FLTK_API_MAJOR == 1 && FLARQ_FLTK_API_MINOR < 3)
|
||||
#include "fileselect_1_1.cxx"
|
||||
#else
|
||||
FSEL::FSEL()
|
||||
: chooser(new Fl_Native_File_Chooser) { }
|
||||
FSEL::~FSEL() { delete chooser; }
|
||||
#include "fileselect_1_3.cxx"
|
||||
#endif
|
||||
|
||||
#if FSEL_THREAD
|
||||
void* FSEL::thread_func(void* arg)
|
||||
{
|
||||
FSEL* fsel = reinterpret_cast<FSEL*>(arg);
|
||||
fsel->result = fsel->chooser->show();
|
||||
sem_post(&fsel_sem);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
const char* FSEL::get_file(void)
|
||||
{
|
||||
// Calling directory() is apparently not enough on Linux
|
||||
#if !defined(__WOE32__) && !defined(__APPLE__)
|
||||
const char* preset = chooser->preset_file();
|
||||
if (preset && *preset != '/' && chooser->directory()) {
|
||||
filename = chooser->directory();
|
||||
filename.append("/").append(preset);
|
||||
chooser->preset_file(filename.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
#if FSEL_THREAD
|
||||
if (pthread_create(&fsel_thread, NULL, thread_func, this) != 0) {
|
||||
fl_alert2("could not create file selector thread");
|
||||
return NULL;
|
||||
}
|
||||
for (;;) {
|
||||
if (sem_trywait(&fsel_sem) == 0)
|
||||
break;
|
||||
Fl::wait(0.1);
|
||||
}
|
||||
#else
|
||||
result = chooser->show();
|
||||
#endif
|
||||
|
||||
switch (result) {
|
||||
case -1:
|
||||
fl_alert2("%s", chooser->errmsg());
|
||||
// fall through
|
||||
case 1:
|
||||
return NULL;
|
||||
default:
|
||||
filename = chooser->filename();
|
||||
string::size_type i = filename.rfind('/');
|
||||
if (i != string::npos)
|
||||
chooser->directory(filename.substr(0, i).c_str());
|
||||
return filename.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
const char* FSEL::select(const char* title, const char* filter, const char* def, int* fsel)
|
||||
{
|
||||
inst->chooser->title(title);
|
||||
inst->chooser->filter(filter);
|
||||
if (def) {
|
||||
char *s = strdup(def), *dir = dirname(s);
|
||||
if (strcmp(".", dir))
|
||||
inst->chooser->directory(dir);
|
||||
free(s);
|
||||
s = strdup(def);
|
||||
inst->chooser->preset_file(basename(s));
|
||||
free(s);
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
inst->chooser->options(MAC_chooser::PREVIEW);
|
||||
inst->chooser->type(MAC_chooser::BROWSE_FILE);
|
||||
#else
|
||||
inst->chooser->options(Fl_Native_File_Chooser::PREVIEW);
|
||||
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_FILE);
|
||||
#endif
|
||||
const char* fn = inst->get_file();
|
||||
if (fsel)
|
||||
*fsel = inst->chooser->filter_value();
|
||||
return fn;
|
||||
}
|
||||
|
||||
const char* FSEL::saveas(const char* title, const char* filter, const char* def, int* fsel)
|
||||
{
|
||||
inst->chooser->title(title);
|
||||
inst->chooser->filter(filter);
|
||||
if (def) {
|
||||
char *s = strdup(def), *dir = dirname(s);
|
||||
if (strcmp(".", dir))
|
||||
inst->chooser->directory(dir);
|
||||
free(s);
|
||||
s = strdup(def);
|
||||
inst->chooser->preset_file(basename(s));
|
||||
free(s);
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
inst->chooser->options( MAC_chooser::SAVEAS_CONFIRM |
|
||||
MAC_chooser::NEW_FOLDER |
|
||||
MAC_chooser::PREVIEW);
|
||||
inst->chooser->type(MAC_chooser::BROWSE_SAVE_FILE);
|
||||
#else
|
||||
inst->chooser->options(Fl_Native_File_Chooser::SAVEAS_CONFIRM |
|
||||
Fl_Native_File_Chooser::NEW_FOLDER |
|
||||
Fl_Native_File_Chooser::PREVIEW);
|
||||
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
|
||||
#endif
|
||||
const char* fn = inst->get_file();
|
||||
if (fsel)
|
||||
*fsel = inst->chooser->filter_value();
|
||||
return fn;
|
||||
}
|
||||
|
||||
const char* FSEL::dir_select(const char* title, const char* filter, const char* def)
|
||||
{
|
||||
inst->chooser->title(title);
|
||||
inst->chooser->filter(filter);
|
||||
if (def)
|
||||
inst->chooser->directory(def);
|
||||
#ifdef __APPLE__
|
||||
inst->chooser->options( MAC_chooser::NEW_FOLDER |
|
||||
MAC_chooser::PREVIEW);
|
||||
inst->chooser->type(MAC_chooser::BROWSE_DIRECTORY);
|
||||
#else
|
||||
inst->chooser->options(Fl_Native_File_Chooser::NEW_FOLDER |
|
||||
Fl_Native_File_Chooser::PREVIEW);
|
||||
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
|
||||
#endif
|
||||
return inst->get_file();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@
|
|||
// along with fldigi. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include <libgen.h>
|
||||
|
|
@ -32,7 +30,7 @@
|
|||
#include "debug.h"
|
||||
|
||||
#include <FL/fl_ask.H>
|
||||
#include <FL/Fl_Native_File_Chooser.H>
|
||||
#include "FL/Native_File_Chooser.H"
|
||||
|
||||
#if FSEL_THREAD
|
||||
# include <FL/Fl.H>
|
||||
|
|
@ -45,47 +43,28 @@ using namespace std;
|
|||
|
||||
FSEL* FSEL::inst = 0;
|
||||
static std::string filename;
|
||||
#if FSEL_THREAD
|
||||
static pthread_t fsel_thread;
|
||||
sem_t fsel_sem;
|
||||
#endif
|
||||
|
||||
void FSEL::create(void)
|
||||
{
|
||||
if (inst)
|
||||
return;
|
||||
#if FSEL_THREAD
|
||||
if (sem_init(&fsel_sem, 0, 0) == -1) {
|
||||
LOG_PERROR("sem_init");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
inst = new FSEL;
|
||||
}
|
||||
|
||||
void FSEL::destroy(void)
|
||||
{
|
||||
#if FSEL_THREAD
|
||||
sem_destroy(&fsel_sem);
|
||||
#endif
|
||||
delete inst;
|
||||
inst = 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __APPLE__
|
||||
FSEL::FSEL()
|
||||
: chooser(new MAC_chooser) { }
|
||||
FSEL::~FSEL() { delete chooser; }
|
||||
#else
|
||||
FSEL::FSEL()
|
||||
: chooser(new Fl_Native_File_Chooser) { }
|
||||
FSEL::~FSEL() { delete chooser; }
|
||||
|
||||
|
||||
#if FSEL_THREAD
|
||||
void* FSEL::thread_func(void* arg)
|
||||
{
|
||||
FSEL* fsel = reinterpret_cast<FSEL*>(arg);
|
||||
fsel->result = fsel->chooser->show();
|
||||
sem_post(&fsel_sem);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
const char* FSEL::get_file(void)
|
||||
|
|
@ -100,19 +79,7 @@ const char* FSEL::get_file(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if FSEL_THREAD
|
||||
if (pthread_create(&fsel_thread, NULL, thread_func, this) != 0) {
|
||||
fl_alert2("could not create file selector thread");
|
||||
return NULL;
|
||||
}
|
||||
for (;;) {
|
||||
if (sem_trywait(&fsel_sem) == 0)
|
||||
break;
|
||||
Fl::wait(0.1);
|
||||
}
|
||||
#else
|
||||
result = chooser->show();
|
||||
#endif
|
||||
|
||||
switch (result) {
|
||||
case -1:
|
||||
|
|
@ -142,9 +109,13 @@ const char* FSEL::select(const char* title, const char* filter, const char* def,
|
|||
inst->chooser->preset_file(basename(s));
|
||||
free(s);
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
inst->chooser->options(MAC_chooser::PREVIEW);
|
||||
inst->chooser->type(MAC_chooser::BROWSE_FILE);
|
||||
#else
|
||||
inst->chooser->options(Fl_Native_File_Chooser::PREVIEW);
|
||||
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_FILE);
|
||||
|
||||
#endif
|
||||
const char* fn = inst->get_file();
|
||||
if (fsel)
|
||||
*fsel = inst->chooser->filter_value();
|
||||
|
|
@ -164,11 +135,17 @@ const char* FSEL::saveas(const char* title, const char* filter, const char* def,
|
|||
inst->chooser->preset_file(basename(s));
|
||||
free(s);
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
inst->chooser->options( MAC_chooser::SAVEAS_CONFIRM |
|
||||
MAC_chooser::NEW_FOLDER |
|
||||
MAC_chooser::PREVIEW);
|
||||
inst->chooser->type(MAC_chooser::BROWSE_SAVE_FILE);
|
||||
#else
|
||||
inst->chooser->options(Fl_Native_File_Chooser::SAVEAS_CONFIRM |
|
||||
Fl_Native_File_Chooser::NEW_FOLDER |
|
||||
Fl_Native_File_Chooser::PREVIEW);
|
||||
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
|
||||
|
||||
#endif
|
||||
const char* fn = inst->get_file();
|
||||
if (fsel)
|
||||
*fsel = inst->chooser->filter_value();
|
||||
|
|
@ -181,9 +158,14 @@ const char* FSEL::dir_select(const char* title, const char* filter, const char*
|
|||
inst->chooser->filter(filter);
|
||||
if (def)
|
||||
inst->chooser->directory(def);
|
||||
#ifdef __APPLE__
|
||||
inst->chooser->options( MAC_chooser::NEW_FOLDER |
|
||||
MAC_chooser::PREVIEW);
|
||||
inst->chooser->type(MAC_chooser::BROWSE_DIRECTORY);
|
||||
#else
|
||||
inst->chooser->options(Fl_Native_File_Chooser::NEW_FOLDER |
|
||||
Fl_Native_File_Chooser::PREVIEW);
|
||||
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
|
||||
|
||||
#endif
|
||||
return inst->get_file();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,177 +21,205 @@
|
|||
// along with fldigi. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include <libgen.h>
|
||||
|
||||
#include "fileselect.h"
|
||||
#include "icons.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <FL/fl_ask.H>
|
||||
#include <FL/Fl_Native_File_Chooser.H>
|
||||
|
||||
#if FSEL_THREAD
|
||||
# include <FL/Fl.H>
|
||||
# include <semaphore.h>
|
||||
# include "threads.h"
|
||||
#endif
|
||||
/**
|
||||
\class Fl_Native_File_Chooser
|
||||
|
||||
This class lets an FLTK application easily and consistently access
|
||||
the operating system's native file chooser. Some operating systems
|
||||
have very complex and specific file choosers that many users want
|
||||
access to specifically, instead of FLTK's default file chooser(s).
|
||||
|
||||
In cases where there is no native file browser, FLTK's own file browser
|
||||
is used instead.
|
||||
|
||||
To use this widget correctly, use the following include in your code:
|
||||
\code
|
||||
#include <FL/Fl_Native_File_Chooser.H>
|
||||
\endcode
|
||||
Do not include the other Fl_Native_File_Choser_XXX.H files in your code;
|
||||
those are platform specific files that will be included automatically
|
||||
depending on your build platform.
|
||||
|
||||
The following example shows how to pick a single file:
|
||||
\code
|
||||
// Create and post the local native file chooser
|
||||
#include <FL/Fl_Native_File_Chooser.H>
|
||||
[..]
|
||||
Fl_Native_File_Chooser fnfc;
|
||||
fnfc.title("Pick a file");
|
||||
fnfc.type(Fl_Native_File_Chooser::BROWSE_FILE);
|
||||
fnfc.filter("Text\t*.txt\n"
|
||||
"C Files\t*.{cxx,h,c}");
|
||||
fnfc.directory("/var/tmp"); // default directory to use
|
||||
// Show native chooser
|
||||
switch ( fnfc.show() ) {
|
||||
case -1: printf("ERROR: %s\n", fnfc.errmsg()); break; // ERROR
|
||||
case 1: printf("CANCEL\n"); break; // CANCEL
|
||||
default: printf("PICKED: %s\n", fnfc.filename()); break; // FILE CHOSEN
|
||||
}
|
||||
\endcode
|
||||
|
||||
<B>Platform Specific Caveats</B>
|
||||
|
||||
- Under X windows, it's best if you call Fl_File_Icon::load_system_icons()
|
||||
at the start of main(), to enable the nicer looking file browser widgets.
|
||||
Use the static public attributes of class Fl_File_Chooser to localize
|
||||
the browser.
|
||||
- Some operating systems support certain OS specific options; see
|
||||
Fl_Native_File_Chooser::options() for a list.
|
||||
|
||||
\image html Fl_Native_File_Chooser.png "The Fl_Native_File_Chooser on different platforms."
|
||||
\image latex Fl_Native_File_Chooser.png "The Fl_Native_File_Chooser on different platforms" width=14cm
|
||||
|
||||
enum Type {
|
||||
BROWSE_FILE = 0, ///< browse files (lets user choose one file)
|
||||
BROWSE_DIRECTORY, ///< browse directories (lets user choose one directory)
|
||||
BROWSE_MULTI_FILE, ///< browse files (lets user choose multiple files)
|
||||
BROWSE_MULTI_DIRECTORY, ///< browse directories (lets user choose multiple directories)
|
||||
BROWSE_SAVE_FILE, ///< browse to save a file
|
||||
BROWSE_SAVE_DIRECTORY ///< browse to save a directory
|
||||
};
|
||||
enum Option {
|
||||
NO_OPTIONS = 0x0000, ///< no options enabled
|
||||
SAVEAS_CONFIRM = 0x0001, ///< Show native 'Save As' overwrite confirm dialog (if supported)
|
||||
NEW_FOLDER = 0x0002, ///< Show 'New Folder' icon (if supported)
|
||||
PREVIEW = 0x0004 ///< enable preview mode
|
||||
};
|
||||
|
||||
IMPORTANT NOTICE:
|
||||
|
||||
The filter type must be terminated with a '\n' on OS X or the application crashes with a Bus timeout
|
||||
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace FSEL {
|
||||
|
||||
FSEL* FSEL::inst = 0;
|
||||
static std::string filename;
|
||||
#if FSEL_THREAD
|
||||
static pthread_t fsel_thread;
|
||||
sem_t fsel_sem;
|
||||
#endif
|
||||
string filename;
|
||||
|
||||
void FSEL::create(void)
|
||||
void create(void) {};
|
||||
void destroy(void) {};
|
||||
|
||||
string stitle, sfilter, sdef;
|
||||
|
||||
const char* select(const char* title, const char* filter, const char* def, int* fsel)
|
||||
{
|
||||
if (inst)
|
||||
return;
|
||||
#if FSEL_THREAD
|
||||
if (sem_init(&fsel_sem, 0, 0) == -1) {
|
||||
LOG_PERROR("sem_init");
|
||||
return;
|
||||
Fl_Native_File_Chooser native;
|
||||
|
||||
stitle.clear();
|
||||
sfilter.clear();
|
||||
sdef.clear();
|
||||
if (title) stitle.assign(title);
|
||||
if (filter) sfilter.assign(filter);
|
||||
if (def) sdef.assign(def);
|
||||
if (!sfilter.empty() && sfilter[sfilter.length()-1] != '\n') sfilter += '\n';
|
||||
|
||||
if (!stitle.empty()) native.title(stitle.c_str());
|
||||
native.type(Fl_Native_File_Chooser::BROWSE_FILE);
|
||||
if (!sfilter.empty()) native.filter(sfilter.c_str());
|
||||
native.options(Fl_Native_File_Chooser::PREVIEW);
|
||||
if (!sdef.empty()) native.preset_file(sdef.c_str());
|
||||
|
||||
filename.clear();
|
||||
switch ( native.show() ) {
|
||||
case -1: LOG_INFO("ERROR: %s\n", native.errmsg()); break; // ERROR
|
||||
case 1: break;
|
||||
default:
|
||||
if ( native.filename() ) {
|
||||
filename = native.filename();
|
||||
} else {
|
||||
filename = "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
inst = new FSEL;
|
||||
}
|
||||
|
||||
void FSEL::destroy(void)
|
||||
{
|
||||
#if FSEL_THREAD
|
||||
sem_destroy(&fsel_sem);
|
||||
#endif
|
||||
delete inst;
|
||||
inst = 0;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
FSEL::FSEL() : chooser(new MAC_chooser) {}
|
||||
#else
|
||||
FSEL::FSEL() : chooser(new Fl_Native_File_Chooser) { }
|
||||
#endif
|
||||
|
||||
FSEL::~FSEL() { delete chooser; }
|
||||
|
||||
|
||||
#if FSEL_THREAD
|
||||
void* FSEL::thread_func(void* arg)
|
||||
{
|
||||
FSEL* fsel = reinterpret_cast<FSEL*>(arg);
|
||||
fsel->result = fsel->chooser->show();
|
||||
sem_post(&fsel_sem);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
const char* FSEL::get_file(void)
|
||||
{
|
||||
// Calling directory() is apparently not enough on Linux
|
||||
#if !defined(__WIN32__) && !defined(__APPLE__)
|
||||
const char* preset = chooser->preset_file();
|
||||
if (preset && *preset != '/' && chooser->directory()) {
|
||||
filename = chooser->directory();
|
||||
filename.append("/").append(preset);
|
||||
chooser->preset_file(filename.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
#if FSEL_THREAD
|
||||
if (pthread_create(&fsel_thread, NULL, thread_func, this) != 0) {
|
||||
fl_alert2("could not create file selector thread");
|
||||
return NULL;
|
||||
}
|
||||
for (;;) {
|
||||
if (sem_trywait(&fsel_sem) == 0)
|
||||
break;
|
||||
Fl::wait(0.1);
|
||||
}
|
||||
#else
|
||||
result = chooser->show();
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
chooser->hide();
|
||||
#endif
|
||||
|
||||
switch (result) {
|
||||
case -1:
|
||||
fl_alert2("%s", chooser->errmsg());
|
||||
// fall through
|
||||
case 1:
|
||||
return NULL;
|
||||
default:
|
||||
filename = chooser->filename();
|
||||
string::size_type i = filename.rfind('/');
|
||||
if (i != string::npos)
|
||||
chooser->directory(filename.substr(0, i).c_str());
|
||||
return filename.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
const char* FSEL::select(const char* title, const char* filter, const char* def, int* fsel)
|
||||
{
|
||||
inst->chooser->title(title);
|
||||
inst->chooser->filter(filter);
|
||||
if (def) {
|
||||
char *s = strdup(def), *dir = dirname(s);
|
||||
if (strcmp(".", dir))
|
||||
inst->chooser->directory(dir);
|
||||
free(s);
|
||||
s = strdup(def);
|
||||
inst->chooser->preset_file(basename(s));
|
||||
free(s);
|
||||
}
|
||||
inst->chooser->options(Fl_Native_File_Chooser::PREVIEW);
|
||||
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_FILE);
|
||||
|
||||
const char* fn = inst->get_file();
|
||||
if (fsel)
|
||||
*fsel = inst->chooser->filter_value();
|
||||
return fn;
|
||||
*fsel = native.filter_value();
|
||||
|
||||
return filename.c_str();
|
||||
}
|
||||
|
||||
const char* FSEL::saveas(const char* title, const char* filter, const char* def, int* fsel)
|
||||
const char* saveas(const char* title, const char* filter, const char* def, int* fsel)
|
||||
{
|
||||
inst->chooser->title(title);
|
||||
inst->chooser->filter(filter);
|
||||
if (def) {
|
||||
char *s = strdup(def), *dir = dirname(s);
|
||||
if (strcmp(".", dir))
|
||||
inst->chooser->directory(dir);
|
||||
free(s);
|
||||
s = strdup(def);
|
||||
inst->chooser->preset_file(basename(s));
|
||||
free(s);
|
||||
Fl_Native_File_Chooser native;
|
||||
|
||||
stitle.clear();
|
||||
sfilter.clear();
|
||||
sdef.clear();
|
||||
if (title) stitle.assign(title);
|
||||
if (filter) sfilter.assign(filter);
|
||||
if (def) sdef.assign(def);
|
||||
if (!sfilter.empty() && sfilter[sfilter.length()-1] != '\n') sfilter += '\n';
|
||||
|
||||
if (!stitle.empty()) native.title(stitle.c_str());
|
||||
native.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
|
||||
if (!sfilter.empty()) native.filter(sfilter.c_str());
|
||||
native.options(Fl_Native_File_Chooser::NEW_FOLDER || Fl_Native_File_Chooser::SAVEAS_CONFIRM);
|
||||
if (!sdef.empty()) native.preset_file(sdef.c_str());
|
||||
|
||||
filename.clear();
|
||||
switch ( native.show() ) {
|
||||
case -1: LOG_INFO("ERROR: %s\n", native.errmsg()); break; // ERROR
|
||||
case 1: break; // CANCEL
|
||||
default:
|
||||
if ( native.filename() ) {
|
||||
filename = native.filename();
|
||||
} else {
|
||||
filename = "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
inst->chooser->options(Fl_Native_File_Chooser::SAVEAS_CONFIRM |
|
||||
Fl_Native_File_Chooser::NEW_FOLDER |
|
||||
Fl_Native_File_Chooser::PREVIEW);
|
||||
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
|
||||
|
||||
const char* fn = inst->get_file();
|
||||
if (fsel)
|
||||
*fsel = inst->chooser->filter_value();
|
||||
return fn;
|
||||
*fsel = native.filter_value();
|
||||
|
||||
return filename.c_str();
|
||||
|
||||
}
|
||||
|
||||
const char* FSEL::dir_select(const char* title, const char* filter, const char* def)
|
||||
const char* dir_select(const char* title, const char* filter, const char* def)
|
||||
{
|
||||
inst->chooser->title(title);
|
||||
inst->chooser->filter(filter);
|
||||
if (def)
|
||||
inst->chooser->directory(def);
|
||||
inst->chooser->options(Fl_Native_File_Chooser::NEW_FOLDER |
|
||||
Fl_Native_File_Chooser::PREVIEW);
|
||||
inst->chooser->type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
|
||||
Fl_Native_File_Chooser native;
|
||||
|
||||
return inst->get_file();
|
||||
stitle.clear();
|
||||
sfilter.clear();
|
||||
sdef.clear();
|
||||
if (title) stitle.assign(title);
|
||||
if (filter) sfilter.assign(filter);
|
||||
if (def) sdef.assign(def);
|
||||
if (!sfilter.empty() && sfilter[sfilter.length()-1] != '\n') sfilter += '\n';
|
||||
|
||||
if (!stitle.empty()) native.title(stitle.c_str());
|
||||
native.type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
|
||||
if (!sfilter.empty()) native.filter(sfilter.c_str());
|
||||
native.options(Fl_Native_File_Chooser::NO_OPTIONS);
|
||||
if (!sdef.empty()) native.directory(sdef.c_str());
|
||||
|
||||
filename.clear();
|
||||
switch ( native.show() ) {
|
||||
case -1: LOG_INFO("ERROR: %s\n", native.errmsg()); break; // ERROR
|
||||
case 1: break; // CANCEL
|
||||
default:
|
||||
if ( native.filename() ) {
|
||||
filename = native.filename();
|
||||
} else {
|
||||
filename = "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return filename.c_str();
|
||||
}
|
||||
|
||||
} // FSEL
|
||||
|
|
|
|||
|
|
@ -4,15 +4,7 @@
|
|||
#include <config.h>
|
||||
|
||||
#if (FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR < 3) || (FLARQ_FLTK_API_MAJOR == 1 && FLARQ_FLTK_API_MINOR < 3)
|
||||
//#ifdef __WIN32__
|
||||
//# define FSEL_THREAD 1
|
||||
//#endif
|
||||
#define FSEL_THREAD 0
|
||||
class Fl_Native_File_Chooser;
|
||||
#else
|
||||
#include "FL/Fl_Native_File_Chooser.H"
|
||||
#define FSEL_THREAD 0
|
||||
#endif
|
||||
|
||||
class FSEL
|
||||
{
|
||||
|
|
@ -42,4 +34,18 @@ private:
|
|||
int result;
|
||||
};
|
||||
|
||||
#else // API >=1.3.0
|
||||
|
||||
namespace FSEL {
|
||||
|
||||
void create(void);
|
||||
void destroy(void);
|
||||
const char* select(const char* title, const char* filter, const char* def = 0, int *fsel = NULL);
|
||||
const char* saveas(const char* title, const char* filter, const char* def = 0, int *fsel = NULL);
|
||||
const char* dir_select(const char* title, const char* filter, const char* def = 0);
|
||||
|
||||
}
|
||||
|
||||
#endif // API < 1.3.0
|
||||
|
||||
#endif // FILESELECT_H
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue