[f-spot/cleanup-backend: 10/23] Add PhotoModelSelection as subclass of Hyena.Collections.Selection
- From: Mike Gemünde <mgemuende src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/cleanup-backend: 10/23] Add PhotoModelSelection as subclass of Hyena.Collections.Selection
- Date: Fri, 16 Jul 2010 17:26:11 +0000 (UTC)
commit 9085700f7412aa88ad12508905c3078dc8371fdd
Author: Mike Gemünde <mike gemuende de>
Date: Fri Jul 16 10:23:29 2010 +0200
Add PhotoModelSelection as subclass of Hyena.Collections.Selection
The new class provides some other selection methods related to photo
collections.
src/Core/Makefile.am | 1 +
src/Core/PhotoSelection.cs | 157 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 158 insertions(+), 0 deletions(-)
---
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index 0493112..8443bd5 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -24,6 +24,7 @@ SOURCES = \
ISource.cs \
PhotoChanges.cs \
PhotosChanges.cs \
+ PhotoSelection.cs \
Roll.cs \
Defines.cs
diff --git a/src/Core/PhotoSelection.cs b/src/Core/PhotoSelection.cs
new file mode 100644
index 0000000..457d61a
--- /dev/null
+++ b/src/Core/PhotoSelection.cs
@@ -0,0 +1,157 @@
+//
+// PhotoSelection.cs
+//
+// Author:
+// Mike Gemuende <mike gemuende de>
+//
+// Copyright (c) 2010 Mike Gemuende <mike gemuende de>
+//
+// This is free software. See COPYING for details.
+//
+
+using System;
+using System.Collections.Generic;
+
+using Hyena.Collections;
+
+namespace FSpot.Collections
+{
+
+
+ public class PhotoSelection : Selection
+ {
+#region Private Fields
+
+ //private IPhotoListModel model;
+ private IBrowsableCollection model;
+
+#endregion
+
+#region Constructors
+
+ public PhotoSelection (/*IPhotoListModel*/ IBrowsableCollection model)
+ {
+ if (model == null)
+ throw new ArgumentNullException ("model");
+
+ this.model = model;
+ }
+
+#endregion
+
+#region Public Interface
+
+ public IBrowsableItem FirstPhoto {
+ get {
+ if (FirstIndex == -1)
+ return null;
+
+ return model [FirstIndex];
+ }
+ }
+
+ public IBrowsableItem LastPhoto {
+ get {
+ if (LastIndex == -1)
+ return null;
+
+ return model [LastIndex];
+ }
+ }
+
+ public void Select (IBrowsableItem photo)
+ {
+ int index = model.IndexOf (photo);
+
+ if (index == -1)
+ throw new ArgumentException ("photo not contained in collection");
+
+ Select (index);
+ }
+
+ public void QuietSelect (IBrowsableItem photo)
+ {
+ int index = model.IndexOf (photo);
+
+ if (index == -1)
+ throw new ArgumentException ("photo not contained in collection");
+
+
+ QuietSelect (index);
+ }
+
+ public void Unselect (IBrowsableItem photo)
+ {
+ int index = model.IndexOf (photo);
+
+ if (index == -1)
+ throw new ArgumentException ("photo not contained in collection");
+
+
+ Unselect (index);
+ }
+
+ public void QuietUnselect (IBrowsableItem photo)
+ {
+ int index = model.IndexOf (photo);
+
+ if (index == -1)
+ throw new ArgumentException ("photo not contained in collection");
+
+
+ QuietUnselect (index);
+ }
+
+ public bool Contains (IBrowsableItem photo)
+ {
+ return Contains (model.IndexOf (photo));
+ }
+
+ public IBrowsableItem FocussedPhoto {
+ get {
+ if (FocusedIndex < 0)
+ return null;
+
+ return model [FocusedIndex];
+ }
+ set {
+ if (value == null) {
+ FocusedIndex = -1;
+ return;
+ }
+
+ int index = model.IndexOf (value);
+
+ if (index == -1)
+ throw new ArgumentException ("photo not contained in collection");
+
+ FocusedIndex = index;
+ }
+ }
+
+ public void QuietToggleSelect (int index)
+ {
+ if (! RangeCollection.Remove (index)) {
+ RangeCollection.Add (index);
+ }
+ }
+
+ public virtual void ToggleAll ()
+ {
+ for (int i = 0; i <= MaxIndex; i++)
+ QuietToggleSelect (i);
+
+ OnChanged ();
+ }
+
+ public IEnumerable<IBrowsableItem> Photos {
+ get {
+ foreach (int index in this) {
+ yield return model [index];
+ }
+ }
+ }
+
+#endregion
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]