8bed5c00dc842b2873bf0002e3e30c66f1fdfa3e — William Casarin 6 months ago b8cd9c4
move_event_to_calendar
1 files changed, 32 insertions(+), 7 deletions(-)

M viscal.c
M viscal.c => viscal.c +32 -7
@@ 680,7 680,6 @@ icalcomponent_add_component(ical, vevent);
  
  	calendar_refresh_events(cal);
- 
  	cal->select_after_sort = vevent;
  
  	return vevent;


@@ 1464,12 1463,37 @@ cal->chord = c;
  }
  
+ static void move_event_to_calendar(struct cal *cal, struct event *event,
+ 				   struct ical *from, struct ical *to)
+ {
+ 	icalcomponent_remove_component(from->calendar, event->vevent);
+ 	icalcomponent_add_component(to->calendar, event->vevent);
+ 	event->ical = to;
+ }
+ 
  static void next_calendar(struct cal *cal)
  {
+ 	struct event *event;
+ 	struct ical *from;
+ 	struct ical *to;
+ 
+ 	from = &cal->calendars[cal->selected_calendar_ind];
+ 
  	cal->selected_calendar_ind =
  		(cal->selected_calendar_ind + 1) % cal->ncalendars;
- 	printf("using calendar %s\n",
- 	       cal->calendars[cal->selected_calendar_ind].source_location);
+ 
+ 	to = &cal->calendars[cal->selected_calendar_ind];
+ 
+ 	printf("using calendar %s\n", to->source_location);
+ 
+ 	// move event to next calendar if we're editing it
+ 	if (cal->flags & CAL_CHANGING) {
+ 		event = get_selected_event(cal);
+ 		if (!event)
+ 			assert(!"no selected event when CAL_CHANGING");
+ 
+ 		move_event_to_calendar(cal, event, from, to);
+ 	}
  }
  
  static gboolean on_keypress (GtkWidget *widget, GdkEvent *event,


@@ 1483,17 1507,18 @@   	switch (event->type) {
  	case GDK_KEY_PRESS:
+ 		key = *event->key.string;
+ 
  		printf("DEBUG keystring %x %d\n",
- 		       *event->key.string, event->key.state);
+ 		       key, event->key.state);
  
- 		if (cal->flags & CAL_CHANGING) {
+ 		// Ctrl-tab during editing still switch cal
+ 		if (key != '\t' && (cal->flags & CAL_CHANGING)) {
  			state_changed = on_edit_keypress(cal, &event->key);
  			debug_edit_buffer(&event->key);
  			goto check_state;
  		}
  
- 		key = *event->key.string;
- 
  		// handle chords
  		if (cal->chord) {
  			chord_cmd *cmd =