refactor: simplify FileImplementedEditor::action_open_file()
No need the 'window' parameter as we can just use &selfmerge-requests/8/head
parent
4d23860806
commit
8c05235e13
|
@ -25,43 +25,43 @@ 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: >k::Notebook, file: gio::File);
|
fn open_file(notebook: >k::Notebook, file: gio::File);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileImplementedEditor for super::EchidnaWindow {
|
impl FileImplementedEditor for super::EchidnaWindow {
|
||||||
/*
|
/*
|
||||||
Open a file and put it in an editor and the opened files bar.
|
Open a file and put it in an editor and the opened files bar.
|
||||||
|
|
||||||
- Open a file chooser dialog.
|
- Open a file chooser dialog.
|
||||||
- Connect a signal to it and get the file choosen.
|
- Connect a signal to it and get the file choosen.
|
||||||
- Read th file's information and
|
- Read th file's information and
|
||||||
- TODO: if it's a plain text,
|
- TODO: if it's a plain text,
|
||||||
- TODO: Load the file's content
|
- TODO: Load the file's content
|
||||||
- TODO: Create an editor
|
- TODO: Create an editor
|
||||||
- TODO: Set the editor's content to the file's content.
|
- TODO: Set the editor's content to the file's content.
|
||||||
- TODO: Somehow keep track of what file belongs to what editor/opened file bar widget.
|
- TODO: Somehow keep track of what file belongs to what editor/opened file bar widget.
|
||||||
- TODO: If the user enables Autosave, listen to the editor's changes and automatically save the editor's content.
|
- TODO: If the user enables Autosave, listen to the editor's changes and automatically save the editor's content.
|
||||||
- TODO: Close the editor and the tab widget when the file is closed (triggered by the X button on them).
|
- TODO: Close the editor and the tab widget when the file is closed (triggered by the X button on them).
|
||||||
|
|
||||||
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(
|
||||||
|
Some("Open a file"),
|
||||||
|
Some(self),
|
||||||
|
FileChooserAction::Open,
|
||||||
|
&[
|
||||||
|
("Cancel", ResponseType::Cancel),
|
||||||
|
("Open", ResponseType::Accept),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let dialog: FileChooserDialog = FileChooserDialog::new(Some("Open a file"),
|
dialog.set_visible(true);
|
||||||
Some(&window),
|
|
||||||
FileChooserAction::Open,
|
|
||||||
&[("Cancel", ResponseType::Cancel),
|
|
||||||
("Open", ResponseType::Accept) ]);
|
|
||||||
|
|
||||||
|
// TODO: Somehow inserts self to this function.
|
||||||
dialog.set_visible(true);
|
// This function sets the callback function as 'static, which for some reasons ban cloning self into it. Idk why.
|
||||||
|
dialog.connect_response(clone!( @weak self as window, =>
|
||||||
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
dialog.connect_response(clone!( @weak window, =>
|
|
||||||
move |dialog, response| {
|
move |dialog, response| {
|
||||||
|
|
||||||
if response == ResponseType::Accept {
|
if response == ResponseType::Accept {
|
||||||
|
|
Loading…
Reference in New Issue