-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
139 lines (124 loc) · 4.16 KB
/
Copy pathmain.cpp
File metadata and controls
139 lines (124 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#define Uses_TApplication
#define Uses_TDeskTop
#define Uses_TProgram
#define Uses_TProgInit
#define Uses_TMenuBar
#define Uses_TMenu
#define Uses_TMenuItem
#define Uses_TSubMenu
#define Uses_TStatusLine
#define Uses_TStatusDef
#define Uses_TStatusItem
#define Uses_TKeys
#define Uses_TWindow
#define Uses_TDialog
#define Uses_MsgBox
#include <tvision/tv.h>
#include "ui/PrepareScriptDialog.h"
#include "ui/MessageExtractDialog.h"
#include "Const.h"
#include "ui/HelpDialog.h"
class MyApp : public TApplication {
public:
MyApp();
static TMenuBar *initMenuBar( TRect r );
static TStatusLine *initStatusLine(TRect r);
virtual void handleEvent( TEvent& event );
private:
PrepareScriptDialog *prepareDcriptDialog;
void openLogExtractor();
};
MyApp::MyApp() : TProgInit(initStatusLine, initMenuBar, initDeskTop), TApplication() {
std::filesystem::create_directories("rsender-data/projects");
std::filesystem::create_directories("rsender-data/generated");
std::filesystem::create_directories("rsender-data/rabbitmqadmin-scripts");
std::filesystem::create_directories("rsender-data/run");
TRect r(2, 2, size.x - 3, size.y - 3);
prepareDcriptDialog = new PrepareScriptDialog(r, "RabbitMQ messages script generator");
prepareDcriptDialog->options |= ofCentered;
prepareDcriptDialog->growMode = gfGrowHiX | gfGrowHiY;
//execView(dlg);
deskTop->insert(prepareDcriptDialog);
}
void MyApp::openLogExtractor() {
TRect r(0, 0, 90, 24);
auto* dlg = new MessageExtractDialog(r);
// dlg->setText(clipboardText);
ushort code = execView(dlg);
if (code == cmOK) {
const LogExtractResult& res = dlg->result();
prepareDcriptDialog->setRoutingKey(res.routingKey);
prepareDcriptDialog->setParameters(res.valuesLine);
prepareDcriptDialog->setProperties(res.propertiesJson.dump(2));
prepareDcriptDialog->setPayload(res.payloadTemplate);
message(prepareDcriptDialog, evBroadcast, cmUpdateTags, nullptr);
}
destroy(dlg);
}
void MyApp::handleEvent(TEvent& ev) {
TApplication::handleEvent(ev);
if (ev.what == evCommand) {
switch (ev.message.command) {
case cmOpenProject:
case cmSaveProject: {
if (deskTop->current) {
message(deskTop->current, ev.what, ev.message.command, nullptr);
clearEvent(ev);
}
return;
}
case cmExtractFromLog: {
openLogExtractor();
clearEvent(ev);
return;
}
case cmShowHelp: {
TRect r(6, 2, deskTop->size.x - 7, deskTop->size.y - 3);
auto* dlg = new HelpDialog(r);
execView(dlg);
destroy(dlg);
clearEvent(ev);
return;
}
case cmAbout: {
messageBox(mfInformation | mfOKButton,
"rsender — RabbitMQ message script generator\n"
"© 2025 Andrzej\n");
clearEvent(ev);
return;
}
default: {
clearEvent(ev);
};
}
}
}
TMenuBar* MyApp::initMenuBar(TRect r) {
r.b.y = r.a.y + 1;
return new TMenuBar(r,
*new TSubMenu("~F~ile", kbAltF)
+ *new TMenuItem("~O~pen...", cmOpenProject, kbF2)
+ *new TMenuItem("~S~ave...", cmSaveProject, kbF3)
+ *new TMenuItem("~E~xtract from log...", cmExtractFromLog, kbF4)
+ newLine()
+ *new TMenuItem("E~x~it", cmQuit, kbAltX, hcNoContext)
+ *new TSubMenu("~H~elp", kbAltH)
+ *new TMenuItem("~H~elp", cmShowHelp, kbF1)
+ *new TMenuItem("~A~bout…", cmAbout, kbF5));
}
TStatusLine *MyApp::initStatusLine( TRect r )
{
r.a.y = r.b.y - 1;
return new TStatusLine( r,
*new TStatusDef( 0, 0xFFFF ) +
*new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit ) +
*new TStatusItem( 0, kbCtrlX, cmCut ) +
*new TStatusItem( 0, kbCtrlC, cmCopy ) +
*new TStatusItem( 0, kbCtrlV, cmPaste )
);
}
int main() {
MyApp *app = new MyApp;
app->run();
return 0;
}