Skip to content

Commit

Permalink
Merge branch 'huanie-huanie/url-drop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nik012003 committed Aug 14, 2023
2 parents b0622b7 + 662363c commit d9e621f
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 149 deletions.
106 changes: 0 additions & 106 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ exclude = ["/.vscode"]
clap = { version = "4.1.8", features = ["derive"] }
gtk = { version = "0.6.6", package = "gtk4", features = ["v4_6"] }
glib-macros = "0.18.0"
infer = "0.13.0"
opener = "0.5.2"
url = "2.3.1"

[profile.release]
strip = true
Expand Down
4 changes: 3 additions & 1 deletion src/compact_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{glib, CssProvider, DragSource, Label, Widget};

use crate::util::{generate_file_model, setup_drag_source_all, setup_drop_target, ListWidget, drag_source_and_exit};
use crate::util::{
drag_source_and_exit, generate_file_model, setup_drag_source_all, setup_drop_target, ListWidget,
};

pub fn generate_compact_view() -> ListWidget {
let file_model = generate_file_model();
Expand Down
8 changes: 6 additions & 2 deletions src/file_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@ impl FileObject {
let obj = Object::builder().property("file", file);
let icon_name = gio::content_type_get_generic_icon_name(&file.mime_type());
// use the default thumbnail
let image = gtk::Image::builder()
let icon = gtk::Image::builder()
.icon_name(icon_name.unwrap_or(glib::GString::format(format_args!("text/default"))))
.pixel_size(ARGS.get().unwrap().icon_size)
.build();
let obj = obj.property("thumbnail", image).build();
let obj = obj.property("thumbnail", icon).build();
let file = file.clone();

// For every image a thumbnail of the image is sent. When it is not an image a None is sent.
// There is no thumbnail for GIFs.
let (sender, receiver) = MainContext::channel(Priority::default());
gio::spawn_blocking(move || {
let print_err = |err| eprintln!("{}", err);
if !file.query_exists(gio::Cancellable::NONE) {
let _ = sender.send(None).map_err(print_err);
}

let mime_type = file.mime_type();
// this only works for images
if !ARGS.get().unwrap().disable_thumbnails
Expand Down
11 changes: 5 additions & 6 deletions src/list_view.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashSet;
use std::path::PathBuf;

use glib_macros::clone;
use gtk::gdk::*;
Expand All @@ -12,8 +11,8 @@ use gtk::{

use crate::file_object::FileObject;
use crate::util::{
generate_content_provider, generate_file_model, setup_drag_source_all, setup_drop_target,
ListWidget, drag_source_and_exit,
drag_source_and_exit, generate_content_provider, generate_file_model, setup_drag_source_all,
setup_drop_target, ListWidget,
};
use crate::{ARGS, CURRENT_DIRECTORY};

Expand Down Expand Up @@ -61,13 +60,13 @@ fn create_drag_source(row: &CenterBox, selection: &MultiSelection) -> DragSource
// This will prevent the click to trigger, a drag should happen!
me.set_state(gtk::EventSequenceState::Claimed);
let selected = selection.selection();
let mut files : HashSet<PathBuf> = HashSet::with_capacity(selected.size() as usize);
let mut files : HashSet<String> = HashSet::with_capacity(selected.size() as usize);
for index in 0..selected.size() {
files.insert(selection.item(selected.nth(index as u32)).unwrap().downcast::<FileObject>().unwrap().file().path().unwrap());
files.insert(selection.item(selected.nth(index as u32)).unwrap().downcast::<FileObject>().unwrap().file().uri().to_string());
}

// Is the activated row also selected?
let row_file = get_file(&row).path().unwrap();
let row_file = get_file(&row).uri().to_string();
if !files.contains(&row_file)
{
selection.unselect_all();
Expand Down
Loading

0 comments on commit d9e621f

Please sign in to comment.