style: format files with Rustfmt

merge-requests/8/head
Nefo Fortressia 2021-10-31 17:30:19 +07:00
parent d68a8a8994
commit 9594ed6539
4 changed files with 165 additions and 174 deletions

View File

@ -55,7 +55,9 @@ impl FileImplementedEditor for super::EchidnaWindow {
Self::open_file(&super::imp::EchidnaWindow::from_instance(&window).notebook, file); Self::open_file(&super::imp::EchidnaWindow::from_instance(&window).notebook, file);
} }
dialog.destroy(); dialog.destroy();
})); }));
} }
@ -130,6 +132,7 @@ impl FileImplementedEditor for super::EchidnaWindow {
}); });
} }
dialog.destroy(); dialog.destroy();
})); }));

View File

@ -7,7 +7,5 @@ trait SidebarImplementedEditor {
} }
impl SidebarImplementedEditor for super::imp::EchidnaEditor { impl SidebarImplementedEditor for super::imp::EchidnaEditor {
fn setup_sidebar(){ fn setup_sidebar() {}
}
} }

View File

@ -2,37 +2,26 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use glib::subclass::types::ObjectSubclassExt; use super::imp::EchidnaEditor;
use super::imp::EchidnaEditor; use gio::Cancellable;
use std::path::Path; use gio::{File, FileQueryInfoFlags, FileType, SimpleAction};
use serde::{Deserialize, Serialize}; use glib::clone;
use relative_path::RelativePath; use glib::subclass::types::ObjectSubclassExt;
use gio::Cancellable;
use gio::{
SimpleAction,
File,
FileQueryInfoFlags,
FileType
};
use gtk::prelude::*;
use glib::clone;
use gtk::{
ApplicationWindow,
FileChooserDialog,
FileChooserAction,
ResponseType,
TreeStore,
};
use glib::types::Type; use glib::types::Type;
use gtk::prelude::*;
use gtk::{ApplicationWindow, FileChooserAction, FileChooserDialog, ResponseType, TreeStore};
use relative_path::RelativePath;
use serde::{Deserialize, Serialize};
use std::path::Path;
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
struct MonacoFolder { struct MonacoFolder {
path: String path: String,
} }
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
struct MonacoWorkspace { struct MonacoWorkspace {
folders: Vec<MonacoFolder> folders: Vec<MonacoFolder>,
} }
trait WorkspaceImplementedEditor { trait WorkspaceImplementedEditor {
@ -50,7 +39,6 @@ trait WorkspaceImplementedEditor {
} }
impl WorkspaceImplementedEditor for EchidnaEditor { impl WorkspaceImplementedEditor for EchidnaEditor {
fn action_open_workspace( fn action_open_workspace(
&self, &self,
window: ApplicationWindow, window: ApplicationWindow,
@ -67,33 +55,25 @@ impl WorkspaceImplementedEditor for EchidnaEditor {
("Open", ResponseType::Accept), ("Open", ResponseType::Accept),
], ],
); );
dialog.set_visible(true); dialog.set_visible(true);
// 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, @weak app => dialog.connect_response(clone!(@weak window, @weak app =>
move |dialog, response| { move |dialog, response| {
if response == ResponseType::Accept { if response == ResponseType::Accept {
let file_option = dialog.file(); let file_option = dialog.file();
match file_option { match file_option {
Some(file) => { Some(file) => {
dialog.destroy(); dialog.destroy();
Self::from_instance(&app).open_workspace(file); Self::from_instance(&app).open_workspace(file);
}, },
None => { None => {}
},
} }
} else if response == ResponseType::Cancel { } else if response == ResponseType::Cancel {
dialog.destroy(); dialog.destroy();
} }));
} }
/** }
));
}
/**
* __Open Workspace__ * __Open Workspace__
* *
* Basically, this is just the same as Open Folder, but it's many folders. * Basically, this is just the same as Open Folder, but it's many folders.
@ -106,61 +86,75 @@ impl WorkspaceImplementedEditor for EchidnaEditor {
* - Create a GFile instance of that path, and call open_folder(file: File) and pass the GFile instance to it. * - Create a GFile instance of that path, and call open_folder(file: File) and pass the GFile instance to it.
* *
*/ */
fn open_workspace(&self, file: File){ fn open_workspace(&self, file: File) {
let cancellable = Cancellable::new(); let cancellable = Cancellable::new();
let filepath_raw = &file.path().expect("Could not get the file path of the file."); let filepath_raw = &file
.path()
.expect("Could not get the file path of the file.");
let filepath = Path::new(&filepath_raw); let filepath = Path::new(&filepath_raw);
let file_info_result = file.query_info( let file_info_result =
"*", file.query_info("*", gio::FileQueryInfoFlags::NONE, Some(&cancellable));
gio::FileQueryInfoFlags::NONE,
Some(&cancellable));
match file_info_result { match file_info_result {
Ok(info) => { Ok(info) => {
match info.content_type() { match info.content_type() {
Some(content_type) => { Some(content_type) => {
println!("Opened {} and found its content type is {}.", "file", content_type.to_string()); println!(
"Opened {} and found its content type is {}.",
"file",
content_type.to_string()
);
let content_cancellable = Cancellable::new(); let content_cancellable = Cancellable::new();
let file_content = file.load_contents(Some(&content_cancellable)); let file_content = file.load_contents(Some(&content_cancellable));
match file_content { match file_content {
Ok(content) => { Ok(content) => {
let (int_vec, _byte_string) = content; let (int_vec, _byte_string) = content;
match serde_json::from_slice::<MonacoWorkspace>(&int_vec) { match serde_json::from_slice::<MonacoWorkspace>(&int_vec) {
Ok(workspace) => for folder in workspace.folders { Ok(workspace) => {
for folder in workspace.folders {
let path = RelativePath::new(&folder.path); let path = RelativePath::new(&folder.path);
let folder = File::for_path(path.to_path(filepath)); let folder = File::for_path(path.to_path(filepath));
// Do something with the folder, perhaps lists its child and . // Do something with the folder, perhaps lists its child and .
self.open_folder(folder); self.open_folder(folder);
}, }
Err(e) => println!("Could not parse {:#?} because of:\n{}", filepath, e), }
Err(e) => println!(
"Could not parse {:#?} because of:\n{}",
filepath, e
),
} }
} }
Err(e) => println!("Could not open {:?} because:\n{}", filepath, e), Err(e) => println!("Could not open {:?} because:\n{}", filepath, e),
} }
}, }
None => println!("It does not seem like {:?} has a type", filepath), None => println!("It does not seem like {:?} has a type", filepath),
}
}
Err(e) => println!(
"Could not retrieve file information for {:?} because:\n{}",
filepath, e
),
}
} }
}, /**
Err(e) => println!("Could not retrieve file information for {:?} because:\n{}", filepath, e),
}
}
/**
* *
* *
*/ */
fn recursive_add_files_into_tree_store(&self, parent_file: File, tree: &TreeStore){ fn recursive_add_files_into_tree_store(&self, parent_file: File, tree: &TreeStore) {
let child_enumerate_cancellable = Cancellable::new(); let child_enumerate_cancellable = Cancellable::new();
let child_files = parent_file.enumerate_children("*", FileQueryInfoFlags::NONE, Some(&child_enumerate_cancellable)); let child_files = parent_file.enumerate_children(
let filepath = &parent_file.path().expect("Could not get the file path of the file."); "*",
FileQueryInfoFlags::NONE,
Some(&child_enumerate_cancellable),
);
let filepath = &parent_file
.path()
.expect("Could not get the file path of the file.");
match child_files { match child_files {
Ok(files) => { Ok(files) => {
for file_iter in files { for file_iter in files {
@ -172,31 +166,27 @@ fn recursive_add_files_into_tree_store(&self, parent_file: File, tree: &TreeStor
if file_info.file_type() == FileType::Directory { if file_info.file_type() == FileType::Directory {
self.recursive_add_files_into_tree_store(file, tree); self.recursive_add_files_into_tree_store(file, tree);
}
}
Err(e) => println!("Could not get information on file because of:\n{}", e),
}
}
}
Err(e) => println!(
"Could not look up the children files of {:?} because:\n{:#?}",
filepath, e
),
}
} }
}, /*
Err(e) => println!("Could not get information on file because of:\n{}", e)
}
}
},
Err(e) => println!("Could not look up the children files of {:?} because:\n{:#?}", filepath, e)
}
}
/*
Loads a folder into the tree view. Loads a folder into the tree view.
- Create a new tree - Create a new tree
- Enumerate over child files of 'file'. (PS: In the Unix family of OS-es, directories are files too) - Enumerate over child files of 'file'. (PS: In the Unix family of OS-es, directories are files too)
*/ */
fn open_folder(&self, file: File){ fn open_folder(&self, file: File) {
let tree = TreeStore::new(&[gdk::Texture::static_type(), Type::STRING]); let tree = TreeStore::new(&[gdk::Texture::static_type(), Type::STRING]);
self.recursive_add_files_into_tree_store(file, &tree); self.recursive_add_files_into_tree_store(file, &tree);
} }
} }