diff --git a/src/app/browser.rs b/src/app/browser.rs index 6c3274d5..8e6afccb 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -1,83 +1,39 @@ -#[path = "browser/header.rs"] mod header; -#[path = "browser/main.rs"] mod main; +#[path = "browser/header.rs"] +mod header; +#[path = "browser/main.rs"] +mod main; use gtk::{ - Application, - ApplicationWindow, gio::ActionEntry, - prelude::{ - ActionMapExtManual, - GtkWindowExt - } + prelude::{ActionMapExtManual, GtkWindowExt}, + Application, ApplicationWindow, }; -pub fn new( - app: &Application, - width: i32, - height: i32 -) -> ApplicationWindow -{ +pub fn new(app: &Application, width: i32, height: i32) -> ApplicationWindow { // Init browser window let browser = ApplicationWindow::builder() - - // Tuneup - .default_width( - width - ) - - .default_height( - height - ) - - // Relate - .application( - app - ) - - // Init components - .titlebar( - &header::new() - ) - - .child( - &main::new() - ) - - // Make + .default_width(width) + .default_height(height) + .application(app) + .titlebar(&header::new()) + .child(&main::new()) .build(); - // Init actions - let action_debug = ActionEntry::builder("debug") - - .activate( - |browser: &ApplicationWindow, _, _| - { - browser.emit_enable_debugging( - true - ); - } - ) - - .build(); - - let action_quit = ActionEntry::builder("quit") - - .activate( - |browser: &ApplicationWindow, _, _| - { - browser.close(); - } - ) + // Init actions + let action_debug = ActionEntry::builder("debug") + .activate(|browser: &ApplicationWindow, _, _| { + browser.emit_enable_debugging(true); + }) + .build(); - .build(); + let action_quit = ActionEntry::builder("quit") + .activate(|browser: &ApplicationWindow, _, _| { + browser.close(); + }) + .build(); - browser.add_action_entries( - [ - action_debug, - action_quit - ] - ); + browser.add_action_entries([action_debug, action_quit]); // Done browser -} \ No newline at end of file +} diff --git a/src/app/browser/header.rs b/src/app/browser/header.rs index 4c388a92..ff082bbd 100644 --- a/src/app/browser/header.rs +++ b/src/app/browser/header.rs @@ -1,21 +1,14 @@ -#[path = "header/subject.rs"] mod subject; -#[path = "header/tray.rs"] mod tray; +#[path = "header/subject.rs"] +mod subject; +#[path = "header/tray.rs"] +mod tray; use gtk::HeaderBar; -pub fn new() -> HeaderBar -{ +pub fn new() -> HeaderBar { let header = HeaderBar::builder().build(); - header.pack_start( - &tray::new() - ); - - header.set_title_widget( - Some( - &subject::new() - ) - ); - + header.pack_start(&tray::new()); + header.set_title_widget(Some(&subject::new())); header -} \ No newline at end of file +} diff --git a/src/app/browser/header/subject.rs b/src/app/browser/header/subject.rs index e4b6ac3f..7a986ac0 100644 --- a/src/app/browser/header/subject.rs +++ b/src/app/browser/header/subject.rs @@ -1,33 +1,22 @@ -#[path = "subject/title.rs"] mod title; -#[path = "subject/description.rs"] mod description; +#[path = "subject/description.rs"] +mod description; +#[path = "subject/title.rs"] +mod title; -use gtk::Box; use gtk::prelude::BoxExt; +use gtk::Box; -pub fn new() -> Box -{ +pub fn new() -> Box { let subject = Box::builder() - // Tuneup - .orientation( - gtk::Orientation::Vertical - ) - - .valign( - gtk::Align::Center - ) - + .orientation(gtk::Orientation::Vertical) + .valign(gtk::Align::Center) .build(); - // Compose childs - subject.append( - &title::new() - ); - - subject.append( - &description::new() - ); + // Compose childs + subject.append(&title::new()); + subject.append(&description::new()); // Done subject -} \ No newline at end of file +} diff --git a/src/app/browser/header/subject/description.rs b/src/app/browser/header/subject/description.rs index 731ac903..639025c9 100644 --- a/src/app/browser/header/subject/description.rs +++ b/src/app/browser/header/subject/description.rs @@ -1,49 +1,27 @@ -use gtk::Label; use gtk::prelude::WidgetExt; +use gtk::Label; -pub fn new() -> Label -{ +pub fn new() -> Label { let description = Label::builder() - - .css_classes( - [ - "subtitle" - ] - ) - - .single_line_mode( - true - ) - - .ellipsize( - gtk::pango::EllipsizeMode::End - ) - + .css_classes(["subtitle"]) + .single_line_mode(true) + .ellipsize(gtk::pango::EllipsizeMode::End) .build(); update( &description, - "" // @TODO + "", // @TODO ); - return description; + description } -pub fn update( - description: &Label, - text: &str -) { - description.set_text( - text - ); +pub fn update(description: &Label, text: &str) { + description.set_text(text); - if text.is_empty() - { + if text.is_empty() { description.hide(); - } - - else - { + } else { description.show(); } -} \ No newline at end of file +} diff --git a/src/app/browser/header/subject/title.rs b/src/app/browser/header/subject/title.rs index 29e3c626..a622d5fd 100644 --- a/src/app/browser/header/subject/title.rs +++ b/src/app/browser/header/subject/title.rs @@ -1,50 +1,23 @@ use gtk::Label; -pub fn new() -> Label -{ +pub fn new() -> Label { let title = Label::builder() - - .css_classes( - [ - "title" - ] - ) - - .single_line_mode( - true - ) - - .ellipsize( - gtk::pango::EllipsizeMode::End - ) - + .css_classes(["title"]) + .single_line_mode(true) + .ellipsize(gtk::pango::EllipsizeMode::End) .build(); - update( - &title, - "Welcome" - ); + update(&title, "Welcome"); return title; } -pub fn update( - title: &Label, - text: &str -) { +pub fn update(title: &Label, text: &str) { let default_text = "Yoda"; // @TODO - if text.is_empty() - { - title.set_text( - default_text - ); + if text.is_empty() { + title.set_text(default_text); + } else { + title.set_text(&format!("{} - {}", text, default_text)); } - - else - { - title.set_text( - &format!("{} - {}", text, default_text) - ); - } -} \ No newline at end of file +} diff --git a/src/app/browser/header/tray.rs b/src/app/browser/header/tray.rs index 8a1e0faa..ae349b78 100644 --- a/src/app/browser/header/tray.rs +++ b/src/app/browser/header/tray.rs @@ -1,31 +1,20 @@ -#[path = "tray/menu.rs"] mod menu; -#[path = "tray/tab.rs"] mod tab; +#[path = "tray/menu.rs"] +mod menu; +#[path = "tray/tab.rs"] +mod tab; -use gtk::Box; use gtk::prelude::BoxExt; +use gtk::Box; -pub fn new() -> Box -{ +pub fn new() -> Box { let tray = Box::builder() - - // Tuneup - .orientation( - gtk::Orientation::Horizontal - ) - + .orientation(gtk::Orientation::Horizontal) .spacing(8) - - // Make .build(); - // Compose childs - tray.append( - &menu::new() - ); - - tray.append( - &tab::new() - ); + // Compose childs + tray.append(&menu::new()); + tray.append(&tab::new()); tray -} \ No newline at end of file +} diff --git a/src/app/browser/header/tray/menu.rs b/src/app/browser/header/tray/menu.rs index 07a06b59..81845360 100644 --- a/src/app/browser/header/tray/menu.rs +++ b/src/app/browser/header/tray/menu.rs @@ -1,45 +1,17 @@ -use gtk::{ - gio, - MenuButton -}; +use gtk::{gio, MenuButton}; -pub fn new() -> MenuButton -{ - let menu = MenuButton::builder() - - .tooltip_text( - "Menu" - ) - - .build(); +pub fn new() -> MenuButton { + let menu = MenuButton::builder().tooltip_text("Menu").build(); let model = gio::Menu::new(); + let model_tab = gio::Menu::new(); - let model_tab = gio::Menu::new(); - - model_tab.append( - Some("Append"), - Some("win.tab_append") - ); - - model.append_submenu( - Some("Tab"), - &model_tab - ); - - model.append( - Some("Debug"), - Some("win.debug") - ); - - model.append( - Some("Quit"), - Some("win.quit") - ); + model_tab.append(Some("Append"), Some("win.tab_append")); + model.append_submenu(Some("Tab"), &model_tab); + model.append(Some("Debug"), Some("win.debug")); + model.append(Some("Quit"), Some("win.quit")); - menu.set_menu_model( - Some(&model) - ); + menu.set_menu_model(Some(&model)); menu -} \ No newline at end of file +} diff --git a/src/app/browser/header/tray/tab.rs b/src/app/browser/header/tray/tab.rs index 5e06d31e..71883583 100644 --- a/src/app/browser/header/tray/tab.rs +++ b/src/app/browser/header/tray/tab.rs @@ -1,18 +1,10 @@ use gtk::Button; -pub fn new() -> Button -{ +pub fn new() -> Button { let tab = Button::builder() - - .icon_name( - "tab-new-symbolic" - ) - - .tooltip_text( - "New tab" - ) - + .icon_name("tab-new-symbolic") + .tooltip_text("New tab") .build(); return tab; -} \ No newline at end of file +} diff --git a/src/app/browser/main.rs b/src/app/browser/main.rs index 52f067d8..40f12ac9 100644 --- a/src/app/browser/main.rs +++ b/src/app/browser/main.rs @@ -1,17 +1,15 @@ -#[path = "main/tab.rs"] mod tab; +#[path = "main/tab.rs"] +mod tab; -use gtk::Box; use gtk::prelude::BoxExt; +use gtk::Box; -pub fn new() -> Box -{ - let main = Box::builder().orientation( - gtk::Orientation::Vertical - ).build(); +pub fn new() -> Box { + let main = Box::builder() + .orientation(gtk::Orientation::Vertical) + .build(); - main.append( - &tab::new() - ); + main.append(&tab::new()); - return main; -} \ No newline at end of file + main +} diff --git a/src/app/browser/main/tab.rs b/src/app/browser/main/tab.rs index d1593408..35a748b6 100644 --- a/src/app/browser/main/tab.rs +++ b/src/app/browser/main/tab.rs @@ -1,54 +1,29 @@ -#[path = "tab/label.rs"] mod label; -#[path = "tab/page.rs"] mod page; +#[path = "tab/label.rs"] +mod label; +#[path = "tab/page.rs"] +mod page; use gtk::Notebook; -pub fn new() -> Notebook -{ - let tab = Notebook::builder() - - .scrollable( - true - ) - - .build(); +pub fn new() -> Notebook { + let tab = Notebook::builder().scrollable(true).build(); // Add test tab @TODO restore from session - append( - &tab, - true - ); + append(&tab, true); - return tab; + tab } -pub fn append( - tab: &Notebook, - current: bool -) -> u32 -{ +pub fn append(tab: &Notebook, current: bool) -> u32 { let page = page::new(); - let page_number = tab.append_page( - &page, - Some( - &label::new() - ) - ); - - tab.set_tab_reorderable( - &page, - true - ); - - if current - { - tab.set_current_page( - Some( - page_number - ) - ); + let page_number = tab.append_page(&page, Some(&label::new())); + + tab.set_tab_reorderable(&page, true); + + if current { + tab.set_current_page(Some(page_number)); } - return page_number; -} \ No newline at end of file + page_number +} diff --git a/src/app/browser/main/tab/label.rs b/src/app/browser/main/tab/label.rs index 4325a8dc..a4573948 100644 --- a/src/app/browser/main/tab/label.rs +++ b/src/app/browser/main/tab/label.rs @@ -1,30 +1,18 @@ -#[path = "label/pin.rs"] mod pin; -#[path = "label/title.rs"] mod title; +#[path = "label/pin.rs"] +mod pin; +#[path = "label/title.rs"] +mod title; -use gtk::Box; use gtk::prelude::BoxExt; +use gtk::Box; -pub fn new() -> Box -{ +pub fn new() -> Box { let label = Box::builder() - - // Tuneup - .orientation( - gtk::Orientation::Horizontal - ) - + .orientation(gtk::Orientation::Horizontal) .build(); - // Components - label.append( - &pin::new( - false - ) - ); - - label.append( - &title::new() - ); + label.append(&pin::new(false)); + label.append(&title::new()); - return label; -} \ No newline at end of file + label +} diff --git a/src/app/browser/main/tab/label/pin.rs b/src/app/browser/main/tab/label/pin.rs index 6a286120..c2c20fe3 100644 --- a/src/app/browser/main/tab/label/pin.rs +++ b/src/app/browser/main/tab/label/pin.rs @@ -1,18 +1,8 @@ use gtk::Image; -pub fn new( - visible : bool -) -> Image -{ - return Image::builder() - - .icon_name( - "view-pin-symbolic" - ) - - .visible( - visible - ) - - .build(); -} \ No newline at end of file +pub fn new(visible: bool) -> Image { + Image::builder() + .icon_name("view-pin-symbolic") + .visible(visible) + .build() +} diff --git a/src/app/browser/main/tab/label/title.rs b/src/app/browser/main/tab/label/title.rs index f011d846..dfda9547 100644 --- a/src/app/browser/main/tab/label/title.rs +++ b/src/app/browser/main/tab/label/title.rs @@ -1,24 +1,10 @@ use gtk::Label; -pub fn new() -> Label -{ - return Label::builder() - - .label( - "New page" - ) - - .ellipsize( - gtk::pango::EllipsizeMode::End - ) - - .width_chars( - 16 - ) - - .single_line_mode( - true - ) - - .build(); -} \ No newline at end of file +pub fn new() -> Label { + Label::builder() + .label("New page") + .ellipsize(gtk::pango::EllipsizeMode::End) + .width_chars(16) + .single_line_mode(true) + .build() +} diff --git a/src/app/browser/main/tab/page.rs b/src/app/browser/main/tab/page.rs index 3c4ab363..62a9aa35 100644 --- a/src/app/browser/main/tab/page.rs +++ b/src/app/browser/main/tab/page.rs @@ -1,22 +1,18 @@ -#[path = "page/navigation.rs"] mod navigation; -#[path = "page/content.rs"] mod content; +#[path = "page/content.rs"] +mod content; +#[path = "page/navigation.rs"] +mod navigation; -use gtk::Box; use gtk::prelude::BoxExt; +use gtk::Box; -pub fn new() -> Box -{ - let page = Box::builder().orientation( - gtk::Orientation::Vertical - ).build(); - - page.append( - &navigation::new() - ); +pub fn new() -> Box { + let page = Box::builder() + .orientation(gtk::Orientation::Vertical) + .build(); - page.append( - &content::new() - ); + page.append(&navigation::new()); + page.append(&content::new()); - return page; -} \ No newline at end of file + page +} diff --git a/src/app/browser/main/tab/page/content.rs b/src/app/browser/main/tab/page/content.rs index 306b3750..f97fc325 100644 --- a/src/app/browser/main/tab/page/content.rs +++ b/src/app/browser/main/tab/page/content.rs @@ -1,9 +1,8 @@ use gtk::Box; // use gtk::prelude::BoxExt; @TODO append -pub fn new() -> Box -{ - return Box::builder().orientation( - gtk::Orientation::Vertical - ).build(); -} \ No newline at end of file +pub fn new() -> Box { + Box::builder() + .orientation(gtk::Orientation::Vertical) + .build() +} diff --git a/src/app/browser/main/tab/page/navigation.rs b/src/app/browser/main/tab/page/navigation.rs index d27a8071..ebdb9243 100644 --- a/src/app/browser/main/tab/page/navigation.rs +++ b/src/app/browser/main/tab/page/navigation.rs @@ -1,50 +1,34 @@ -#[path = "navigation/base.rs"] mod base; -#[path = "navigation/history.rs"] mod history; -#[path = "navigation/reload.rs"] mod reload; -#[path = "navigation/request.rs"] mod request; -#[path = "navigation/bookmark.rs"] mod bookmark; +#[path = "navigation/base.rs"] +mod base; +#[path = "navigation/bookmark.rs"] +mod bookmark; +#[path = "navigation/history.rs"] +mod history; +#[path = "navigation/reload.rs"] +mod reload; +#[path = "navigation/request.rs"] +mod request; -use gtk::Box; use gtk::prelude::BoxExt; +use gtk::Box; -pub fn new() -> Box -{ +pub fn new() -> Box { let navigation = Box::builder() - // Tuneup - .orientation( - gtk::Orientation::Horizontal - ) - + .orientation(gtk::Orientation::Horizontal) .spacing(8) - .margin_top(8) .margin_start(8) .margin_end(8) .margin_bottom(8) - .build(); - // Compose childs - navigation.append( - &base::new() - ); - - navigation.append( - &history::new() - ); - - navigation.append( - &reload::new() - ); - - navigation.append( - &request::new() - ); - - navigation.append( - &bookmark::new() - ); + // Compose childs + navigation.append(&base::new()); + navigation.append(&history::new()); + navigation.append(&reload::new()); + navigation.append(&request::new()); + navigation.append(&bookmark::new()); - return navigation; -} \ No newline at end of file + navigation +} diff --git a/src/app/browser/main/tab/page/navigation/base.rs b/src/app/browser/main/tab/page/navigation/base.rs index dcf9099f..f32dd080 100644 --- a/src/app/browser/main/tab/page/navigation/base.rs +++ b/src/app/browser/main/tab/page/navigation/base.rs @@ -1,22 +1,9 @@ use gtk::Button; -pub fn new() -> Button -{ - let button = Button::builder() - - .icon_name( - "go-home-symbolic" - ) - - .tooltip_text( - "Base" - ) - - .sensitive( - false - ) - - .build(); - - return button; -} \ No newline at end of file +pub fn new() -> Button { + Button::builder() + .icon_name("go-home-symbolic") + .tooltip_text("Base") + .sensitive(false) + .build() +} diff --git a/src/app/browser/main/tab/page/navigation/bookmark.rs b/src/app/browser/main/tab/page/navigation/bookmark.rs index 0704adeb..67f33960 100644 --- a/src/app/browser/main/tab/page/navigation/bookmark.rs +++ b/src/app/browser/main/tab/page/navigation/bookmark.rs @@ -1,22 +1,9 @@ use gtk::Button; -pub fn new() -> Button -{ - let button = Button::builder() - - .icon_name( - "starred-symbolic" - ) - - .tooltip_text( - "Toggle bookmark" - ) - - .sensitive( - false - ) - - .build(); - - return button; -} \ No newline at end of file +pub fn new() -> Button { + Button::builder() + .icon_name("starred-symbolic") + .tooltip_text("Toggle bookmark") + .sensitive(false) + .build() +} diff --git a/src/app/browser/main/tab/page/navigation/history.rs b/src/app/browser/main/tab/page/navigation/history.rs index 6835921a..6d9fe07e 100644 --- a/src/app/browser/main/tab/page/navigation/history.rs +++ b/src/app/browser/main/tab/page/navigation/history.rs @@ -1,34 +1,22 @@ -#[path = "history/back.rs"] mod back; -#[path = "history/forward.rs"] mod forward; +#[path = "history/back.rs"] +mod back; +#[path = "history/forward.rs"] +mod forward; -use gtk::Box; use gtk::prelude::BoxExt; +use gtk::Box; -pub fn new() -> Box -{ +pub fn new() -> Box { let history = Box::builder() - - // Tuneup - .orientation( - gtk::Orientation::Horizontal - ) - - .css_classes( - [ - "linked" // merge childs - ] - ) - + .orientation(gtk::Orientation::Horizontal) + .css_classes([ + "linked", // merge childs + ]) .build(); // Compose childs - history.append( - &back::new() - ); - - history.append( - &forward::new() - ); + history.append(&back::new()); + history.append(&forward::new()); - return history; -} \ No newline at end of file + history +} diff --git a/src/app/browser/main/tab/page/navigation/history/back.rs b/src/app/browser/main/tab/page/navigation/history/back.rs index b63494d9..8a5c2959 100644 --- a/src/app/browser/main/tab/page/navigation/history/back.rs +++ b/src/app/browser/main/tab/page/navigation/history/back.rs @@ -1,22 +1,9 @@ use gtk::Button; -pub fn new() -> Button -{ - let button = Button::builder() - - .icon_name( - "go-previous-symbolic" - ) - - .tooltip_text( - "Back" - ) - - .sensitive( - false - ) - - .build(); - - return button; -} \ No newline at end of file +pub fn new() -> Button { + Button::builder() + .icon_name("go-previous-symbolic") + .tooltip_text("Back") + .sensitive(false) + .build() +} diff --git a/src/app/browser/main/tab/page/navigation/history/forward.rs b/src/app/browser/main/tab/page/navigation/history/forward.rs index 95c58ede..2d9c5098 100644 --- a/src/app/browser/main/tab/page/navigation/history/forward.rs +++ b/src/app/browser/main/tab/page/navigation/history/forward.rs @@ -1,22 +1,9 @@ use gtk::Button; -pub fn new() -> Button -{ - let button = Button::builder() - - .icon_name( - "go-next-symbolic" - ) - - .tooltip_text( - "Forward" - ) - - .sensitive( - false - ) - - .build(); - - return button; -} \ No newline at end of file +pub fn new() -> Button { + Button::builder() + .icon_name("go-next-symbolic") + .tooltip_text("Forward") + .sensitive(false) + .build() +} diff --git a/src/app/browser/main/tab/page/navigation/reload.rs b/src/app/browser/main/tab/page/navigation/reload.rs index 5f4e3c4a..78d7c3a9 100644 --- a/src/app/browser/main/tab/page/navigation/reload.rs +++ b/src/app/browser/main/tab/page/navigation/reload.rs @@ -1,22 +1,9 @@ use gtk::Button; -pub fn new() -> Button -{ - let button = Button::builder() - - .icon_name( - "view-refresh-symbolic" - ) - - .tooltip_text( - "Reload" - ) - - .sensitive( - false - ) - +pub fn new() -> Button { + return Button::builder() + .icon_name("view-refresh-symbolic") + .tooltip_text("Reload") + .sensitive(false) .build(); - - return button; -} \ No newline at end of file +} diff --git a/src/app/browser/main/tab/page/navigation/request.rs b/src/app/browser/main/tab/page/navigation/request.rs index 7b17ba90..5624ef6a 100644 --- a/src/app/browser/main/tab/page/navigation/request.rs +++ b/src/app/browser/main/tab/page/navigation/request.rs @@ -1,22 +1,9 @@ use gtk::Entry; -pub fn new() -> Entry -{ - let entry = Entry::builder() - - .placeholder_text( - "URL or search term..." - ) - - .hexpand( - true - ) - - .progress_pulse_step( - 0.1 - ) - - .build(); - - return entry; -} \ No newline at end of file +pub fn new() -> Entry { + Entry::builder() + .placeholder_text("URL or search term...") + .hexpand(true) + .progress_pulse_step(0.1) + .build() +} diff --git a/src/main.rs b/src/main.rs index a9370b65..be7c84bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,53 +1,27 @@ -#[path = "app/browser.rs"] mod browser; +#[path = "app/browser.rs"] +mod browser; -use gtk::prelude::{ - ApplicationExt, - ApplicationExtManual, - GtkApplicationExt, - GtkWindowExt -}; +use gtk::prelude::{ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt}; -use gtk::{ - Application, - glib -}; +use gtk::{glib, Application}; -fn main() -> glib::ExitCode -{ +fn main() -> glib::ExitCode { // Init app - let app = Application::builder().application_id( - "io.github.yggverse.Yoda.app" - ).build(); + let app = Application::builder() + .application_id("io.github.yggverse.Yoda.app") + .build(); // Init accels - app.set_accels_for_action( - "win.tab_append", &["t"] - ); - - app.set_accels_for_action( - "win.tab_close", &["q"] - ); - - app.set_accels_for_action( - "win.debug", &["i"] - ); - - app.set_accels_for_action( - "win.quit", &["Escape"] - ); + app.set_accels_for_action("win.tab_append", &["t"]); + app.set_accels_for_action("win.tab_close", &["q"]); + app.set_accels_for_action("win.debug", &["i"]); + app.set_accels_for_action("win.quit", &["Escape"]); // Create new window - app.connect_activate( - |app| - { - browser::new( - app, - 640, - 480 - ).present(); - } - ); + app.connect_activate(|app| { + browser::new(app, 640, 480).present(); + }); // Start app.run() -} \ No newline at end of file +}