private void OnPhotoUploaded(IPhoto item) { Debug.Assert(null != item); if (!model.AttachTags && !model.RemoveTags) { return; } PhotoStore photo_store = FSpot.App.Instance.Database.Photos; FSpot.Photo photo = photo_store.GetByUri( item.DefaultVersion.Uri); Debug.Assert(null != photo); if (null == photo) { return; } if (model.AttachTags) { photo.AddTag(model.AttachedTags); } if (model.RemoveTags) { photo.RemoveTag(model.RemovedTags); } photo_store.Commit(photo); }
public void HandleDragDataReceived(object o, DragDataReceivedArgs args) { TreePath path; TreeViewDropPosition position; if (!GetDestRowAtPos((int)args.X, (int)args.Y, out path, out position)) { return; } Tag tag = path == null ? null : TagByPath(path); if (tag == null) { return; } if (args.Info == DragDropTargets.PhotoListEntry.Info) { database.BeginTransaction(); Photo[] photos = args.SelectionData.GetPhotosData(); foreach (Photo photo in photos) { if (photo == null) { continue; } photo.AddTag(tag); database.Photos.Commit(photo); // FIXME: AddTagExtendes from Mainwindow.cs does some tag-icon handling. // this should be done here or completely located to the Tag-class. } database.CommitTransaction(); // FIXME: this needs to be done somewhere: //query_widget.PhotoTagsChanged (new Tag[] {tag}); return; } if (args.Info == (uint)DragDropTargets.TargetType.UriList) { UriList list = args.SelectionData.GetUriListData(); database.BeginTransaction(); List <Photo> photos = new List <Photo> (); foreach (var photo_uri in list) { Photo photo = database.Photos.GetByUri(photo_uri); // FIXME - at this point we should import the photo, and then continue if (photo == null) { continue; } // FIXME this should really follow the AddTagsExtended path too photo.AddTag(new Tag[] { tag }); photos.Add(photo); } database.Photos.Commit(photos.ToArray()); database.CommitTransaction(); // FIXME: this need to be done //InvalidateViews (); // but it seems not to be needed. tags are updated through in IconView through PhotoChanged return; } if (args.Info == DragDropTargets.TagListEntry.Info) { Category parent; if (position == TreeViewDropPosition.Before || position == TreeViewDropPosition.After) { parent = tag.Category; } else { parent = tag as Category; } if (parent == null || TagHighlight.Length < 1) { args.RetVal = false; return; } int moved_count = 0; Tag [] highlighted_tags = TagHighlight; foreach (Tag child in TagHighlight) { // FIXME with this reparenting via dnd, you cannot move a tag to root. if (child != parent && child.Category != parent && !child.IsAncestorOf(parent)) { child.Category = parent; // Saving changes will automatically cause the TreeView to be updated database.Tags.Commit(child); moved_count++; } } // Reselect the same tags TagHighlight = highlighted_tags; args.RetVal = moved_count > 0; } }