Skip to content

Commit 629a0b3

Browse files
committed
Implemented deleteAllItems
1 parent 21d886c commit 629a0b3

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

src/YMGANCMenuBar.cc

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,25 @@ NCursesEvent YMGANCMenuBar::wHandleInput( wint_t key )
216216
yuiDebug() << "wHandleInput " << key << std::endl;
217217
NCursesEvent ret;
218218

219-
switch ( key )
219+
if (itemsBegin() != itemsEnd())
220220
{
221-
case KEY_LEFT:
222-
d->selected = d->getPrevious();
223-
wRedraw();
224-
break;
225-
case KEY_RIGHT:
226-
d->selected = d->getNext();
227-
wRedraw();
228-
break;
229-
case KEY_HOTKEY:
230-
case KEY_SPACE:
231-
case KEY_RETURN:
232-
case KEY_DOWN:
233-
ret = postMenu();
234-
break;
221+
switch ( key )
222+
{
223+
case KEY_LEFT:
224+
d->selected = d->getPrevious();
225+
wRedraw();
226+
break;
227+
case KEY_RIGHT:
228+
d->selected = d->getNext();
229+
wRedraw();
230+
break;
231+
case KEY_HOTKEY:
232+
case KEY_SPACE:
233+
case KEY_RETURN:
234+
case KEY_DOWN:
235+
ret = postMenu();
236+
break;
237+
}
235238
}
236239

237240
return ret;
@@ -268,6 +271,12 @@ void YMGANCMenuBar::wRedraw()
268271
if ( !win )
269272
return;
270273

274+
if (itemsBegin() == itemsEnd())
275+
{
276+
win->deleteln();
277+
return;
278+
}
279+
271280
int col=0;
272281
for ( YItemConstIterator it = itemsBegin() ; it != itemsEnd(); ++it )
273282
{
@@ -459,6 +468,16 @@ void YMGANCMenuBar::hideItem(YItem* menu_item, bool invisible)
459468
YMGAMenuBar::hideItem(menu_item, invisible);
460469
}
461470

471+
void YMGANCMenuBar::deleteAllItems()
472+
{
473+
for (__MBItem *i : d->items)
474+
delete i;
475+
d->items.clear();
476+
477+
YSelectionWidget::deleteAllItems();
478+
wRedraw();
479+
}
480+
462481

463482

464483
static void resolveShortcutsConflictFlat(YItemConstIterator begin, YItemConstIterator end)

src/YMGANCMenuBar.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ class YMGANCMenuBar : public YMGAMenuBar, public NCWidget
102102
**/
103103
virtual void hideItem(YItem * menu_item, bool invisible=true);
104104

105+
/**
106+
* Delete all items.
107+
*
108+
* Reimplemented from YSelectionWidget
109+
**/
110+
virtual void deleteAllItems();
111+
105112
private:
106113
/**
107114
* Recursively find the first menu item with the specified index.

0 commit comments

Comments
 (0)