added keyboard shortcuts to the playlist editor window
This commit is contained in:
parent
f6e8fbbb3b
commit
797a2d8312
2 changed files with 138 additions and 8 deletions
|
@ -52,6 +52,20 @@ using namespace LiveSupport::GLiveSupport;
|
||||||
|
|
||||||
/* ================================================ local constants & macros */
|
/* ================================================ local constants & macros */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The modifier keys we check against in onKeyPressed().
|
||||||
|
* The following modifiers are omitted, hence ignored:
|
||||||
|
* GDK_LOCK_MASK (caps lock),
|
||||||
|
* GDK_MOD2_MASK (don't know what; always on on my computer),
|
||||||
|
* GDK_MOD3_MASK (don't know what; always off on my computer),
|
||||||
|
* GDK_BUTTONX_MASK (mouse buttons, X = 1..5).
|
||||||
|
*/
|
||||||
|
static const guint MODIFIERS_CHECKED = GDK_SHIFT_MASK
|
||||||
|
| GDK_CONTROL_MASK
|
||||||
|
| GDK_MOD1_MASK // Alt
|
||||||
|
| GDK_MOD4_MASK // Windows key
|
||||||
|
| GDK_MOD5_MASK; // Alt-gr
|
||||||
|
|
||||||
|
|
||||||
/* =============================================== local function prototypes */
|
/* =============================================== local function prototypes */
|
||||||
|
|
||||||
|
@ -132,6 +146,8 @@ SimplePlaylistManagementWindow :: SimplePlaylistManagementWindow (
|
||||||
*this, &SimplePlaylistManagementWindow::onEntryClicked ));
|
*this, &SimplePlaylistManagementWindow::onEntryClicked ));
|
||||||
entriesView->signalCellEdited().connect(sigc::mem_fun(
|
entriesView->signalCellEdited().connect(sigc::mem_fun(
|
||||||
*this, &SimplePlaylistManagementWindow::onFadeInfoEdited ));
|
*this, &SimplePlaylistManagementWindow::onFadeInfoEdited ));
|
||||||
|
entriesView->signal_key_press_event().connect(sigc::mem_fun(
|
||||||
|
*this, &SimplePlaylistManagementWindow::onKeyPressed));
|
||||||
|
|
||||||
// create the right-click entry context menu
|
// create the right-click entry context menu
|
||||||
rightClickMenu = Gtk::manage(new Gtk::Menu());
|
rightClickMenu = Gtk::manage(new Gtk::Menu());
|
||||||
|
@ -608,11 +624,14 @@ void
|
||||||
SimplePlaylistManagementWindow :: onUpItem(void) throw()
|
SimplePlaylistManagementWindow :: onUpItem(void) throw()
|
||||||
{
|
{
|
||||||
if (currentItem && currentItem != entriesModel->children().begin()) {
|
if (currentItem && currentItem != entriesModel->children().begin()) {
|
||||||
|
int rowNumber = (*currentItem)
|
||||||
|
[modelColumns.rowNumberColumn];
|
||||||
Gtk::TreeIter previousItem = currentItem;
|
Gtk::TreeIter previousItem = currentItem;
|
||||||
--previousItem;
|
--previousItem;
|
||||||
swapPlaylistElements(previousItem, currentItem);
|
swapPlaylistElements(previousItem, currentItem);
|
||||||
isPlaylistModified = true;
|
isPlaylistModified = true;
|
||||||
showContents();
|
showContents();
|
||||||
|
selectRow(--rowNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,12 +643,15 @@ void
|
||||||
SimplePlaylistManagementWindow :: onDownItem(void) throw()
|
SimplePlaylistManagementWindow :: onDownItem(void) throw()
|
||||||
{
|
{
|
||||||
if (currentItem) {
|
if (currentItem) {
|
||||||
Gtk::TreeIter nextItem = currentItem;
|
Gtk::TreeIter nextItem = currentItem;
|
||||||
++nextItem;
|
++nextItem;
|
||||||
if (nextItem) {
|
if (nextItem) {
|
||||||
|
int rowNumber = (*currentItem)
|
||||||
|
[modelColumns.rowNumberColumn];
|
||||||
swapPlaylistElements(currentItem, nextItem);
|
swapPlaylistElements(currentItem, nextItem);
|
||||||
isPlaylistModified = true;
|
isPlaylistModified = true;
|
||||||
showContents();
|
showContents();
|
||||||
|
selectRow(++rowNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -719,14 +741,82 @@ SimplePlaylistManagementWindow :: swapPlaylistElements(
|
||||||
void
|
void
|
||||||
SimplePlaylistManagementWindow :: onRemoveItem(void) throw()
|
SimplePlaylistManagementWindow :: onRemoveItem(void) throw()
|
||||||
{
|
{
|
||||||
Ptr<Playlist>::Ref playlist = gLiveSupport->getEditedPlaylist();
|
if (currentItem) {
|
||||||
Ptr<PlaylistElement>::Ref playlistElement
|
Ptr<Playlist>::Ref
|
||||||
= (*currentItem)[modelColumns.playlistElementColumn];
|
playlist = gLiveSupport->getEditedPlaylist();
|
||||||
|
Ptr<PlaylistElement>::Ref
|
||||||
|
playlistElement = (*currentItem)
|
||||||
|
[modelColumns.playlistElementColumn];
|
||||||
|
|
||||||
playlist->removePlaylistElement(playlistElement->getId());
|
playlist->removePlaylistElement(playlistElement->getId());
|
||||||
playlist->eliminateGaps();
|
playlist->eliminateGaps();
|
||||||
|
|
||||||
isPlaylistModified = true;
|
isPlaylistModified = true;
|
||||||
showContents();
|
showContents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Event handler for a key pressed.
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
bool
|
||||||
|
SimplePlaylistManagementWindow :: onKeyPressed(GdkEventKey * event)
|
||||||
|
throw ()
|
||||||
|
{
|
||||||
|
if (event->type == GDK_KEY_PRESS) {
|
||||||
|
if ((event->keyval == GDK_Up
|
||||||
|
|| event->keyval == GDK_KP_Up)
|
||||||
|
&& (event->state & MODIFIERS_CHECKED) == GDK_MOD1_MASK) {
|
||||||
|
findCurrentItem();
|
||||||
|
onUpItem();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else if ((event->keyval == GDK_Down
|
||||||
|
|| event->keyval == GDK_KP_Down)
|
||||||
|
&& (event->state & MODIFIERS_CHECKED) == GDK_MOD1_MASK) {
|
||||||
|
findCurrentItem();
|
||||||
|
onDownItem();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else if (event->keyval == GDK_Delete
|
||||||
|
|| event->keyval == GDK_KP_Delete) {
|
||||||
|
findCurrentItem();
|
||||||
|
onRemoveItem();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Find (an iterator pointing to) the currently selected row.
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
SimplePlaylistManagementWindow :: findCurrentItem(void) throw ()
|
||||||
|
{
|
||||||
|
Glib::RefPtr<Gtk::TreeView::Selection> selection
|
||||||
|
= entriesView->get_selection();
|
||||||
|
currentItem = selection->get_selected();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Select (highlight) the nth row.
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
SimplePlaylistManagementWindow :: selectRow(int rowNumber) throw ()
|
||||||
|
{
|
||||||
|
Gtk::TreeModel::iterator iter = entriesModel->children().begin();
|
||||||
|
for (; rowNumber > 0; --rowNumber) {
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
if (iter) {
|
||||||
|
Glib::RefPtr<Gtk::TreeView::Selection> selection
|
||||||
|
= entriesView->get_selection();
|
||||||
|
selection->select(iter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,46 @@ class SimplePlaylistManagementWindow : public WhiteWindow,
|
||||||
void
|
void
|
||||||
onEntryClicked(GdkEventButton * event) throw ();
|
onEntryClicked(GdkEventButton * event) throw ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signal handler for a key pressed at one of the entries.
|
||||||
|
* The keys handled are:
|
||||||
|
* <ul>
|
||||||
|
* <li>Alt-Up : move item up</li>
|
||||||
|
* <li>Alt-Down : move item down</li>
|
||||||
|
* <li>Delete : remove item</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* Technical note: the symbolic key names are found in
|
||||||
|
* <code>/usr/include/gtk-2.0/gdk/gdkkeysyms.h</code>,
|
||||||
|
* and the symbolic modifier names are found in
|
||||||
|
* <code>/usr/include/gtk-2.0/gdk/gdktypes.h</code>.
|
||||||
|
*
|
||||||
|
* TODO: make keys customizable from a config file?
|
||||||
|
*
|
||||||
|
* @param event the button event recieved
|
||||||
|
* @return true if the key press was fully handled, false if not
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
onKeyPressed(GdkEventKey * event) throw ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find (an iterator pointing to) the currently selected row.
|
||||||
|
*
|
||||||
|
* This is an auxilliary function used by onKeyPressed().
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
findCurrentItem(void) throw ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select (highlight) the nth row.
|
||||||
|
*
|
||||||
|
* This is an auxilliary function used by onUpItem() and onDownItem().
|
||||||
|
*
|
||||||
|
* @param rowNumber the number of the row to be selected.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
selectRow(int rowNumber) throw ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signal handler for the save button clicked.
|
* Signal handler for the save button clicked.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue