fix active menu item when inserting or removing other items
Mark Tiefenbruck mark@fluxbox.org
3 files changed,
11 insertions(+),
6 deletions(-)
M
src/FbTk/Menu.cc
→
src/FbTk/Menu.cc
@@ -219,6 +219,8 @@ menuitems.push_back(item);
} else { menuitems.insert(menuitems.begin() + pos, item); fixMenuItemIndices(); + if (m_active_index >= pos) + m_active_index++; } m_need_update = true; // we need to redraw the menu return menuitems.size();@@ -233,7 +235,7 @@ int Menu::remove(unsigned int index) {
if (index >= menuitems.size()) { #ifdef DEBUG cout << "Bad index (" << index << ") given to Menu::remove()" - << " -- should be between 0 and " << menuitems.size() + << " -- should be between 0 and " << menuitems.size()-1 << " inclusive." << endl; #endif // DEBUG return -1;@@ -270,6 +272,9 @@ if (static_cast<unsigned int>(m_which_sub) == index)
m_which_sub = -1; else if (static_cast<unsigned int>(m_which_sub) > index) m_which_sub--; + + if (static_cast<unsigned int>(m_active_index) > index) + m_active_index--; m_need_update = true; // we need to redraw the menu@@ -366,7 +371,7 @@ void Menu::enableTitle() {
setTitleVisibility(true); } -void Menu::updateMenu(int active_index) { +void Menu::updateMenu() { if (m_title_vis) { menu.item_w = theme()->titleFont().textWidth(menu.label, menu.label.size());
M
src/FbTk/Menu.hh
→
src/FbTk/Menu.hh
@@ -109,7 +109,7 @@ /// set label string
void setLabel(const FbString &labelstr); /// move menu to x,y virtual void move(int x, int y); - virtual void updateMenu(int active_index = -1); + virtual void updateMenu(); void setItemSelected(unsigned int index, bool val); void setItemEnabled(unsigned int index, bool val); void setMinimumSublevels(int m) { menu.minsub = m; }
M
src/WorkspaceMenu.cc
→
src/WorkspaceMenu.cc
@@ -80,7 +80,7 @@ mb_menu->setCommand(3, jump_cmd);
insert(mb_menu, workspace + IDX_AFTER_ICONS); } - updateMenu(-1); + updateMenu(); } void WorkspaceMenu::workspaceChanged(BScreen& screen) {@@ -89,12 +89,12 @@ for (unsigned int i = 0; i < screen.numberOfWorkspaces(); ++i) {
item = find(i + IDX_AFTER_ICONS); if (item && item->isSelected()) { setItemSelected(i + IDX_AFTER_ICONS, false); - updateMenu(i + IDX_AFTER_ICONS); + updateMenu(); break; } } setItemSelected(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS, true); - updateMenu(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS); + updateMenu(); } void WorkspaceMenu::init(BScreen &screen) {