1
0
Fork 0
mirror of synced 2024-04-25 16:22:07 +12:00

Enable sorting for simple treeviews (#487)

This commit is contained in:
Rafał Mikrut 2021-12-04 20:41:02 +01:00 committed by GitHub
parent 5296e1c708
commit 875ed2c8a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 124 additions and 54 deletions

View file

@ -312,11 +312,12 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
for path in vector {
let (directory, file) = split_path(&path);
let values: [(u32, &dyn ToValue); 4] = [
let values: [(u32, &dyn ToValue); 5] = [
(ColumnsEmptyFolders::SelectionButton as u32, &false),
(ColumnsEmptyFolders::Name as u32, &file),
(ColumnsEmptyFolders::Path as u32, &directory),
(ColumnsEmptyFolders::Modification as u32, &(NaiveDateTime::from_timestamp(hashmap.get(&path).unwrap().modified_date as i64, 0).to_string())),
(ColumnsEmptyFolders::ModificationAsSecs as u32, &(hashmap.get(&path).unwrap().modified_date as u64)),
];
list_store.set(&list_store.append(), &values);
}
@ -359,11 +360,12 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
for file_entry in vector {
let (directory, file) = split_path(&file_entry.path);
let values: [(u32, &dyn ToValue); 4] = [
let values: [(u32, &dyn ToValue); 5] = [
(ColumnsEmptyFiles::SelectionButton as u32, &false),
(ColumnsEmptyFiles::Name as u32, &file),
(ColumnsEmptyFiles::Path as u32, &directory),
(ColumnsEmptyFiles::Modification as u32, &(NaiveDateTime::from_timestamp(file_entry.modified_date as i64, 0).to_string())),
(ColumnsEmptyFiles::ModificationAsSecs as u32, &(file_entry.modified_date as i64)),
];
list_store.set(&list_store.append(), &values);
}
@ -405,12 +407,14 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
});
for file_entry in vector {
let (directory, file) = split_path(&file_entry.path);
let values: [(u32, &dyn ToValue); 5] = [
let values: [(u32, &dyn ToValue); 7] = [
(ColumnsBigFiles::SelectionButton as u32, &false),
(ColumnsBigFiles::Size as u32, &(format!("{} ({} bytes)", size.file_size(options::BINARY).unwrap(), size))),
(ColumnsBigFiles::Name as u32, &file),
(ColumnsBigFiles::Path as u32, &directory),
(ColumnsBigFiles::Modification as u32, &(NaiveDateTime::from_timestamp(file_entry.modified_date as i64, 0).to_string())),
(ColumnsBigFiles::ModificationAsSecs as u32, &(file_entry.modified_date as i64)),
(ColumnsBigFiles::SizeAsBytes as u32, &(size)),
];
list_store.set(&list_store.append(), &values);
}
@ -454,11 +458,12 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
for file_entry in vector {
let (directory, file) = split_path(&file_entry.path);
let values: [(u32, &dyn ToValue); 4] = [
let values: [(u32, &dyn ToValue); 5] = [
(ColumnsTemporaryFiles::SelectionButton as u32, &false),
(ColumnsTemporaryFiles::Name as u32, &file),
(ColumnsTemporaryFiles::Path as u32, &directory),
(ColumnsTemporaryFiles::Modification as u32, &(NaiveDateTime::from_timestamp(file_entry.modified_date as i64, 0).to_string())),
(ColumnsTemporaryFiles::ModificationAsSecs as u32, &(file_entry.modified_date as i64)),
];
list_store.set(&list_store.append(), &values);
}
@ -783,13 +788,14 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
for file_entry in vector {
let (directory, file) = split_path(&file_entry.symlink_path);
let values: [(u32, &dyn ToValue); 6] = [
let values: [(u32, &dyn ToValue); 7] = [
(ColumnsInvalidSymlinks::SelectionButton as u32, &false),
(ColumnsInvalidSymlinks::Name as u32, &file),
(ColumnsInvalidSymlinks::Path as u32, &directory),
(ColumnsInvalidSymlinks::DestinationPath as u32, &file_entry.destination_path.to_string_lossy().to_string()),
(ColumnsInvalidSymlinks::TypeOfError as u32, &get_text_from_invalid_symlink_cause(&file_entry.type_of_error)),
(ColumnsInvalidSymlinks::Modification as u32, &(NaiveDateTime::from_timestamp(file_entry.modified_date as i64, 0).to_string())),
(ColumnsInvalidSymlinks::ModificationAsSecs as u32, &(file_entry.modified_date as i64)),
];
list_store.set(&list_store.append(), &values);
}
@ -832,12 +838,13 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
for file_entry in vector {
let (directory, file) = split_path(&file_entry.path);
let values: [(u32, &dyn ToValue); 5] = [
let values: [(u32, &dyn ToValue); 6] = [
(ColumnsBrokenFiles::SelectionButton as u32, &false),
(ColumnsBrokenFiles::Name as u32, &file),
(ColumnsBrokenFiles::Path as u32, &directory),
(ColumnsBrokenFiles::ErrorType as u32, &file_entry.error_string),
(ColumnsBrokenFiles::Modification as u32, &(NaiveDateTime::from_timestamp(file_entry.modified_date as i64, 0).to_string())),
(ColumnsBrokenFiles::ModificationAsSecs as u32, &(file_entry.modified_date as i64)),
];
list_store.set(&list_store.append(), &values);
}

View file

@ -88,6 +88,7 @@ pub fn create_tree_view_empty_folders(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsEmptyFolders::Name as i32);
column.set_sort_column_id(ColumnsEmptyFolders::Name as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -97,6 +98,7 @@ pub fn create_tree_view_empty_folders(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsEmptyFolders::Path as i32);
column.set_sort_column_id(ColumnsEmptyFolders::Path as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -106,6 +108,7 @@ pub fn create_tree_view_empty_folders(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsEmptyFolders::Modification as i32);
column.set_sort_column_id(ColumnsEmptyFolders::ModificationAsSecs as i32);
tree_view.append_column(&column);
tree_view.set_vexpand(true);
@ -138,8 +141,9 @@ pub fn create_tree_view_big_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsBigFiles::Size as i32);
column.set_sort_column_id(ColumnsBigFiles::SizeAsBytes as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
let column: gtk::TreeViewColumn = TreeViewColumn::new();
column.pack_start(&renderer, true);
@ -147,6 +151,7 @@ pub fn create_tree_view_big_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsBigFiles::Name as i32);
column.set_sort_column_id(ColumnsBigFiles::Name as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -156,6 +161,7 @@ pub fn create_tree_view_big_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsBigFiles::Path as i32);
column.set_sort_column_id(ColumnsBigFiles::Path as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -165,6 +171,7 @@ pub fn create_tree_view_big_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsBigFiles::Modification as i32);
column.set_sort_column_id(ColumnsBigFiles::ModificationAsSecs as i32);
tree_view.append_column(&column);
tree_view.set_vexpand(true);
@ -197,6 +204,7 @@ pub fn create_tree_view_temporary_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsTemporaryFiles::Name as i32);
column.set_sort_column_id(ColumnsTemporaryFiles::Name as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -206,6 +214,7 @@ pub fn create_tree_view_temporary_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsTemporaryFiles::Path as i32);
column.set_sort_column_id(ColumnsTemporaryFiles::Path as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -215,6 +224,7 @@ pub fn create_tree_view_temporary_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsTemporaryFiles::Modification as i32);
column.set_sort_column_id(ColumnsTemporaryFiles::ModificationAsSecs as i32);
tree_view.append_column(&column);
tree_view.set_vexpand(true);
@ -247,6 +257,7 @@ pub fn create_tree_view_empty_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsEmptyFiles::Name as i32);
column.set_sort_column_id(ColumnsEmptyFiles::Name as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -256,6 +267,7 @@ pub fn create_tree_view_empty_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsEmptyFiles::Path as i32);
column.set_sort_column_id(ColumnsEmptyFiles::Path as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -265,6 +277,7 @@ pub fn create_tree_view_empty_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsEmptyFiles::Modification as i32);
column.set_sort_column_id(ColumnsEmptyFiles::ModificationAsSecs as i32);
tree_view.append_column(&column);
tree_view.set_vexpand(true);
@ -591,6 +604,7 @@ pub fn create_tree_view_invalid_symlinks(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsInvalidSymlinks::Name as i32);
column.set_sort_column_id(ColumnsInvalidSymlinks::Name as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -600,6 +614,7 @@ pub fn create_tree_view_invalid_symlinks(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsInvalidSymlinks::Path as i32);
column.set_sort_column_id(ColumnsInvalidSymlinks::Path as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -609,6 +624,7 @@ pub fn create_tree_view_invalid_symlinks(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsInvalidSymlinks::DestinationPath as i32);
column.set_sort_column_id(ColumnsInvalidSymlinks::DestinationPath as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -618,6 +634,7 @@ pub fn create_tree_view_invalid_symlinks(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsInvalidSymlinks::TypeOfError as i32);
column.set_sort_column_id(ColumnsInvalidSymlinks::TypeOfError as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -627,6 +644,7 @@ pub fn create_tree_view_invalid_symlinks(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsInvalidSymlinks::Modification as i32);
column.set_sort_column_id(ColumnsInvalidSymlinks::ModificationAsSecs as i32);
tree_view.append_column(&column);
tree_view.set_vexpand(true);
@ -659,6 +677,7 @@ pub fn create_tree_view_broken_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsBrokenFiles::Name as i32);
column.set_sort_column_id(ColumnsBrokenFiles::Name as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -668,6 +687,7 @@ pub fn create_tree_view_broken_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsBrokenFiles::Path as i32);
column.set_sort_column_id(ColumnsBrokenFiles::Path as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -677,6 +697,7 @@ pub fn create_tree_view_broken_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsBrokenFiles::ErrorType as i32);
column.set_sort_column_id(ColumnsBrokenFiles::ErrorType as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
@ -686,6 +707,7 @@ pub fn create_tree_view_broken_files(tree_view: &mut gtk::TreeView) {
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsBrokenFiles::Modification as i32);
column.set_sort_column_id(ColumnsBrokenFiles::ModificationAsSecs as i32);
tree_view.append_column(&column);
tree_view.set_vexpand(true);

View file

@ -218,6 +218,7 @@ pub enum ColumnsEmptyFolders {
Name,
Path,
Modification,
ModificationAsSecs,
}
pub enum ColumnsDirectory {
@ -231,6 +232,8 @@ pub enum ColumnsBigFiles {
Name,
Path,
Modification,
SizeAsBytes,
ModificationAsSecs,
}
pub enum ColumnsEmptyFiles {
@ -238,6 +241,7 @@ pub enum ColumnsEmptyFiles {
Name,
Path,
Modification,
ModificationAsSecs,
}
pub enum ColumnsTemporaryFiles {
@ -245,6 +249,7 @@ pub enum ColumnsTemporaryFiles {
Name,
Path,
Modification,
ModificationAsSecs,
}
pub enum ColumnsSimilarImages {
@ -300,6 +305,7 @@ pub enum ColumnsInvalidSymlinks {
DestinationPath,
TypeOfError,
Modification,
ModificationAsSecs,
}
pub enum ColumnsBrokenFiles {
@ -308,6 +314,7 @@ pub enum ColumnsBrokenFiles {
Path,
ErrorType,
Modification,
ModificationAsSecs,
}
pub const TEXT_COLOR: &str = "#ffffff";

View file

@ -82,14 +82,14 @@ pub fn initialize_gui(gui_data: &mut GuiData) {
image_preview_duplicates.hide();
let col_types: [glib::types::Type; 8] = [
glib::types::Type::BOOL,
glib::types::Type::BOOL,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::U64,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::BOOL, // ActivatableSelectButton
glib::types::Type::BOOL, // SelectionButton
glib::types::Type::STRING, // Name
glib::types::Type::STRING, // Path
glib::types::Type::STRING, // Modification
glib::types::Type::U64, // ModificationAsSecs
glib::types::Type::STRING, // Color
glib::types::Type::STRING, // TextColor
];
let list_store: gtk::ListStore = gtk::ListStore::new(&col_types);
@ -137,7 +137,13 @@ pub fn initialize_gui(gui_data: &mut GuiData) {
}
// Empty Folders
{
let col_types: [glib::types::Type; 4] = [glib::types::Type::BOOL, glib::types::Type::STRING, glib::types::Type::STRING, glib::types::Type::STRING];
let col_types: [glib::types::Type; 5] = [
glib::types::Type::BOOL, // SelectionButton
glib::types::Type::STRING, // Name
glib::types::Type::STRING, // Path
glib::types::Type::STRING, // Modification
glib::types::Type::U64, // ModificationAsSecs
];
let list_store: gtk::ListStore = gtk::ListStore::new(&col_types);
let mut tree_view: gtk::TreeView = TreeView::with_model(&list_store);
@ -160,7 +166,13 @@ pub fn initialize_gui(gui_data: &mut GuiData) {
}
// Empty Files
{
let col_types: [glib::types::Type; 4] = [glib::types::Type::BOOL, glib::types::Type::STRING, glib::types::Type::STRING, glib::types::Type::STRING];
let col_types: [glib::types::Type; 5] = [
glib::types::Type::BOOL, // SelectionButton
glib::types::Type::STRING, // Name
glib::types::Type::STRING, // Path
glib::types::Type::STRING, // Modification
glib::types::Type::U64, // ModificationAsSecs
];
let list_store: gtk::ListStore = gtk::ListStore::new(&col_types);
let mut tree_view: gtk::TreeView = TreeView::with_model(&list_store);
@ -182,7 +194,13 @@ pub fn initialize_gui(gui_data: &mut GuiData) {
}
// Temporary Files
{
let col_types: [glib::types::Type; 4] = [glib::types::Type::BOOL, glib::types::Type::STRING, glib::types::Type::STRING, glib::types::Type::STRING];
let col_types: [glib::types::Type; 5] = [
glib::types::Type::BOOL, // SelectionButton
glib::types::Type::STRING, // Name
glib::types::Type::STRING, // Path
glib::types::Type::STRING, // Modification
glib::types::Type::U64, // ModificationAsSecs
];
let list_store: gtk::ListStore = gtk::ListStore::new(&col_types);
let mut tree_view: gtk::TreeView = TreeView::with_model(&list_store);
@ -204,7 +222,15 @@ pub fn initialize_gui(gui_data: &mut GuiData) {
}
// Big Files
{
let col_types: [glib::types::Type; 5] = [glib::types::Type::BOOL, glib::types::Type::STRING, glib::types::Type::STRING, glib::types::Type::STRING, glib::types::Type::STRING];
let col_types: [glib::types::Type; 7] = [
glib::types::Type::BOOL, // SelectionButton
glib::types::Type::STRING, // Size
glib::types::Type::STRING, // Name
glib::types::Type::STRING, // Path
glib::types::Type::STRING, // Modification
glib::types::Type::U64, // SizeAsBytes
glib::types::Type::U64, // ModificationAsSecs
];
let list_store: gtk::ListStore = gtk::ListStore::new(&col_types);
let mut tree_view: gtk::TreeView = TreeView::with_model(&list_store);
@ -230,18 +256,18 @@ pub fn initialize_gui(gui_data: &mut GuiData) {
image_preview_similar_images.hide();
let col_types: [glib::types::Type; 12] = [
glib::types::Type::BOOL,
glib::types::Type::BOOL,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::U64,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::U64,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::BOOL, // ActivatableSelectButton
glib::types::Type::BOOL, // SelectionButton
glib::types::Type::STRING, // Similarity
glib::types::Type::STRING, // Size
glib::types::Type::U64, // SizeAsBytes
glib::types::Type::STRING, // Dimensions
glib::types::Type::STRING, // Name
glib::types::Type::STRING, // Path
glib::types::Type::STRING, // Modification
glib::types::Type::U64, // ModificationAsSecs
glib::types::Type::STRING, // Color
glib::types::Type::STRING, // TextColor
];
let list_store: gtk::ListStore = gtk::ListStore::new(&col_types);
@ -323,21 +349,21 @@ pub fn initialize_gui(gui_data: &mut GuiData) {
// Same Music
{
let col_types: [glib::types::Type; 15] = [
glib::types::Type::BOOL,
glib::types::Type::BOOL,
glib::types::Type::STRING,
glib::types::Type::U64,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::U64,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::BOOL, // ActivatableSelectButton
glib::types::Type::BOOL, // SelectionButton
glib::types::Type::STRING, // Size
glib::types::Type::U64, // SizeAsBytes
glib::types::Type::STRING, // Name
glib::types::Type::STRING, // Path
glib::types::Type::STRING, // Title
glib::types::Type::STRING, // Artist
glib::types::Type::STRING, // AlbumTitle
glib::types::Type::STRING, // AlbumArtist
glib::types::Type::STRING, // Year
glib::types::Type::STRING, // Modification
glib::types::Type::U64, // ModificationAsSecs
glib::types::Type::STRING, // Color
glib::types::Type::STRING, // TextColor
];
let list_store: gtk::ListStore = gtk::ListStore::new(&col_types);
@ -361,13 +387,14 @@ pub fn initialize_gui(gui_data: &mut GuiData) {
}
// Invalid Symlinks
{
let col_types: [glib::types::Type; 6] = [
glib::types::Type::BOOL,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
glib::types::Type::STRING,
let col_types: [glib::types::Type; 7] = [
glib::types::Type::BOOL, // SelectionButton
glib::types::Type::STRING, // Name
glib::types::Type::STRING, // Path
glib::types::Type::STRING, // DestinationPath
glib::types::Type::STRING, // TypeOfError
glib::types::Type::STRING, // Modification
glib::types::Type::U64, // ModificationAsSecs
];
let list_store: gtk::ListStore = gtk::ListStore::new(&col_types);
@ -390,7 +417,14 @@ pub fn initialize_gui(gui_data: &mut GuiData) {
}
// Broken Files
{
let col_types: [glib::types::Type; 5] = [glib::types::Type::BOOL, glib::types::Type::STRING, glib::types::Type::STRING, glib::types::Type::STRING, glib::types::Type::STRING];
let col_types: [glib::types::Type; 6] = [
glib::types::Type::BOOL, // SelectionButton
glib::types::Type::STRING, // Name
glib::types::Type::STRING, // Path
glib::types::Type::STRING, // ErrorType
glib::types::Type::STRING, // Modification
glib::types::Type::U64, // ModificationAsSecs
];
let list_store: gtk::ListStore = gtk::ListStore::new(&col_types);
let mut tree_view: gtk::TreeView = TreeView::with_model(&list_store);