Skip to content

Commit

Permalink
Add send button / Enter key settings
Browse files Browse the repository at this point in the history
Two new switches have been added to the application preferences:

- Enable send button
- Use Enter to insert newline ('\n')

The latter cannot be active or sensitive if the former is not active.
Otherwise, users would not be able to send messages.

Thanks to horazont for suggesting a separate switch for the behaviour
of the Enter key.
  • Loading branch information
XaviDCR92 authored and VadimNk committed Mar 27, 2024
1 parent a23ab3a commit 1774c4b
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 4 deletions.
28 changes: 28 additions & 0 deletions libdino/src/entity/settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Settings : Object {
convert_utf8_smileys_ = col_to_bool_or_default("convert_utf8_smileys", true);
check_spelling = col_to_bool_or_default("check_spelling", true);
default_encryption = col_to_encryption_or_default("default_encryption", Encryption.UNKNOWN);
send_button = col_to_bool_or_default("send_button", false);
enter_newline = col_to_bool_or_default("enter_newline", false);
}

private bool col_to_bool_or_default(string key, bool def) {
Expand Down Expand Up @@ -100,6 +102,32 @@ public class Settings : Object {
}
}


public signal void send_button_update(bool visible);
private bool send_button_;
public bool send_button {
get { return send_button_; }
set {
db.settings.upsert()
.value(db.settings.key, "send_button", true)
.value(db.settings.value, value.to_string())
.perform();
send_button_ = value;
send_button_update(value);
}
}

private bool enter_newline_;
public bool enter_newline {
get { return enter_newline_; }
set {
db.settings.upsert()
.value(db.settings.key, "enter_newline", true)
.value(db.settings.value, value.to_string())
.perform();
enter_newline_ = value;
}
}
}

}
20 changes: 17 additions & 3 deletions main/data/chat_input.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<object class="GtkButton" id="file_button">
<property name="icon-name">mail-attachment-symbolic</property>
<property name="margin-top">2</property>
<property name="valign">start</property>
<property name="valign">center</property>
<style>
<class name="flat"/>
<class name="dino-chatinput-button"/>
Expand Down Expand Up @@ -54,7 +54,7 @@
<property name="icon-name">emoji-people-symbolic</property>
<property name="has-frame">False</property>
<property name="margin-top">2</property>
<property name="valign">start</property>
<property name="valign">center</property>
<style>
<class name="flat"/>
<class name="dino-chatinput-button"/>
Expand All @@ -67,7 +67,21 @@
<property name="icon-name">changes-allow-symbolic</property>
<property name="has-frame">False</property>
<property name="margin-top">2</property>
<property name="valign">start</property>
<property name="valign">center</property>
<style>
<class name="flat"/>
<class name="dino-chatinput-button"/>
<class name="image-button"/>
</style>
</object>
</child>
<child>
<object class="GtkButton" id="send_button">
<property name="icon-name">document-send</property>
<property name="has-frame">False</property>
<property name="margin-top">2</property>
<property name="valign">center</property>
<property name="sensitive">false</property>
<style>
<class name="flat"/>
<class name="dino-chatinput-button"/>
Expand Down
29 changes: 29 additions & 0 deletions main/data/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,35 @@
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">_Display send button</property>
<property name="use-underline">True</property>
<property name="activatable-widget">send_button_switch</property>
<child type="suffix">
<object class="GtkSwitch" id="send_button_switch">
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">_Use Enter key to start a new line</property>
<property name="subtitle" translatable="yes">If disabled, use Shift+Enter to start a new line</property>
<property name="use-underline">True</property>
<property name="activatable-widget">enter_newline_switch</property>
<child type="suffix">
<object class="GtkSwitch" id="enter_newline_switch">
<property name="valign">center</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
Expand Down
5 changes: 4 additions & 1 deletion main/src/ui/chat_input/chat_text_view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ public class ChatTextView : Box {
return true;
}

if ((state & ModifierType.SHIFT_MASK) > 0) {
Dino.Entities.Settings settings = Dino.Application.get_default().settings;

if ((state & ModifierType.SHIFT_MASK) > 0
|| settings.enter_newline) {
text_view.buffer.insert_at_cursor("\n", 1);
} else if (text_view.buffer.text.strip() != "") {
send_text();
Expand Down
22 changes: 22 additions & 0 deletions main/src/ui/chat_input/view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class View : Box {
[GtkChild] public unowned MenuButton encryption_button;
[GtkChild] public unowned Separator file_separator;
[GtkChild] public unowned Label chat_input_status;
[GtkChild] public unowned Button send_button;

public EncryptionButton encryption_widget;

Expand All @@ -47,6 +48,27 @@ public class View : Box {

Util.force_css(frame, "* { border-radius: 3px; }");

Dino.Entities.Settings settings = Dino.Application.get_default().settings;

chat_text_view.text_view.buffer.changed.connect(() => {
if (chat_text_view.text_view.buffer.text != "") {
send_button.sensitive = true;
}
else {
send_button.sensitive = false;
}
});

send_button.visible = settings.send_button;

settings.send_button_update.connect((visible) => {
send_button.visible = visible;
});

send_button.clicked.connect(() => {
chat_text_view.send_text();
});

return this;
}

Expand Down
14 changes: 14 additions & 0 deletions main/src/ui/settings_dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class SettingsDialog : Adw.PreferencesWindow {
[GtkChild] private unowned CheckButton encryption_radio_undecided;
[GtkChild] private unowned CheckButton encryption_radio_omemo;
[GtkChild] private unowned CheckButton encryption_radio_openpgp;
[GtkChild] private unowned Switch send_button_switch;
[GtkChild] private unowned Switch enter_newline_switch;

Dino.Entities.Settings settings = Dino.Application.get_default().settings;

Expand All @@ -27,6 +29,9 @@ class SettingsDialog : Adw.PreferencesWindow {
encryption_radio_omemo.active = settings.default_encryption == Encryption.OMEMO;
encryption_radio_openpgp.active = settings.default_encryption == Encryption.PGP;

send_button_switch.active = settings.send_button;
enter_newline_switch.active = settings.enter_newline;
enter_newline_switch.sensitive = settings.send_button;

typing_switch.notify["active"].connect(() => { settings.send_typing = typing_switch.active; } );
marker_switch.notify["active"].connect(() => { settings.send_marker = marker_switch.active; } );
Expand All @@ -51,6 +56,15 @@ class SettingsDialog : Adw.PreferencesWindow {
}
});

send_button_switch.notify["active"].connect(() => { settings.send_button = send_button_switch.active; });
enter_newline_switch.notify["active"].connect(() => { settings.enter_newline = enter_newline_switch.active; });
settings.send_button_update.connect((visible) => {
enter_newline_switch.sensitive = visible;

if (visible == false) {
enter_newline_switch.active = visible;
}
});
}
}

Expand Down

0 comments on commit 1774c4b

Please sign in to comment.