d for delete

master
denes 8 years ago
parent a1e682fc82
commit 44b47fecb3
Signed by: denes
GPG Key ID: A7D50EAD42F9FC9F

@ -50,7 +50,7 @@ void GraphBrowser::destroy()
endwin(); endwin();
} }
GraphBrowser::GraphBrowser(const Graph<std::string>& g) GraphBrowser::GraphBrowser(Graph<std::string>& g)
: menu_(0) : menu_(0)
, current_win_(0) , current_win_(0)
, n_win(0) , n_win(0)
@ -92,7 +92,7 @@ GraphBrowser::GraphBrowser(const Graph<std::string>& g)
wrefresh(n_of_n_win_); wrefresh(n_of_n_win_);
// bottom text // bottom text
mvprintw(TERM_MAX_Y-1, 0, "ESC to exit, cursor keys to navigate"); mvprintw(TERM_MAX_Y-1, 0, "ESC to exit, cursor keys to navigate, d to delete");
refresh(); refresh();
} }
@ -144,7 +144,21 @@ void GraphBrowser::mainLoop()
menu_driver(menu_, REQ_SCR_UPAGE); menu_driver(menu_, REQ_SCR_UPAGE);
break; break;
case KEY_DEL: {
const std::string current = history_.back();
if (current == history_.front()) // cannot delete the first
break;
graph_.removeVertex(current);
history_.pop_back();
const std::string prev = history_.back();
updateCurrent(prev);
updateNeighbours();
} }
}
wrefresh(current_win_); wrefresh(current_win_);
} }
} }

@ -13,7 +13,10 @@ public:
static constexpr size_t TERM_MAX_X = 80; static constexpr size_t TERM_MAX_X = 80;
static constexpr size_t TERM_MAX_Y = 24; static constexpr size_t TERM_MAX_Y = 24;
static constexpr int KEY_ESC = 27; static constexpr int KEY_ESC = 27;
static constexpr int KEY_DEL = 100; // d
static constexpr size_t window_height = TERM_MAX_Y-2; static constexpr size_t window_height = TERM_MAX_Y-2;
static constexpr size_t current_window_width = TERM_MAX_X/4; static constexpr size_t current_window_width = TERM_MAX_X/4;
static constexpr size_t n_window_width = TERM_MAX_X/4; static constexpr size_t n_window_width = TERM_MAX_X/4;
@ -21,7 +24,7 @@ public:
void static init(); void static init();
void static destroy(); void static destroy();
GraphBrowser(const Graph<std::string>& g); GraphBrowser(Graph<std::string>& g);
~GraphBrowser(); ~GraphBrowser();
void mainLoop(); void mainLoop();
@ -36,7 +39,7 @@ private:
MENU *menu_; MENU *menu_;
WINDOW *current_win_, *n_win, * n_of_n_win_; WINDOW *current_win_, *n_win, * n_of_n_win_;
ITEM **items_; ITEM **items_;
const Graph<std::string>& graph_; Graph<std::string>& graph_;
std::deque<std::string> history_; std::deque<std::string> history_;
}; };

@ -52,7 +52,7 @@ Graph<std::string> generateRandomGraph(size_t number_of_vertices,
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
const Graph<std::string> g = generateRandomGraph(10, 200, 5, 20); Graph<std::string> g = generateRandomGraph(10, 200, 5, 20);
GraphBrowser::init(); GraphBrowser::init();

Loading…
Cancel
Save