2015-09-25 21:37:19 +02:00
|
|
|
// File: ffiledialog.h
|
2016-10-01 23:18:49 +02:00
|
|
|
// Provides: class FFileDialog
|
2015-09-25 21:37:19 +02:00
|
|
|
//
|
|
|
|
// Inheritance diagram
|
|
|
|
// ═══════════════════
|
|
|
|
//
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FObject ▏ ▕ FTerm ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲ ▲
|
|
|
|
// │ │
|
|
|
|
// └─────┬─────┘
|
|
|
|
// │
|
2016-10-11 04:57:36 +02:00
|
|
|
// ▕▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FVTerm ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲
|
|
|
|
// │
|
2015-09-25 21:37:19 +02:00
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FWidget ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲
|
|
|
|
// │
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FWindow ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲
|
|
|
|
// │
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FDialog ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲
|
|
|
|
// │
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FFileDialog ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
#ifndef _FFILEDIALOG_H
|
|
|
|
#define _FFILEDIALOG_H
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <fnmatch.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "fbutton.h"
|
|
|
|
#include "fcheckbox.h"
|
|
|
|
#include "fdialog.h"
|
|
|
|
#include "flineedit.h"
|
|
|
|
#include "flistbox.h"
|
|
|
|
#include "fmessagebox.h"
|
|
|
|
#include "fstatusbar.h"
|
|
|
|
#include "fterm.h"
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FFileDialog
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FFileDialog : public FDialog
|
|
|
|
{
|
|
|
|
public:
|
2016-11-02 00:37:58 +01:00
|
|
|
// Enumeration
|
2015-05-23 13:35:12 +02:00
|
|
|
enum DialogType
|
|
|
|
{
|
|
|
|
Open = 0,
|
|
|
|
Save = 1
|
|
|
|
};
|
2016-09-30 04:55:28 +02:00
|
|
|
|
|
|
|
// Constructors
|
2015-09-27 16:45:28 +02:00
|
|
|
explicit FFileDialog (FWidget* = 0);
|
2016-09-30 04:55:28 +02:00
|
|
|
FFileDialog (const FFileDialog&); // copy constructor
|
2015-09-22 04:18:20 +02:00
|
|
|
FFileDialog ( const FString&
|
|
|
|
, const FString&
|
2015-09-27 16:45:28 +02:00
|
|
|
, DialogType = FFileDialog::Open
|
|
|
|
, FWidget* = 0 );
|
2016-09-30 04:55:28 +02:00
|
|
|
// Destructor
|
2015-05-23 13:35:12 +02:00
|
|
|
~FFileDialog();
|
2016-09-30 04:55:28 +02:00
|
|
|
|
|
|
|
// Assignment operator (=)
|
|
|
|
FFileDialog& operator = (const FFileDialog&);
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Accessors
|
2015-09-22 04:18:20 +02:00
|
|
|
const char* getClassName() const;
|
2015-05-23 13:35:12 +02:00
|
|
|
const FString getPath() const;
|
|
|
|
const FString getFilter() const;
|
|
|
|
const FString getSelectedFile() const;
|
2016-11-02 00:37:58 +01:00
|
|
|
bool getShowHiddenFiles();
|
|
|
|
|
|
|
|
// Mutators
|
|
|
|
void setPath (const FString&);
|
|
|
|
void setFilter (const FString&);
|
2015-09-22 04:18:20 +02:00
|
|
|
bool setShowHiddenFiles(bool);
|
|
|
|
bool setShowHiddenFiles();
|
|
|
|
bool unsetShowHiddenFiles();
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Event handler
|
|
|
|
void onKeyPress (FKeyEvent*);
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
int readDir();
|
2015-09-22 04:18:20 +02:00
|
|
|
static FString fileOpenChooser ( FWidget*
|
|
|
|
, const FString& = FString()
|
|
|
|
, const FString& = FString() );
|
|
|
|
static FString fileSaveChooser ( FWidget*
|
|
|
|
, const FString& = FString()
|
|
|
|
, const FString& = FString() );
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Method
|
|
|
|
void adjustSize();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Typedef
|
|
|
|
struct dir_entry
|
|
|
|
{
|
|
|
|
char* name;
|
|
|
|
uChar type;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<dir_entry> dirEntries;
|
|
|
|
|
|
|
|
// Method
|
|
|
|
void init();
|
|
|
|
static char* getHomeDir();
|
|
|
|
inline bool pattern_match (const char*, const char*);
|
|
|
|
void clear();
|
|
|
|
int numOfDirs();
|
|
|
|
int changeDir (const FString&);
|
|
|
|
void printPath (const FString&);
|
|
|
|
|
|
|
|
// Callback methods
|
2017-02-24 00:30:07 +01:00
|
|
|
void cb_processActivate (FWidget*, data_ptr);
|
|
|
|
void cb_processRowChanged (FWidget*, data_ptr);
|
|
|
|
void cb_processClicked (FWidget*, data_ptr);
|
|
|
|
void cb_processCancel (FWidget*, data_ptr);
|
|
|
|
void cb_processOpen (FWidget*, data_ptr);
|
|
|
|
void cb_processShowHidden (FWidget*, data_ptr);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// Data Members
|
|
|
|
DIR* directory_stream;
|
|
|
|
dirEntries dir_entries;
|
|
|
|
FString directory;
|
|
|
|
FString filter_pattern;
|
|
|
|
FListBox* filebrowser;
|
|
|
|
FLineEdit* filename;
|
|
|
|
FCheckBox* hidden;
|
|
|
|
FButton* cancel;
|
|
|
|
FButton* open;
|
|
|
|
DialogType dlg_type;
|
|
|
|
bool show_hidden;
|
|
|
|
|
|
|
|
// Friend functions
|
|
|
|
friend bool sortByName ( const FFileDialog::dir_entry&
|
|
|
|
, const FFileDialog::dir_entry& );
|
|
|
|
friend bool sortDirFirst ( const FFileDialog::dir_entry&
|
|
|
|
, const FFileDialog::dir_entry& );
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
// FMessageBox inline functions
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const char* FFileDialog::getClassName() const
|
|
|
|
{ return "FFileDialog"; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const FString FFileDialog::getPath() const
|
|
|
|
{ return directory; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const FString FFileDialog::getFilter() const
|
|
|
|
{ return filter_pattern; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FFileDialog::setShowHiddenFiles()
|
|
|
|
{ return setShowHiddenFiles(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FFileDialog::unsetShowHiddenFiles()
|
|
|
|
{ return setShowHiddenFiles(false); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FFileDialog::getShowHiddenFiles()
|
|
|
|
{ return show_hidden; }
|
|
|
|
|
|
|
|
#endif // _FFILEDIALOG_H
|
|
|
|
|