Browse Source

event-details-dialog: Use CopyableRow

merge-requests/1461/merge
Kévin Commaille 2 years ago
parent
commit
2cceb4fcdd
No known key found for this signature in database
GPG Key ID: 29A48C1F03620416
  1. 81
      src/session/view/event_details_dialog.rs
  2. 120
      src/session/view/event_details_dialog.ui

81
src/session/view/event_details_dialog.rs

@ -4,7 +4,7 @@ use gtk::{glib, CompositeTemplate};
use sourceview::prelude::*;
use crate::{
components::{ButtonRow, ToastableDialog},
components::{ButtonRow, CopyableRow, ToastableDialog},
prelude::*,
session::model::Event,
toast, utils,
@ -27,18 +27,6 @@ mod imp {
#[template_child]
pub navigation_view: TemplateChild<adw::NavigationView>,
#[template_child]
pub original_event_id_row: TemplateChild<adw::ActionRow>,
#[template_child]
pub room_id_row: TemplateChild<adw::ActionRow>,
#[template_child]
pub sender_id_row: TemplateChild<adw::ActionRow>,
#[template_child]
pub original_timestamp_row: TemplateChild<adw::ActionRow>,
#[template_child]
pub edit_event_id_row: TemplateChild<adw::ActionRow>,
#[template_child]
pub edit_timestamp_row: TemplateChild<adw::ActionRow>,
#[template_child]
pub source_page: TemplateChild<adw::NavigationPage>,
#[template_child]
pub source_view: TemplateChild<sourceview::View>,
@ -52,76 +40,11 @@ mod imp {
fn class_init(klass: &mut Self::Class) {
ButtonRow::static_type();
CopyableRow::static_type();
Self::bind_template(klass);
Self::Type::bind_template_callbacks(klass);
klass.install_action(
"event-details-dialog.copy-original-event-id",
None,
move |obj, _, _| {
let clipboard = obj.clipboard();
let subtitle = obj.imp().original_event_id_row.subtitle();
clipboard.set_text(subtitle.as_deref().unwrap_or_default());
toast!(obj, gettext("Event ID copied to clipboard"))
},
);
klass.install_action(
"event-details-dialog.copy-room-id",
None,
move |obj, _, _| {
let clipboard = obj.clipboard();
let subtitle = obj.imp().room_id_row.subtitle();
clipboard.set_text(subtitle.as_deref().unwrap_or_default());
toast!(obj, gettext("Room ID copied to clipboard"))
},
);
klass.install_action(
"event-details-dialog.copy-sender-id",
None,
move |obj, _, _| {
let clipboard = obj.clipboard();
let subtitle = obj.imp().sender_id_row.subtitle();
clipboard.set_text(subtitle.as_deref().unwrap_or_default());
toast!(obj, gettext("Sender ID copied to clipboard"))
},
);
klass.install_action(
"event-details-dialog.copy-original-timestamp",
None,
move |obj, _, _| {
let clipboard = obj.clipboard();
let subtitle = obj.imp().original_timestamp_row.subtitle();
clipboard.set_text(subtitle.as_deref().unwrap_or_default());
toast!(obj, gettext("Timestamp copied to clipboard"))
},
);
klass.install_action(
"event-details-dialog.copy-edit-event-id",
None,
move |obj, _, _| {
let clipboard = obj.clipboard();
let subtitle = obj.imp().edit_event_id_row.subtitle();
clipboard.set_text(subtitle.as_deref().unwrap_or_default());
toast!(obj, gettext("Event ID copied to clipboard"))
},
);
klass.install_action(
"event-details-dialog.copy-edit-timestamp",
None,
move |obj, _, _| {
let clipboard = obj.clipboard();
let subtitle = obj.imp().edit_timestamp_row.subtitle();
clipboard.set_text(subtitle.as_deref().unwrap_or_default());
toast!(obj, gettext("Timestamp copied to clipboard"))
},
);
klass.install_action(
"event-details-dialog.copy-source",
None,

120
src/session/view/event_details_dialog.ui

@ -58,32 +58,21 @@
<class name="boxed-list"/>
</style>
<child>
<object class="AdwActionRow" id="original_event_id_row">
<object class="CopyableRow" id="original_event_id_row">
<property name="main-title">subtitle</property>
<property name="title" translatable="yes">Event ID</property>
<binding name="subtitle">
<lookup name="event-id-string">
<lookup name="event">EventDetailsDialog</lookup>
</lookup>
</binding>
<property name="selectable">False</property>
<style>
<class name="property"/>
</style>
<child>
<object class="GtkButton">
<property name="icon-name">copy-symbolic</property>
<property name="action-name">event-details-dialog.copy-original-event-id</property>
<property name="tooltip-text" translatable="yes">Copy event ID to clipboard</property>
<property name="valign">center</property>
<style>
<class name="flat"/>
</style>
</object>
</child>
<property name="copy-button-tooltip-text" translatable="yes">Copy event ID to clipboard</property>
<property name="toast-text" translatable="yes">Event ID copied to clipboard</property>
</object>
</child>
<child>
<object class="AdwActionRow" id="room_id_row">
<object class="CopyableRow" id="room_id_row">
<property name="main-title">subtitle</property>
<property name="title" translatable="yes">Room ID</property>
<binding name="subtitle">
<lookup name="room-id-string">
@ -92,71 +81,34 @@
</lookup>
</lookup>
</binding>
<property name="selectable">False</property>
<style>
<class name="property"/>
</style>
<child>
<object class="GtkButton">
<property name="icon-name">copy-symbolic</property>
<property name="action-name">event-details-dialog.copy-room-id</property>
<property name="tooltip-text" translatable="yes">Copy room ID to clipboard</property>
<property name="valign">center</property>
<style>
<class name="flat"/>
</style>
</object>
</child>
<property name="copy-button-tooltip-text" translatable="yes">Copy room ID to clipboard</property>
<property name="toast-text" translatable="yes">Room ID copied to clipboard</property>
</object>
</child>
<child>
<object class="AdwActionRow" id="sender_id_row">
<object class="CopyableRow" id="sender_id_row">
<property name="main-title">subtitle</property>
<property name="title" translatable="yes">Sender ID</property>
<binding name="subtitle">
<lookup name="sender-id-string">
<lookup name="event">EventDetailsDialog</lookup>
</lookup>
</binding>
<property name="selectable">False</property>
<style>
<class name="property"/>
</style>
<child>
<object class="GtkButton">
<property name="icon-name">copy-symbolic</property>
<property name="action-name">event-details-dialog.copy-sender-id</property>
<property name="tooltip-text" translatable="yes">Copy sender ID to clipboard</property>
<property name="valign">center</property>
<style>
<class name="flat"/>
</style>
</object>
</child>
<property name="copy-button-tooltip-text" translatable="yes">Copy sender ID to clipboard</property>
<property name="toast-text" translatable="yes">Sender ID copied to clipboard</property>
</object>
</child>
<child>
<object class="AdwActionRow" id="original_timestamp_row">
<object class="CopyableRow" id="original_timestamp_row">
<property name="main-title">subtitle</property>
<property name="title" translatable="yes">Timestamp</property>
<binding name="subtitle">
<lookup name="timestamp-full">
<lookup name="event">EventDetailsDialog</lookup>
</lookup>
</binding>
<property name="selectable">False</property>
<style>
<class name="property"/>
</style>
<child>
<object class="GtkButton">
<property name="icon-name">copy-symbolic</property>
<property name="action-name">event-details-dialog.copy-original-timestamp</property>
<property name="tooltip-text" translatable="yes">Copy timestamp to clipboard</property>
<property name="valign">center</property>
<style>
<class name="flat"/>
</style>
</object>
</child>
<property name="copy-button-tooltip-text" translatable="yes">Copy timestamp to clipboard</property>
<property name="toast-text" translatable="yes">Timestamp copied to clipboard</property>
</object>
</child>
<child>
@ -195,53 +147,29 @@
<class name="boxed-list"/>
</style>
<child>
<object class="AdwActionRow" id="edit_event_id_row">
<object class="CopyableRow" id="edit_event_id_row">
<property name="main-title">subtitle</property>
<property name="title" translatable="yes">Event ID</property>
<binding name="subtitle">
<lookup name="latest-edit-event-id-string">
<lookup name="event">EventDetailsDialog</lookup>
</lookup>
</binding>
<property name="selectable">False</property>
<style>
<class name="property"/>
</style>
<child>
<object class="GtkButton">
<property name="icon-name">copy-symbolic</property>
<property name="action-name">event-details-dialog.copy-edit-event-id</property>
<property name="tooltip-text" translatable="yes">Copy event ID to clipboard</property>
<property name="valign">center</property>
<style>
<class name="flat"/>
</style>
</object>
</child>
<property name="copy-button-tooltip-text" translatable="yes">Copy event ID to clipboard</property>
<property name="toast-text" translatable="yes">Event ID copied to clipboard</property>
</object>
</child>
<child>
<object class="AdwActionRow" id="edit_timestamp_row">
<object class="CopyableRow" id="edit_timestamp_row">
<property name="main-title">subtitle</property>
<property name="title" translatable="yes">Timestamp</property>
<binding name="subtitle">
<lookup name="latest-edit-timestamp-full">
<lookup name="event">EventDetailsDialog</lookup>
</lookup>
</binding>
<property name="selectable">False</property>
<style>
<class name="property"/>
</style>
<child>
<object class="GtkButton">
<property name="icon-name">copy-symbolic</property>
<property name="action-name">event-details-dialog.copy-edit-timestamp</property>
<property name="tooltip-text" translatable="yes">Copy timestamp to clipboard</property>
<property name="valign">center</property>
<style>
<class name="flat"/>
</style>
</object>
</child>
<property name="copy-button-tooltip-text" translatable="yes">Copy timestamp to clipboard</property>
<property name="toast-text" translatable="yes">Timestamp copied to clipboard</property>
</object>
</child>
<child>

Loading…
Cancel
Save