From 6e73bae3153970692e903476901b41650df96733 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 19 Jun 2007 09:23:11 +0000 Subject: [PATCH] added a "move tab" option to the jucer tab component --- .../components/jucer_TabbedComponentHandler.h | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/extras/the jucer/src/model/components/jucer_TabbedComponentHandler.h b/extras/the jucer/src/model/components/jucer_TabbedComponentHandler.h index d8097ba841..afb057428f 100644 --- a/extras/the jucer/src/model/components/jucer_TabbedComponentHandler.h +++ b/extras/the jucer/src/model/components/jucer_TabbedComponentHandler.h @@ -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 + { + public: + MoveTabAction (TabbedComponent* const comp, ComponentLayout& layout, + const int oldIndex_, const int newIndex_) + : ComponentUndoableAction (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; + }; + }; };