gui: Implement tab reordering
And prevent tabs from being moved into the perma-tab area. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
cefd8b865b
commit
0e4c05350a
|
@ -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")
|
||||
|
|
17
gui/tabs.cpp
17
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<PlayqueueModel> model;
|
||||
Gtk::Notebook *notebook;
|
||||
|
||||
OcarinaTab *tab;
|
||||
|
@ -170,6 +169,7 @@ private:
|
|||
|
||||
public:
|
||||
Gtk::ToggleButton page_random;
|
||||
Glib::RefPtr<PlayqueueModel> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
26
lib/deck.cpp
26
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<Playqueue>::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<Playqueue>::iterator it_old = playqueue_deck.begin();
|
||||
std::list<Playqueue>::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;
|
||||
|
|
Loading…
Reference in New Issue