refactoring, moving up GraphBrowser::deleteElement

master
denes 8 years ago
parent 1f6d8eedde
commit d2936e76d0
Signed by: denes
GPG Key ID: A7D50EAD42F9FC9F

@ -172,69 +172,57 @@ void GraphBrowser::mainLoop()
}
case KEY_UPPER_CASE_D: { // delete node
const std::string current = history_.back();
const ITEM* c_item = current_item(menu_);
if (c_item == 0)
break;
const std::string selected = item_name(c_item);
if (selected == history_.front()) // cannot delete start node
break;
graph_.removeVertex(selected);
removeFromHistory(history_, selected);
const int selected_index = item_index(c_item);
updateCurrent(current);
const int number_of_items = item_count(menu_);
if (number_of_items == 0)
break;
ITEM* newly_selected_item = getNthItem(menu_, std::min(selected_index, number_of_items-1));
const int r = set_current_item(menu_, newly_selected_item);
assert (r == E_OK);
updateNeighbours();
deleteElement(true);
break;
}
case KEY_UPPER_CASE_I: { // insert node
break;
}
case KEY_LOWER_CASE_D: { // delete edge
deleteElement(false);
break;
}
case KEY_LOWER_CASE_I: { // insert edge
break;
}
}
wrefresh(current_win_);
}
}
void GraphBrowser::deleteElement(bool delete_node)
{
const std::string current = history_.back();
const ITEM* c_item = current_item(menu_);
if (c_item == 0)
break;
return;
const std::string selected = item_name(c_item);
if (delete_node) {
if (selected == history_.front()) // cannot delete start node
return;
graph_.removeVertex(selected);
removeFromHistory(history_, selected);
} else {
graph_.removeEdge(current, selected);
}
const int selected_index = item_index(c_item);
updateCurrent(current);
const int number_of_items = item_count(menu_);
if (number_of_items == 0)
break;
return;
ITEM* newly_selected_item = getNthItem(menu_, std::min(selected_index, number_of_items-1));
const int r = set_current_item(menu_, newly_selected_item);
assert (r == E_OK);
updateNeighbours();
break;
}
case KEY_LOWER_CASE_I: { // insert edge
break;
}
}
wrefresh(current_win_);
}
}
void GraphBrowser::setStartVertex(const std::string& s)
{

@ -38,6 +38,7 @@ private:
void updateCurrent(const std::string& s);
void updateNeighbours();
void addItems(const std::vector<std::string>& stringVector);
void deleteElement(bool delete_node);
MENU *menu_;
WINDOW *current_win_, *n_win, * n_of_n_win_;

Loading…
Cancel
Save