Merge branch 'master' into 'gtk3'
This commit is contained in:
@@ -17,27 +17,57 @@
|
||||
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "dirbrowser.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
#define _WIN32_WINNT 0x0600
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "options.h"
|
||||
#include "multilangmgr.h"
|
||||
#include "../rtengine/safegtk.h"
|
||||
|
||||
#include <cstring>
|
||||
#include "guiutils.h"
|
||||
#include "rtimage.h"
|
||||
#include "multilangmgr.h"
|
||||
#include "options.h"
|
||||
|
||||
#define CHECKTIME 5000
|
||||
namespace
|
||||
{
|
||||
|
||||
std::vector<Glib::ustring> listSubDirs (const Glib::RefPtr<Gio::File>& dir, bool addHidden)
|
||||
{
|
||||
std::vector<Glib::ustring> subDirs;
|
||||
|
||||
try {
|
||||
|
||||
// CD-ROM with no disc inserted are reported, but do not exist.
|
||||
if (!Glib::file_test (dir->get_path (), Glib::FILE_TEST_EXISTS)) {
|
||||
return subDirs;
|
||||
}
|
||||
|
||||
auto enumerator = dir->enumerate_children ("standard::name,standard::type,standard::is-hidden");
|
||||
|
||||
while (auto file = enumerator->next_file ()) {
|
||||
if (file->get_file_type () != Gio::FILE_TYPE_DIRECTORY) {
|
||||
continue;
|
||||
}
|
||||
if (!addHidden && file->is_hidden ()) {
|
||||
continue;
|
||||
}
|
||||
subDirs.push_back (file->get_name ());
|
||||
}
|
||||
|
||||
} catch (const Glib::Exception& exception) {
|
||||
|
||||
if (options.rtSettings.verbose) {
|
||||
std::cerr << "Failed to list subdirectories of \"" << dir << "\": " << exception.what () << std::endl;
|
||||
}
|
||||
|
||||
struct DirNameComparator {
|
||||
template<class T>
|
||||
bool operator()(T const &firstDir, T const &secondDir) const
|
||||
{
|
||||
return options.dirBrowserSortType == Gtk::SORT_ASCENDING ? firstDir < secondDir : firstDir > secondDir;
|
||||
}
|
||||
};
|
||||
|
||||
return subDirs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DirBrowser::DirBrowser () : dirTreeModel(),
|
||||
dtColumns(),
|
||||
@@ -71,13 +101,13 @@ DirBrowser::DirBrowser () : dirTreeModel(),
|
||||
void DirBrowser::fillDirTree ()
|
||||
{
|
||||
|
||||
openfolder = safe_create_from_file ("gtk-open.png");
|
||||
closedfolder = safe_create_from_file ("folder.png");
|
||||
icdrom = safe_create_from_file ("drive-optical.png");
|
||||
ifloppy = safe_create_from_file ("drive-removable-media.png");
|
||||
ihdd = safe_create_from_file ("drive-harddisk.png");
|
||||
iremovable = safe_create_from_file ("media-usb.png");
|
||||
inetwork = safe_create_from_file ("network.png");
|
||||
openfolder = RTImage::createFromFile ("gtk-open.png");
|
||||
closedfolder = RTImage::createFromFile ("folder.png");
|
||||
icdrom = RTImage::createFromFile ("drive-optical.png");
|
||||
ifloppy = RTImage::createFromFile ("drive-removable-media.png");
|
||||
ihdd = RTImage::createFromFile ("drive-harddisk.png");
|
||||
iremovable = RTImage::createFromFile ("media-usb.png");
|
||||
inetwork = RTImage::createFromFile ("network.png");
|
||||
|
||||
//Create the Tree model:
|
||||
dirTreeModel = Gtk::TreeStore::create(dtColumns);
|
||||
@@ -220,7 +250,7 @@ void DirBrowser::fillRoot ()
|
||||
}
|
||||
|
||||
// since sigc++ is not thread safe, we have to use the glib function
|
||||
g_timeout_add (CHECKTIME, updateVolumesUI, this);
|
||||
g_timeout_add (5000, updateVolumesUI, this);
|
||||
#else
|
||||
Gtk::TreeModel::Row rootRow = *(dirTreeModel->append());
|
||||
rootRow[dtColumns.filename] = "/";
|
||||
@@ -243,19 +273,15 @@ void DirBrowser::row_expanded (const Gtk::TreeModel::iterator& iter, const Gtk::
|
||||
// We will disable model's sorting because it decreases speed of inserting new items
|
||||
// in list tree dramatically. Therefore will do:
|
||||
// 1) Disable sorting in model
|
||||
// 2) Manually sort data by DirNameComparator
|
||||
// 2) Manually sort data in the order determined by the options
|
||||
// 3) Enable sorting in model again for UI (sorting by click on header)
|
||||
int prevSortColumn;
|
||||
Gtk::SortType prevSortType;
|
||||
dirTreeModel->get_sort_column_id(prevSortColumn, prevSortType);
|
||||
dirTreeModel->set_sort_column(Gtk::TreeSortable::DEFAULT_UNSORTED_COLUMN_ID, Gtk::SORT_ASCENDING);
|
||||
|
||||
typedef std::vector<Glib::ustring> DirPathType;
|
||||
|
||||
DirPathType subDirs;
|
||||
Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path (iter->get_value (dtColumns.dirname));
|
||||
|
||||
safe_build_subdir_list (dir, subDirs, options.fbShowHidden);
|
||||
auto dir = Gio::File::create_for_path (iter->get_value (dtColumns.dirname));
|
||||
auto subDirs = listSubDirs (dir, options.fbShowHidden);
|
||||
|
||||
if (subDirs.empty()) {
|
||||
dirtree->collapse_row(path);
|
||||
@@ -263,14 +289,22 @@ void DirBrowser::row_expanded (const Gtk::TreeModel::iterator& iter, const Gtk::
|
||||
Gtk::TreeNodeChildren children = iter->children();
|
||||
std::list<Gtk::TreeIter> forErase(children.begin(), children.end());
|
||||
|
||||
DirNameComparator comparator;
|
||||
sort(subDirs.begin(), subDirs.end(), comparator);
|
||||
std::sort (subDirs.begin (), subDirs.end (), [] (const Glib::ustring& firstDir, const Glib::ustring& secondDir)
|
||||
{
|
||||
switch (options.dirBrowserSortType) {
|
||||
default:
|
||||
case Gtk::SORT_ASCENDING:
|
||||
return firstDir < secondDir;
|
||||
case Gtk::SORT_DESCENDING:
|
||||
return firstDir > secondDir;
|
||||
}
|
||||
});
|
||||
|
||||
for (DirPathType::const_iterator it = subDirs.begin(), end = subDirs.end(); it != end; ++it) {
|
||||
for (auto it = subDirs.begin(), end = subDirs.end(); it != end; ++it) {
|
||||
addDir(iter, *it);
|
||||
}
|
||||
|
||||
for (std::list<Gtk::TreeIter>::const_iterator it = forErase.begin(), end = forErase.end(); it != end; ++it) {
|
||||
for (auto it = forErase.begin(), end = forErase.end(); it != end; ++it) {
|
||||
dirTreeModel->erase(*it);
|
||||
}
|
||||
|
||||
@@ -299,8 +333,8 @@ void DirBrowser::updateDir (const Gtk::TreeModel::iterator& iter)
|
||||
change = false;
|
||||
|
||||
for (Gtk::TreeModel::iterator it = iter->children().begin(); it != iter->children().end(); it++)
|
||||
if (!safe_file_test (it->get_value (dtColumns.dirname), Glib::FILE_TEST_EXISTS)
|
||||
|| !safe_file_test (it->get_value (dtColumns.dirname), Glib::FILE_TEST_IS_DIR)) {
|
||||
if (!Glib::file_test (it->get_value (dtColumns.dirname), Glib::FILE_TEST_EXISTS)
|
||||
|| !Glib::file_test (it->get_value (dtColumns.dirname), Glib::FILE_TEST_IS_DIR)) {
|
||||
GThreadLock lock;
|
||||
dirTreeModel->erase (it);
|
||||
change = true;
|
||||
@@ -309,9 +343,8 @@ void DirBrowser::updateDir (const Gtk::TreeModel::iterator& iter)
|
||||
}
|
||||
|
||||
// test if new files are created
|
||||
std::vector<Glib::ustring> subDirs;
|
||||
Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path (iter->get_value (dtColumns.dirname));
|
||||
safe_build_subdir_list (dir, subDirs, options.fbShowHidden);
|
||||
auto dir = Gio::File::create_for_path (iter->get_value (dtColumns.dirname));
|
||||
auto subDirs = listSubDirs (dir, options.fbShowHidden);
|
||||
|
||||
for (int i = 0; i < subDirs.size(); i++) {
|
||||
bool found = false;
|
||||
@@ -345,7 +378,7 @@ void DirBrowser::row_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewC
|
||||
|
||||
Glib::ustring dname = dirTreeModel->get_iter (path)->get_value (dtColumns.dirname);
|
||||
|
||||
if (safe_file_test (dname, Glib::FILE_TEST_IS_DIR))
|
||||
if (Glib::file_test (dname, Glib::FILE_TEST_IS_DIR))
|
||||
dirSelectionSignal (dname, Glib::ustring());
|
||||
}
|
||||
|
||||
@@ -442,7 +475,7 @@ void DirBrowser::open (const Glib::ustring& dirname, const Glib::ustring& fileNa
|
||||
void DirBrowser::file_changed (const Glib::RefPtr<Gio::File>& file, const Glib::RefPtr<Gio::File>& other_file, Gio::FileMonitorEvent event_type, const Gtk::TreeModel::iterator& iter, const Glib::ustring& dirName)
|
||||
{
|
||||
|
||||
if (!file || !safe_file_test (dirName, Glib::FILE_TEST_IS_DIR) || event_type == Gio::FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED) {
|
||||
if (!file || !Glib::file_test (dirName, Glib::FILE_TEST_IS_DIR) || event_type == Gio::FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user