headerbar: Replace Add error label with icon
Validation errors of an entry should be displayed by an icon with a tooltip explaining the reason. For the situation when you add a podcast URL I remove the existing error label and show the former label text as tooltip of an error icon in the entry.
This commit is contained in:
parent
d5945f6ac6
commit
51bbe4193b
@ -126,18 +126,6 @@ Tobias Bernard
|
|||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
|
||||||
<object class="GtkLabel" id="result_label">
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="halign">start</property>
|
|
||||||
<property name="label" translatable="yes">You are already subscribed to that feed!</property>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">2</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|||||||
@ -51,7 +51,6 @@ pub(crate) struct Header {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct AddPopover {
|
struct AddPopover {
|
||||||
container: gtk::Popover,
|
container: gtk::Popover,
|
||||||
result: gtk::Label,
|
|
||||||
entry: gtk::Entry,
|
entry: gtk::Entry,
|
||||||
add: gtk::Button,
|
add: gtk::Button,
|
||||||
toggle: gtk::MenuButton,
|
toggle: gtk::MenuButton,
|
||||||
@ -108,25 +107,37 @@ impl AddPopover {
|
|||||||
match Url::parse(&url) {
|
match Url::parse(&url) {
|
||||||
Ok(u) => {
|
Ok(u) => {
|
||||||
if !dbqueries::source_exists(u.as_str())? {
|
if !dbqueries::source_exists(u.as_str())? {
|
||||||
|
self.entry
|
||||||
|
.set_icon_from_icon_name(gtk::EntryIconPosition::Secondary, None);
|
||||||
self.add.set_sensitive(true);
|
self.add.set_sensitive(true);
|
||||||
self.result.hide();
|
|
||||||
self.result.set_label("");
|
|
||||||
} else {
|
} else {
|
||||||
|
self.entry.set_icon_from_icon_name(
|
||||||
|
gtk::EntryIconPosition::Secondary,
|
||||||
|
"dialog-error-symbolic",
|
||||||
|
);
|
||||||
|
self.entry.set_icon_tooltip_text(
|
||||||
|
gtk::EntryIconPosition::Secondary,
|
||||||
|
i18n("You are already subscribed to this show").as_str(),
|
||||||
|
);
|
||||||
self.add.set_sensitive(false);
|
self.add.set_sensitive(false);
|
||||||
self.result
|
|
||||||
.set_label(i18n("You are already subscribed to this show").as_str());
|
|
||||||
self.result.show();
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.add.set_sensitive(false);
|
self.add.set_sensitive(false);
|
||||||
if !url.is_empty() {
|
if !url.is_empty() {
|
||||||
self.result.set_label(i18n("Invalid URL").as_str());
|
self.entry.set_icon_from_icon_name(
|
||||||
self.result.show();
|
gtk::EntryIconPosition::Secondary,
|
||||||
|
"dialog-error-symbolic",
|
||||||
|
);
|
||||||
|
self.entry.set_icon_tooltip_text(
|
||||||
|
gtk::EntryIconPosition::Secondary,
|
||||||
|
i18n("Invalid URL").as_str(),
|
||||||
|
);
|
||||||
error!("Error: {}", err);
|
error!("Error: {}", err);
|
||||||
} else {
|
} else {
|
||||||
self.result.hide();
|
self.entry
|
||||||
|
.set_icon_from_icon_name(gtk::EntryIconPosition::Secondary, None);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -156,13 +167,11 @@ impl Default for Header {
|
|||||||
let add_popover = builder.get_object("add_popover").unwrap();
|
let add_popover = builder.get_object("add_popover").unwrap();
|
||||||
let new_url = builder.get_object("new_url").unwrap();
|
let new_url = builder.get_object("new_url").unwrap();
|
||||||
let add_button = builder.get_object("add_button").unwrap();
|
let add_button = builder.get_object("add_button").unwrap();
|
||||||
let result = builder.get_object("result_label").unwrap();
|
|
||||||
let add = AddPopover {
|
let add = AddPopover {
|
||||||
container: add_popover,
|
container: add_popover,
|
||||||
entry: new_url,
|
entry: new_url,
|
||||||
toggle: add_toggle,
|
toggle: add_toggle,
|
||||||
add: add_button,
|
add: add_button,
|
||||||
result,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Header {
|
Header {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user