From b9504e881e89d13beeb17cbe7d316810227ae9c2 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sun, 31 Jul 2022 19:33:21 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20unwrap=20group=20if=20double=20c?= =?UTF-8?q?licked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 4 ++-- src/application_browser.rs | 32 ++++++++++++++++++++++++++++++++ src/main.rs | 1 - 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 377937a..c50ccc9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,9 +102,9 @@ checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" [[package]] name = "bytes" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cachyos-hello" diff --git a/src/application_browser.rs b/src/application_browser.rs index a26b662..4a1c206 100644 --- a/src/application_browser.rs +++ b/src/application_browser.rs @@ -210,6 +210,7 @@ impl ApplicationBrowser { self.tree_view.set_activate_on_single_click(true); self.tree_view.set_has_tooltip(true); self.tree_view.connect_query_tooltip(on_query_tooltip_tree_view); + self.tree_view.connect_button_press_event(on_button_press_event_tree_view); // column model: icon let icon = gtk::CellRendererPixbuf::new(); @@ -364,6 +365,37 @@ fn on_query_tooltip_tree_view( false } +fn on_button_press_event_tree_view( + treeview: >k::TreeView, + event_btn: &gdk::EventButton, +) -> gtk::glib::signal::Inhibit { + if event_btn.button() == 1 && event_btn.event_type() == gdk::EventType::DoubleButtonPress { + if let Some(coords) = event_btn.coords() { + let (x, y) = coords; + let path_info = treeview.path_at_pos(x as i32, y as i32); + if path_info == None { + return gtk::glib::signal::Inhibit(true); + } + + let (path, ..) = path_info.unwrap(); + let app_browser = unsafe { &mut G_APP_BROWSER.lock().unwrap() }; + let app_store = app_browser.app_store.clone(); + let iter_a = app_store.iter(&path.clone().unwrap()).unwrap(); + let value_gobj = app_store.value(&iter_a, PACKAGE as i32); + + if value_gobj.get::<&str>().is_err() { + if treeview.row_expanded(&path.clone().unwrap()) { + treeview.collapse_row(&path.unwrap()); + } else { + treeview.expand_to_path(&path.unwrap()); + } + } + } + } + + gtk::glib::signal::Inhibit(false) +} + fn on_app_toggle(_cell: >k::CellRendererToggle, path: gtk::TreePath) { let app_browser = unsafe { &mut G_APP_BROWSER.lock().unwrap() }; let app_store = app_browser.app_store.clone(); diff --git a/src/main.rs b/src/main.rs index 73fac6b..895cd41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -#![feature(const_slice_from_raw_parts)] #![feature(const_str_from_utf8)] #![feature(string_remove_matches)] #![allow(non_upper_case_globals)]