parent
097143ecf7
commit
fa2a65d6c1
5 changed files with 62 additions and 2 deletions
@ -0,0 +1,34 @@ |
||||
#include <modes/Exit.hpp> |
||||
#include <Editor.hpp> |
||||
|
||||
|
||||
namespace groove { |
||||
namespace modes { |
||||
|
||||
void Exit::input(int c) { |
||||
if (!this->editor.buffer->changed) { |
||||
this->editor.mode_ = groove::Mode::QUIT; |
||||
|
||||
return; |
||||
} |
||||
|
||||
this->status_ = "Save file '" + this->editor.filename + "'? [Y/N]:"; |
||||
switch (c) { |
||||
case 27: |
||||
this->status_ = ""; |
||||
this->editor.mode_ = groove::Mode::EDIT; |
||||
this->editor.input(' '); |
||||
break; |
||||
case 'n': |
||||
this->editor.mode_ = groove::Mode::QUIT; |
||||
break; |
||||
case 'y': |
||||
if (!this->editor.save()) |
||||
std::cerr << "Could not write to file: '" << this->editor.filename << "'\n"; |
||||
this->editor.mode_ = groove::Mode::QUIT; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,18 @@ |
||||
#pragma once |
||||
|
||||
#include <modes/Mode.hpp> |
||||
|
||||
namespace groove { |
||||
namespace modes { |
||||
|
||||
class Exit : public Mode { |
||||
public: |
||||
using Mode::Mode; |
||||
std::string status() { |
||||
return this->status_; |
||||
} |
||||
void input(int c); |
||||
}; |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue