Debian Codegraph @

plugins/dm.gui/ReadableReloader.h

raw
1 #pragma once
2
3 #include "gui/GuiManager.h"
4 #include "wxutil/dataview/VFSTreePopulator.h"
5 #include "wxutil/ModalProgressDialog.h"
6 #include "EventRateLimiter.h"
7 #include "ui/imainframe.h"
8 #include "i18n.h"
9
10 namespace ui
11 {
12
13 /**
14 * greebo: A helper class reloading all GUI definitions.
15 */
16 class ReadableReloader :
17 public gui::GuiManager::Visitor
18 {
19 private:
20 // Progress dialog and model count
21 wxutil::ModalProgressDialog _progress;
22 std::size_t _count;
23 std::size_t _numGuis;
24
25 // Event rate limiter for progress dialog
26 EventRateLimiter _evLimiter;
27
28 public:
29 ReadableReloader() :
30 _progress(_("Reloading Guis")),
31 _count(0),
32 _evLimiter(50)
33 {
34 _numGuis = GlobalGuiManager().getNumGuis();
35 }
36
37 void visit(const std::string& guiPath, const gui::GuiType& guiType)
38 {
39 _count++;
40
41 if (_evLimiter.readyForEvent())
42 {
43 float fraction = static_cast<float>(_count) / _numGuis;
44 _progress.setTextAndFraction(guiPath.substr(guiPath.rfind('/') + 1), fraction);
45 }
46
47 if (guiType != gui::NOT_LOADED_YET)
48 {
49 GlobalGuiManager().reloadGui(guiPath);
50 }
51 }
52
53 static void run(const cmd::ArgumentList& args)
54 {
55 try
56 {
57 GlobalGuiManager().reloadGuis();
58
59 ReadableReloader reloader;
60 GlobalGuiManager().foreachGui(reloader);
61 }
62 catch (wxutil::ModalProgressDialog::OperationAbortedException&)
63 {}
64 }
65 };
66
67 } // namespace
68