mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-29 20:44:25 +00:00
show icon depending of current entry value
This commit is contained in:
parent
5348417a73
commit
c22413b973
@ -76,7 +76,6 @@ impl Navigation {
|
|||||||
self.reload.update(!request_text.is_empty());
|
self.reload.update(!request_text.is_empty());
|
||||||
self.request.update(
|
self.request.update(
|
||||||
progress_fraction,
|
progress_fraction,
|
||||||
!request_text.is_empty() && request_text.starts_with("gemini"),
|
|
||||||
self.profile
|
self.profile
|
||||||
.identity
|
.identity
|
||||||
.gemini
|
.gemini
|
||||||
|
@ -25,17 +25,8 @@ impl Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(
|
pub fn update(&self, progress_fraction: Option<f64>, is_identity_active: bool) {
|
||||||
&self,
|
self.widget.update(progress_fraction, is_identity_active);
|
||||||
progress_fraction: Option<f64>,
|
|
||||||
is_identity_applicable: bool,
|
|
||||||
is_identity_active: bool,
|
|
||||||
) {
|
|
||||||
self.widget.update(
|
|
||||||
progress_fraction,
|
|
||||||
is_identity_applicable,
|
|
||||||
is_identity_active,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clean(
|
pub fn clean(
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
mod database;
|
mod database;
|
||||||
|
mod primary_icon;
|
||||||
|
|
||||||
|
use primary_icon::PrimaryIcon;
|
||||||
|
|
||||||
use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction};
|
use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction};
|
||||||
use gtk::{
|
use gtk::{
|
||||||
@ -15,16 +18,6 @@ use std::{
|
|||||||
|
|
||||||
const PLACEHOLDER_TEXT: &str = "URL or search term...";
|
const PLACEHOLDER_TEXT: &str = "URL or search term...";
|
||||||
|
|
||||||
const GO_TOOLTIP_TEXT: &str = "Go to the address";
|
|
||||||
const GO_ICON_NAME: &str = "pan-end-symbolic";
|
|
||||||
|
|
||||||
const IDENTITY_TOOLTIP_TEXT: (&str, &str) = (
|
|
||||||
"Identity",
|
|
||||||
"Identity feature not available for this location",
|
|
||||||
);
|
|
||||||
const IDENTITY_ICON_NAME: (&str, &str) =
|
|
||||||
("avatar-default-symbolic", "applications-system-symbolic");
|
|
||||||
|
|
||||||
// Progress bar animation setup
|
// Progress bar animation setup
|
||||||
const PROGRESS_ANIMATION_STEP: f64 = 0.05;
|
const PROGRESS_ANIMATION_STEP: f64 = 0.05;
|
||||||
const PROGRESS_ANIMATION_TIME: u64 = 20; //ms
|
const PROGRESS_ANIMATION_TIME: u64 = 20; //ms
|
||||||
@ -57,12 +50,6 @@ impl Widget {
|
|||||||
.hexpand(true)
|
.hexpand(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
entry.set_primary_icon_name(Some(IDENTITY_ICON_NAME.0));
|
|
||||||
entry.set_primary_icon_tooltip_text(Some(IDENTITY_TOOLTIP_TEXT.0));
|
|
||||||
|
|
||||||
entry.set_secondary_icon_name(Some(GO_ICON_NAME));
|
|
||||||
entry.set_secondary_icon_tooltip_text(Some(GO_TOOLTIP_TEXT));
|
|
||||||
|
|
||||||
// Connect events
|
// Connect events
|
||||||
entry.connect_icon_release({
|
entry.connect_icon_release({
|
||||||
let tab_action = tab_action.clone();
|
let tab_action = tab_action.clone();
|
||||||
@ -186,32 +173,52 @@ impl Widget {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(
|
pub fn update(&self, progress_fraction: Option<f64>, is_identity_active: bool) {
|
||||||
&self,
|
// Update primary icon
|
||||||
progress_fraction: Option<f64>,
|
|
||||||
is_identity_applicable: bool,
|
|
||||||
is_identity_active: bool,
|
|
||||||
) {
|
|
||||||
// Update identity
|
|
||||||
self.entry
|
|
||||||
.set_primary_icon_activatable(is_identity_applicable);
|
|
||||||
self.entry
|
|
||||||
.set_primary_icon_sensitive(is_identity_applicable);
|
|
||||||
|
|
||||||
if is_identity_applicable {
|
|
||||||
self.entry.set_primary_icon_name(Some(IDENTITY_ICON_NAME.0));
|
|
||||||
self.entry
|
|
||||||
.set_primary_icon_tooltip_text(Some(IDENTITY_TOOLTIP_TEXT.0));
|
|
||||||
} else {
|
|
||||||
self.entry.set_primary_icon_name(Some(IDENTITY_ICON_NAME.1));
|
|
||||||
self.entry
|
|
||||||
.set_primary_icon_tooltip_text(Some(IDENTITY_TOOLTIP_TEXT.1));
|
|
||||||
}
|
|
||||||
|
|
||||||
let identity = self.entry.first_child().unwrap(); // @TODO handle
|
let identity = self.entry.first_child().unwrap(); // @TODO handle
|
||||||
identity.remove_css_class("success");
|
identity.remove_css_class("success");
|
||||||
if is_identity_active {
|
|
||||||
identity.add_css_class("success");
|
self.entry.set_primary_icon_activatable(false);
|
||||||
|
self.entry.set_primary_icon_sensitive(false);
|
||||||
|
|
||||||
|
match primary_icon::from(&self.entry.text()) {
|
||||||
|
PrimaryIcon::Download {
|
||||||
|
icon_name,
|
||||||
|
tooltip_text,
|
||||||
|
} => {
|
||||||
|
self.entry.set_primary_icon_name(Some(icon_name));
|
||||||
|
self.entry.set_primary_icon_tooltip_text(Some(tooltip_text));
|
||||||
|
}
|
||||||
|
PrimaryIcon::Gemini {
|
||||||
|
icon_name,
|
||||||
|
tooltip_text,
|
||||||
|
} => {
|
||||||
|
self.entry.set_primary_icon_activatable(true);
|
||||||
|
self.entry.set_primary_icon_sensitive(true);
|
||||||
|
self.entry.set_primary_icon_name(Some(icon_name));
|
||||||
|
if is_identity_active {
|
||||||
|
self.entry
|
||||||
|
.set_primary_icon_tooltip_text(Some(tooltip_text.1));
|
||||||
|
identity.add_css_class("success");
|
||||||
|
} else {
|
||||||
|
self.entry
|
||||||
|
.set_primary_icon_tooltip_text(Some(tooltip_text.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PrimaryIcon::Search {
|
||||||
|
icon_name,
|
||||||
|
tooltip_text,
|
||||||
|
} => {
|
||||||
|
self.entry.set_primary_icon_name(Some(icon_name));
|
||||||
|
self.entry.set_primary_icon_tooltip_text(Some(tooltip_text));
|
||||||
|
}
|
||||||
|
PrimaryIcon::Source {
|
||||||
|
icon_name,
|
||||||
|
tooltip_text,
|
||||||
|
} => {
|
||||||
|
self.entry.set_primary_icon_name(Some(icon_name));
|
||||||
|
self.entry.set_primary_icon_tooltip_text(Some(tooltip_text));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update progress
|
// Update progress
|
||||||
@ -261,6 +268,7 @@ impl Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tools
|
// Tools
|
||||||
|
|
||||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||||
// Migrate self components
|
// Migrate self components
|
||||||
if let Err(e) = database::init(tx) {
|
if let Err(e) = database::init(tx) {
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
pub enum PrimaryIcon<'a> {
|
||||||
|
Download {
|
||||||
|
icon_name: &'a str,
|
||||||
|
tooltip_text: &'a str,
|
||||||
|
},
|
||||||
|
Gemini {
|
||||||
|
icon_name: &'a str,
|
||||||
|
tooltip_text: (&'a str, &'a str),
|
||||||
|
},
|
||||||
|
Search {
|
||||||
|
icon_name: &'a str,
|
||||||
|
tooltip_text: &'a str,
|
||||||
|
},
|
||||||
|
Source {
|
||||||
|
icon_name: &'a str,
|
||||||
|
tooltip_text: &'a str,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from(request: &str) -> PrimaryIcon {
|
||||||
|
if request.starts_with("download:") {
|
||||||
|
return PrimaryIcon::Download {
|
||||||
|
icon_name: "document-save-symbolic",
|
||||||
|
tooltip_text: "Download",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if request.starts_with("source:") {
|
||||||
|
return PrimaryIcon::Source {
|
||||||
|
icon_name: "applications-system-symbolic",
|
||||||
|
tooltip_text: "Source view",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if request.starts_with("gemini:") {
|
||||||
|
return PrimaryIcon::Gemini {
|
||||||
|
icon_name: "avatar-default-symbolic",
|
||||||
|
tooltip_text: ("Guest session", "User session"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
PrimaryIcon::Search {
|
||||||
|
icon_name: "system-search-symbolic",
|
||||||
|
tooltip_text: "Search",
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user