refactor: simplify FileImplementedEditor::action_open_file()

No need the 'window' parameter as we can just use &self
merge-requests/8/head
Nefo Fortressia 2021-10-26 16:44:40 +07:00
parent 4d23860806
commit 8c05235e13
1 changed files with 29 additions and 29 deletions

View File

@ -25,7 +25,7 @@ use gtk::{
}; };
pub trait FileImplementedEditor { pub trait FileImplementedEditor {
fn action_open_file/*<P: IsA<gtk::Application>>*/(window: Self); fn action_open_file(&self);
fn open_file(notebook: &gtk::Notebook, file: gio::File); fn open_file(notebook: &gtk::Notebook, file: gio::File);
} }
@ -46,22 +46,22 @@ impl FileImplementedEditor for super::EchidnaWindow {
Perhaps some of the last points should not be implemented in this function but rather in another function that keeps track of every files. Perhaps some of the last points should not be implemented in this function but rather in another function that keeps track of every files.
*/ */
fn action_open_file/*<P: IsA<gtk::Application>>*/(window: Self){ fn action_open_file(&self) {
let dialog: FileChooserDialog = FileChooserDialog::new(
let dialog: FileChooserDialog = FileChooserDialog::new(Some("Open a file"), Some("Open a file"),
Some(&window), Some(self),
FileChooserAction::Open, FileChooserAction::Open,
&[("Cancel", ResponseType::Cancel), &[
("Open", ResponseType::Accept) ]); ("Cancel", ResponseType::Cancel),
("Open", ResponseType::Accept),
],
);
dialog.set_visible(true); dialog.set_visible(true);
// TODO: Somehow inserts self to this function. // TODO: Somehow inserts self to this function.
// This function sets the callback function as 'static, which for some reasons ban cloning self into it. Idk why. // This function sets the callback function as 'static, which for some reasons ban cloning self into it. Idk why.
dialog.connect_response(clone!( @weak window, => dialog.connect_response(clone!( @weak self as window, =>
move |dialog, response| { move |dialog, response| {
if response == ResponseType::Accept { if response == ResponseType::Accept {