refactor: use match when processing EchidnaCoreEditor's initial file

Just like in 8e31be7.
merge-requests/23/head
Nefo Fortressia 2021-12-18 17:29:39 +07:00
parent 8e31be7e47
commit 9b99932fdd
Signed by: fortressia
GPG Key ID: 6D7972CC76174995
1 changed files with 37 additions and 35 deletions

View File

@ -21,47 +21,47 @@ impl EchidnaCoreEditor {
// Without cloning it, for some reasons the Rust compiler complains about &this.to_imp().sourceview not being IsA<sourceview::View> // Without cloning it, for some reasons the Rust compiler complains about &this.to_imp().sourceview not being IsA<sourceview::View>
this_imp.minimap.set_view(&this_imp.sourceview.clone()); this_imp.minimap.set_view(&this_imp.sourceview.clone());
if file.is_some() { match file {
let file = file.unwrap(); Some(file) => {
let file_location = file let file_location = file
.location() .location()
.expect("file is required to have a location"); .expect("file is required to have a location");
this.set_property("file", &file) this.set_property("file", &file)
.expect("Could not set the 'file' property of EchidnaCoreEditor"); .expect("Could not set the 'file' property of EchidnaCoreEditor");
let cancellable = gio::Cancellable::new(); let cancellable = gio::Cancellable::new();
let filepath = file_location.path().expect("No filepath"); let filepath = file_location.path().expect("No filepath");
let info = file_location let info = file_location
.query_info("*", gio::FileQueryInfoFlags::NONE, Some(&cancellable)) .query_info("*", gio::FileQueryInfoFlags::NONE, Some(&cancellable))
.expect("Could not query the info for file"); .expect("Could not query the info for file");
let content_type = info let content_type = info
.content_type() .content_type()
.expect(format!("It does not seem like {:?} has a type", filepath).as_str()); .expect(format!("It does not seem like {:?} has a type", filepath).as_str());
{ {
println!( println!(
"Opened {} and found its content type is {}.", "Opened {} and found its content type is {}.",
"file", "file",
content_type.to_string() content_type.to_string()
); );
let buffer = this_imp.sourceview.buffer().downcast::<Buffer>().expect("Cannot downcast the sourceview's buffer. Maybe the sourceview's buffer is not IsA<sourceview::Buffer>."); let buffer = this_imp.sourceview.buffer().downcast::<Buffer>().expect("Cannot downcast the sourceview's buffer. Maybe the sourceview's buffer is not IsA<sourceview::Buffer>.");
let language_manager = LanguageManager::new(); let language_manager = LanguageManager::new();
let language = language_manager.guess_language( let language = language_manager.guess_language(
Some(&info.name().to_str().expect( Some(&info.name().to_str().expect(
"Could not open the file because its name is not supported by Unicode.", "Could not open the file because its name is not supported by Unicode.",
)), )),
None, None,
); );
match language { match language {
Some(lang) => buffer.set_language(Some(&lang)), Some(lang) => buffer.set_language(Some(&lang)),
None => {} None => {}
} }
let file_loader: FileLoader = FileLoader::new(&buffer, &file); let file_loader: FileLoader = FileLoader::new(&buffer, &file);
file_loader.load_async( file_loader.load_async(
glib::Priority::default(), glib::Priority::default(),
Some(&cancellable), Some(&cancellable),
|_, _| {}, |_, _| {},
@ -71,7 +71,9 @@ impl EchidnaCoreEditor {
} }
}, },
); );
}
} }
None => {}
} }
this this
} }