Manually call selection_changed() after removing a screen (#2418).
[dcpomatic.git] / src / wx / screens_panel.cc
1 /*
2     Copyright (C) 2015-2022 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "cinema_dialog.h"
23 #include "dcpomatic_button.h"
24 #include "screen_dialog.h"
25 #include "screens_panel.h"
26 #include "wx_ptr.h"
27 #include "wx_util.h"
28 #include "lib/cinema.h"
29 #include "lib/config.h"
30 #include "lib/scope_guard.h"
31 #include "lib/screen.h"
32 #include "lib/timer.h"
33
34
35 using std::cout;
36 using std::list;
37 using std::make_pair;
38 using std::make_shared;
39 using std::map;
40 using std::pair;
41 using std::shared_ptr;
42 using std::string;
43 using std::vector;
44 using boost::optional;
45 #if BOOST_VERSION >= 106100
46 using namespace boost::placeholders;
47 #endif
48 using namespace dcpomatic;
49
50
51 ScreensPanel::ScreensPanel (wxWindow* parent)
52         : wxPanel (parent, wxID_ANY)
53 {
54         auto sizer = new wxBoxSizer (wxVERTICAL);
55
56         _search = new wxSearchCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, search_ctrl_height()));
57 #ifndef __WXGTK3__
58         /* The cancel button seems to be strangely broken in GTK3; clicking on it twice sometimes works */
59         _search->ShowCancelButton (true);
60 #endif
61         sizer->Add (_search, 0, wxBOTTOM, DCPOMATIC_SIZER_GAP);
62
63         auto targets = new wxBoxSizer (wxHORIZONTAL);
64         _targets = new wxTreeListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_MULTIPLE | wxTL_3STATE | wxTL_NO_HEADER);
65         _targets->AppendColumn (wxT("foo"));
66
67         targets->Add (_targets, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
68
69         add_cinemas ();
70
71         auto side_buttons = new wxBoxSizer (wxVERTICAL);
72
73         auto target_buttons = new wxBoxSizer (wxVERTICAL);
74
75         _add_cinema = new Button (this, _("Add Cinema..."));
76         target_buttons->Add (_add_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
77         _edit_cinema = new Button (this, _("Edit Cinema..."));
78         target_buttons->Add (_edit_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
79         _remove_cinema = new Button (this, _("Remove Cinema"));
80         target_buttons->Add (_remove_cinema, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
81         _add_screen = new Button (this, _("Add Screen..."));
82         target_buttons->Add (_add_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
83         _edit_screen = new Button (this, _("Edit Screen..."));
84         target_buttons->Add (_edit_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
85         _remove_screen = new Button (this, _("Remove Screen"));
86         target_buttons->Add (_remove_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
87
88         side_buttons->Add (target_buttons, 0, 0);
89
90         auto check_buttons = new wxBoxSizer (wxVERTICAL);
91
92         _check_all = new Button (this, _("Check all"));
93         check_buttons->Add (_check_all, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
94         _uncheck_all = new Button (this, _("Uncheck all"));
95         check_buttons->Add (_uncheck_all, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
96
97         side_buttons->Add (check_buttons, 1, wxEXPAND | wxTOP, DCPOMATIC_BUTTON_STACK_GAP * 8);
98
99         targets->Add (side_buttons, 0, 0);
100
101         sizer->Add (targets, 1, wxEXPAND);
102
103         _search->Bind        (wxEVT_TEXT, boost::bind (&ScreensPanel::search_changed, this));
104         _targets->Bind       (wxEVT_TREELIST_SELECTION_CHANGED, &ScreensPanel::selection_changed_shim, this);
105         _targets->Bind       (wxEVT_TREELIST_ITEM_CHECKED, &ScreensPanel::checkbox_changed, this);
106
107         _add_cinema->Bind    (wxEVT_BUTTON, boost::bind (&ScreensPanel::add_cinema_clicked, this));
108         _edit_cinema->Bind   (wxEVT_BUTTON, boost::bind (&ScreensPanel::edit_cinema_clicked, this));
109         _remove_cinema->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::remove_cinema_clicked, this));
110
111         _add_screen->Bind    (wxEVT_BUTTON, boost::bind (&ScreensPanel::add_screen_clicked, this));
112         _edit_screen->Bind   (wxEVT_BUTTON, boost::bind (&ScreensPanel::edit_screen_clicked, this));
113         _remove_screen->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::remove_screen_clicked, this));
114
115         _check_all->Bind     (wxEVT_BUTTON, boost::bind(&ScreensPanel::check_all, this));
116         _uncheck_all->Bind   (wxEVT_BUTTON, boost::bind(&ScreensPanel::uncheck_all, this));
117
118         SetSizer (sizer);
119
120         _config_connection = Config::instance()->Changed.connect(boost::bind(&ScreensPanel::config_changed, this, _1));
121 }
122
123
124 ScreensPanel::~ScreensPanel ()
125 {
126         _targets->Unbind (wxEVT_TREELIST_SELECTION_CHANGED, &ScreensPanel::selection_changed_shim, this);
127         _targets->Unbind (wxEVT_TREELIST_ITEM_CHECKED, &ScreensPanel::checkbox_changed, this);
128 }
129
130
131 void
132 ScreensPanel::check_all ()
133 {
134         for (auto cinema = _targets->GetFirstChild(_targets->GetRootItem()); cinema.IsOk();  cinema = _targets->GetNextSibling(cinema)) {
135                 _targets->CheckItem(cinema, wxCHK_CHECKED);
136                 for (auto screen = _targets->GetFirstChild(cinema); screen.IsOk(); screen = _targets->GetNextSibling(screen)) {
137                         _targets->CheckItem(screen, wxCHK_CHECKED);
138                         set_screen_checked(screen, true);
139                 }
140         }
141 }
142
143
144 void
145 ScreensPanel::uncheck_all ()
146 {
147         for (auto cinema = _targets->GetFirstChild(_targets->GetRootItem()); cinema.IsOk();  cinema = _targets->GetNextSibling(cinema)) {
148                 _targets->CheckItem(cinema, wxCHK_UNCHECKED);
149                 for (auto screen = _targets->GetFirstChild(cinema); screen.IsOk(); screen = _targets->GetNextSibling(screen)) {
150                         _targets->CheckItem(screen, wxCHK_UNCHECKED);
151                         set_screen_checked(screen, false);
152                 }
153         }
154 }
155
156
157 void
158 ScreensPanel::setup_sensitivity ()
159 {
160         bool const sc = _selected_cinemas.size() == 1;
161         bool const ss = _selected_screens.size() == 1;
162
163         _edit_cinema->Enable (sc || ss);
164         _remove_cinema->Enable (_selected_cinemas.size() >= 1);
165
166         _add_screen->Enable (sc || ss);
167         _edit_screen->Enable (ss);
168         _remove_screen->Enable (_selected_screens.size() >= 1);
169 }
170
171
172 void
173 ScreensPanel::convert_to_lower(string& s)
174 {
175         transform(s.begin(), s.end(), s.begin(), ::tolower);
176 }
177
178
179 bool
180 ScreensPanel::matches_search(shared_ptr<const Cinema> cinema, string lower_case_search)
181 {
182         if (lower_case_search.empty()) {
183                 return true;
184         }
185
186         auto name = cinema->name;
187         convert_to_lower(name);
188         return name.find(lower_case_search) != string::npos;
189 }
190
191
192 optional<wxTreeListItem>
193 ScreensPanel::add_cinema (shared_ptr<Cinema> cinema, wxTreeListItem previous)
194 {
195         auto search = wx_to_std (_search->GetValue ());
196         convert_to_lower(search);
197         if (!matches_search(cinema, search)) {
198                 return {};
199         }
200
201         auto id = _targets->InsertItem(_targets->GetRootItem(), previous, std_to_wx(cinema->name));
202
203         _item_to_cinema[id] = cinema;
204         _cinema_to_item[cinema] = id;
205
206         for (auto screen: cinema->screens()) {
207                 add_screen (cinema, screen);
208         }
209
210         return id;
211 }
212
213
214 optional<wxTreeListItem>
215 ScreensPanel::add_screen (shared_ptr<Cinema> cinema, shared_ptr<Screen> screen)
216 {
217         auto item = cinema_to_item(cinema);
218         if (!item) {
219                 return {};
220         }
221
222         auto id = _targets->AppendItem(*item, std_to_wx(screen->name));
223
224         _item_to_screen[id] = screen;
225         _screen_to_item[screen] = id;
226
227         return item;
228 }
229
230
231 void
232 ScreensPanel::add_cinema_clicked ()
233 {
234         auto dialog = make_wx<CinemaDialog>(GetParent(), _("Add Cinema"));
235
236         if (dialog->ShowModal() == wxID_OK) {
237                 auto cinema = make_shared<Cinema>(dialog->name(), dialog->emails(), dialog->notes(), dialog->utc_offset_hour(), dialog->utc_offset_minute());
238
239                 auto cinemas = sorted_cinemas();
240
241                 try {
242                         _ignore_cinemas_changed = true;
243                         ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
244                         Config::instance()->add_cinema(cinema);
245                 } catch (FileError& e) {
246                         error_dialog(GetParent(), _("Could not write cinema details to the cinemas.xml file.  Check that the location of cinemas.xml is valid in DCP-o-matic's preferences."), std_to_wx(e.what()));
247                         return;
248                 }
249
250                 wxTreeListItem previous = wxTLI_FIRST;
251                 bool found = false;
252                 auto search = wx_to_std(_search->GetValue());
253                 convert_to_lower(search);
254                 for (auto existing_cinema: cinemas) {
255                         if (!matches_search(existing_cinema, search)) {
256                                 continue;
257                         }
258                         if (_collator.compare(dialog->name(), existing_cinema->name) < 0) {
259                                 /* existing_cinema should be after the one we're inserting */
260                                 found = true;
261                                 break;
262                         }
263                         auto item = cinema_to_item(existing_cinema);
264                         DCPOMATIC_ASSERT(item);
265                         previous = *item;
266                 }
267
268                 auto item = add_cinema(cinema, found ? previous : wxTLI_LAST);
269
270                 if (item) {
271                         _targets->UnselectAll ();
272                         _targets->Select (*item);
273                 }
274         }
275
276         selection_changed ();
277 }
278
279
280 shared_ptr<Cinema>
281 ScreensPanel::cinema_for_operation () const
282 {
283         if (_selected_cinemas.size() == 1) {
284                 return _selected_cinemas[0];
285         } else if (_selected_screens.size() == 1) {
286                 return _selected_screens[0]->cinema;
287         }
288
289         return {};
290 }
291
292
293 void
294 ScreensPanel::edit_cinema_clicked ()
295 {
296         auto cinema = cinema_for_operation ();
297         if (!cinema) {
298                 return;
299         }
300
301         auto dialog = make_wx<CinemaDialog>(
302                 GetParent(), _("Edit cinema"), cinema->name, cinema->emails, cinema->notes, cinema->utc_offset_hour(), cinema->utc_offset_minute()
303                 );
304
305         if (dialog->ShowModal() == wxID_OK) {
306                 cinema->name = dialog->name();
307                 cinema->emails = dialog->emails();
308                 cinema->notes = dialog->notes();
309                 cinema->set_utc_offset_hour(dialog->utc_offset_hour());
310                 cinema->set_utc_offset_minute(dialog->utc_offset_minute());
311                 notify_cinemas_changed();
312                 auto item = cinema_to_item(cinema);
313                 DCPOMATIC_ASSERT(item);
314                 _targets->SetItemText (*item, std_to_wx(dialog->name()));
315         }
316 }
317
318
319 void
320 ScreensPanel::remove_cinema_clicked ()
321 {
322         if (_selected_cinemas.size() == 1) {
323                 if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the cinema '%s'?"), std_to_wx(_selected_cinemas[0]->name)))) {
324                         return;
325                 }
326         } else {
327                 if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove %d cinemas?"), int(_selected_cinemas.size())))) {
328                         return;
329                 }
330         }
331
332         for (auto const& cinema: _selected_cinemas) {
333                 _ignore_cinemas_changed = true;
334                 ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
335                 Config::instance()->remove_cinema(cinema);
336                 auto item = cinema_to_item(cinema);
337                 DCPOMATIC_ASSERT(item);
338                 _targets->DeleteItem(*item);
339         }
340
341         selection_changed ();
342 }
343
344
345 void
346 ScreensPanel::add_screen_clicked ()
347 {
348         auto cinema = cinema_for_operation ();
349         if (!cinema) {
350                 return;
351         }
352
353         auto dialog = make_wx<ScreenDialog>(GetParent(), _("Add Screen"));
354
355         if (dialog->ShowModal () != wxID_OK) {
356                 return;
357         }
358
359         for (auto screen: cinema->screens()) {
360                 if (screen->name == dialog->name()) {
361                         error_dialog (
362                                 GetParent(),
363                                 wxString::Format (
364                                         _("You cannot add a screen called '%s' as the cinema already has a screen with this name."),
365                                         std_to_wx(dialog->name()).data()
366                                         )
367                                 );
368                         return;
369                 }
370         }
371
372         auto screen = std::make_shared<Screen>(dialog->name(), dialog->notes(), dialog->recipient(), dialog->recipient_file(), dialog->trusted_devices());
373         cinema->add_screen (screen);
374         notify_cinemas_changed();
375
376         auto id = add_screen (cinema, screen);
377         if (id) {
378                 _targets->Expand (id.get ());
379         }
380 }
381
382
383 void
384 ScreensPanel::edit_screen_clicked ()
385 {
386         if (_selected_screens.size() != 1) {
387                 return;
388         }
389
390         auto edit_screen = _selected_screens[0];
391
392         auto dialog = make_wx<ScreenDialog>(
393                 GetParent(), _("Edit screen"),
394                 edit_screen->name,
395                 edit_screen->notes,
396                 edit_screen->recipient,
397                 edit_screen->recipient_file,
398                 edit_screen->trusted_devices
399                 );
400
401         if (dialog->ShowModal() != wxID_OK) {
402                 return;
403         }
404
405         auto cinema = edit_screen->cinema;
406         for (auto screen: cinema->screens()) {
407                 if (screen != edit_screen && screen->name == dialog->name()) {
408                         error_dialog (
409                                 GetParent(),
410                                 wxString::Format (
411                                         _("You cannot change this screen's name to '%s' as the cinema already has a screen with this name."),
412                                         std_to_wx(dialog->name()).data()
413                                         )
414                                 );
415                         return;
416                 }
417         }
418
419         edit_screen->name = dialog->name();
420         edit_screen->notes = dialog->notes();
421         edit_screen->recipient = dialog->recipient();
422         edit_screen->recipient_file = dialog->recipient_file();
423         edit_screen->trusted_devices = dialog->trusted_devices();
424         notify_cinemas_changed();
425
426         auto item = screen_to_item(edit_screen);
427         DCPOMATIC_ASSERT (item);
428         _targets->SetItemText (*item, std_to_wx(dialog->name()));
429 }
430
431
432 void
433 ScreensPanel::remove_screen_clicked ()
434 {
435         if (_selected_screens.size() == 1) {
436                 if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the screen '%s'?"), std_to_wx(_selected_screens[0]->name)))) {
437                         return;
438                 }
439         } else {
440                 if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove %d screens?"), int(_selected_screens.size())))) {
441                         return;
442                 }
443         }
444
445         for (auto const& screen: _selected_screens) {
446                 screen->cinema->remove_screen(screen);
447                 auto item = screen_to_item(screen);
448                 DCPOMATIC_ASSERT(item);
449                 _targets->DeleteItem(*item);
450         }
451
452         /* This is called by the signal on Linux, but not it seems on Windows, so we call it ourselves
453          * as well.
454          */
455         selection_changed();
456         notify_cinemas_changed();
457 }
458
459
460 vector<shared_ptr<Screen>>
461 ScreensPanel::screens () const
462 {
463         vector<shared_ptr<Screen>> output;
464         std::copy (_checked_screens.begin(), _checked_screens.end(), std::back_inserter(output));
465         return output;
466 }
467
468
469 void
470 ScreensPanel::selection_changed_shim (wxTreeListEvent &)
471 {
472         selection_changed ();
473 }
474
475
476 void
477 ScreensPanel::selection_changed ()
478 {
479         if (_ignore_selection_change) {
480                 return;
481         }
482
483         wxTreeListItems selection;
484         _targets->GetSelections (selection);
485
486         _selected_cinemas.clear ();
487         _selected_screens.clear ();
488
489         for (size_t i = 0; i < selection.size(); ++i) {
490                 if (auto cinema = item_to_cinema(selection[i])) {
491                         _selected_cinemas.push_back(cinema);
492                 }
493                 if (auto screen = item_to_screen(selection[i])) {
494                         _selected_screens.push_back(screen);
495                 }
496         }
497
498         setup_sensitivity ();
499 }
500
501
502 list<shared_ptr<Cinema>>
503 ScreensPanel::sorted_cinemas() const
504 {
505         auto cinemas = Config::instance()->cinemas();
506
507         cinemas.sort(
508                 [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return _collator.compare(a->name, b->name) < 0; }
509                 );
510
511         return cinemas;
512 }
513
514
515 void
516 ScreensPanel::add_cinemas ()
517 {
518         for (auto cinema: sorted_cinemas()) {
519                 add_cinema (cinema, wxTLI_LAST);
520         }
521 }
522
523
524 void
525 ScreensPanel::clear_and_re_add()
526 {
527         _targets->DeleteAllItems ();
528
529         _item_to_cinema.clear ();
530         _cinema_to_item.clear ();
531         _item_to_screen.clear ();
532         _screen_to_item.clear ();
533
534         add_cinemas ();
535 }
536
537
538 void
539 ScreensPanel::search_changed ()
540 {
541         clear_and_re_add();
542
543         _ignore_selection_change = true;
544
545         for (auto const& selection: _selected_cinemas) {
546                 if (auto item = cinema_to_item(selection)) {
547                         _targets->Select (*item);
548                 }
549         }
550
551         for (auto const& selection: _selected_screens) {
552                 if (auto item = screen_to_item(selection)) {
553                         _targets->Select (*item);
554                 }
555         }
556
557         _ignore_selection_change = false;
558
559         _ignore_check_change = true;
560
561         for (auto const& checked: _checked_screens) {
562                 if (auto item = screen_to_item(checked)) {
563                         _targets->CheckItem(*item, wxCHK_CHECKED);
564                         setup_cinema_checked_state(*item);
565                 }
566         }
567
568         _ignore_check_change = false;
569 }
570
571
572 void
573 ScreensPanel::set_screen_checked (wxTreeListItem item, bool checked)
574 {
575         auto screen = item_to_screen(item);
576         DCPOMATIC_ASSERT(screen);
577         if (checked) {
578                 _checked_screens.insert(screen);
579         } else {
580                 _checked_screens.erase(screen);
581         }
582 }
583
584
585 void
586 ScreensPanel::setup_cinema_checked_state (wxTreeListItem screen)
587 {
588         auto cinema = _targets->GetItemParent(screen);
589         DCPOMATIC_ASSERT (cinema.IsOk());
590         int checked = 0;
591         int unchecked = 0;
592         for (auto child = _targets->GetFirstChild(cinema); child.IsOk(); child = _targets->GetNextSibling(child)) {
593                 if (_targets->GetCheckedState(child) == wxCHK_CHECKED) {
594                     ++checked;
595                 } else {
596                     ++unchecked;
597                 }
598         }
599         if (checked == 0) {
600                 _targets->CheckItem(cinema, wxCHK_UNCHECKED);
601         } else if (unchecked == 0) {
602                 _targets->CheckItem(cinema, wxCHK_CHECKED);
603         } else {
604                 _targets->CheckItem(cinema, wxCHK_UNDETERMINED);
605         }
606 }
607
608
609 void
610 ScreensPanel::checkbox_changed (wxTreeListEvent& ev)
611 {
612         if (_ignore_check_change) {
613                 return;
614         }
615
616         if (item_to_cinema(ev.GetItem())) {
617                 /* Cinema: check/uncheck all children */
618                 auto const checked = _targets->GetCheckedState(ev.GetItem());
619                 for (auto child = _targets->GetFirstChild(ev.GetItem()); child.IsOk(); child = _targets->GetNextSibling(child)) {
620                         _targets->CheckItem(child, checked);
621                         set_screen_checked(child, checked);
622                 }
623         } else {
624                 set_screen_checked(ev.GetItem(), _targets->GetCheckedState(ev.GetItem()));
625                 setup_cinema_checked_state(ev.GetItem());
626         }
627
628         ScreensChanged ();
629 }
630
631
632 shared_ptr<Cinema>
633 ScreensPanel::item_to_cinema (wxTreeListItem item) const
634 {
635         auto iter = _item_to_cinema.find (item);
636         if (iter == _item_to_cinema.end()) {
637                 return {};
638         }
639
640         return iter->second;
641 }
642
643
644 shared_ptr<Screen>
645 ScreensPanel::item_to_screen (wxTreeListItem item) const
646 {
647         auto iter = _item_to_screen.find (item);
648         if (iter == _item_to_screen.end()) {
649                 return {};
650         }
651
652         return iter->second;
653 }
654
655
656 optional<wxTreeListItem>
657 ScreensPanel::cinema_to_item (shared_ptr<Cinema> cinema) const
658 {
659         auto iter = _cinema_to_item.find (cinema);
660         if (iter == _cinema_to_item.end()) {
661                 return {};
662         }
663
664         return iter->second;
665 }
666
667
668 optional<wxTreeListItem>
669 ScreensPanel::screen_to_item (shared_ptr<Screen> screen) const
670 {
671         auto iter = _screen_to_item.find (screen);
672         if (iter == _screen_to_item.end()) {
673                 return {};
674         }
675
676         return iter->second;
677 }
678
679
680 bool
681 ScreensPanel::notify_cinemas_changed()
682 {
683         _ignore_cinemas_changed = true;
684         ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
685
686         try {
687                 Config::instance()->changed(Config::CINEMAS);
688         } catch (FileError& e) {
689                 error_dialog(GetParent(), _("Could not write cinema details to the cinemas.xml file.  Check that the location of cinemas.xml is valid in DCP-o-matic's preferences."), std_to_wx(e.what()));
690                 return false;
691         }
692
693         return true;
694 }
695
696
697 void
698 ScreensPanel::config_changed(Config::Property property)
699 {
700         if (property == Config::Property::CINEMAS && !_ignore_cinemas_changed) {
701                 clear_and_re_add();
702         }
703 }