diff options
| Commit | 37d6c0ffdd0dd8f99b094f5012316e98ae60b8df (patch) | |
|---|---|---|
| Author | 2022-05-30 18:37:49 +0300 | |
| Committer | 2022-05-30 18:37:49 +0300 | |
| Files | aacdf6ee6876f92466ef36c0d5c08dd426b668f0 /src | |
| FMI-OOP-P2_Tables-37d6c0ffdd0dd8f99b094f5012316e98ae60b8df.tar FMI-OOP-P2_Tables-37d6c0ffdd0dd8f99b094f5012316e98ae60b8df.tar.gz FMI-OOP-P2_Tables-37d6c0ffdd0dd8f99b094f5012316e98ae60b8df.zip | ||
| Parent | 7b141af08628069241ed7d1ac30b5f544e62bc82 (diff) | |
Autocommit at 30.05.2022 @ 18:37
2 files changed, 20 insertions, 1 deletions
| -rw-r--r-- | src/UserInterface/UserInterface.cpp | 20 | ||||
| -rw-r--r-- | src/UserInterface/UserInterface.h | 1 |
diff --git a/src/UserInterface/UserInterface.cpp b/src/UserInterface/UserInterface.cpp index 3272f0d..8445d0b 100644 --- a/src/UserInterface/UserInterface.cpp +++ b/src/UserInterface/UserInterface.cpp @@ -7,7 +7,9 @@ /* Private (static) */ Table* UserInterface::table = nullptr; -String fileName = String(); +String UserInterface::fileName = String(); +bool UserInterface::saved = false; + void UserInterface::com_open(const char* params) { if (table != nullptr) { @@ -18,6 +20,7 @@ void UserInterface::com_open(const char* params) { try { table = new Table(params); fileName = params; + saved = true; } catch (std::logic_error err) { printLine(err.what()); @@ -39,6 +42,14 @@ void UserInterface::com_saveas(const char* params) { printLine("No file has been opened!"); return; } + + try { + table->saveToFile(params); + saved = true; + } + catch (std::logic_error err) { + printLine(err.what()); + } } void UserInterface::com_help(const char* params) { @@ -52,6 +63,12 @@ void UserInterface::com_help(const char* params) { } void UserInterface::com_exit(const char* params) { + if (!saved && table != nullptr) { + printLine("You have an open file with unsaved changes, please select close or save first."); + return; + } + + printLine("Exiting program..."); } void UserInterface::com_print(const char* params) { @@ -68,6 +85,7 @@ void UserInterface::com_edit(const char* params) { while (*params != ' ') params++; table->putCell(row, col, params); + saved = false; } /* Public */ diff --git a/src/UserInterface/UserInterface.h b/src/UserInterface/UserInterface.h index 2a83580..61d0dda 100644 --- a/src/UserInterface/UserInterface.h +++ b/src/UserInterface/UserInterface.h @@ -10,6 +10,7 @@ class UserInterface { static Table* table; static String fileName; + static bool saved; static void com_open(const char* params); static void com_close(const char* params); |
