mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
add 200ms delay before starting drag'n'drop
This commit is contained in:
@@ -155,9 +155,12 @@ CardsOnClipboard::CardsOnClipboard(const SetP& set, const String id, const vecto
|
|||||||
}
|
}
|
||||||
String temp_path = wxFileName::CreateTempFileName(_("mse")) + _(".png");
|
String temp_path = wxFileName::CreateTempFileName(_("mse")) + _(".png");
|
||||||
img.SaveFile(temp_path, wxBITMAP_TYPE_PNG);
|
img.SaveFile(temp_path, wxBITMAP_TYPE_PNG);
|
||||||
wxFileDataObject* data = new wxFileDataObject();
|
wxFileDataObject* fileData = new wxFileDataObject();
|
||||||
data->AddFile(temp_path);
|
fileData->AddFile(temp_path);
|
||||||
Add(data);
|
Add(fileData);
|
||||||
|
wxImageDataObject* imgData = new wxImageDataObject();
|
||||||
|
imgData->SetImage(img);
|
||||||
|
Add(imgData);
|
||||||
}
|
}
|
||||||
// Conversion to serialized card format
|
// Conversion to serialized card format
|
||||||
Add(new CardsDataObject(set, id, cards), true);
|
Add(new CardsDataObject(set, id, cards), true);
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ CardListBase* CardSelectEvent::getTheCardList() const {
|
|||||||
// ----------------------------------------------------------------------------- : CardListBase
|
// ----------------------------------------------------------------------------- : CardListBase
|
||||||
|
|
||||||
CardListBase::CardListBase(Window* parent, int id, long additional_style)
|
CardListBase::CardListBase(Window* parent, int id, long additional_style)
|
||||||
: ItemList(parent, id, additional_style, true)
|
: ItemList(parent, id, additional_style, true) , drop_timer(this, ID_DROP_TIMER)
|
||||||
{
|
{
|
||||||
drop_target = new CardListDropTarget(this);
|
drop_target = new CardListDropTarget(this);
|
||||||
}
|
}
|
||||||
@@ -626,17 +626,23 @@ void CardListBase::onChar(wxKeyEvent& ev) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardListBase::onBeginDrag(wxListEvent&) {
|
void CardListBase::onBeginDrag(wxListEvent&) {
|
||||||
vector<CardP> cards;
|
drop_timer.Start(200, wxTIMER_ONE_SHOT);
|
||||||
getSelection(cards);
|
|
||||||
String transaction_id = generate_uid();
|
|
||||||
CardsOnClipboard* card_data = new CardsOnClipboard(set, transaction_id, cards);
|
|
||||||
drop_target->ignored_id = transaction_id;
|
|
||||||
wxDropSource drag_source(this);
|
|
||||||
drag_source.SetData(*card_data);
|
|
||||||
drag_source.DoDragDrop(wxDrag_CopyOnly);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardListBase::OnDragTimer(wxTimerEvent& ev) {
|
||||||
|
if (ev.GetId() == ID_DROP_TIMER && wxGetMouseState().LeftIsDown()) {
|
||||||
|
vector<CardP> cards;
|
||||||
|
getSelection(cards);
|
||||||
|
String transaction_id = generate_uid();
|
||||||
|
CardsOnClipboard* card_data = new CardsOnClipboard(set, transaction_id, cards);
|
||||||
|
drop_target->ignored_id = transaction_id;
|
||||||
|
wxDropSource drag_source(this);
|
||||||
|
drag_source.SetData(*card_data);
|
||||||
|
drag_source.DoDragDrop(wxDrag_CopyOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CardListBase::onDrag(wxMouseEvent& ev) {
|
void CardListBase::onDrag(wxMouseEvent& ev) {
|
||||||
ev.Skip();
|
ev.Skip();
|
||||||
if (!allowModify()) return;
|
if (!allowModify()) return;
|
||||||
@@ -704,7 +710,8 @@ BEGIN_EVENT_TABLE(CardListBase, ItemList)
|
|||||||
EVT_LIST_COL_RIGHT_CLICK (wxID_ANY, CardListBase::onColumnRightClick)
|
EVT_LIST_COL_RIGHT_CLICK (wxID_ANY, CardListBase::onColumnRightClick)
|
||||||
EVT_LIST_COL_END_DRAG (wxID_ANY, CardListBase::onColumnResize)
|
EVT_LIST_COL_END_DRAG (wxID_ANY, CardListBase::onColumnResize)
|
||||||
EVT_LIST_ITEM_ACTIVATED (wxID_ANY, CardListBase::onItemActivate)
|
EVT_LIST_ITEM_ACTIVATED (wxID_ANY, CardListBase::onItemActivate)
|
||||||
EVT_LIST_BEGIN_DRAG (wxID_ANY, CardListBase::onBeginDrag)
|
EVT_LIST_BEGIN_DRAG (wxID_ANY, CardListBase::onBeginDrag)
|
||||||
|
EVT_TIMER (ID_DROP_TIMER, CardListBase::OnDragTimer)
|
||||||
EVT_CHAR ( CardListBase::onChar)
|
EVT_CHAR ( CardListBase::onChar)
|
||||||
EVT_MOTION ( CardListBase::onDrag)
|
EVT_MOTION ( CardListBase::onDrag)
|
||||||
EVT_MENU (ID_SELECT_COLUMNS, CardListBase::onSelectColumns)
|
EVT_MENU (ID_SELECT_COLUMNS, CardListBase::onSelectColumns)
|
||||||
|
|||||||
@@ -70,8 +70,9 @@ public:
|
|||||||
inline void setCard(const CardP& card, bool event = false) { selectItem(card, true, event); }
|
inline void setCard(const CardP& card, bool event = false) { selectItem(card, true, event); }
|
||||||
|
|
||||||
// --------------------------------------------------- : Clipboard and Drag'n'Drop
|
// --------------------------------------------------- : Clipboard and Drag'n'Drop
|
||||||
|
|
||||||
CardListDropTarget* drop_target;
|
CardListDropTarget* drop_target;
|
||||||
|
wxTimer drop_timer;
|
||||||
|
|
||||||
bool canCut() const override;
|
bool canCut() const override;
|
||||||
bool canCopy() const override;
|
bool canCopy() const override;
|
||||||
@@ -167,7 +168,8 @@ private:
|
|||||||
void onItemActivate (wxListEvent&);
|
void onItemActivate (wxListEvent&);
|
||||||
void onSelectColumns (wxCommandEvent&);
|
void onSelectColumns (wxCommandEvent&);
|
||||||
void onChar (wxKeyEvent&);
|
void onChar (wxKeyEvent&);
|
||||||
void onBeginDrag (wxListEvent&);
|
void onBeginDrag (wxListEvent&);
|
||||||
|
void OnDragTimer (wxTimerEvent&);
|
||||||
void onDrag (wxMouseEvent&);
|
void onDrag (wxMouseEvent&);
|
||||||
void onContextMenu (wxContextMenuEvent&);
|
void onContextMenu (wxContextMenuEvent&);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -321,7 +321,10 @@ ScriptValueP json_to_mse(const boost::json::value& jv, Set* set) {
|
|||||||
// if the string contains nul bytes, we have to use the std::string constructor, even though we can't specify the encoding
|
// if the string contains nul bytes, we have to use the std::string constructor, even though we can't specify the encoding
|
||||||
if (nulpos < string.size()) return to_script(String(string));
|
if (nulpos < string.size()) return to_script(String(string));
|
||||||
// if the string doesn't contain nul bytes, we can use the constructor that allows to specify the encoding
|
// if the string doesn't contain nul bytes, we can use the constructor that allows to specify the encoding
|
||||||
else return to_script(String(cstring, wxConvUTF8));
|
String wxstring(cstring, wxConvUTF8);
|
||||||
|
if (!wxstring.empty()) return to_script(wxstring);
|
||||||
|
// if all else fails, use "Whatever Works"
|
||||||
|
return to_script(String(cstring, wxConvWhateverWorks));
|
||||||
}
|
}
|
||||||
else if (jv.is_array()) {
|
else if (jv.is_array()) {
|
||||||
boost::json::array array = jv.get_array();
|
boost::json::array array = jv.get_array();
|
||||||
|
|||||||
@@ -279,6 +279,8 @@ enum ControlID {
|
|||||||
ID_MOVE_DOWN,
|
ID_MOVE_DOWN,
|
||||||
ID_SHOW,
|
ID_SHOW,
|
||||||
ID_HIDE,
|
ID_HIDE,
|
||||||
|
// Card list drag'n'drop timer
|
||||||
|
ID_DROP_TIMER,
|
||||||
// Card select
|
// Card select
|
||||||
ID_SELECT_CARDS,
|
ID_SELECT_CARDS,
|
||||||
ID_SELECTION_CHOICE,
|
ID_SELECTION_CHOICE,
|
||||||
|
|||||||
Reference in New Issue
Block a user