1 /* ide-terminal-popover-row.c
2 *
3 * Copyright 2019 Christian Hergert <chergert@redhat.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21 #define G_LOG_DOMAIN "ide-terminal-popover-row"
22
23 #include "config.h"
24
25 #include "ide-terminal-popover-row.h"
26
27 struct _IdeTerminalPopoverRow
28 {
29 GtkListBoxRow parent_instance;
30
31 IdeRuntime *runtime;
32
33 GtkLabel *label;
34 GtkImage *check;
35 };
36
G_DEFINE_FINAL_TYPE(IdeTerminalPopoverRow,ide_terminal_popover_row,GTK_TYPE_LIST_BOX_ROW)37 G_DEFINE_FINAL_TYPE (IdeTerminalPopoverRow, ide_terminal_popover_row, GTK_TYPE_LIST_BOX_ROW)
38
39 static void
40 ide_terminal_popover_row_finalize (GObject *object)
41 {
42 IdeTerminalPopoverRow *self = (IdeTerminalPopoverRow *)object;
43
44 g_clear_object (&self->runtime);
45
46 G_OBJECT_CLASS (ide_terminal_popover_row_parent_class)->finalize (object);
47 }
48
49 static void
ide_terminal_popover_row_class_init(IdeTerminalPopoverRowClass * klass)50 ide_terminal_popover_row_class_init (IdeTerminalPopoverRowClass *klass)
51 {
52 GObjectClass *object_class = G_OBJECT_CLASS (klass);
53 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
54
55 object_class->finalize = ide_terminal_popover_row_finalize;
56
57 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/libide-terminal/ui/ide-terminal-popover-row.ui");
58 gtk_widget_class_bind_template_child (widget_class, IdeTerminalPopoverRow, label);
59 gtk_widget_class_bind_template_child (widget_class, IdeTerminalPopoverRow, check);
60 }
61
62 static void
ide_terminal_popover_row_init(IdeTerminalPopoverRow * self)63 ide_terminal_popover_row_init (IdeTerminalPopoverRow *self)
64 {
65 gtk_widget_init_template (GTK_WIDGET (self));
66 }
67
68 GtkWidget *
ide_terminal_popover_row_new(IdeRuntime * runtime)69 ide_terminal_popover_row_new (IdeRuntime *runtime)
70 {
71 IdeTerminalPopoverRow *self;
72
73 g_return_val_if_fail (IDE_IS_RUNTIME (runtime), NULL);
74
75 self = g_object_new (IDE_TYPE_TERMINAL_POPOVER_ROW,
76 "visible", TRUE,
77 NULL);
78 self->runtime = g_object_ref (runtime);
79 gtk_label_set_label (self->label, ide_runtime_get_display_name (runtime));
80
81 return GTK_WIDGET (g_steal_pointer (&self));
82 }
83
84 void
ide_terminal_popover_row_set_selected(IdeTerminalPopoverRow * self,gboolean selected)85 ide_terminal_popover_row_set_selected (IdeTerminalPopoverRow *self,
86 gboolean selected)
87 {
88 g_return_if_fail (IDE_IS_TERMINAL_POPOVER_ROW (self));
89
90 /* Always keep image visible */
91 g_object_set (self->check,
92 "icon-name", selected ? "object-select-symbolic" : NULL,
93 NULL);
94 }
95
96 /**
97 * ide_terminal_popover_row_get_runtime:
98 * @self: a #IdeTerminalPopoverRow
99 *
100 * Gets the runtime for a row.
101 *
102 * Returns: (transfer none): an #IdeRuntime, or %NULL
103 */
104 IdeRuntime *
ide_terminal_popover_row_get_runtime(IdeTerminalPopoverRow * self)105 ide_terminal_popover_row_get_runtime (IdeTerminalPopoverRow *self)
106 {
107 g_return_val_if_fail (IDE_IS_TERMINAL_POPOVER_ROW (self), NULL);
108
109 return self->runtime;
110 }
111