[fractal] Add send button
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] Add send button
- Date: Mon, 20 Apr 2020 08:58:06 +0000 (UTC)
commit c9ac3c0cee8af43a10092a2d74e39b17caef8e73
Author: Juraj Fiala <jurf riseup net>
Date: Mon Apr 20 08:57:58 2020 +0000
Add send button
fractal-gtk/res/icons/send-symbolic.svg | 52 +++++++++++++++++++++++++++++
fractal-gtk/res/resources.xml | 1 +
fractal-gtk/src/actions/global.rs | 26 +++++++++++++++
fractal-gtk/src/app/connect/send.rs | 18 +++-------
fractal-gtk/src/widgets/sourceview_entry.rs | 11 ++++++
5 files changed, 94 insertions(+), 14 deletions(-)
---
diff --git a/fractal-gtk/res/icons/send-symbolic.svg b/fractal-gtk/res/icons/send-symbolic.svg
new file mode 100644
index 00000000..01f60ca8
--- /dev/null
+++ b/fractal-gtk/res/icons/send-symbolic.svg
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ height="16"
+ id="svg7384"
+ version="1.1"
+ width="16">
+ <metadata
+ id="metadata90">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title>Gnome Symbolic Icon Theme</dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <title
+ id="title9167">Gnome Symbolic Icon Theme</title>
+ <defs
+ id="defs7386">
+ <linearGradient
+ id="linearGradient7212"
+ osb:paint="solid">
+ <stop
+ id="stop7214"
+ offset="0"
+ style="stop-color:#000000;stop-opacity:1;" />
+ </linearGradient>
+ </defs>
+ <g
+ id="layer9"
+ style="display:inline"
+ transform="translate(-323.0002,125)">
+ <g
+ style="enable-background:new"
+ id="g876"
+ transform="translate(311.00017,-893)">
+ <path
+ id="path20012"
+ d="m 12.999904,769 14.000126,7.00002 -14.000126,6.99999 v -6 L 22.000471,776.00002 12.999904,775 Z"
+
style="fill:#241f31;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
/>
+ </g>
+ </g>
+</svg>
diff --git a/fractal-gtk/res/resources.xml b/fractal-gtk/res/resources.xml
index b835a9af..a9b101d6 100644
--- a/fractal-gtk/res/resources.xml
+++ b/fractal-gtk/res/resources.xml
@@ -4,6 +4,7 @@
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<file preprocess="xml-stripblanks"
alias="org.gnome.Fractal.svg">icons/hicolor/scalable/apps/org.gnome.Fractal.svg</file>
<file preprocess="xml-stripblanks">icons/chat-icon.svg</file>
+ <file preprocess="xml-stripblanks">icons/send-symbolic.svg</file>
<file>app.css</file>
<file preprocess="xml-stripblanks">ui/audio_player.ui</file>
<file preprocess="xml-stripblanks">ui/add_room_menu.ui</file>
diff --git a/fractal-gtk/src/actions/global.rs b/fractal-gtk/src/actions/global.rs
index afec9d03..0095d648 100644
--- a/fractal-gtk/src/actions/global.rs
+++ b/fractal-gtk/src/actions/global.rs
@@ -90,6 +90,7 @@ pub fn new(app: >k::Application, op: &Arc<Mutex<AppOp>>) {
let room_settings = SimpleAction::new("open-room-settings", None);
// TODO: send file should be a message action
let send_file = SimpleAction::new("send-file", None);
+ let send_message = SimpleAction::new("send-message", None);
let previous_room = SimpleAction::new("previous-room", None);
let next_room = SimpleAction::new("next-room", None);
@@ -122,6 +123,7 @@ pub fn new(app: >k::Application, op: &Arc<Mutex<AppOp>>) {
app.add_action(&account);
app.add_action(&send_file);
+ app.add_action(&send_message);
app.add_action(&previous_room);
app.add_action(&next_room);
@@ -295,6 +297,30 @@ pub fn new(app: >k::Application, op: &Arc<Mutex<AppOp>>) {
}
});
+ send_message.connect_activate(clone!(op => move |_, _| {
+ let msg_entry = op.lock().unwrap().ui.sventry.view.clone();
+ if let Some(buffer) = msg_entry.get_buffer() {
+ let start = buffer.get_start_iter();
+ let end = buffer.get_end_iter();
+
+ if let Some(text) = buffer.get_text(&start, &end, false) {
+ op.lock().unwrap().send_message(text.to_string());
+ }
+
+ buffer.set_text("");
+ }
+ }));
+
+ send_message.set_enabled(false);
+ let buffer = op.lock().unwrap().ui.sventry.buffer.clone();
+ buffer.connect_changed(move |buffer| {
+ if 0 < buffer.get_char_count() {
+ send_message.set_enabled(true);
+ } else {
+ send_message.set_enabled(false);
+ }
+ });
+
/* Add Keybindings to actions */
app.set_accels_for_action("app.quit", &["<Ctrl>Q"]);
app.set_accels_for_action("app.previous-room", &["<Ctrl>Page_Up"]);
diff --git a/fractal-gtk/src/app/connect/send.rs b/fractal-gtk/src/app/connect/send.rs
index 0e168ece..a3805cd0 100644
--- a/fractal-gtk/src/app/connect/send.rs
+++ b/fractal-gtk/src/app/connect/send.rs
@@ -5,6 +5,7 @@ use gtk;
use gtk::prelude::*;
use sourceview4::BufferExt;
+use crate::actions::activate_action;
use crate::app::App;
const MAX_INPUT_HEIGHT: i32 = 100;
@@ -33,29 +34,18 @@ impl App {
.get_object::<gtk::Popover>("autocomplete_popover")
.expect("Can't find autocomplete_popover in ui file.");
- let mut op = self.op.clone();
- msg_entry.connect_key_press_event(move |entry, key| match key.get_keyval() {
+ msg_entry.connect_key_press_event(move |_, key| match key.get_keyval() {
gdk::enums::key::Return | gdk::enums::key::KP_Enter
if !key.get_state().contains(gdk::ModifierType::SHIFT_MASK)
&& !autocomplete_popover.is_visible() =>
{
- if let Some(buffer) = entry.get_buffer() {
- let start = buffer.get_start_iter();
- let end = buffer.get_end_iter();
-
- if let Some(text) = buffer.get_text(&start, &end, false) {
- op.lock().unwrap().send_message(text.to_string());
- }
-
- buffer.set_text("");
- }
-
+ activate_action("app", "send-message");
Inhibit(true)
}
_ => Inhibit(false),
});
- op = self.op.clone();
+ let mut op = self.op.clone();
msg_entry.connect_key_release_event(move |_, _| {
op.lock().unwrap().send_typing();
Inhibit(false)
diff --git a/fractal-gtk/src/widgets/sourceview_entry.rs b/fractal-gtk/src/widgets/sourceview_entry.rs
index f7d70fbe..2aa3bb7c 100644
--- a/fractal-gtk/src/widgets/sourceview_entry.rs
+++ b/fractal-gtk/src/widgets/sourceview_entry.rs
@@ -15,6 +15,7 @@ pub struct SVEntry {
pub scroll: gtk::ScrolledWindow,
pub view: sourceview4::View,
pub buffer: sourceview4::Buffer,
+ pub send: gtk::Button,
}
impl Default for SVEntry {
@@ -83,9 +84,18 @@ impl Default for SVEntry {
scroll.set_propagate_natural_height(true);
entry_box.add(&scroll);
+ let send = gtk::Button::new();
+ let send_img = gtk::Image::new_from_icon_name(Some("send-symbolic"), size);
+ send.set_image(Some(&send_img));
+ send.set_valign(gtk::Align::End);
+ send.set_receives_default(true);
+ send.get_style_context().add_class("suggested-action");
+ send.set_action_name(Some("app.send-message"));
+
container.pack_start(&attach, false, false, 0);
container.pack_start(&markdown, false, false, 0);
container.pack_start(&entry_box, false, true, 0);
+ container.pack_start(&send, false, false, 0);
column.add(&container);
column.show_all();
@@ -103,6 +113,7 @@ impl Default for SVEntry {
scroll,
view,
buffer,
+ send,
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]