[blam: 4/5] ChanneList: refactor drag and drop
- From: Carlos Martín Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam: 4/5] ChanneList: refactor drag and drop
- Date: Thu, 20 Jun 2013 23:43:42 +0000 (UTC)
commit 4050b706ac8ea2a20b43d33c55e2266ed0939a61
Author: Carlos Martín Nieto <cmn dwim me>
Date: Fri Jun 21 01:42:02 2013 +0200
ChanneList: refactor drag and drop
src/ChannelList.cs | 86 +++++++++++++++++++++++++++-------------------------
1 files changed, 45 insertions(+), 41 deletions(-)
---
diff --git a/src/ChannelList.cs b/src/ChannelList.cs
index 0a8a13d..139f2e5 100644
--- a/src/ChannelList.cs
+++ b/src/ChannelList.cs
@@ -158,59 +158,63 @@ namespace Imendio.Blam {
if (path == null)
return;
- /* Not directly over a channel. */
+ /* Not directly over a channel or group. */
if(pos == TreeViewDropPosition.After || pos == TreeViewDropPosition.Before){
- TreePath tmp_path = path.Copy();
- tmp_path.Up();
- TreePath tmp_path_src = Model.GetPath(src.Iter).Copy();
- tmp_path_src.Up();
- // if they have the same parent, we don't do anything
- if (tmp_path.Equals(tmp_path_src))
+ var src_path = Model.GetPath(src.Iter).Copy();
+ // both at the top level, don't do anything
+ if (path.Depth == 1 && src_path.Depth == 1)
return;
- Model.GetIter(out tmp_iter, tmp_path);
- IChannel drop_parent = Model.GetValue(tmp_iter, 0) as IChannel;
- //System.Console.WriteLine("dp: {0} depth:{1}", drop_parent.GetType(),
path.Depth);
- if(path.Depth == 2 && drop_parent is ChannelGroup){ // Dropped inside a group.
- Collection.Move(src, drop_parent);
- } else{
+ // target depth 1, source >1 means we need to lift the channel out of the
group
+ if (path.Depth == 1 && src_path.Depth > 1) {
Collection.Move(src, null);
+ return;
}
- /* Directly over a channel. */
+ // the depth of both is higher than 1, so both are in a group, and this is a
channel
+ var src_parent_path = src_path.Copy();
+ src_parent_path.Up();
+ var trg_parent_path = path.Copy();
+ trg_parent_path.Up();
+
+ // if they have the same parent, we don't need to do anything
+ if (src_parent_path.Equals(trg_parent_path))
+ return;
+
+ // now we know that we want to move the channel into this channel's group
+ TreeIter parent_iter;
+ Model.GetIter(out parent_iter, trg_parent_path);
+ ChannelGroup parent = (ChannelGroup)Model.GetValue(parent_iter, 0);
+ Collection.Move(src, parent);
} else {
- TreePath tmp_path_src = Model.GetPath(src.Iter).Copy();
- tmp_path_src.Up();
- TreePath dst_path_parent = path.Copy();
- dst_path_parent.Up();
-
- if(dst is Channel && path.Depth == 1 && // dst is top-level
- src is Channel && Model.GetPath(src.Iter).Depth == 2){ // src is in a group
- Console.WriteLine("think you dropped on a group add -> remove");
- Collection.Move(src, null);
+ // on top of a group, move it here
+ if (dst is ChannelGroup) {
+ // if it's already in this group, don't do anything
+ var grp = (ChannelGroup)dst;
+ if (grp.Channels.Contains(src))
+ return;
+
+ Collection.Move(src, dst);
+ return;
}
-
- /*
- * A channel can't become a group and a group can't be
- * inside another group and it doesn't make sense to move
- * it into the same group.
- * FIXME: Make it possible for a group to be inside another group.
- */
- if((dst is Channel && path.Depth == 1) || src is ChannelGroup ||
- path == tmp_path_src){ // Move to the same group
- Console.WriteLine("not doing anything as you dropped on a top-level
channel");
+ // on top of a channel
+ var src_path = Model.GetPath(src.Iter).Copy();
+ if (path.Depth == 1 && src_path.Depth == 1)
+ return;
+ if (path.Depth == 1 && src_path.Depth > 1) {
+ Collection.Move(src, null);
return;
}
- /*
- * If we drop on a channel which is inside a group, we add that channel to
- * the group.
- */
+ // dropped on a channel inside a group
+ var dst_parent_path = path.Copy();
+ dst_parent_path.Up();
- if(dst is Channel && path.Depth == 2){ // Channel inside a group.
- Model.GetIter(out tmp_iter, dst_path_parent);
- dst = Model.GetValue(tmp_iter, 0) as ChannelGroup;
- }
+ var src_parent_path = src_path.Copy();
+ src_parent_path.Up();
+ // already in the same group
+ if (src_parent_path.Equals(dst_parent_path))
+ return;
Collection.Move(src, dst);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]