2017-10-02 07:32:33 +02:00
|
|
|
/************************************************************************
|
|
|
|
* ffiledialog.cpp - Widget FFileDialog (a file chooser dialog) *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
|
|
|
* Copyright 2014-2017 Markus Gans *
|
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut 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 General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
************************************************************************/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/ffiledialog.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// non-member functions
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool sortByName ( const FFileDialog::dir_entry& lhs
|
|
|
|
, const FFileDialog::dir_entry& rhs )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
// lhs < rhs
|
|
|
|
return bool(strcasecmp(lhs.name, rhs.name) < 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
bool sortDirFirst ( const FFileDialog::dir_entry& lhs
|
|
|
|
, const FFileDialog::dir_entry& rhs )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
// sort directories first
|
|
|
|
if ( lhs.type == DT_DIR && rhs.type != DT_DIR )
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FFileDialog
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2016-10-01 23:18:49 +02:00
|
|
|
FFileDialog::FFileDialog (FWidget* parent)
|
2015-09-22 04:18:20 +02:00
|
|
|
: FDialog(parent)
|
|
|
|
, directory_stream(0)
|
|
|
|
, dir_entries()
|
|
|
|
, directory()
|
|
|
|
, filter_pattern()
|
|
|
|
, filebrowser()
|
|
|
|
, filename()
|
|
|
|
, hidden()
|
|
|
|
, cancel()
|
|
|
|
, open()
|
|
|
|
, dlg_type(FFileDialog::Open)
|
|
|
|
, show_hidden(false)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FFileDialog::FFileDialog (const FFileDialog& fdlg)
|
2016-07-03 20:08:39 +02:00
|
|
|
: FDialog(fdlg.getParentWidget())
|
2015-09-22 04:18:20 +02:00
|
|
|
, directory_stream(0)
|
|
|
|
, dir_entries()
|
|
|
|
, directory(fdlg.directory)
|
|
|
|
, filter_pattern(fdlg.filter_pattern)
|
|
|
|
, filebrowser()
|
|
|
|
, filename()
|
|
|
|
, hidden()
|
|
|
|
, cancel()
|
|
|
|
, open()
|
|
|
|
, dlg_type(fdlg.dlg_type)
|
|
|
|
, show_hidden(fdlg.show_hidden)
|
|
|
|
{
|
|
|
|
if ( directory )
|
|
|
|
setPath(directory);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-09-22 04:18:20 +02:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FFileDialog::FFileDialog ( const FString& dirname
|
|
|
|
, const FString& filter
|
|
|
|
, DialogType type
|
|
|
|
, FWidget* parent )
|
|
|
|
: FDialog(parent)
|
|
|
|
, directory_stream(0)
|
|
|
|
, dir_entries()
|
|
|
|
, directory()
|
|
|
|
, filter_pattern(filter)
|
|
|
|
, filebrowser()
|
|
|
|
, filename()
|
|
|
|
, hidden()
|
|
|
|
, cancel()
|
|
|
|
, open()
|
|
|
|
, dlg_type(type)
|
|
|
|
, show_hidden(false)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
if ( dirname )
|
|
|
|
setPath(dirname);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FFileDialog::~FFileDialog() // destructor
|
|
|
|
{
|
|
|
|
delete open;
|
|
|
|
delete cancel;
|
|
|
|
delete hidden;
|
|
|
|
delete filebrowser;
|
|
|
|
delete filename;
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// public methods of FFileDialog
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( &fdlg == this )
|
2016-08-21 21:27:44 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
return *this;
|
2016-08-21 21:27:44 +02:00
|
|
|
}
|
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
delete open;
|
|
|
|
delete cancel;
|
|
|
|
delete hidden;
|
|
|
|
delete filebrowser;
|
|
|
|
delete filename;
|
|
|
|
clear();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( fdlg.getParentWidget() )
|
|
|
|
fdlg.getParentWidget()->addChild (this);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
directory = fdlg.directory;
|
|
|
|
filter_pattern = fdlg.filter_pattern;
|
|
|
|
dlg_type = fdlg.dlg_type;
|
|
|
|
show_hidden = fdlg.show_hidden;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( directory )
|
|
|
|
setPath(directory);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
init();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
const FString FFileDialog::getSelectedFile() const
|
|
|
|
{
|
|
|
|
uLong n = uLong(filebrowser->currentItem() - 1);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( dir_entries[n].type == DT_DIR )
|
|
|
|
return FString("");
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
return FString(dir_entries[n].name);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FFileDialog::setPath (const FString& dir)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-03-17 22:59:06 +01:00
|
|
|
const char* const dirname = dir.c_str();
|
2016-11-02 00:37:58 +01:00
|
|
|
char resolved_path[MAXPATHLEN];
|
|
|
|
FString r_dir;
|
|
|
|
struct stat sb;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( stat(dirname, &sb) != 0 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
directory = '/';
|
|
|
|
return;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( S_ISLNK(sb.st_mode) )
|
|
|
|
{
|
|
|
|
if ( lstat(dirname, &sb) != 0 )
|
|
|
|
{
|
|
|
|
directory = '/';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! S_ISDIR(sb.st_mode) )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
directory = '/';
|
|
|
|
return;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( realpath(dir.c_str(), resolved_path) != 0 )
|
|
|
|
r_dir = resolved_path;
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
r_dir = dir;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
if ( r_dir[r_dir.getLength() - 1] != '/' )
|
2016-11-02 00:37:58 +01:00
|
|
|
directory = r_dir + "/";
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
directory = r_dir;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FFileDialog::setFilter (const FString& filter)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
filter_pattern = filter;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FFileDialog::setShowHiddenFiles (bool on)
|
|
|
|
{
|
|
|
|
if ( on == show_hidden )
|
|
|
|
return show_hidden;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
show_hidden = on;
|
|
|
|
readDir();
|
|
|
|
filebrowser->redraw();
|
|
|
|
return show_hidden;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FFileDialog::onKeyPress (FKeyEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! isEnabled() )
|
|
|
|
return;
|
2016-10-17 08:44:38 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
FDialog::onKeyPress (ev);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! filebrowser->hasFocus() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int key = ev->key();
|
|
|
|
|
|
|
|
switch ( key )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
case fc::Fkey_erase:
|
|
|
|
case fc::Fkey_backspace:
|
|
|
|
changeDir("..");
|
|
|
|
ev->accept();
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
default:
|
|
|
|
break;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
int FFileDialog::readDir()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
int start, dir_num;
|
2017-03-17 22:59:06 +01:00
|
|
|
const char* const dir = directory.c_str();
|
|
|
|
const char* const filter = filter_pattern.c_str();
|
2016-11-02 00:37:58 +01:00
|
|
|
directory_stream = opendir(dir);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! directory_stream )
|
|
|
|
{
|
|
|
|
FMessageBox::error (this, "Can't open directory\n" + directory);
|
|
|
|
return -1;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
clear();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
while ( true )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-10-14 20:29:29 +02:00
|
|
|
errno = 0;
|
|
|
|
struct dirent* next = readdir(directory_stream);
|
2015-09-20 05:44:50 +02:00
|
|
|
|
2017-10-14 20:29:29 +02:00
|
|
|
if ( next )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-10-14 20:29:29 +02:00
|
|
|
if ( next->d_name[0] == '.' && next->d_name[1] == '\0' )
|
2016-11-02 00:37:58 +01:00
|
|
|
continue;
|
2015-09-20 05:44:50 +02:00
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( ! show_hidden
|
2017-10-14 20:29:29 +02:00
|
|
|
&& next->d_name[0] == '.'
|
|
|
|
&& next->d_name[1] != '\0'
|
|
|
|
&& next->d_name[1] != '.' )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
if ( dir[0] == '/' && dir[1] == '\0'
|
2017-10-14 20:29:29 +02:00
|
|
|
&& std::strcmp(next->d_name, "..") == 0 )
|
2016-11-02 00:37:58 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
dir_entry entry;
|
2017-10-14 20:29:29 +02:00
|
|
|
entry.name = strdup(next->d_name);
|
|
|
|
entry.type = next->d_type;
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-10-14 20:29:29 +02:00
|
|
|
if ( next->d_type == DT_LNK ) // symbolic link
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
char resolved_path[MAXPATHLEN] = {};
|
|
|
|
char symLink[MAXPATHLEN] = {};
|
|
|
|
std::strncpy (symLink, dir, sizeof(symLink) - 1);
|
2017-09-11 03:06:02 +02:00
|
|
|
std::strncat ( symLink
|
2017-10-14 20:29:29 +02:00
|
|
|
, next->d_name
|
2017-09-11 03:06:02 +02:00
|
|
|
, sizeof(symLink) - std::strlen(symLink) - 1);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( realpath(symLink, resolved_path) != 0 ) // follow link
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
struct stat sb;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( lstat(resolved_path, &sb) == 0 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( S_ISDIR(sb.st_mode) )
|
|
|
|
entry.type = DT_DIR;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( entry.type == DT_DIR )
|
|
|
|
dir_entries.push_back (entry);
|
|
|
|
else if ( pattern_match(filter, entry.name) )
|
|
|
|
dir_entries.push_back (entry);
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
std::free(entry.name);
|
|
|
|
}
|
2017-10-14 20:29:29 +02:00
|
|
|
else if ( errno != 0 )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
FMessageBox::error (this, "Reading directory\n" + directory);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-10-14 20:29:29 +02:00
|
|
|
if ( errno == EOVERFLOW ) // Value too large to be stored in data type
|
2016-11-02 00:37:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
} // end while
|
2015-09-20 05:44:50 +02:00
|
|
|
|
2017-10-14 20:29:29 +02:00
|
|
|
if ( closedir(directory_stream) != 0 )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
FMessageBox::error (this, "Closing directory\n" + directory);
|
|
|
|
return -2;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( std::strcmp((*dir_entries.begin()).name, "..") == 0 )
|
2017-10-02 07:32:33 +02:00
|
|
|
start = 1;
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2017-10-02 07:32:33 +02:00
|
|
|
start = 0;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
dir_num = numOfDirs();
|
|
|
|
// directories first
|
2017-09-11 03:06:02 +02:00
|
|
|
std::sort ( dir_entries.begin() + start
|
|
|
|
, dir_entries.end()
|
|
|
|
, sortDirFirst );
|
2016-11-02 00:37:58 +01:00
|
|
|
// sort directories by name
|
2017-09-11 03:06:02 +02:00
|
|
|
std::sort ( dir_entries.begin() + start
|
|
|
|
, dir_entries.begin() + dir_num
|
|
|
|
, sortByName );
|
2016-11-02 00:37:58 +01:00
|
|
|
// sort files by name
|
2017-09-11 03:06:02 +02:00
|
|
|
std::sort ( dir_entries.begin() + dir_num
|
|
|
|
, dir_entries.end()
|
|
|
|
, sortByName );
|
2016-11-02 00:37:58 +01:00
|
|
|
// fill list with directory entries
|
|
|
|
filebrowser->clear();
|
|
|
|
|
|
|
|
if ( ! dir_entries.empty() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
std::vector<dir_entry>::const_iterator iter, last;
|
2016-11-02 00:37:58 +01:00
|
|
|
iter = dir_entries.begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
last = dir_entries.end();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( (*iter).type == DT_DIR )
|
|
|
|
filebrowser->insert(FString((*iter).name), fc::SquareBrackets);
|
|
|
|
else
|
|
|
|
filebrowser->insert(FString((*iter).name));
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
++iter;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
return 0;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-17 22:59:06 +01:00
|
|
|
const FString FFileDialog::fileOpenChooser ( FWidget* parent
|
|
|
|
, const FString& dirname
|
|
|
|
, const FString& filter )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FFileDialog* fileopen;
|
|
|
|
FString ret;
|
|
|
|
FString path = dirname;
|
|
|
|
FString file_filter = filter;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( path.isNull() || path.isEmpty() )
|
|
|
|
{
|
|
|
|
path = getHomeDir();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-03-26 20:40:04 +02:00
|
|
|
if ( path.isNull() || path.isEmpty() )
|
2016-11-02 00:37:58 +01:00
|
|
|
path = FString("/");
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( file_filter.isNull() || file_filter.isEmpty() )
|
|
|
|
file_filter = FString("*");
|
|
|
|
|
2017-08-12 22:55:29 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
fileopen = new FFileDialog ( path
|
|
|
|
, file_filter
|
|
|
|
, FFileDialog::Open
|
|
|
|
, parent );
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
|
|
|
return FString();
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( fileopen->exec() == FDialog::Accept )
|
|
|
|
ret = fileopen->getPath() + fileopen->getSelectedFile();
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
ret = FString();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
delete fileopen;
|
|
|
|
return ret;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-17 22:59:06 +01:00
|
|
|
const FString FFileDialog::fileSaveChooser ( FWidget* parent
|
|
|
|
, const FString& dirname
|
|
|
|
, const FString& filter )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FFileDialog* fileopen;
|
|
|
|
FString ret;
|
|
|
|
FString path = dirname;
|
|
|
|
FString file_filter = filter;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( path.isNull() || path.isEmpty() )
|
|
|
|
{
|
|
|
|
path = getHomeDir();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-03-26 20:40:04 +02:00
|
|
|
if ( path.isNull() || path.isEmpty() )
|
2016-11-02 00:37:58 +01:00
|
|
|
path = FString("/");
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( file_filter.isNull() || file_filter.isEmpty() )
|
|
|
|
file_filter = FString("*");
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-08-12 22:55:29 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
fileopen = new FFileDialog ( path
|
|
|
|
, file_filter
|
|
|
|
, FFileDialog::Save
|
|
|
|
, parent );
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
|
|
|
return FString();
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( fileopen->exec() == FDialog::Accept )
|
|
|
|
ret = fileopen->getPath() + fileopen->getSelectedFile();
|
|
|
|
else
|
|
|
|
ret = FString();
|
|
|
|
|
|
|
|
delete fileopen;
|
|
|
|
return ret;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// protected methods of FFileDialog
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FFileDialog::adjustSize()
|
|
|
|
{
|
2017-10-02 07:32:33 +02:00
|
|
|
int h
|
|
|
|
, X
|
|
|
|
, Y
|
|
|
|
, max_width
|
|
|
|
, max_height;
|
2016-08-21 21:27:44 +02:00
|
|
|
FWidget* root_widget = getRootWidget();
|
|
|
|
|
|
|
|
if ( root_widget )
|
|
|
|
{
|
|
|
|
max_width = root_widget->getClientWidth();
|
|
|
|
max_height = root_widget->getClientHeight();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-03 16:56:32 +02:00
|
|
|
// fallback to xterm default size
|
2016-08-21 21:27:44 +02:00
|
|
|
max_width = 80;
|
|
|
|
max_height = 24;
|
|
|
|
}
|
|
|
|
|
|
|
|
h = max_height - 6;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( h < 15 ) // minimum
|
|
|
|
h = 15;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( h > 30 ) // maximum
|
|
|
|
h = 30;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
setHeight (h, false);
|
2016-09-25 23:53:48 +02:00
|
|
|
X = 1 + int((max_width - getWidth()) / 2);
|
|
|
|
Y = 1 + int((max_height - getHeight()) / 3);
|
2016-07-31 20:25:25 +02:00
|
|
|
setPos(X, Y, false);
|
2017-08-27 09:50:30 +02:00
|
|
|
filebrowser->setHeight (h - 8, false);
|
|
|
|
hidden->setY (h - 4, false);
|
|
|
|
cancel->setY (h - 4, false);
|
|
|
|
open->setY (h - 4, false);
|
2015-05-23 13:35:12 +02:00
|
|
|
FDialog::adjustSize();
|
|
|
|
printPath(directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// private methods of FFileDialog
|
2015-09-22 04:18:20 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FFileDialog::init()
|
2015-09-22 04:18:20 +02:00
|
|
|
{
|
2017-07-03 16:56:32 +02:00
|
|
|
static const int w = 42;
|
|
|
|
static const int h = 15;
|
|
|
|
int x, y;
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget* parent_widget;
|
2017-07-12 01:16:57 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
setGeometry(1, 1, w, h, false);
|
|
|
|
parent_widget = getParentWidget();
|
|
|
|
|
|
|
|
if ( parent_widget )
|
2016-10-17 08:44:38 +02:00
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
x = 1 + int((parent_widget->getWidth() - w) / 2);
|
|
|
|
y = 1 + int((parent_widget->getHeight() - h) / 3);
|
2016-10-17 08:44:38 +02:00
|
|
|
}
|
2015-09-22 04:18:20 +02:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
x = y = 1;
|
2016-08-21 21:27:44 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( dlg_type == FFileDialog::Save )
|
|
|
|
FDialog::setText("Save file");
|
|
|
|
else
|
|
|
|
FDialog::setText("Open file");
|
2016-08-21 21:27:44 +02:00
|
|
|
|
2017-08-12 22:55:29 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
filename = new FLineEdit(this);
|
|
|
|
filename->setLabelText("File&name");
|
|
|
|
filename->setText(filter_pattern);
|
|
|
|
filename->setGeometry(11, 1, 28, 1);
|
|
|
|
filename->setFocus();
|
2015-09-22 04:18:20 +02:00
|
|
|
|
2017-08-12 22:55:29 +02:00
|
|
|
filebrowser = new FListBox(this);
|
|
|
|
filebrowser->setGeometry(2, 3, 38, 6);
|
|
|
|
printPath(directory);
|
2015-09-22 04:18:20 +02:00
|
|
|
|
2017-08-12 22:55:29 +02:00
|
|
|
hidden = new FCheckBox("&hidden files", this);
|
|
|
|
hidden->setGeometry(2, 10, 16, 1);
|
2015-09-22 04:18:20 +02:00
|
|
|
|
2017-08-12 22:55:29 +02:00
|
|
|
cancel = new FButton("&Cancel", this);
|
|
|
|
cancel->setGeometry(19, 10, 9, 1);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-08-12 22:55:29 +02:00
|
|
|
if ( dlg_type == FFileDialog::Save )
|
2017-09-11 03:06:02 +02:00
|
|
|
open = new FButton("&Save", this);
|
2017-08-12 22:55:29 +02:00
|
|
|
else
|
2017-09-11 03:06:02 +02:00
|
|
|
open = new FButton("&Open", this);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-08-12 22:55:29 +02:00
|
|
|
open->setGeometry(30, 10, 9, 1);
|
|
|
|
setGeometry (x, y, getWidth(), getHeight());
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
filename->addCallback
|
|
|
|
(
|
|
|
|
"activate",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FFileDialog::cb_processActivate)
|
2016-11-02 00:37:58 +01:00
|
|
|
);
|
2016-07-10 00:23:39 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
filebrowser->addCallback
|
|
|
|
(
|
|
|
|
"row-changed",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FFileDialog::cb_processRowChanged)
|
2016-11-02 00:37:58 +01:00
|
|
|
);
|
2015-09-20 05:44:50 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
filebrowser->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FFileDialog::cb_processClicked)
|
2016-11-02 00:37:58 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
hidden->addCallback
|
|
|
|
(
|
|
|
|
"toggled",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FFileDialog::cb_processShowHidden)
|
2016-11-02 00:37:58 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
cancel->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FFileDialog::cb_processCancel)
|
2016-11-02 00:37:58 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
open->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FFileDialog::cb_processOpen)
|
2016-11-02 00:37:58 +01:00
|
|
|
);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
setModal();
|
|
|
|
readDir();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-03-17 22:59:06 +01:00
|
|
|
inline bool FFileDialog::pattern_match ( const char* const pattern
|
|
|
|
, char*& fname )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
char search[128] = {};
|
|
|
|
|
|
|
|
if ( show_hidden && fname[0] == '.' && fname[1] != '\0' ) // hidden files
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
search[0] = '.';
|
|
|
|
search[1] = '\0';
|
|
|
|
std::strncat(search, pattern, sizeof(search) - std::strlen(search) - 1);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
std::strncpy(search, pattern, sizeof(search) - 1);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( fnmatch (search, fname, FNM_PERIOD) == 0 )
|
|
|
|
return true;
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
return false;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FFileDialog::clear()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
std::vector<dir_entry>::const_iterator iter, last;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( dir_entries.empty() )
|
|
|
|
return;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// delete all directory entries;
|
|
|
|
iter = dir_entries.begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
last = dir_entries.end();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
std::free ((*iter).name);
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
dir_entries.clear();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
int FFileDialog::numOfDirs()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( dir_entries.empty() )
|
|
|
|
return 0;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
int n = 0;
|
2017-09-17 01:50:41 +02:00
|
|
|
std::vector<dir_entry>::const_iterator iter, last;
|
2016-11-02 00:37:58 +01:00
|
|
|
iter = dir_entries.begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
last = dir_entries.end();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( (*iter).type == DT_DIR && std::strcmp((*iter).name, ".") != 0 )
|
|
|
|
n++;
|
|
|
|
|
|
|
|
++iter;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
return n;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int FFileDialog::changeDir (const FString& dirname)
|
|
|
|
{
|
|
|
|
FString lastdir = directory;
|
|
|
|
FString newdir = dirname;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( newdir.includes('~') )
|
|
|
|
newdir = newdir.replace('~', getHomeDir());
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( newdir[0] == '/' )
|
|
|
|
setPath(newdir);
|
|
|
|
else
|
|
|
|
setPath(directory + newdir);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
switch ( readDir() )
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
setPath(lastdir);
|
|
|
|
return -1;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case -2:
|
|
|
|
setPath(lastdir);
|
|
|
|
readDir();
|
|
|
|
return -2;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
case 0:
|
|
|
|
if ( newdir == FString("..") )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( lastdir == FString('/') )
|
|
|
|
filename->setText('/');
|
|
|
|
else if ( ! dir_entries.empty() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
int i = 1;
|
2017-09-17 01:50:41 +02:00
|
|
|
std::vector<dir_entry>::const_iterator iter, last;
|
2017-09-11 03:06:02 +02:00
|
|
|
const char* const baseName = \
|
|
|
|
basename(const_cast<char*>(lastdir.c_str()));
|
2016-11-02 00:37:58 +01:00
|
|
|
iter = dir_entries.begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
last = dir_entries.end();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2015-10-01 03:48:58 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( std::strcmp((*iter).name, baseName) == 0 )
|
|
|
|
{
|
|
|
|
filebrowser->setCurrentItem(i);
|
|
|
|
filename->setText(FString(baseName) + '/');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
++iter;
|
2015-10-01 03:48:58 +02:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
FString firstname = dir_entries[0].name;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( dir_entries[0].type == DT_DIR )
|
|
|
|
filename->setText(firstname + '/');
|
|
|
|
else
|
|
|
|
filename->setText(firstname);
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
printPath(directory);
|
|
|
|
filename->redraw();
|
|
|
|
filebrowser->redraw();
|
2017-08-11 10:50:39 +02:00
|
|
|
// fall through
|
2016-11-02 00:37:58 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FFileDialog::printPath (const FString& txt)
|
|
|
|
{
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& path = txt;
|
|
|
|
const uInt max_width = uInt(filebrowser->getWidth()) - 4;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( path.getLength() > max_width )
|
2017-08-27 09:50:30 +02:00
|
|
|
filebrowser->setText(".." + path.right(max_width - 2));
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
|
|
|
filebrowser->setText(path);
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-11 22:50:07 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
const FString FFileDialog::getHomeDir()
|
|
|
|
{
|
|
|
|
struct passwd pwd;
|
|
|
|
struct passwd* pwd_ptr;
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
if ( getpwuid_r (geteuid(), &pwd, buf, sizeof(buf), &pwd_ptr) )
|
|
|
|
return FString("");
|
|
|
|
else
|
|
|
|
return FString(pwd.pw_dir);
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FFileDialog::cb_processActivate (FWidget*, data_ptr)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( filename->getText().includes('*')
|
|
|
|
|| filename->getText().includes('?') )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
setFilter(filename->getText());
|
|
|
|
readDir();
|
|
|
|
filebrowser->redraw();
|
|
|
|
}
|
|
|
|
else if ( filename->getText().getLength() == 0 )
|
|
|
|
{
|
|
|
|
setFilter("*");
|
|
|
|
readDir();
|
|
|
|
filebrowser->redraw();
|
|
|
|
}
|
2016-12-18 23:34:11 +01:00
|
|
|
else if ( filename->getText().trim() == FString("..")
|
|
|
|
|| filename->getText().includes('/')
|
|
|
|
|| filename->getText().includes('~') )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
changeDir(filename->getText().trim());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool found = false;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! dir_entries.empty() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
std::vector<dir_entry>::const_iterator iter, last;
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& input = filename->getText().trim();
|
2016-11-02 00:37:58 +01:00
|
|
|
iter = dir_entries.begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
last = dir_entries.end();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != last )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-09-11 03:48:21 +02:00
|
|
|
if ( (*iter).name && input && ! input.isNull()
|
2017-04-08 13:41:37 +02:00
|
|
|
&& std::strcmp((*iter).name, input) == 0
|
|
|
|
&& (*iter).type == DT_DIR )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
changeDir(input);
|
|
|
|
break;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( ! found )
|
|
|
|
done (FDialog::Accept);
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FFileDialog::cb_processRowChanged (FWidget*, data_ptr)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-09-09 22:03:17 +02:00
|
|
|
const int n = filebrowser->currentItem();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( n == 0 )
|
|
|
|
return;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& name = dir_entries[uLong(n - 1)].name;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
if ( dir_entries[uLong(n - 1)].type == DT_DIR )
|
2016-11-02 00:37:58 +01:00
|
|
|
filename->setText( name + '/' );
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
filename->setText( name );
|
2015-09-22 04:18:20 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
filename->redraw();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FFileDialog::cb_processClicked (FWidget*, data_ptr)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-09-09 22:03:17 +02:00
|
|
|
const uLong n = uLong(filebrowser->currentItem() - 1);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( dir_entries[n].type == DT_DIR )
|
|
|
|
changeDir(dir_entries[n].name);
|
|
|
|
else
|
|
|
|
done (FDialog::Accept);
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FFileDialog::cb_processCancel (FWidget*, data_ptr)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
done (FDialog::Reject);
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FFileDialog::cb_processOpen (FWidget*, data_ptr)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
done (FDialog::Accept);
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FFileDialog::cb_processShowHidden (FWidget*, data_ptr)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
setShowHiddenFiles(not show_hidden);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|