f-spot r4227 - in trunk: . src src/Widgets
- From: rubenv svn gnome org
- To: svn-commits-list gnome org
- Subject: f-spot r4227 - in trunk: . src src/Widgets
- Date: Wed, 6 Aug 2008 12:49:13 +0000 (UTC)
Author: rubenv
Date: Wed Aug 6 12:49:13 2008
New Revision: 4227
URL: http://svn.gnome.org/viewvc/f-spot?rev=4227&view=rev
Log:
2008-08-06 Ruben Vermeersch <ruben savanne be>
Do context-aware sidebar switching. This means that the sidebar switches
to a different page according to what you are doing. A default Most
Recently Used switching strategy is provided, this can be changed easily
if desired.
* src/MainWindow.cs: Don't try to be smart with the sidebar. Stop storing
and restoring the active entry.
* src/Makefile.am: Move Sidebar.cs back to the main assembly, as it
depends on the Extensions.
* src/Preferences.cs: Remove all SIDEBAR_TOP_ENTRY related code, it's
obsolete.
* src/SingleView.cs: Initialize the context rather than the
ViewModeCondition. The same applies for MainWindow.cs.
* src/Widgets/Sidebar.cs: Add a SidebarContextSwitchStrategy, which
defines the way context switches are handled. Implemented using the
Strategy pattern.
Modified:
trunk/ChangeLog
trunk/src/MainWindow.cs
trunk/src/Makefile.am
trunk/src/Preferences.cs
trunk/src/SingleView.cs
trunk/src/Widgets/Sidebar.cs
Modified: trunk/src/MainWindow.cs
==============================================================================
--- trunk/src/MainWindow.cs (original)
+++ trunk/src/MainWindow.cs Wed Aug 6 12:49:13 2008
@@ -299,6 +299,7 @@
toolbar.Insert (ss_button, -1);
sidebar = new Sidebar ();
+ ViewModeChanged += sidebar.HandleMainWindowViewModeChanged;
sidebar_vbox.Add (sidebar);
tag_selection_scrolled = new ScrolledWindow ();
@@ -308,8 +309,9 @@
sidebar.AppendPage (tag_selection_scrolled, Catalog.GetString ("Tags"), "gtk-new");
- ViewModeCondition.Initialize (FSpot.Extensions.ViewMode.Library);
AddinManager.AddExtensionNodeHandler ("/FSpot/Sidebar", OnSidebarExtensionChanged);
+
+ sidebar.Context = ViewContext.Library;
sidebar.CloseRequested += HideSidebar;
sidebar.Show ();
@@ -469,7 +471,6 @@
UpdateFindByTagMenu ();
- LoadPreference (Preferences.SIDEBAR_TOP_ENTRY);
LoadPreference (Preferences.SHOW_TOOLBAR);
LoadPreference (Preferences.SHOW_SIDEBAR);
LoadPreference (Preferences.SHOW_TIMELINE);
@@ -1844,7 +1845,6 @@
Preferences.Set (Preferences.SHOW_TOOLBAR, toolbar.Visible);
Preferences.Set (Preferences.SHOW_SIDEBAR, info_vbox.Visible);
- Preferences.Set (Preferences.SIDEBAR_TOP_ENTRY, sidebar.CurrentPage);
Preferences.Set (Preferences.SHOW_TIMELINE, display_timeline.Active);
Preferences.Set (Preferences.SHOW_FILMSTRIP, display_filmstrip.Active);
Preferences.Set (Preferences.SHOW_TAGS, icon_view.DisplayTags);
@@ -2686,10 +2686,6 @@
main_hpaned.Position = Preferences.Get<int> (key);
break;
- case Preferences.SIDEBAR_TOP_ENTRY:
- sidebar.SwitchTo (Preferences.Get<int> (key));
- break;
-
case Preferences.TAG_ICON_SIZE:
int s = Preferences.Get<int> (key);
tag_icon_hidden.Active = (s == (int) Tag.IconSize.Hidden);
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Wed Aug 6 12:49:13 2008
@@ -73,7 +73,6 @@
$(srcdir)/Widgets/Rating.cs \
$(srcdir)/Widgets/SaneTreeView.cs \
$(srcdir)/Widgets/ScrolledView.cs \
- $(srcdir)/Widgets/Sidebar.cs \
$(srcdir)/Widgets/TagView.cs
F_SPOT_CSDISTFILES = \
@@ -253,6 +252,7 @@
$(srcdir)/Widgets/RatingMenuItem.cs \
$(srcdir)/Widgets/Reveal.cs \
$(srcdir)/Widgets/ScalingIconView.cs \
+ $(srcdir)/Widgets/Sidebar.cs \
$(srcdir)/Widgets/SoftFocus.cs \
$(srcdir)/Widgets/TagEntry.cs \
$(srcdir)/Widgets/TagMenu.cs \
Modified: trunk/src/Preferences.cs
==============================================================================
--- trunk/src/Preferences.cs (original)
+++ trunk/src/Preferences.cs Wed Aug 6 12:49:13 2008
@@ -48,7 +48,6 @@
public const string GROUP_ADAPTOR_ORDER_ASC = "/apps/f-spot/ui/group_adaptor_sort_asc";
public const string SIDEBAR_POSITION = "/apps/f-spot/ui/sidebar_size";
- public const string SIDEBAR_TOP_ENTRY = "/apps/f-spot/ui/sidebar_top_entry";
public const string ZOOM = "/apps/f-spot/ui/zoom";
public const string EXPORT_EMAIL_SIZE = "/apps/f-spot/export/email/size";
@@ -167,7 +166,6 @@
case PROXY_USE_PROXY:
return false;
- case SIDEBAR_TOP_ENTRY:
case PROXY_PORT:
return 0;
case PROXY_USER:
Modified: trunk/src/SingleView.cs
==============================================================================
--- trunk/src/SingleView.cs (original)
+++ trunk/src/SingleView.cs Wed Aug 6 12:49:13 2008
@@ -121,9 +121,10 @@
info_vbox.Add (sidebar);
sidebar.AppendPage (directory_scrolled, Catalog.GetString ("Folder"), "gtk-directory");
- ViewModeCondition.Initialize (FSpot.Extensions.ViewMode.Single);
AddinManager.AddExtensionNodeHandler ("/FSpot/Sidebar", OnSidebarExtensionChanged);
+ sidebar.Context = ViewContext.Single;
+
sidebar.CloseRequested += HandleHideSidePane;
sidebar.Show ();
Modified: trunk/src/Widgets/Sidebar.cs
==============================================================================
--- trunk/src/Widgets/Sidebar.cs (original)
+++ trunk/src/Widgets/Sidebar.cs Wed Aug 6 12:49:13 2008
@@ -9,13 +9,25 @@
* This is free software. See COPYING for details.
*/
+using FSpot.Extensions;
using FSpot.Utils;
using Gtk;
using Mono.Addins;
+using Mono.Unix;
using System;
using System.Collections.Generic;
namespace FSpot.Widgets {
+ // This nasty enum serves to differentiate between the different view
+ // modes. As we have both SingleView and normal F-Spot, there is no
+ // uniform way of naming these contexts.
+ public enum ViewContext {
+ Unknown,
+ Single,
+ Library,
+ Edit
+ }
+
[ExtensionNode ("SidebarPage")]
public class SidebarPageNode : ExtensionNode {
[NodeAttribute (Required=true)]
@@ -26,6 +38,51 @@
}
}
+ // Decides which sidebar page should be shown for each context. Implemented
+ // using the Strategy pattern, to make it swappable easily, in case the
+ // default MRUSidebarContextSwitchStrategy is not sufficiently usable.
+ public abstract class SidebarContextSwitchStrategy {
+ private readonly Sidebar Sidebar;
+
+ public SidebarContextSwitchStrategy (Sidebar sidebar) {
+ Sidebar = sidebar;
+ }
+
+ public abstract string PageForContext (ViewContext context);
+
+ public abstract void SwitchedToPage (ViewContext context, string name);
+ }
+
+ // Implements a Most Recently Used switching strategy. The last page you used
+ // for a given context is used.
+ public class MRUSidebarContextSwitchStrategy : SidebarContextSwitchStrategy {
+ public const string PREF_PREFIX = Preferences.APP_FSPOT + "ui/sidebar";
+
+ public MRUSidebarContextSwitchStrategy (Sidebar sidebar) : base (sidebar) {
+ }
+
+ private string PrefKeyForContext (ViewContext context) {
+ return String.Format ("{0}/{1}", PREF_PREFIX, context);
+ }
+
+ public override string PageForContext (ViewContext context) {
+ string name = Preferences.Get<string> (PrefKeyForContext (context));
+ if (name == null)
+ name = DefaultForContext (context);
+ return name;
+ }
+
+ public override void SwitchedToPage (ViewContext context, string name) {
+ Preferences.Set (PrefKeyForContext (context), name);
+ }
+
+ private string DefaultForContext (ViewContext context) {
+ if (context == ViewContext.Edit)
+ return Catalog.GetString ("Edit");
+ // Don't care otherwise, Tags sounds reasonable
+ return Catalog.GetString ("Tags");
+ }
+ }
public class SidebarPage {
// The widget shown on the sidebar page.
@@ -109,8 +166,25 @@
private set { selection = value; }
}
+ public event EventHandler ContextChanged;
+
+ private ViewContext view_context = ViewContext.Unknown;
+ public ViewContext Context {
+ get { return view_context; }
+ set {
+ view_context = value;
+ if (ContextChanged != null)
+ ContextChanged (this, null);
+ }
+ }
+
+ private readonly SidebarContextSwitchStrategy ContextSwitchStrategy;
+
public Sidebar () : base ()
{
+ ContextSwitchStrategy = new MRUSidebarContextSwitchStrategy (this);
+ ContextChanged += HandleContextChanged;
+
button_box = new HBox ();
PackStart (button_box, false, false, 0);
@@ -141,6 +215,20 @@
pages = new List<SidebarPage> ();
}
+ private void HandleContextChanged (object sender, EventArgs args)
+ {
+ // Make sure the ViewModeCondition is set correctly.
+ if (Context == ViewContext.Single)
+ ViewModeCondition.Initialize (FSpot.Extensions.ViewMode.Single);
+ else if (Context == ViewContext.Library || Context == ViewContext.Edit)
+ ViewModeCondition.Initialize (FSpot.Extensions.ViewMode.Library);
+ else
+ ViewModeCondition.Initialize (FSpot.Extensions.ViewMode.Unknown);
+
+ string name = ContextSwitchStrategy.PageForContext (Context);
+ SwitchTo (name);
+ }
+
private void HandleCanSelectChanged (object sender, EventArgs args)
{
//Log.DebugFormat ("Can select changed for {0} to {1}", sender, (sender as SidebarPage).CanSelect);
@@ -161,6 +249,7 @@
string icon_name = page.IconName;
notebook.AppendPage (page.SidebarWidget, new Label (label));
+ page.SidebarWidget.Show ();
MenuItem item;
if (icon_name == null)
@@ -174,18 +263,28 @@
choose_menu.Append (item);
item.Show ();
- if (notebook.Children.Length == 1)
- {
+ if (notebook.Children.Length == 1) {
choose_button.Label = label;
choose_button.Image.IconName = icon_name;
}
menu_list.Add (label);
image_list.Add (icon_name);
}
+
+ public void HandleMainWindowViewModeChanged (object o, EventArgs args)
+ {
+ MainWindow.ModeType mode = MainWindow.Toplevel.ViewMode;
+ if (mode == MainWindow.ModeType.IconView)
+ Context = ViewContext.Library;
+ else if (mode == MainWindow.ModeType.PhotoView)
+ Context = ViewContext.Edit;
+ }
public void HandleItemClicked (object o, EventArgs args)
{
- SwitchTo (menu_list.IndexOf (((o as MenuItem).Child as Label).Text));
+ string name = ((o as MenuItem).Child as Label).Text;
+ SwitchTo (name);
+ ContextSwitchStrategy.SwitchedToPage (Context, name);
}
public void HandleCloseButtonPressed (object sender, EventArgs args)
@@ -212,9 +311,8 @@
public void SwitchTo (string name)
{
- if (menu_list.Contains (name)) {
+ if (menu_list.Contains (name))
SwitchTo (menu_list.IndexOf (name));
- }
}
public bool IsActive (SidebarPage page)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]