[f-spot/cleanup-backend: 8/8] Switch InfoBox and PhotoVersionMenu to IBrowsableItem
- From: Mike Gemünde <mgemuende src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/cleanup-backend: 8/8] Switch InfoBox and PhotoVersionMenu to IBrowsableItem
- Date: Fri, 9 Jul 2010 08:49:03 +0000 (UTC)
commit 9e9f253ea88198f3d2b9adb47740102c4e0b58cf
Author: Mike Gemünde <mike gemuende de>
Date: Tue Jul 6 15:07:10 2010 +0200
Switch InfoBox and PhotoVersionMenu to IBrowsableItem
src/InfoOverlay.cs | 12 ++++----
src/MainWindow.cs | 14 ++++++---
src/PhotoVersionMenu.cs | 71 ++++++++++++++++++-----------------------------
src/Widgets/InfoBox.cs | 54 ++++++++++++++++++------------------
4 files changed, 69 insertions(+), 82 deletions(-)
---
diff --git a/src/InfoOverlay.cs b/src/InfoOverlay.cs
index 92131c5..0a767c7 100644
--- a/src/InfoOverlay.cs
+++ b/src/InfoOverlay.cs
@@ -19,7 +19,7 @@ namespace FSpot {
this.item = item;
item.Changed += HandleItemChanged;
HandleItemChanged (item, null);
- VersionIdChanged += HandleVersionIdChanged;
+ VersionChanged += HandleVersionChanged;
ShowTags = true;
ShowRating = true;
Context = ViewContext.FullScreen;
@@ -27,16 +27,16 @@ namespace FSpot {
private void HandleItemChanged (object sender, BrowsablePointerChangedEventArgs args)
{
- Photo = item.Current as Photo;
+ Photo = item.Current;
}
- private void HandleVersionIdChanged (InfoBox box, uint version_id)
+ private void HandleVersionChanged (InfoBox box, IBrowsableItemVersion version)
{
- Photo p = item.Current as Photo;
+ IBrowsableItemVersionable versionable = item.Current as IBrowsableItemVersionable;
PhotoQuery q = item.Collection as PhotoQuery;
- if (p != null && q != null) {
- p.DefaultVersionId = version_id;
+ if (versionable != null && q != null) {
+ versionable.SetDefaultVersion (version);
q.Commit (item.Index);
}
}
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
index 29b1f77..224ee6c 100644
--- a/src/MainWindow.cs
+++ b/src/MainWindow.cs
@@ -357,7 +357,7 @@ namespace FSpot
InfoBox = new InfoBox ();
ViewModeChanged += InfoBox.HandleMainWindowViewModeChanged;
- InfoBox.VersionIdChanged += delegate (InfoBox box, uint version_id) { UpdateForVersionIdChange (version_id);};
+ InfoBox.VersionChanged += delegate (InfoBox box, IBrowsableItemVersion version) { UpdateForVersionChange (version);};
sidebar_vbox.PackEnd (InfoBox, false, false, 0);
InfoBox.Context = ViewContext.Library;
@@ -2475,10 +2475,14 @@ namespace FSpot
// Version Id updates.
- void UpdateForVersionIdChange (uint version_id)
+ void UpdateForVersionChange (IBrowsableItemVersion version)
{
- CurrentPhoto.DefaultVersionId = version_id;
- query.Commit (ActiveIndex ());
+ IBrowsableItemVersionable versionable = CurrentPhoto as IBrowsableItemVersionable;
+
+ if (versionable != null) {
+ versionable.SetDefaultVersion (version);
+ query.Commit (ActiveIndex ());
+ }
}
// Queries.
@@ -2608,7 +2612,7 @@ namespace FSpot
}
versions_submenu = new PhotoVersionMenu (CurrentPhoto);
- versions_submenu.VersionIdChanged += delegate (PhotoVersionMenu menu) { UpdateForVersionIdChange (menu.VersionId);};
+ versions_submenu.VersionChanged += delegate (PhotoVersionMenu menu) { UpdateForVersionChange (menu.Version);};
version_menu_item.Submenu = versions_submenu;
sharpen.Sensitive = (ViewMode == ModeType.IconView ? false : true);
diff --git a/src/PhotoVersionMenu.cs b/src/PhotoVersionMenu.cs
index e3d3ac4..1c1f4f8 100644
--- a/src/PhotoVersionMenu.cs
+++ b/src/PhotoVersionMenu.cs
@@ -1,73 +1,56 @@
+
using Gtk;
+
using System;
-using FSpot;
-public class PhotoVersionMenu : Menu {
- private uint version_id;
- public uint VersionId {
- get {
- return version_id;
- }
+using System.Collections.Generic;
- set {
- version_id = value;
- }
- }
+using FSpot;
- public delegate void VersionIdChangedHandler (PhotoVersionMenu menu);
- public event VersionIdChangedHandler VersionIdChanged;
- private struct MenuItemInfo {
- public MenuItem Item;
- public uint VersionId;
+public class PhotoVersionMenu : Menu {
- public MenuItemInfo (MenuItem menu_item, uint id)
- {
- Item = menu_item;
- VersionId = id;
- }
+ public IBrowsableItemVersion Version {
+ get; private set;
}
- private MenuItemInfo [] item_infos;
+ public delegate void VersionChangedHandler (PhotoVersionMenu menu);
+ public event VersionChangedHandler VersionChanged;
+
+ private Dictionary <MenuItem, IBrowsableItemVersion> version_mapping;
- // Lame way to emulate radio menu items since the the radio menu item API in GTK# is kinda busted.
private void HandleMenuItemActivated (object sender, EventArgs args)
{
- foreach (MenuItemInfo info in item_infos) {
- if (info.Item == sender && info.VersionId != VersionId) {
- VersionId = info.VersionId;
- if (VersionIdChanged != null)
- VersionIdChanged (this);
- break;
- }
+ MenuItem item = sender as MenuItem;
+
+ if (item != null && version_mapping.ContainsKey (item)) {
+ Version = version_mapping [item];
+ VersionChanged (this);
}
}
- public PhotoVersionMenu (Photo photo)
+ public PhotoVersionMenu (IBrowsableItem photo)
{
- version_id = photo.DefaultVersionId;
+ Version = photo.DefaultVersion;
- uint [] version_ids = photo.VersionIds;
- item_infos = new MenuItemInfo [version_ids.Length];
+ version_mapping = new Dictionary<MenuItem, IBrowsableItemVersion> ();
- int i = 0;
- foreach (uint id in version_ids) {
- MenuItem menu_item = new MenuItem (photo.GetVersion (id).Name);
+ foreach (IBrowsableItemVersion version in photo.Versions) {
+ MenuItem menu_item = new MenuItem (version.Name);
menu_item.Show ();
menu_item.Sensitive = true;
- Gtk.Label child = ((Gtk.Label)menu_item.Child);
- child.UseUnderline = false;
- if (photo.DefaultVersionId == id) {
+ Gtk.Label child = ((Gtk.Label) menu_item.Child);
+
+ if (version == photo.DefaultVersion) {
child.UseMarkup = true;
- child.Markup = "<b>" + photo.GetVersion (id).Name + "</b>";
+ child.Markup = String.Format ("<b>{0}</b>", version.Name);
}
- menu_item.Activated += new EventHandler (HandleMenuItemActivated);
- item_infos [i ++] = new MenuItemInfo (menu_item, id);
+ version_mapping.Add (menu_item, version);
Append (menu_item);
}
- if (version_ids.Length == 1) {
+ if (version_mapping.Count == 1) {
MenuItem no_edits_menu_item = new MenuItem (Mono.Unix.Catalog.GetString ("(No Edits)"));
no_edits_menu_item.Show ();
no_edits_menu_item.Sensitive = false;
diff --git a/src/Widgets/InfoBox.cs b/src/Widgets/InfoBox.cs
index b8bdd2c..4c645e2 100644
--- a/src/Widgets/InfoBox.cs
+++ b/src/Widgets/InfoBox.cs
@@ -32,8 +32,8 @@ namespace FSpot.Widgets
public class InfoBox : VBox {
Delay update_delay;
- private Photo [] photos = new Photo[0];
- public Photo [] Photos {
+ private IBrowsableItem [] photos = new IBrowsableItem [0];
+ public IBrowsableItem [] Photos {
set {
photos = value;
update_delay.Start ();
@@ -43,10 +43,10 @@ namespace FSpot.Widgets
}
}
- public Photo Photo {
+ public IBrowsableItem Photo {
set {
if (value != null) {
- Photos = new Photo[] { value };
+ Photos = new IBrowsableItem [] { value };
}
}
}
@@ -76,8 +76,8 @@ namespace FSpot.Widgets
}
}
- public delegate void VersionIdChangedHandler (InfoBox info_box, uint version_id);
- public event VersionIdChangedHandler VersionIdChanged;
+ public delegate void VersionChangedHandler (InfoBox info_box, IBrowsableItemVersion version);
+ public event VersionChangedHandler VersionChanged;
private Expander info_expander;
private Expander histogram_expander;
@@ -251,7 +251,7 @@ namespace FSpot.Widgets
size_value_label = AttachLabel (info_table, 3, name_value_label);
exposure_value_label = AttachLabel (info_table, 4, name_value_label);
- version_list = new ListStore (typeof (uint), typeof (string), typeof (bool));
+ version_list = new ListStore (typeof (IBrowsableItemVersion), typeof (string), typeof (bool));
version_combo = new ComboBox ();
CellRendererText version_name_cell = new CellRendererText ();
version_name_cell.Ellipsize = Pango.EllipsizeMode.End;
@@ -395,7 +395,7 @@ namespace FSpot.Widgets
{
ImageInfo info;
- Photo photo = Photos[0];
+ IBrowsableItem photo = Photos [0];
histogram_expander.Visible = true;
UpdateHistogram ();
@@ -457,21 +457,21 @@ namespace FSpot.Widgets
version_list.Clear ();
version_combo.Changed -= OnVersionComboChanged;
- bool hasVersions = photo.VersionIds.Length > 1;
- version_combo.Sensitive = hasVersions;
- if (hasVersions) {
- int i = 0;
- foreach (uint version_id in photo.VersionIds) {
- version_list.AppendValues (version_id, (photo.GetVersion (version_id) as PhotoVersion).Name, true);
- if (version_id == photo.DefaultVersionId)
- version_combo.Active = i;
- i++;
- }
- version_combo.TooltipText = String.Format (Catalog.GetPluralString ("(One Edit)", "({0} Edits)", i - 1), i - 1);
- } else {
- version_list.AppendValues (photo.DefaultVersionId, photo.DefaultVersion.Name + " " + Catalog.GetString ("(No Edits)"), true);
- version_combo.Active = 0;
+ int count = 0;
+ foreach (IBrowsableItemVersion version in photo.Versions) {
+ version_list.AppendValues (version, version.Name, true);
+ if (version == photo.DefaultVersion)
+ version_combo.Active = count;
+ count++;
+ }
+
+ if (count <= 1) {
+ version_combo.Sensitive = false;
version_combo.TooltipText = Catalog.GetString ("(No Edits)");
+ } else {
+ version_combo.Sensitive = true;
+ version_combo.TooltipText =
+ String.Format (Catalog.GetPluralString ("(One Edit)", "({0} Edits)", count - 1), count - 1);
}
version_combo.Changed += OnVersionComboChanged;
@@ -518,7 +518,7 @@ namespace FSpot.Widgets
TreeIter iter;
if (combo.GetActiveIter (out iter))
- VersionIdChanged (this, (uint)version_list.GetValue (iter, 0));
+ VersionChanged (this, (IBrowsableItemVersion)version_list.GetValue (iter, 0));
}
private void UpdateMultiple ()
@@ -542,8 +542,8 @@ namespace FSpot.Widgets
camera_value_label.Visible = false;
if (show_date) {
- Photo first = Photos[Photos.Length-1];
- Photo last = Photos[0];
+ IBrowsableItem first = Photos[Photos.Length-1];
+ IBrowsableItem last = Photos [0];
if (first.Time.Date == last.Time.Date) {
//Note for translators: {0} is a date, {1} and {2} are times.
date_value_label.Text = String.Format(Catalog.GetString("On {0} between \n{1} and {2}"),
@@ -561,7 +561,7 @@ namespace FSpot.Widgets
if (show_file_size) {
long file_size = 0;
- foreach (Photo photo in Photos) {
+ foreach (IBrowsableItem photo in Photos) {
try {
GFile file = FileFactory.NewForUri (photo.DefaultVersion.Uri);
@@ -607,7 +607,7 @@ namespace FSpot.Widgets
if (Photos.Length == 0)
return false;
- Photo photo = Photos[0];
+ IBrowsableItem photo = Photos [0];
Gdk.Pixbuf hint = histogram_hint;
histogram_hint = null;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]