c4f26883b1
* Add reference folder * Basic tree view cleaning * Computations * Similar Images * Muzyka i Wideo * Podwójne dwa razy, cztery razy! * Rozmiar i Nazwa * Spanko i działanko(przynajmniej zdaje mi się że działa) * Translatanko
241 lines
9.4 KiB
Rust
241 lines
9.4 KiB
Rust
use gdk::ModifierType;
|
|
use gtk::prelude::*;
|
|
|
|
use crate::help_functions::*;
|
|
use crate::notebook_enums::NotebookUpperEnum;
|
|
|
|
// TODO add option to open files and folders from context menu activated by pressing ONCE with right mouse button
|
|
|
|
pub fn opening_enter_function_ported(event_controller: >k::EventControllerKey, _key_value: u32, key_code: u32, _modifier_type: ModifierType) -> bool {
|
|
let tree_view = event_controller.widget().unwrap().downcast::<gtk::TreeView>().unwrap();
|
|
#[cfg(debug_assertions)]
|
|
{
|
|
println!("key_code {}", key_code);
|
|
}
|
|
|
|
let nt_object = get_notebook_object_from_tree_view(&tree_view);
|
|
handle_tree_keypress(
|
|
&tree_view,
|
|
key_code,
|
|
nt_object.column_name,
|
|
nt_object.column_path,
|
|
nt_object.column_selection,
|
|
nt_object.column_color,
|
|
);
|
|
false // True catches signal, and don't send it to function, e.g. up button is catched and don't move selection
|
|
}
|
|
|
|
pub fn opening_enter_function_ported_upper_directories(event_controller: >k::EventControllerKey, _key_value: u32, key_code: u32, _modifier_type: ModifierType) -> bool {
|
|
let tree_view = event_controller.widget().unwrap().downcast::<gtk::TreeView>().unwrap();
|
|
#[cfg(debug_assertions)]
|
|
{
|
|
println!("key_code {}", key_code);
|
|
}
|
|
|
|
match get_notebook_upper_enum_from_tree_view(&tree_view) {
|
|
NotebookUpperEnum::IncludedDirectories => {
|
|
handle_tree_keypress_upper_directories(
|
|
&tree_view,
|
|
key_code,
|
|
ColumnsIncludedDirectory::Path as i32,
|
|
Some(ColumnsIncludedDirectory::ReferenceButton as i32),
|
|
);
|
|
}
|
|
NotebookUpperEnum::ExcludedDirectories => {
|
|
handle_tree_keypress_upper_directories(&tree_view, key_code, ColumnsExcludedDirectory::Path as i32, None);
|
|
}
|
|
_ => {
|
|
panic!()
|
|
}
|
|
}
|
|
false // True catches signal, and don't send it to function, e.g. up button is catched and don't move selection
|
|
}
|
|
|
|
pub fn opening_double_click_function(tree_view: >k::TreeView, event: &gdk::EventButton) -> gtk::Inhibit {
|
|
let nt_object = get_notebook_object_from_tree_view(tree_view);
|
|
if event.event_type() == gdk::EventType::DoubleButtonPress && event.button() == 1 {
|
|
common_open_function(tree_view, nt_object.column_name, nt_object.column_path, OpenMode::PathAndName);
|
|
} else if event.event_type() == gdk::EventType::DoubleButtonPress && event.button() == 3 {
|
|
common_open_function(tree_view, nt_object.column_name, nt_object.column_path, OpenMode::OnlyPath);
|
|
}
|
|
gtk::Inhibit(false)
|
|
}
|
|
|
|
pub fn opening_double_click_function_directories(tree_view: >k::TreeView, event: &gdk::EventButton) -> gtk::Inhibit {
|
|
if event.event_type() == gdk::EventType::DoubleButtonPress && (event.button() == 1 || event.button() == 3) {
|
|
match get_notebook_upper_enum_from_tree_view(tree_view) {
|
|
NotebookUpperEnum::IncludedDirectories => {
|
|
common_open_function_upper_directories(tree_view, ColumnsIncludedDirectory::Path as i32);
|
|
}
|
|
NotebookUpperEnum::ExcludedDirectories => {
|
|
common_open_function_upper_directories(tree_view, ColumnsExcludedDirectory::Path as i32);
|
|
}
|
|
_ => {
|
|
panic!()
|
|
}
|
|
}
|
|
}
|
|
gtk::Inhibit(false)
|
|
}
|
|
|
|
// // GTK 4
|
|
// pub fn opening_enter_function_ported(event_controller: >k4::EventControllerKey, _key: gdk4::keys::Key, key_code: u32, _modifier_type: ModifierType) -> gtk4::Inhibit {
|
|
// let tree_view = event_controller.widget().unwrap().downcast::<gtk4::TreeView>().unwrap();
|
|
// #[cfg(debug_assertions)]
|
|
// {
|
|
// println!("key_code {}", key_code);
|
|
// }
|
|
//
|
|
// let nt_object = get_notebook_object_from_tree_view(&tree_view);
|
|
// handle_tree_keypress(&tree_view, key_code, nt_object.column_name, nt_object.column_path, nt_object.column_selection);
|
|
// Inhibit(false) // True catches signal, and don't send it to function, e.g. up button is catched and don't move selection
|
|
// }
|
|
//
|
|
// pub fn opening_double_click_function(gesture_click: &GestureClick, number_of_clicks: i32, _b: f64, _c: f64) {
|
|
// let tree_view = gesture_click.widget().unwrap().downcast::<gtk4::TreeView>().unwrap();
|
|
//
|
|
// let nt_object = get_notebook_object_from_tree_view(&tree_view);
|
|
// if number_of_clicks == 2 {
|
|
// if gesture_click.current_button() == 1 {
|
|
// common_open_function(&tree_view, nt_object.column_name, nt_object.column_path, OpenMode::PathAndName);
|
|
// } else if gesture_click.current_button() == 3 {
|
|
// common_open_function(&tree_view, nt_object.column_name, nt_object.column_path, OpenMode::OnlyPath);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
enum OpenMode {
|
|
OnlyPath,
|
|
PathAndName,
|
|
}
|
|
|
|
fn common_mark_function(tree_view: >k::TreeView, column_selection: i32, column_color: Option<i32>) {
|
|
let selection = tree_view.selection();
|
|
let (selected_rows, tree_model) = selection.selected_rows();
|
|
|
|
let model = get_list_store(tree_view);
|
|
|
|
for tree_path in selected_rows.iter().rev() {
|
|
if let Some(column_color) = column_color {
|
|
if model.value(&model.iter(tree_path).unwrap(), column_color).get::<String>().unwrap() == HEADER_ROW_COLOR {
|
|
continue;
|
|
}
|
|
}
|
|
let value = !tree_model.value(&tree_model.iter(tree_path).unwrap(), column_selection).get::<bool>().unwrap();
|
|
model.set_value(&tree_model.iter(tree_path).unwrap(), column_selection as u32, &value.to_value());
|
|
}
|
|
}
|
|
|
|
fn common_open_function(tree_view: >k::TreeView, column_name: i32, column_path: i32, opening_mode: OpenMode) {
|
|
let selection = tree_view.selection();
|
|
let (selected_rows, tree_model) = selection.selected_rows();
|
|
|
|
for tree_path in selected_rows.iter().rev() {
|
|
let name = tree_model.value(&tree_model.iter(tree_path).unwrap(), column_name).get::<String>().unwrap();
|
|
let path = tree_model.value(&tree_model.iter(tree_path).unwrap(), column_path).get::<String>().unwrap();
|
|
|
|
let end_path = match opening_mode {
|
|
OpenMode::OnlyPath => path,
|
|
OpenMode::PathAndName => get_full_name_from_path_name(&path, &name),
|
|
};
|
|
|
|
open::that_in_background(&end_path);
|
|
|
|
// if let Err(e) = open::that(&end_path) {
|
|
// println!("Failed to open {} - Error {}", end_path, e);
|
|
// }
|
|
}
|
|
}
|
|
|
|
fn common_open_function_upper_directories(tree_view: >k::TreeView, column_full_path: i32) {
|
|
let selection = tree_view.selection();
|
|
let (selected_rows, tree_model) = selection.selected_rows();
|
|
|
|
for tree_path in selected_rows.iter().rev() {
|
|
let full_path = tree_model.value(&tree_model.iter(tree_path).unwrap(), column_full_path).get::<String>().unwrap();
|
|
|
|
open::that_in_background(&full_path);
|
|
}
|
|
}
|
|
|
|
fn handle_tree_keypress_upper_directories(tree_view: >k::TreeView, key_code: u32, full_path_column: i32, mark_column: Option<i32>) {
|
|
match key_code {
|
|
KEY_ENTER => {
|
|
common_open_function_upper_directories(tree_view, full_path_column);
|
|
}
|
|
KEY_SPACE => {
|
|
if let Some(mark_column) = mark_column {
|
|
common_mark_function(tree_view, mark_column, None);
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
fn handle_tree_keypress(tree_view: >k::TreeView, key_code: u32, name_column: i32, path_column: i32, mark_column: i32, column_color: Option<i32>) {
|
|
match key_code {
|
|
KEY_ENTER => {
|
|
common_open_function(tree_view, name_column, path_column, OpenMode::PathAndName);
|
|
}
|
|
KEY_SPACE => {
|
|
common_mark_function(tree_view, mark_column, column_color);
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
pub fn select_function_duplicates(_tree_selection: >k::TreeSelection, tree_model: >k::TreeModel, tree_path: >k::TreePath, _is_path_currently_selected: bool) -> bool {
|
|
let color = tree_model
|
|
.value(&tree_model.iter(tree_path).unwrap(), ColumnsDuplicates::Color as i32)
|
|
.get::<String>()
|
|
.unwrap();
|
|
|
|
if color == HEADER_ROW_COLOR {
|
|
return false;
|
|
}
|
|
|
|
true
|
|
}
|
|
|
|
pub fn select_function_same_music(_tree_selection: >k::TreeSelection, tree_model: >k::TreeModel, tree_path: >k::TreePath, _is_path_currently_selected: bool) -> bool {
|
|
let color = tree_model
|
|
.value(&tree_model.iter(tree_path).unwrap(), ColumnsSameMusic::Color as i32)
|
|
.get::<String>()
|
|
.unwrap();
|
|
|
|
if color == HEADER_ROW_COLOR {
|
|
return false;
|
|
}
|
|
|
|
true
|
|
}
|
|
|
|
pub fn select_function_similar_images(_tree_selection: >k::TreeSelection, tree_model: >k::TreeModel, tree_path: >k::TreePath, _is_path_currently_selected: bool) -> bool {
|
|
let color = tree_model
|
|
.value(&tree_model.iter(tree_path).unwrap(), ColumnsSimilarImages::Color as i32)
|
|
.get::<String>()
|
|
.unwrap();
|
|
|
|
if color == HEADER_ROW_COLOR {
|
|
return false;
|
|
}
|
|
|
|
true
|
|
}
|
|
|
|
pub fn select_function_similar_videos(_tree_selection: >k::TreeSelection, tree_model: >k::TreeModel, tree_path: >k::TreePath, _is_path_currently_selected: bool) -> bool {
|
|
let color = tree_model
|
|
.value(&tree_model.iter(tree_path).unwrap(), ColumnsSimilarVideos::Color as i32)
|
|
.get::<String>()
|
|
.unwrap();
|
|
|
|
if color == HEADER_ROW_COLOR {
|
|
return false;
|
|
}
|
|
|
|
true
|
|
}
|
|
pub fn select_function_always_true(_tree_selection: >k::TreeSelection, _tree_model: >k::TreeModel, _tree_path: >k::TreePath, _is_path_currently_selected: bool) -> bool {
|
|
true
|
|
}
|