Skip to content

Commit

Permalink
Open directories from the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
salihgerdan committed Mar 10, 2023
1 parent 45d4244 commit f8ed3d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use crate::config;
use gtk::{prelude::*, ResponseType};
use gtk::{gio::ApplicationFlags, glib, prelude::*, ResponseType};
use std::rc::Rc;
mod treemap_widget;
use treemap_widget::TreeMapWidget;

pub fn initiate_ui() {
let application = gtk::Application::new(Some(config::APP_NAME), Default::default());
application.connect_activate(build_ui);
let application = gtk::Application::new(Some(config::APP_NAME), ApplicationFlags::HANDLES_OPEN);
application.connect_open(build_ui);
application.connect_activate(|app| build_ui(app, &[], ""));
application.run();
}

fn build_ui(application: &gtk::Application) {
fn build_ui(application: &gtk::Application, arg_dirs: &[gtk::gio::File], _: &str) {
let window = gtk::ApplicationWindow::new(application);

window.set_title(Some(config::APP_TITLE));
Expand All @@ -34,21 +35,25 @@ fn build_ui(application: &gtk::Application) {
Some("Cancel"),
);

file_chooser.connect_response(move |d: &gtk::FileChooserNative, response: ResponseType| {
file_chooser.connect_response(glib::clone!(@weak treemap_widget => move |d: &gtk::FileChooserNative, response: ResponseType| {
if response == ResponseType::Accept {
let directory = d.file().expect("Couldn't get directory");
let path = directory.path().expect("Couldn't get path");
treemap_widget.start_scan(&path.display().to_string());
treemap_widget.start_scan(path.to_str().unwrap());
println!("{}", path.display());
}

d.hide();
});
}));

let open_button = gtk::Button::new();
open_button.set_icon_name("document-open");
headerbar.pack_start(&open_button);
open_button.connect_clicked(move |_| file_chooser.show());

if let Some(dir) = arg_dirs.get(0) {
treemap_widget.start_scan(dir.path().expect("Couldn't get path").to_str().unwrap());
}

window.show();
}
2 changes: 1 addition & 1 deletion src/gui/treemap_widget/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl ObjectImpl for TreeMapWidget {

fn constructed(&self) {
self.parent_constructed();
self.scan_complete_flag.replace(false);
self.scan_complete_flag.replace(true);
let obj = self.obj();
obj.set_width_request(100);
obj.set_height_request(100);
Expand Down

0 comments on commit f8ed3d6

Please sign in to comment.