diff options
Diffstat (limited to 'main/src/ui/chat_input')
-rw-r--r-- | main/src/ui/chat_input/chat_text_view.vala | 26 | ||||
-rw-r--r-- | main/src/ui/chat_input/encryption_button.vala | 54 | ||||
-rw-r--r-- | main/src/ui/chat_input/view.vala | 20 |
3 files changed, 48 insertions, 52 deletions
diff --git a/main/src/ui/chat_input/chat_text_view.vala b/main/src/ui/chat_input/chat_text_view.vala index b1f719b6..437950ea 100644 --- a/main/src/ui/chat_input/chat_text_view.vala +++ b/main/src/ui/chat_input/chat_text_view.vala @@ -26,7 +26,6 @@ public class ChatTextViewController : Object { public void initialize_for_conversation(Conversation conversation) { occupants_tab_completor.initialize_for_conversation(conversation); - widget.initialize_for_conversation(conversation); } } @@ -39,40 +38,31 @@ public class ChatTextView : Box { public TextView text_view = new TextView() { hexpand=true, wrap_mode=Gtk.WrapMode.WORD_CHAR, valign=Align.CENTER, margin_top=7, margin_bottom=7 }; private int vscrollbar_min_height; private SmileyConverter smiley_converter; -// private SpellChecker spell_checker; construct { scrolled_window.set_child(text_view); this.append(scrolled_window); - smiley_converter = new SmileyConverter(text_view); - -// scrolled_window.get_vscrollbar().get_preferred_size(out vscrollbar_min_size, null); - scrolled_window.vadjustment.notify["upper"].connect(on_upper_notify); - var text_input_key_events = new EventControllerKey(); text_input_key_events.key_pressed.connect(on_text_input_key_press); text_view.add_controller(text_input_key_events); + smiley_converter = new SmileyConverter(text_view); + + scrolled_window.vadjustment.changed.connect(on_upper_notify); + text_view.realize.connect(() => { var minimum_size = new Requisition(); scrolled_window.get_preferred_size(out minimum_size, null); vscrollbar_min_height = minimum_size.height; }); -// Gtk.drag_dest_unset(text_view); } - public void initialize_for_conversation(Conversation conversation) { -// spell_checker.initialize_for_conversation(conversation); - } - -// public override void get_preferred_size(out Gtk.Requisition minimum_size, out Gtk.Requisition natural_size) { -// base.get_preferred_height(out min_height, out nat_height); -// min_height = nat_height; -// } - private void on_upper_notify() { - scrolled_window.vadjustment.value = scrolled_window.vadjustment.upper - scrolled_window.vadjustment.page_size; + // hack. otherwise the textview would only show the last row(s) when entering a new row on some systems. + if (text_view.get_height() < scrolled_window.max_content_height - 20) { + scrolled_window.vadjustment.page_size = scrolled_window.vadjustment.upper; + } // hack for vscrollbar not requiring space and making textview higher //TODO doesn't resize immediately scrolled_window.get_vscrollbar().visible = (scrolled_window.vadjustment.upper > scrolled_window.max_content_height - 2 * this.vscrollbar_min_height); diff --git a/main/src/ui/chat_input/encryption_button.vala b/main/src/ui/chat_input/encryption_button.vala index e5831802..ab463f44 100644 --- a/main/src/ui/chat_input/encryption_button.vala +++ b/main/src/ui/chat_input/encryption_button.vala @@ -15,16 +15,39 @@ public class EncryptionButton { private Map<CheckButton, Plugins.EncryptionListEntry> encryption_radios = new HashMap<CheckButton, Plugins.EncryptionListEntry>(); private string? current_icon; private StreamInteractor stream_interactor; + private SimpleAction action; public EncryptionButton(StreamInteractor stream_interactor, MenuButton menu_button) { this.stream_interactor = stream_interactor; this.menu_button = menu_button; - Builder builder = new Builder.from_resource("/im/dino/Dino/menu_encryption.ui"); - menu_button.popover = builder.get_object("menu_encryption") as PopoverMenu; - Box encryption_box = builder.get_object("encryption_box") as Box; - button_unencrypted = builder.get_object("button_unencrypted") as CheckButton; - button_unencrypted.toggled.connect(encryption_button_toggled); + // Build menu model including "Unencrypted" and all registered encryption entries + Menu menu_model = new Menu(); + + MenuItem unencrypted_item = new MenuItem(_("Unencrypted"), "enc.encryption"); + unencrypted_item.set_action_and_target_value("enc.encryption", new Variant.int32(Encryption.NONE)); + menu_model.append_item(unencrypted_item); + + Application app = GLib.Application.get_default() as Application; + foreach (var e in app.plugin_registry.encryption_list_entries) { + MenuItem item = new MenuItem(e.name, "enc.encryption"); + item.set_action_and_target_value("enc.encryption", new Variant.int32(e.encryption)); + menu_model.append_item(item); + } + + // Create action to act on menu selections (stateful => radio buttons) + SimpleActionGroup action_group = new SimpleActionGroup(); + action = new SimpleAction.stateful("encryption", VariantType.INT32, new Variant.int32(Encryption.NONE)); + action.activate.connect((parameter) => { + action.set_state(parameter); + this.conversation.encryption = (Encryption) parameter.get_int32(); + }); + action_group.insert(action); + menu_button.insert_action_group("enc", action_group); + + // Create and set popover menu + Gtk.PopoverMenu popover_menu = new Gtk.PopoverMenu.from_model(menu_model); + menu_button.popover = popover_menu; stream_interactor.get_module(MucManager.IDENTITY).room_info_updated.connect((account, muc_jid) => { if (conversation != null && conversation.account.equals(account) && conversation.counterpart.equals(muc_jid)) { @@ -32,15 +55,6 @@ public class EncryptionButton { } }); - Application app = GLib.Application.get_default() as Application; - foreach (var e in app.plugin_registry.encryption_list_entries) { - CheckButton btn = new CheckButton.with_label(e.name); - btn.set_group(button_unencrypted); - encryption_radios[btn] = e; - btn.toggled.connect(encryption_button_toggled); - btn.visible = true; - encryption_box.prepend(btn); - } menu_button.activate.connect(update_encryption_menu_state); } @@ -61,16 +75,8 @@ public class EncryptionButton { } private void update_encryption_menu_state() { - foreach (CheckButton e in encryption_radios.keys) { - if (conversation.encryption == encryption_radios[e].encryption) { - e.set_active(true); - encryption_changed(encryption_radios[e]); - } - } - if (conversation.encryption == Encryption.NONE) { - button_unencrypted.set_active(true); - encryption_changed(null); - } + action.set_state(new Variant.int32(conversation.encryption)); + action.change_state(new Variant.int32(conversation.encryption)); } private void set_icon(string icon) { diff --git a/main/src/ui/chat_input/view.vala b/main/src/ui/chat_input/view.vala index 6524a825..81f2bd0f 100644 --- a/main/src/ui/chat_input/view.vala +++ b/main/src/ui/chat_input/view.vala @@ -66,28 +66,28 @@ public class View : Box { public void set_input_state(Plugins.InputFieldStatus.MessageType message_type) { switch (message_type) { case Plugins.InputFieldStatus.MessageType.NONE: - this.get_style_context().remove_class("dino-input-warning"); - this.get_style_context().remove_class("dino-input-error"); + this.remove_css_class("dino-input-warning"); + this.remove_css_class("dino-input-error"); break; case Plugins.InputFieldStatus.MessageType.INFO: - this.get_style_context().remove_class("dino-input-warning"); - this.get_style_context().remove_class("dino-input-error"); + this.remove_css_class("dino-input-warning"); + this.remove_css_class("dino-input-error"); break; case Plugins.InputFieldStatus.MessageType.WARNING: - this.get_style_context().add_class("dino-input-warning"); - this.get_style_context().remove_class("dino-input-error"); + this.add_css_class("dino-input-warning"); + this.remove_css_class("dino-input-error"); break; case Plugins.InputFieldStatus.MessageType.ERROR: - this.get_style_context().remove_class("dino-input-warning"); - this.get_style_context().add_class("dino-input-error"); + this.remove_css_class("dino-input-warning"); + this.add_css_class("dino-input-error"); break; } } public void highlight_state_description() { - chat_input_status.get_style_context().add_class("input-status-highlight-once"); + chat_input_status.add_css_class("input-status-highlight-once"); Timeout.add_seconds(1, () => { - chat_input_status.get_style_context().remove_class("input-status-highlight-once"); + chat_input_status.remove_css_class("input-status-highlight-once"); return false; }); } |