-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.cpp
More file actions
76 lines (74 loc) · 2.82 KB
/
Copy pathView.cpp
File metadata and controls
76 lines (74 loc) · 2.82 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
#include "View.h"
#include <unordered_map>
#include <functional>
#include <iostream>
#include <string>
#include <limits>
void View::show() const
{
bool running = true;
std::unordered_map<std::string, std::function<void()>> commands = {
{ "help", [this]() {
if (onActionHelpTriggered)
onActionHelpTriggered();
} },
{ "add", [this]() {
std::string name;
std::cout << "Enter the document name: ";
std::cin >> name;
if (onActionAddTriggered)
onActionAddTriggered(name);
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
} },
{ "import", [this]() {
std::string name;
std::cout << "Enter the path to the file: ";
std::cin >> name;
if (onActionImportTriggered)
onActionImportTriggered(name);
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
} },
{ "export", [this]() {
std::string name;
std::cout << "Enter the path to the file: ";
std::cin >> name;
if (onActionExportTriggered)
onActionExportTriggered(name);
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
} },
{ "insertGr", [this]() {
std::string type;
std::cout << "Enter the type of grObject (Line, Circle, Rectangle): " << std::endl;
std::cin >> type;
if (onActionInsertGrObjectTriggered)
onActionInsertGrObjectTriggered(type);
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
} },
{ "listGr", [this]() {
if (onActionListGrObjectTriggered)
onActionListGrObjectTriggered();
} },
{ "removeGr", [this]() {
std::string id;
std::cout << "Enter ID of grObject: ";
std::cin >> id;
if (onActionRemoveGrObjectTriggered)
onActionRemoveGrObjectTriggered(id);
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
} },
{ "exit", [&running]() {
std::cout << "Exit...";
running = false;
} },
};
while (running) {
std::cout << "Enter command: ";
std::string input;
std::getline(std::cin, input);
if (auto it = commands.find(input); it != commands.end()) {
it->second();
}
else
std::cerr << "Error! Unknown command. 'help' to observer command list\n";
}
}