|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | + * SPDX-FileCopyrightText: 2017-2024 Lains |
| 4 | + * 2025 Stella & Charlie (teamcons.carrd.co) |
| 5 | + * 2025 Contributions from the ellie_Commons community (github.com/ellie-commons/) |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | +* We use Granite.Bin to subclass ActionBar. |
| 10 | +* Everything is kept there but most widgets are public |
| 11 | +*/ |
| 12 | + public class Jorts.ActionBar : Granite.Bin { |
| 13 | + |
| 14 | + public Gtk.ActionBar actionbar; |
| 15 | + public Gtk.MenuButton emoji_button; |
| 16 | + public Gtk.EmojiChooser emojichooser_popover; |
| 17 | + public Gtk.MenuButton menu_button; |
| 18 | + |
| 19 | + construct { |
| 20 | + |
| 21 | + /* **** LEFT **** */ |
| 22 | + var new_item = new Gtk.Button () { |
| 23 | + icon_name = "list-add-symbolic", |
| 24 | + width_request = 32, |
| 25 | + height_request = 32, |
| 26 | + tooltip_markup = Granite.markup_accel_tooltip ( |
| 27 | + {"<Control>n"}, |
| 28 | + _("New sticky note") |
| 29 | + ) |
| 30 | + }; |
| 31 | + new_item.action_name = Application.ACTION_PREFIX + Application.ACTION_NEW; |
| 32 | + new_item.add_css_class ("themedbutton"); |
| 33 | + |
| 34 | + delete_item = new Gtk.Button () { |
| 35 | + icon_name = "edit-delete-symbolic", |
| 36 | + width_request = 32, |
| 37 | + height_request = 32, |
| 38 | + tooltip_markup = Granite.markup_accel_tooltip ( |
| 39 | + {"<Control>w"}, |
| 40 | + _("Delete sticky note") |
| 41 | + ) |
| 42 | + }; |
| 43 | + delete_item.add_css_class ("themedbutton"); |
| 44 | + |
| 45 | + /* **** RIGHT **** */ |
| 46 | + emojichooser_popover = new Gtk.EmojiChooser (); |
| 47 | + |
| 48 | + emoji_button = new Gtk.MenuButton () { |
| 49 | + icon_name = Jorts.Utils.random_emote (), |
| 50 | + width_request = 32, |
| 51 | + height_request = 32, |
| 52 | + tooltip_markup = Granite.markup_accel_tooltip ( |
| 53 | + {"<Control>period"}, |
| 54 | + _("Insert emoji") |
| 55 | + ) |
| 56 | + }; |
| 57 | + emoji_button.add_css_class ("themedbutton"); |
| 58 | + emoji_button.popover = emojichooser_popover; |
| 59 | + |
| 60 | + menu_button = new Gtk.MenuButton () { |
| 61 | + icon_name = "open-menu-symbolic", |
| 62 | + width_request = 32, |
| 63 | + height_request = 32, |
| 64 | + tooltip_markup = Granite.markup_accel_tooltip ( |
| 65 | + {"<Control>M"}, |
| 66 | + _("Preferences for this sticky note") |
| 67 | + ) |
| 68 | + }; |
| 69 | + menu_button.direction = Gtk.ArrowType.UP; |
| 70 | + menu_button.add_css_class ("themedbutton"); |
| 71 | + |
| 72 | + /* **** Widget **** */ |
| 73 | + actionbar = new Gtk.ActionBar () { |
| 74 | + hexpand = true |
| 75 | + }; |
| 76 | + actionbar.revealed = false; |
| 77 | + actionbar.pack_start (new_item); |
| 78 | + actionbar.pack_start (delete_item); |
| 79 | + actionbar.pack_end (menu_button); |
| 80 | + actionbar.pack_end (emoji_button); |
| 81 | + |
| 82 | + var handle = new Gtk.WindowHandle () { |
| 83 | + child = actionbar |
| 84 | + }; |
| 85 | + |
| 86 | + child = handle; |
| 87 | + |
| 88 | + // Randomize-skip emoji icon |
| 89 | + emojichooser_popover.show.connect (on_emoji_popover); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Allow control of when to respect the hide-bar setting |
| 94 | + * StickyNoteWindow will decide itself whether to show immediately or not |
| 95 | + */ |
| 96 | + public void reveal_bind () { |
| 97 | + Application.gsettings.bind ("hide-bar", actionbar, "revealed", SettingsBindFlags.INVERT_BOOLEAN); |
| 98 | + } |
| 99 | + |
| 100 | + // Skip the current icon to avoid picking it twice |
| 101 | + private void on_emoji_popover () { |
| 102 | + debug ("Emote requested!"); |
| 103 | + |
| 104 | + emoji_button.set_icon_name ( |
| 105 | + Jorts.Utils.random_emote ( |
| 106 | + emoji_button.get_icon_name () |
| 107 | + ) |
| 108 | + ); |
| 109 | + } |
| 110 | +} |
0 commit comments