Compare commits

...

8 Commits

Author SHA1 Message Date
Nefo Fortressia f785463540
refactor: refactor things with Clippy's help
Merge branch 'refactor/clippy' of https://gitea.treehouse.systems/fortressia/echidna

See #23
2021-12-27 20:59:09 +07:00
Nefo Fortressia e0d353a10b
refactor: remove double pointer in setting a file's tab title
This is because the file name is an &OsStr converted to &str and thus already a pointer.
2021-12-18 17:34:27 +07:00
Nefo Fortressia b53915afa0
refactor: set unused parameters in TabLabel as unused 2021-12-18 17:30:28 +07:00
Nefo Fortressia 9b99932fdd
refactor: use match when processing EchidnaCoreEditor's initial file
Just like in 8e31be7.
2021-12-18 17:29:39 +07:00
Nefo Fortressia 8e31be7e47
refactor: don't unwrap tab label' childs and use match when prepending it
If statements are for booleans, matches are intended for Options like these.

See: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap
2021-12-18 17:21:50 +07:00
Nefo Fortressia c8fd305d90
refactor: removed unused imports in closeable_tab.rs 2021-12-18 17:17:53 +07:00
Nefo Fortressia 10ae0cf783
feat: implement Default for EchidnaSidebar
EchidnaSidebar doesn't take any parameters, thus allowing Default to be easily implemented on it.
2021-12-18 17:17:15 +07:00
Nefo Fortressia 9e06e96fed
chore: remove clippy.toml
Clippy categories can only be configured trough parameters and clippy macros.

They can't be configured in config files.
2021-12-18 17:16:16 +07:00
7 changed files with 50 additions and 42 deletions

View File

@ -1 +0,0 @@
"clippy::style" = "deny"

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>
this_imp.minimap.set_view(&this_imp.sourceview.clone());
if file.is_some() {
let file = file.unwrap();
let file_location = file
.location()
.expect("file is required to have a location");
match file {
Some(file) => {
let file_location = file
.location()
.expect("file is required to have a location");
this.set_property("file", &file)
.expect("Could not set the 'file' property of EchidnaCoreEditor");
this.set_property("file", &file)
.expect("Could not set the 'file' property of EchidnaCoreEditor");
let cancellable = gio::Cancellable::new();
let filepath = file_location.path().expect("No filepath");
let info = file_location
.query_info("*", gio::FileQueryInfoFlags::NONE, Some(&cancellable))
.expect("Could not query the info for file");
let cancellable = gio::Cancellable::new();
let filepath = file_location.path().expect("No filepath");
let info = file_location
.query_info("*", gio::FileQueryInfoFlags::NONE, Some(&cancellable))
.expect("Could not query the info for file");
let content_type = info
.content_type()
.expect(format!("It does not seem like {:?} has a type", filepath).as_str());
{
println!(
"Opened {} and found its content type is {}.",
"file",
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 language_manager = LanguageManager::new();
let language = language_manager.guess_language(
Some(&info.name().to_str().expect(
"Could not open the file because its name is not supported by Unicode.",
)),
None,
);
let content_type = info
.content_type()
.expect(format!("It does not seem like {:?} has a type", filepath).as_str());
{
println!(
"Opened {} and found its content type is {}.",
"file",
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 language_manager = LanguageManager::new();
let language = language_manager.guess_language(
Some(&info.name().to_str().expect(
"Could not open the file because its name is not supported by Unicode.",
)),
None,
);
match language {
Some(lang) => buffer.set_language(Some(&lang)),
None => {}
}
match language {
Some(lang) => buffer.set_language(Some(&lang)),
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(),
Some(&cancellable),
|_, _| {},
@ -71,7 +71,9 @@ impl EchidnaCoreEditor {
}
},
);
}
}
None => {}
}
this
}

View File

@ -15,3 +15,9 @@ impl EchidnaSidebar {
glib::Object::new(&[]).expect("Failed to create 'EchidnaSidebar' component.")
}
}
impl Default for EchidnaSidebar {
fn default() -> Self {
Self::new()
}
}

View File

@ -36,9 +36,9 @@ impl BuildableImpl for TabLabel {
fn add_child(
&self,
buildable: &Self::Type,
builder: &gtk::Builder,
_builder: &gtk::Builder,
child: &glib::Object,
type_: Option<&str>,
_type_: Option<&str>,
) {
buildable.prepend(child.downcast_ref::<gtk::Widget>().unwrap());
}

View File

@ -17,8 +17,9 @@ impl TabLabel {
pub fn new<U: IsA<gtk::Widget>>(tab_label: Option<&U>) -> Self {
let this: Self = glib::Object::new(&[]).expect("Failed to create 'TabLabel' component.");
if tab_label.is_some() {
this.prepend(tab_label.unwrap());
match tab_label {
Some(tab_label) => this.prepend(tab_label),
None => {}
}
this
}

View File

@ -67,7 +67,7 @@ impl FileImplementedEditor for super::EchidnaWindow {
notebook.prepend_closable_page(
&editor_page,
Some(&Label::new(Some(
&file_location
file_location
.path()
.expect("The file's path is missing")
.file_name()

View File

@ -4,7 +4,7 @@
use crate::components::tab_label::TabLabel;
use glib::IsA;
use gtk::{prelude::*, Box, Button, Widget};
use gtk::{prelude::*, Widget};
pub trait ClosableTabImplementedNotebook {
fn prepend_closable_page<T: IsA<Widget>, U: IsA<Widget>>(