Browse Source

added a "move tab" option to the jucer tab component

tags/2021-05-28
jules 18 years ago
parent
commit
6e73bae315
1 changed files with 86 additions and 0 deletions
  1. +86
    -0
      extras/the jucer/src/model/components/jucer_TabbedComponentHandler.h

+ 86
- 0
extras/the jucer/src/model/components/jucer_TabbedComponentHandler.h View File

@@ -154,6 +154,8 @@ public:
properties.add (new TabContentConstructorParamsProperty (t, document, i));
properties.add (new TabMoveProperty (t, document, i, t->getNumTabs()));
panel.addSection (T("Tab ") + String (i), properties);
}
}
@@ -1160,6 +1162,90 @@ private:
String newValue, oldValue;
};
};
//==============================================================================
class TabMoveProperty : public ButtonPropertyComponent
{
public:
TabMoveProperty (TabbedComponent* comp, JucerDocument& document_,
const int tabIndex_, const int totalNumTabs_)
: ButtonPropertyComponent (T("add tab"), false),
component (comp),
document (document_),
tabIndex (tabIndex_),
totalNumTabs (totalNumTabs_)
{
}
void buttonClicked()
{
PopupMenu m;
m.addItem (1, T("Move this tab up"), tabIndex > 0);
m.addItem (2, T("Move this tab down"), tabIndex < totalNumTabs - 1);
const int r = m.showAt (this);
if (r != 0)
{
document.perform (new MoveTabAction (component, *document.getComponentLayout(), tabIndex, tabIndex + (r == 2 ? 1 : -1)),
T("Move a tab"));
}
}
const String getButtonText() const
{
return T("Move this tab...");
}
TabbedComponent* const component;
JucerDocument& document;
const int tabIndex, totalNumTabs;
private:
class MoveTabAction : public ComponentUndoableAction <TabbedComponent>
{
public:
MoveTabAction (TabbedComponent* const comp, ComponentLayout& layout,
const int oldIndex_, const int newIndex_)
: ComponentUndoableAction <TabbedComponent> (comp, layout),
oldIndex (oldIndex_),
newIndex (newIndex_)
{
}
void move (int from, int to)
{
showCorrectTab();
XmlElement* const state = getTabState (getComponent(), from);
getComponent()->removeTab (from);
addNewTab (getComponent(), to);
restoreTabState (getComponent(), to, *state);
delete state;
layout.getDocument()->refreshAllPropertyComps();
changed();
}
bool perform()
{
move (oldIndex, newIndex);
return true;
}
bool undo()
{
move (newIndex, oldIndex);
return true;
}
private:
const int oldIndex, newIndex;
};
};
};


Loading…
Cancel
Save