2015-09-25 21:37:19 +02:00
|
|
|
// File: ffiledialog.h
|
|
|
|
// Provides: class FFileDialog.h
|
|
|
|
//
|
|
|
|
// Inheritance diagram
|
|
|
|
// ═══════════════════
|
|
|
|
//
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FObject ▏ ▕ FTerm ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲ ▲
|
|
|
|
// │ │
|
|
|
|
// └─────┬─────┘
|
|
|
|
// │
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ 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"
|
|
|
|
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
struct dir_entry
|
|
|
|
{
|
|
|
|
char* name;
|
|
|
|
uChar type;
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FFileDialog
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FFileDialog : public FDialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum DialogType
|
|
|
|
{
|
|
|
|
Open = 0,
|
|
|
|
Save = 1
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
DIR* directory_stream;
|
|
|
|
std::vector<dir_entry> dir_entries;
|
|
|
|
|
|
|
|
FString directory;
|
|
|
|
FString filter_pattern;
|
|
|
|
FListBox* filebrowser;
|
|
|
|
FLineEdit* filename;
|
|
|
|
FCheckBox* hidden;
|
|
|
|
FButton* cancel;
|
|
|
|
FButton* open;
|
|
|
|
DialogType dlg_type;
|
|
|
|
bool show_hidden;
|
|
|
|
|
|
|
|
private:
|
2015-09-22 04:18:20 +02:00
|
|
|
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&);
|
|
|
|
void cb_processActivate (FWidget*, void*);
|
|
|
|
void cb_processRowChanged (FWidget*, void*);
|
|
|
|
void cb_processClicked (FWidget*, void*);
|
|
|
|
void cb_processCancel (FWidget*, void*);
|
|
|
|
void cb_processOpen (FWidget*, void*);
|
|
|
|
void cb_processShowHidden (FWidget*, void*);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void adjustSize();
|
|
|
|
|
|
|
|
public:
|
2015-09-27 16:45:28 +02:00
|
|
|
explicit FFileDialog (FWidget* = 0);
|
2015-09-22 04:18:20 +02:00
|
|
|
FFileDialog (const FFileDialog&); // copy constructor
|
|
|
|
FFileDialog ( const FString&
|
|
|
|
, const FString&
|
2015-09-27 16:45:28 +02:00
|
|
|
, DialogType = FFileDialog::Open
|
|
|
|
, FWidget* = 0 );
|
2015-05-23 13:35:12 +02:00
|
|
|
~FFileDialog();
|
2015-09-22 04:18:20 +02:00
|
|
|
FFileDialog& operator = (const FFileDialog&); // assignment
|
|
|
|
const char* getClassName() const;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2015-09-22 04:18:20 +02:00
|
|
|
void onKeyPress (FKeyEvent*);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
const FString getPath() const;
|
2015-09-22 04:18:20 +02:00
|
|
|
void setPath (const FString&);
|
2015-05-23 13:35:12 +02:00
|
|
|
const FString getFilter() const;
|
2015-09-22 04:18:20 +02:00
|
|
|
void setFilter (const FString&);
|
2015-05-23 13:35:12 +02:00
|
|
|
const FString getSelectedFile() const;
|
2015-09-22 04:18:20 +02:00
|
|
|
int readDir();
|
|
|
|
bool setShowHiddenFiles(bool);
|
|
|
|
bool setShowHiddenFiles();
|
|
|
|
bool unsetShowHiddenFiles();
|
|
|
|
bool getShowHiddenFiles();
|
|
|
|
|
|
|
|
static FString fileOpenChooser ( FWidget*
|
|
|
|
, const FString& = FString()
|
|
|
|
, const FString& = FString() );
|
|
|
|
static FString fileSaveChooser ( FWidget*
|
|
|
|
, const FString& = FString()
|
|
|
|
, const FString& = FString() );
|
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
|
|
|
|
|