/src/neomutt/index/ipanel.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * @file |
3 | | * Index Panel |
4 | | * |
5 | | * @authors |
6 | | * Copyright (C) 2021 Richard Russon <rich@flatcap.org> |
7 | | * |
8 | | * @copyright |
9 | | * This program is free software: you can redistribute it and/or modify it under |
10 | | * the terms of the GNU General Public License as published by the Free Software |
11 | | * Foundation, either version 2 of the License, or (at your option) any later |
12 | | * version. |
13 | | * |
14 | | * This program is distributed in the hope that it will be useful, but WITHOUT |
15 | | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
16 | | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
17 | | * details. |
18 | | * |
19 | | * You should have received a copy of the GNU General Public License along with |
20 | | * this program. If not, see <http://www.gnu.org/licenses/>. |
21 | | */ |
22 | | |
23 | | /** |
24 | | * @page index_ipanel Index Panel |
25 | | * |
26 | | * The Index Panel is a non-interactive container around the email list and a |
27 | | * status bar. |
28 | | * |
29 | | * ## Windows |
30 | | * |
31 | | * | Name | Type | Constructor | |
32 | | * | :---------- | :-------- | :----------- | |
33 | | * | Index Panel | #WT_INDEX | ipanel_new() | |
34 | | * |
35 | | * **Parent** |
36 | | * - @ref index_dlg_index |
37 | | * |
38 | | * **Children** |
39 | | * - @ref index_index |
40 | | * - @ref index_ibar |
41 | | * |
42 | | * ## Data |
43 | | * - #IndexPrivateData |
44 | | * |
45 | | * ## Events |
46 | | * |
47 | | * Once constructed, it is controlled by the following events: |
48 | | * |
49 | | * | Event Type | Handler | |
50 | | * | :---------- | :----------------------- | |
51 | | * | #NT_CONFIG | ipanel_config_observer() | |
52 | | * | #NT_WINDOW | ipanel_window_observer() | |
53 | | * |
54 | | * The Index Panel does not implement MuttWindow::recalc() or MuttWindow::repaint(). |
55 | | */ |
56 | | |
57 | | #include "config.h" |
58 | | #include <stdbool.h> |
59 | | #include "private.h" |
60 | | #include "mutt/lib.h" |
61 | | #include "config/lib.h" |
62 | | #include "core/lib.h" |
63 | | #include "gui/lib.h" |
64 | | #include "ibar.h" |
65 | | #include "private_data.h" |
66 | | |
67 | | struct IndexSharedData; |
68 | | |
69 | | /** |
70 | | * ipanel_config_observer - Notification that a Config Variable has changed - Implements ::observer_t - @ingroup observer_api |
71 | | */ |
72 | | static int ipanel_config_observer(struct NotifyCallback *nc) |
73 | 0 | { |
74 | 0 | if (nc->event_type != NT_CONFIG) |
75 | 0 | return 0; |
76 | 0 | if (!nc->global_data || !nc->event_data) |
77 | 0 | return -1; |
78 | | |
79 | 0 | struct EventConfig *ev_c = nc->event_data; |
80 | 0 | struct MuttWindow *panel_index = nc->global_data; |
81 | |
|
82 | 0 | if (mutt_str_equal(ev_c->name, "status_on_top")) |
83 | 0 | { |
84 | 0 | window_status_on_top(panel_index, NeoMutt->sub); |
85 | 0 | mutt_debug(LL_DEBUG5, "config done\n"); |
86 | 0 | } |
87 | |
|
88 | 0 | return 0; |
89 | 0 | } |
90 | | |
91 | | /** |
92 | | * ipanel_window_observer - Notification that a Window has changed - Implements ::observer_t - @ingroup observer_api |
93 | | */ |
94 | | static int ipanel_window_observer(struct NotifyCallback *nc) |
95 | 0 | { |
96 | 0 | if (nc->event_type != NT_WINDOW) |
97 | 0 | return 0; |
98 | 0 | if (!nc->global_data || !nc->event_data) |
99 | 0 | return -1; |
100 | 0 | if (nc->event_subtype != NT_WINDOW_DELETE) |
101 | 0 | return 0; |
102 | | |
103 | 0 | struct MuttWindow *panel_index = nc->global_data; |
104 | 0 | struct EventWindow *ev_w = nc->event_data; |
105 | 0 | if (ev_w->win != panel_index) |
106 | 0 | return 0; |
107 | | |
108 | 0 | notify_observer_remove(NeoMutt->notify, ipanel_config_observer, panel_index); |
109 | 0 | notify_observer_remove(panel_index->notify, ipanel_window_observer, panel_index); |
110 | 0 | mutt_debug(LL_DEBUG5, "window delete done\n"); |
111 | |
|
112 | 0 | return 0; |
113 | 0 | } |
114 | | |
115 | | /** |
116 | | * ipanel_new - Create the Windows for the Index panel |
117 | | * @param status_on_top true, if the Index bar should be on top |
118 | | * @param shared Shared Index data |
119 | | * @retval ptr New Index Panel |
120 | | */ |
121 | | struct MuttWindow *ipanel_new(bool status_on_top, struct IndexSharedData *shared) |
122 | 0 | { |
123 | 0 | struct MuttWindow *panel_index = mutt_window_new(WT_INDEX, MUTT_WIN_ORIENT_VERTICAL, |
124 | 0 | MUTT_WIN_SIZE_MAXIMISE, MUTT_WIN_SIZE_UNLIMITED, |
125 | 0 | MUTT_WIN_SIZE_UNLIMITED); |
126 | |
|
127 | 0 | struct IndexPrivateData *priv = index_private_data_new(shared); |
128 | 0 | panel_index->wdata = priv; |
129 | 0 | panel_index->wdata_free = index_private_data_free; |
130 | |
|
131 | 0 | struct MuttWindow *win_index = index_window_new(priv); |
132 | 0 | panel_index->focus = win_index; |
133 | |
|
134 | 0 | struct MuttWindow *win_ibar = ibar_new(panel_index, shared, priv); |
135 | 0 | if (status_on_top) |
136 | 0 | { |
137 | 0 | mutt_window_add_child(panel_index, win_ibar); |
138 | 0 | mutt_window_add_child(panel_index, win_index); |
139 | 0 | } |
140 | 0 | else |
141 | 0 | { |
142 | 0 | mutt_window_add_child(panel_index, win_index); |
143 | 0 | mutt_window_add_child(panel_index, win_ibar); |
144 | 0 | } |
145 | |
|
146 | 0 | notify_observer_add(NeoMutt->notify, NT_CONFIG, ipanel_config_observer, panel_index); |
147 | 0 | notify_observer_add(panel_index->notify, NT_WINDOW, ipanel_window_observer, panel_index); |
148 | |
|
149 | 0 | return panel_index; |
150 | 0 | } |