99public class Maya.View.EventButton : Gtk .Bin {
1010 public ECal . Component comp { get ; construct set ; }
1111
12+ private const Gtk . TargetEntry DND = {" binary/calendar" , 0 , 0 };
13+ private const Gtk . TargetEntry DND2 = {" text/uri-list" , 0 , 1 };
14+
1215 private Gtk . Revealer revealer;
1316 private Gtk . Label label;
1417 private Gtk . StyleContext grid_style_context;
@@ -84,24 +87,9 @@ public class Maya.View.EventButton : Gtk.Bin {
8487 long_press_gesture. reset ();
8588 });
8689
87- Gtk . TargetEntry dnd = {" binary/calendar" , 0 , 0 };
88- Gtk . TargetEntry dnd2 = {" text/uri-list" , 0 , 0 };
89- Gtk . drag_source_set (event_box, Gdk . ModifierType . BUTTON1_MASK , {dnd, dnd2}, Gdk . DragAction . MOVE );
90-
91- event_box. drag_data_get. connect ( (ctx, sel, info, time) = > {
92- Calendar . EventStore . get_default (). drag_component = comp;
93- unowned ICal . Component icalcomp = comp. get_icalcomponent ();
94- var ical_str = icalcomp. as_ical_string ();
95- sel. set_text (ical_str, ical_str. length);
96- try {
97- var path = GLib . Path . build_filename (GLib . Environment . get_tmp_dir (), icalcomp. get_summary () + " .ics" );
98- var file = File . new_for_path (path);
99- if (file. replace_contents (ical_str. data, null , false , FileCreateFlags . PRIVATE , null ))
100- sel. set_uris ({file. get_uri ()});
101- } catch (Error e) {
102- critical (e. message);
103- }
104- });
90+ Gtk . drag_source_set (event_box, Gdk . ModifierType . BUTTON1_MASK , {DND , DND2 }, Gdk . DragAction . MOVE );
91+
92+ event_box. drag_data_get. connect (on_drag_data_get);
10593
10694 E . Source source = comp. get_data (" source" );
10795
@@ -114,6 +102,29 @@ public class Maya.View.EventButton : Gtk.Bin {
114102 });
115103 }
116104
105+ private void on_drag_data_get (Gtk . Widget widget, Gdk . DragContext context, Gtk . SelectionData selection_data, uint target_type, uint time) {
106+ Calendar . EventStore . get_default (). drag_component = comp;
107+
108+ unowned var icalcomp = comp. get_icalcomponent ();
109+ var ical_str = icalcomp. as_ical_string ();
110+ switch (target_type) {
111+ case 0 :
112+ selection_data. set_text (ical_str, ical_str. length);
113+ break ;
114+ case 1 :
115+ try {
116+ var path = GLib . Path . build_filename (GLib . Environment . get_tmp_dir (), icalcomp. get_summary () + " .ics" );
117+ var file = File . new_for_path (path);
118+ if (file. replace_contents (ical_str. data, null , false , FileCreateFlags . PRIVATE , null )) {
119+ selection_data. set_uris ({file. get_uri ()});
120+ }
121+ } catch (Error e) {
122+ critical (e. message);
123+ }
124+ break ;
125+ };
126+ }
127+
117128 public string get_uid () {
118129 return comp. get_id (). get_uid ();
119130 }
0 commit comments