drag and drop, first step
This commit is contained in:
parent
d700e16530
commit
66ac275957
4 changed files with 218 additions and 18 deletions
|
@ -107,6 +107,7 @@ ScratchpadWindow :: ScratchpadWindow (
|
|||
&ScratchpadWindow::onDoubleClick));
|
||||
treeView->signal_key_press_event().connect(sigc::mem_fun(*this,
|
||||
&ScratchpadWindow::onKeyPressed));
|
||||
setupDndCallbacks();
|
||||
|
||||
// create the cue player widget
|
||||
cuePlayer.reset(new CuePlayer(this,
|
||||
|
@ -618,3 +619,94 @@ ScratchpadWindow :: hide(void) throw ()
|
|||
GuiWindow::hide();
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Set up the D'n'D callbacks.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ScratchpadWindow :: setupDndCallbacks (void) throw ()
|
||||
{
|
||||
std::list<Gtk::TargetEntry> targets;
|
||||
targets.push_back(Gtk::TargetEntry("STRING",
|
||||
Gtk::TARGET_SAME_APP));
|
||||
|
||||
// set up the tree view as a d'n'd source
|
||||
treeView->enable_model_drag_source(targets);
|
||||
treeView->signal_drag_data_get().connect(sigc::mem_fun(*this,
|
||||
&ScratchpadWindow::onTreeViewDragDataGet));
|
||||
|
||||
// set up the tree view as a d'n'd target
|
||||
treeView->enable_model_drag_dest(targets);
|
||||
treeView->signal_drag_data_received().connect(sigc::mem_fun(*this,
|
||||
&ScratchpadWindow::onTreeViewDragDataReceived));
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The callback for supplying the data for the drag and drop.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ScratchpadWindow :: onTreeViewDragDataGet(
|
||||
const Glib::RefPtr<Gdk::DragContext> & context,
|
||||
Gtk::SelectionData & selectionData,
|
||||
guint info,
|
||||
guint time)
|
||||
throw ()
|
||||
{
|
||||
Glib::ustring dropString = bundleName;
|
||||
Ptr<Playable>::Ref playable = getFirstSelectedPlayable();
|
||||
|
||||
while ((playable = getNextSelectedPlayable())) {
|
||||
dropString += " ";
|
||||
dropString += std::string(*playable->getId());
|
||||
}
|
||||
|
||||
selectionData.set(selectionData.get_target(),
|
||||
8 /* 8 bits format*/,
|
||||
(const guchar *) dropString.c_str(),
|
||||
dropString.bytes());
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The callback for processing the data delivered by drag and drop.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ScratchpadWindow :: onTreeViewDragDataReceived(
|
||||
const Glib::RefPtr<Gdk::DragContext> & context,
|
||||
int x,
|
||||
int y,
|
||||
const Gtk::SelectionData & selectionData,
|
||||
guint info,
|
||||
guint time)
|
||||
throw ()
|
||||
{
|
||||
if (selectionData.get_length() < 0 || selectionData.get_format() != 8) {
|
||||
std::cerr << "unknown type of data dropped on the tree view in "
|
||||
<< bundleName << std::endl;
|
||||
context->drag_finish(false, false, time);
|
||||
return;
|
||||
}
|
||||
|
||||
// Glib::ustring data = selectionData.get_data_as_string();
|
||||
Glib::ustring data = "searchWindow 123 456 789 abc";
|
||||
std::stringstream dataStream(data);
|
||||
Glib::ustring sourceWindow;
|
||||
dataStream >> sourceWindow;
|
||||
|
||||
|
||||
Glib::ustring playableId;
|
||||
while (dataStream >> playableId) {
|
||||
if (sourceWindow == bundleName) {
|
||||
//insertRow(destination, x, y, stripped, ROW_MOVE);
|
||||
std::cerr << "same window; move " << playableId << std::endl;
|
||||
context->drag_finish(true, true, time);
|
||||
|
||||
} else {
|
||||
//insertRow(destination, x, y, stripped, ROW_COPY);
|
||||
std::cerr << "other window: " << sourceWindow
|
||||
<< "; copy " << playableId << std::endl;
|
||||
context->drag_finish(true, false, time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -147,6 +147,12 @@ class ScratchpadWindow : public GuiWindow,
|
|||
void
|
||||
removeItem(Ptr<const UniqueId>::Ref id) throw ();
|
||||
|
||||
/**
|
||||
* Set up the D'n'D callbacks.
|
||||
*/
|
||||
void
|
||||
setupDndCallbacks (void) throw ();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -306,6 +312,42 @@ class ScratchpadWindow : public GuiWindow,
|
|||
virtual void
|
||||
onRemoveMenuOption(void) throw ();
|
||||
|
||||
/**
|
||||
* The callback for supplying the data for the drag and drop.
|
||||
*
|
||||
* @param context the drag context.
|
||||
* @param selectionData the data (filled in by this function).
|
||||
* @param info not used.
|
||||
* @param time timestamp for the d'n'd operation.
|
||||
*/
|
||||
void
|
||||
onTreeViewDragDataGet(
|
||||
const Glib::RefPtr<Gdk::DragContext> & context,
|
||||
Gtk::SelectionData & selectionData,
|
||||
guint info,
|
||||
guint time)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* The callback for processing the data delivered by drag and drop.
|
||||
*
|
||||
* @param context the drag context.
|
||||
* @param x the x coord where the data was dropped.
|
||||
* @param y the y coord where the data was dropped.
|
||||
* @param selectionData the data.
|
||||
* @param info not used.
|
||||
* @param time timestamp for the d'n'd operation.
|
||||
*/
|
||||
virtual void
|
||||
onTreeViewDragDataReceived(
|
||||
const Glib::RefPtr<Gdk::DragContext> & context,
|
||||
int x,
|
||||
int y,
|
||||
const Gtk::SelectionData & selectionData,
|
||||
guint info,
|
||||
guint time)
|
||||
throw ();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -237,6 +237,7 @@ SearchWindow :: constructSearchResultsView(void) throw ()
|
|||
false /* call this first */);
|
||||
searchResultsTreeView->signal_row_activated().connect(sigc::mem_fun(*this,
|
||||
&SearchWindow::onDoubleClick));
|
||||
setupDndCallbacks();
|
||||
|
||||
audioClipContextMenu = constructAudioClipContextMenu();
|
||||
playlistContextMenu = constructPlaylistContextMenu();
|
||||
|
@ -1120,3 +1121,46 @@ SearchWindow :: updatePagingToolbar(void) throw ()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Set up the D'n'D callbacks.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SearchWindow :: setupDndCallbacks (void) throw ()
|
||||
{
|
||||
std::list<Gtk::TargetEntry> targets;
|
||||
targets.push_back(Gtk::TargetEntry("STRING",
|
||||
Gtk::TARGET_SAME_APP));
|
||||
|
||||
// set up the tree view as a d'n'd source
|
||||
searchResultsTreeView->enable_model_drag_source(targets);
|
||||
searchResultsTreeView->signal_drag_data_get().connect(sigc::mem_fun(*this,
|
||||
&SearchWindow::onTreeViewDragDataGet));
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The callback for supplying the data for the drag and drop.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SearchWindow :: onTreeViewDragDataGet(
|
||||
const Glib::RefPtr<Gdk::DragContext> & context,
|
||||
Gtk::SelectionData & selectionData,
|
||||
guint info,
|
||||
guint time)
|
||||
throw ()
|
||||
{
|
||||
Glib::ustring dropString = bundleName;
|
||||
Ptr<Playable>::Ref playable = getFirstSelectedPlayable();
|
||||
|
||||
while ((playable = getNextSelectedPlayable())) {
|
||||
dropString += " ";
|
||||
dropString += std::string(*playable->getId());
|
||||
}
|
||||
|
||||
selectionData.set(selectionData.get_target(),
|
||||
8 /* 8 bits format*/,
|
||||
(const guchar *) dropString.c_str(),
|
||||
dropString.bytes());
|
||||
}
|
||||
|
||||
|
|
|
@ -420,6 +420,12 @@ class SearchWindow : public GuiWindow,
|
|||
Ptr<Playable>::Ref
|
||||
getNextSelectedPlayable(void) throw ();
|
||||
|
||||
/**
|
||||
* Set up the D'n'D callbacks.
|
||||
*/
|
||||
void
|
||||
setupDndCallbacks (void) throw ();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -618,6 +624,22 @@ class SearchWindow : public GuiWindow,
|
|||
void
|
||||
onForwardButtonClicked(void) throw ();
|
||||
|
||||
/**
|
||||
* The callback for supplying the data for the drag and drop.
|
||||
*
|
||||
* @param context the drag context.
|
||||
* @param selectionData the data (filled in by this function).
|
||||
* @param info not used.
|
||||
* @param time timestamp for the d'n'd operation.
|
||||
*/
|
||||
void
|
||||
onTreeViewDragDataGet(
|
||||
const Glib::RefPtr<Gdk::DragContext> & context,
|
||||
Gtk::SelectionData & selectionData,
|
||||
guint info,
|
||||
guint time)
|
||||
throw ();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue