From 0e4c05350a121115d75db82b349fc050d0149e90 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 31 Jan 2014 22:45:26 -0500 Subject: [PATCH] gui: Implement tab reordering And prevent tabs from being moved into the perma-tab area. Signed-off-by: Anna Schumaker --- gui/Sconscript | 3 +++ gui/tabs.cpp | 17 ++++++++++++++++- include/deck.h | 2 ++ lib/deck.cpp | 26 ++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/gui/Sconscript b/gui/Sconscript index f7253909..2d07327c 100644 --- a/gui/Sconscript +++ b/gui/Sconscript @@ -3,5 +3,8 @@ Import("env", "CONFIG") CONFIG.package("gtkmm-3.0") +CONFIG.reset(ALL = True) +ocarina = env.Program("ocarina", Glob("*.cpp") + SConscript("../lib/Sconscript")) +Default(ocarina) res = Glob("*.cpp") Return("res") diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 7fae9f04..9cd82e63 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -149,7 +149,6 @@ void PQTab::set_size(unsigned int size) class OcarinaPage : public Gtk::VBox { private: unsigned int init_flags; - Glib::RefPtr model; Gtk::Notebook *notebook; OcarinaTab *tab; @@ -170,6 +169,7 @@ private: public: Gtk::ToggleButton page_random; + Glib::RefPtr model; OcarinaPage(const std::string &, const std::string &, Playqueue *, unsigned int); @@ -208,6 +208,7 @@ OcarinaPage::OcarinaPage(Playqueue *pq, unsigned int flags, unsigned int pg) pqt->close_button.signal_clicked().connect(sigc::mem_fun(*this, &OcarinaPage::on_close_clicked)); setup_common(pq, pg); + notebook->set_tab_reorderable(*this); } OcarinaPage::~OcarinaPage() @@ -459,6 +460,19 @@ static void on_switch_page(Gtk::Widget *page, int num) sort_timeout_count = 0; } +static void on_page_reordered(Gtk::Widget *page, int num) +{ + Gtk::Notebook *notebook; + OcarinaPage *tab = (OcarinaPage *)page; + + get_builder()->get_widget("o_notebook", notebook); + + if ((unsigned int)num >= deck :: size()) + notebook->reorder_child(*page, deck::size() - 1); + else + deck :: move(tab->model->queue, num); +} + static void on_pq_created(Playqueue *pq, unsigned int num) { OcarinaPage *page = new OcarinaPage(pq, PQ_RANDOM | PQ_REPEAT, num); @@ -498,6 +512,7 @@ void init_tabs() get_callbacks()->on_queue_track_changed = on_track_changed; notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page)); + notebook->signal_page_reordered().connect(sigc::ptr_fun(on_page_reordered)); notebook->set_current_page(0); } diff --git a/include/deck.h b/include/deck.h index c0acff30..0c3005cb 100644 --- a/include/deck.h +++ b/include/deck.h @@ -16,7 +16,9 @@ namespace deck Playqueue *create(bool); void remove(unsigned int); Playqueue *get(unsigned int); + unsigned int size(); void move(unsigned int, unsigned int); + void move(Playqueue *, unsigned int); unsigned int next(); Playqueue *get_library_pq(); diff --git a/lib/deck.cpp b/lib/deck.cpp index 5e02ca6e..0acc4233 100644 --- a/lib/deck.cpp +++ b/lib/deck.cpp @@ -132,6 +132,11 @@ Playqueue *deck :: get(unsigned int id) return &(*it); } +unsigned int deck :: size() +{ + return playqueue_deck.size(); +} + void deck :: move(unsigned int old_pos, unsigned int new_pos) { std::list::iterator it_old = playqueue_deck.begin(); @@ -150,6 +155,27 @@ void deck :: move(unsigned int old_pos, unsigned int new_pos) playqueue_deck.splice(it_new, playqueue_deck, it_old); } +void deck :: move(Playqueue *pq, unsigned int new_pos) +{ + unsigned int old_pos = 0; + std::list::iterator it_old = playqueue_deck.begin(); + std::list::iterator it_new = playqueue_deck.begin(); + + for (unsigned int i = 0; i < playqueue_deck.size(); i++) { + if (&(*it_old) != pq) { + it_old++; + old_pos++; + } + if (i < new_pos) + it_new++; + } + + if (new_pos > old_pos) + it_new++; + + playqueue_deck.splice(it_new, playqueue_deck, it_old); +} + unsigned int deck :: next() { unsigned int id = 0;