style: format files with Rustfmt
parent
d68a8a8994
commit
9594ed6539
|
@ -55,7 +55,9 @@ impl FileImplementedEditor for super::EchidnaWindow {
|
|||
Self::open_file(&super::imp::EchidnaWindow::from_instance(&window).notebook, file);
|
||||
|
||||
}
|
||||
|
||||
dialog.destroy();
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -130,6 +132,7 @@ impl FileImplementedEditor for super::EchidnaWindow {
|
|||
});
|
||||
|
||||
}
|
||||
|
||||
dialog.destroy();
|
||||
|
||||
}));
|
||||
|
|
|
@ -7,7 +7,5 @@ trait SidebarImplementedEditor {
|
|||
}
|
||||
|
||||
impl SidebarImplementedEditor for super::imp::EchidnaEditor {
|
||||
fn setup_sidebar(){
|
||||
|
||||
}
|
||||
fn setup_sidebar() {}
|
||||
}
|
|
@ -2,37 +2,26 @@
|
|||
* 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/. */
|
||||
|
||||
use glib::subclass::types::ObjectSubclassExt;
|
||||
use super::imp::EchidnaEditor;
|
||||
use std::path::Path;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use relative_path::RelativePath;
|
||||
use gio::Cancellable;
|
||||
use gio::{
|
||||
SimpleAction,
|
||||
File,
|
||||
FileQueryInfoFlags,
|
||||
FileType
|
||||
};
|
||||
use gtk::prelude::*;
|
||||
use gio::{File, FileQueryInfoFlags, FileType, SimpleAction};
|
||||
use glib::clone;
|
||||
use gtk::{
|
||||
ApplicationWindow,
|
||||
FileChooserDialog,
|
||||
FileChooserAction,
|
||||
ResponseType,
|
||||
TreeStore,
|
||||
};
|
||||
use glib::subclass::types::ObjectSubclassExt;
|
||||
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)]
|
||||
struct MonacoFolder {
|
||||
path: String
|
||||
path: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct MonacoWorkspace {
|
||||
folders: Vec<MonacoFolder>
|
||||
folders: Vec<MonacoFolder>,
|
||||
}
|
||||
|
||||
trait WorkspaceImplementedEditor {
|
||||
|
@ -50,7 +39,6 @@ trait WorkspaceImplementedEditor {
|
|||
}
|
||||
|
||||
impl WorkspaceImplementedEditor for EchidnaEditor {
|
||||
|
||||
fn action_open_workspace(
|
||||
&self,
|
||||
window: ApplicationWindow,
|
||||
|
@ -67,31 +55,23 @@ impl WorkspaceImplementedEditor for EchidnaEditor {
|
|||
("Open", ResponseType::Accept),
|
||||
],
|
||||
);
|
||||
|
||||
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 =>
|
||||
move |dialog, response| {
|
||||
|
||||
if response == ResponseType::Accept {
|
||||
|
||||
let file_option = dialog.file();
|
||||
|
||||
match file_option {
|
||||
Some(file) => {
|
||||
dialog.destroy();
|
||||
Self::from_instance(&app).open_workspace(file);
|
||||
},
|
||||
None => {
|
||||
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
} else if response == ResponseType::Cancel {
|
||||
dialog.destroy();
|
||||
|
||||
} }));
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
/**
|
||||
* __Open Workspace__
|
||||
|
@ -108,50 +88,58 @@ impl WorkspaceImplementedEditor for EchidnaEditor {
|
|||
*/
|
||||
fn open_workspace(&self, file: File) {
|
||||
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 file_info_result = file.query_info(
|
||||
"*",
|
||||
gio::FileQueryInfoFlags::NONE,
|
||||
Some(&cancellable));
|
||||
let file_info_result =
|
||||
file.query_info("*", gio::FileQueryInfoFlags::NONE, Some(&cancellable));
|
||||
|
||||
match file_info_result {
|
||||
Ok(info) => {
|
||||
match info.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 file_content = file.load_contents(Some(&content_cancellable));
|
||||
|
||||
match file_content {
|
||||
Ok(content) => {
|
||||
let (int_vec, _byte_string) = content;
|
||||
|
||||
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 folder = File::for_path(path.to_path(filepath));
|
||||
|
||||
// Do something with the folder, perhaps lists its child and .
|
||||
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),
|
||||
}
|
||||
},
|
||||
}
|
||||
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
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -159,8 +147,14 @@ fn open_workspace(&self, file: File){
|
|||
*/
|
||||
fn recursive_add_files_into_tree_store(&self, parent_file: File, tree: &TreeStore) {
|
||||
let child_enumerate_cancellable = Cancellable::new();
|
||||
let child_files = parent_file.enumerate_children("*", FileQueryInfoFlags::NONE, Some(&child_enumerate_cancellable));
|
||||
let filepath = &parent_file.path().expect("Could not get the file path of the file.");
|
||||
let child_files = parent_file.enumerate_children(
|
||||
"*",
|
||||
FileQueryInfoFlags::NONE,
|
||||
Some(&child_enumerate_cancellable),
|
||||
);
|
||||
let filepath = &parent_file
|
||||
.path()
|
||||
.expect("Could not get the file path of the file.");
|
||||
match child_files {
|
||||
Ok(files) => {
|
||||
for file_iter in files {
|
||||
|
@ -172,17 +166,16 @@ fn recursive_add_files_into_tree_store(&self, parent_file: File, tree: &TreeStor
|
|||
|
||||
if file_info.file_type() == FileType::Directory {
|
||||
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 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 look up the children files of {:?} because:\n{:#?}",
|
||||
filepath, e
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,8 +188,5 @@ fn recursive_add_files_into_tree_store(&self, parent_file: File, tree: &TreeStor
|
|||
fn open_folder(&self, file: File) {
|
||||
let tree = TreeStore::new(&[gdk::Texture::static_type(), Type::STRING]);
|
||||
self.recursive_add_files_into_tree_store(file, &tree);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue