[f-spot/cleanup-backend: 12/23] Completely replace IconView.SelectionCollection with PhotoSelection



commit 4ff227bdee3573793d652bcd0fa57afbb6ccfe0c
Author: Mike Gemünde <mike gemuende de>
Date:   Fri Jul 16 10:43:07 2010 +0200

    Completely replace IconView.SelectionCollection with PhotoSelection

 src/MainWindow.cs                 |    5 +++--
 src/SingleView.cs                 |   11 +++++++----
 src/UI.Dialog/AdjustTimeDialog.cs |    5 +++--
 src/UI.Dialog/ImportDialog.cs     |    6 ++++--
 src/Widgets/IconView.cs           |   36 ++++++------------------------------
 5 files changed, 23 insertions(+), 40 deletions(-)
---
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
index 24d141b..6e634f4 100644
--- a/src/MainWindow.cs
+++ b/src/MainWindow.cs
@@ -10,6 +10,7 @@ using System;
 using System.Text;
 using System.Collections;
 using System.Collections.Generic;
+using System.Linq;
 
 using Gdk;
 using Gtk;
@@ -696,7 +697,7 @@ namespace FSpot
 			else {
 				switch (ViewMode) {
 				case ModeType.IconView:
-					ids = icon_view.Selection.Ids;
+					ids = icon_view.Selection.ToArray ();
 					break;
 				default:
 				case ModeType.PhotoView:
@@ -790,7 +791,7 @@ namespace FSpot
 	
 						break;
 					case ModeType.IconView:
-						return win.icon_view.Selection.Items;
+						return win.icon_view.Selection.Photos.ToArray ();
 					}
 					return new IBrowsableItem [0];
 				}
diff --git a/src/SingleView.cs b/src/SingleView.cs
index 8175cca..7bb0812 100644
--- a/src/SingleView.cs
+++ b/src/SingleView.cs
@@ -2,6 +2,7 @@ using Gtk;
 using Gdk;
 using System;
 using System.Collections.Generic;
+using System.Linq;
 
 using Mono.Addins;
 using Mono.Unix;
@@ -187,7 +188,9 @@ namespace FSpot {
 
 		void HandleExportActivated (object o, EventArgs e)
 		{
-			FSpot.Extensions.ExportMenuItemNode.SelectedImages = delegate () {return new PhotoList (directory_view.Selection.Items); };
+			FSpot.Extensions.ExportMenuItemNode.SelectedImages = delegate () {
+                return new PhotoList (directory_view.Selection.Photos.ToArray ());
+            };
 		}
 
 		public void HandleCollectionChanged (IBrowsableCollection collection)
@@ -256,9 +259,9 @@ namespace FSpot {
 
 		private void HandleSelectionChanged (object sender, EventArgs e)
 		{
-
-			if (directory_view.Selection.Count > 0) {
-				image_view.Item.Index = (directory_view.Selection).Ids[0];
+            int first = directory_view.Selection.FirstIndex;
+			if (first != -1) {
+				image_view.Item.Index = first;
 
 				zoom_scale.Value = image_view.NormalizedZoom;
 			}
diff --git a/src/UI.Dialog/AdjustTimeDialog.cs b/src/UI.Dialog/AdjustTimeDialog.cs
index 6e83456..cc53ce4 100644
--- a/src/UI.Dialog/AdjustTimeDialog.cs
+++ b/src/UI.Dialog/AdjustTimeDialog.cs
@@ -253,9 +253,10 @@ namespace FSpot.UI.Dialog {
 
 		void HandleSelectionChanged (object sender, EventArgs e)
 		{
-			if (tray.Selection.Count > 0) {
-				view.Item.Index = (tray.Selection).Ids[0];
+            int first = tray.Selection.FirstIndex;
 
+			if (first != -1) {
+				view.Item.Index = first;
 			}
 		}
 
diff --git a/src/UI.Dialog/ImportDialog.cs b/src/UI.Dialog/ImportDialog.cs
index fd8a61e..9414fad 100644
--- a/src/UI.Dialog/ImportDialog.cs
+++ b/src/UI.Dialog/ImportDialog.cs
@@ -60,8 +60,10 @@ namespace FSpot.UI.Dialog
 
             var tray = new ScalingIconView (Controller.Photos);
             tray.Selection.Changed += delegate {
-                if (tray.Selection.Count > 0)
-                    photo_view.Item.Index = tray.Selection.Ids[0];
+                int first = tray.Selection.FirstIndex;
+
+                if (first != -1)
+                    photo_view.Item.Index = first;
             };
             icon_scrolled.Add (tray);
             tray.DisplayTags = false;
diff --git a/src/Widgets/IconView.cs b/src/Widgets/IconView.cs
index f7b535d..9233d88 100644
--- a/src/Widgets/IconView.cs
+++ b/src/Widgets/IconView.cs
@@ -12,6 +12,7 @@
 using Gtk;
 using Gdk;
 using System;
+using System.Linq;
 using System.Reflection;
 using System.Collections;
 using System.Collections.Generic;
@@ -229,7 +230,7 @@ namespace FSpot.Widgets
 		public IconView (FSpot.IBrowsableCollection collection) : this ()
 		{
 			this.collection = collection;
-			this.selection = new SelectionCollection (collection);
+			this.selection = new FSpot.Collections.PhotoSelection (collection);
 
 			Name = "ImageContainer";
 			collection.Changed += HandleChanged;
@@ -274,36 +275,11 @@ namespace FSpot.Widgets
 			}
 		}
 
-		protected SelectionCollection selection;
-		public SelectionCollection Selection {
-			get {
-				return selection;
-			}
+		protected FSpot.Collections.PhotoSelection selection;
+		public FSpot.Collections.PhotoSelection Selection {
+			get { return selection; }
 		}
 
-		// FIXME right now a selection change triggers a complete view redraw
-		// This should be optimized away by directly notifyiing the view of changed
-		// indexes rather than having the view connect to the collection.Changed event.
-		public class SelectionCollection : FSpot.Collections.PhotoSelection {
-
-            public SelectionCollection (IBrowsableCollection collection) : base (collection)
-            {}
-
-			public int [] Ids {
-				get {
-                    List<int> indices = new List<int> (this);
-                    return indices.ToArray ();
-				}
-			}
-
-			public IBrowsableItem [] Items {
-				get {
-                    List<IBrowsableItem> items = new List<IBrowsableItem> (this.Photos);
-
-                    return items.ToArray ();
-				}
-			}
-		}
 
 		// Updating.
 		public void UpdateThumbnail (int thumbnail_num)
@@ -1352,7 +1328,7 @@ namespace FSpot.Widgets
 							if ((args.Event.State & (ModifierType.ShiftMask | ModifierType.ControlMask)) == 0)
 								selection.Clear ();
 
-							start_select_selection = selection.Ids; // keep initial selection
+							start_select_selection = selection.ToArray (); // keep initial selection
 							// no rect draw at beginning
 							rect_select = new Rectangle ();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]