2010-07-04 10:39:16 +00:00
|
|
|
// SparkleShare, an instant update workflow to Git.
|
|
|
|
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
using Gtk;
|
2010-07-13 18:23:59 +00:00
|
|
|
using Mono.Unix;
|
2010-07-04 10:39:16 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace SparkleShare {
|
|
|
|
|
|
|
|
// A custom widget containing an image view,
|
|
|
|
// previous/next buttons and a combobox
|
|
|
|
public class RevisionView : VBox
|
|
|
|
{
|
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
// Short alias for the translations
|
|
|
|
public static string _ (string s)
|
|
|
|
{
|
|
|
|
return Catalog.GetString (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-04 10:39:16 +00:00
|
|
|
public ScrolledWindow ScrolledWindow;
|
2010-07-13 18:23:59 +00:00
|
|
|
public IconView IconView;
|
2010-07-13 19:19:11 +00:00
|
|
|
public int Selected;
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-15 11:22:32 +00:00
|
|
|
public ToggleButton ToggleButton;
|
2010-07-13 18:23:59 +00:00
|
|
|
private Viewport Viewport;
|
|
|
|
private ListStore Store;
|
2010-07-04 10:39:16 +00:00
|
|
|
private Image Image;
|
2010-07-13 18:23:59 +00:00
|
|
|
private int Count;
|
2010-07-15 11:22:32 +00:00
|
|
|
private string SecondaryTextColor;
|
|
|
|
private string SelectedTextColor;
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
|
|
|
|
public RevisionView () : base (false, 0)
|
2010-07-04 10:39:16 +00:00
|
|
|
{
|
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
Count = 0;
|
|
|
|
Selected = 0;
|
|
|
|
|
2010-07-15 11:22:32 +00:00
|
|
|
TreeView treeview = new TreeView ();
|
|
|
|
SelectedTextColor = GdkColorToHex (treeview.Style.Foreground (StateType.Selected));
|
|
|
|
|
|
|
|
Window window = new Window ("");
|
|
|
|
SecondaryTextColor = GdkColorToHex (window.Style.Foreground (StateType.Insensitive));
|
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
ToggleButton = new ToggleButton ();
|
|
|
|
ToggleButton.Clicked += ToggleView;
|
|
|
|
ToggleButton.Relief = ReliefStyle.None;
|
2010-07-04 10:39:16 +00:00
|
|
|
|
|
|
|
ScrolledWindow = new ScrolledWindow ();
|
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
Viewport = new Viewport ();
|
|
|
|
Viewport.Add (new Label (""));
|
|
|
|
|
2010-08-07 16:54:10 +00:00
|
|
|
Store = new ListStore (typeof (Gdk.Pixbuf),
|
|
|
|
typeof (string),
|
|
|
|
typeof (int));
|
2010-07-13 18:23:59 +00:00
|
|
|
|
|
|
|
IconView = new IconView (Store);
|
|
|
|
IconView.SelectionChanged += ChangeSelection;
|
|
|
|
IconView.MarkupColumn = 1;
|
|
|
|
IconView.Margin = 12;
|
|
|
|
IconView.Orientation = Orientation.Horizontal;
|
|
|
|
IconView.PixbufColumn = 0;
|
|
|
|
IconView.Spacing = 12;
|
|
|
|
|
|
|
|
Image = new Image ();
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
ScrolledWindow.Add (Viewport);
|
|
|
|
PackStart (ScrolledWindow, true, true, 0);
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
}
|
|
|
|
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
// Changes the selection and enforces a policy of always having something selected
|
|
|
|
public void ChangeSelection (object o, EventArgs args)
|
|
|
|
{
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-15 11:22:32 +00:00
|
|
|
TreeIter iter;
|
|
|
|
Store.GetIter (out iter, new TreePath (GetSelected ().ToString ()));
|
|
|
|
string text = (string) Store.GetValue (iter, 1);
|
|
|
|
Store.SetValue (iter, 1, text.Replace (SelectedTextColor, SecondaryTextColor));
|
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
if (IconView.SelectedItems.Length > 0) {
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
Store.GetIter (out iter, IconView.SelectedItems [0]);
|
|
|
|
SetSelected ((int) Store.GetValue (iter, 2));
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-15 11:22:32 +00:00
|
|
|
text = (string) Store.GetValue (iter, 1);
|
|
|
|
text = text.Replace (SecondaryTextColor, SelectedTextColor);
|
|
|
|
Store.SetValue (iter, 1, text);
|
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
} else {
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
IconView.SelectPath (new TreePath (GetSelected ().ToString()));
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
}
|
2010-07-15 11:22:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Converts a Gdk RGB color to a hex value.
|
|
|
|
// Example: from "rgb:0,0,0" to "#000000"
|
|
|
|
public string GdkColorToHex (Gdk.Color color)
|
|
|
|
{
|
2010-08-01 15:41:45 +00:00
|
|
|
|
2010-07-15 11:22:32 +00:00
|
|
|
return String.Format("#{0:X2}{1:X2}{2:X2}",
|
|
|
|
(int) Math.Truncate(color.Red / 256.00),
|
|
|
|
(int) Math.Truncate(color.Green / 256.00),
|
|
|
|
(int) Math.Truncate(color.Blue / 256.00));
|
2010-08-01 15:41:45 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
}
|
2010-07-04 10:39:16 +00:00
|
|
|
|
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
// Makes sure everything is in place before showing the widget
|
|
|
|
new public void ShowAll ()
|
|
|
|
{
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
if (Children.Length == 2) {
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
ToggleButton = (ToggleButton) Children [0];
|
|
|
|
ToggleButton.Remove (ToggleButton.Child);
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
} else {
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
ToggleButton = new ToggleButton ();
|
|
|
|
ToggleButton.Relief = ReliefStyle.None;
|
|
|
|
ToggleButton.Clicked += ToggleView;
|
|
|
|
PackStart (ToggleButton, false, false, 6);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
HBox layout_horizontal = new HBox (false, 12);
|
|
|
|
layout_horizontal.BorderWidth = 6;
|
|
|
|
|
|
|
|
TreeIter iter;
|
|
|
|
Store.GetIter (out iter, new TreePath (GetSelected ().ToString()));
|
|
|
|
|
|
|
|
string text = (string) Store.GetValue (iter, 1);
|
|
|
|
Gdk.Pixbuf pixbuf = (Gdk.Pixbuf) Store.GetValue (iter, 0);
|
2010-07-15 11:22:32 +00:00
|
|
|
|
|
|
|
Label label = new Label (text.Replace (SelectedTextColor, SecondaryTextColor));
|
2010-07-13 18:23:59 +00:00
|
|
|
label.UseMarkup = true;
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
Arrow arrow_down = new Arrow (ArrowType.Down, ShadowType.None);
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
layout_horizontal.PackStart (new Image (pixbuf), false, false, 0);
|
|
|
|
layout_horizontal.PackStart (label, false, false, 0);
|
|
|
|
layout_horizontal.PackStart (new Label (""), true, true, 0);
|
|
|
|
layout_horizontal.PackStart (arrow_down, false, false, 0);
|
|
|
|
|
|
|
|
ToggleButton.Add (layout_horizontal);
|
|
|
|
ReorderChild (ToggleButton, 0);
|
|
|
|
|
|
|
|
TreePath path = new TreePath (Selected.ToString());
|
|
|
|
IconView.SelectPath (path);
|
|
|
|
|
|
|
|
base.ShowAll ();
|
2010-07-04 10:39:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
// Adds a revision to the combobox
|
|
|
|
public void AddRow (Gdk.Pixbuf pixbuf, string header, string subtext)
|
|
|
|
{
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-15 11:22:32 +00:00
|
|
|
Store.AppendValues (pixbuf, "<b>" + header + "</b>\n" +
|
|
|
|
"<span fgcolor='" + SecondaryTextColor + "'>" + subtext + "</span>",
|
|
|
|
Count);
|
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
IconView.Model = Store;
|
|
|
|
Count++;
|
2010-07-04 10:39:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-15 11:22:32 +00:00
|
|
|
// Toggles between a displayed image and a list of revisions
|
2010-07-13 18:23:59 +00:00
|
|
|
public void ToggleView (object o, EventArgs args)
|
|
|
|
{
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
Viewport.Remove (Viewport.Child);
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
if (ToggleButton.Active) {
|
|
|
|
|
|
|
|
Viewport.Add (IconView);
|
|
|
|
TreePath path = new TreePath (GetSelected ().ToString());
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
IconView.ScrollToPath (path, (float) 0.5, (float) 0.5);
|
2010-07-14 15:28:33 +00:00
|
|
|
IconView.GrabFocus ();
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
} else {
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
Viewport.Add (Image);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowAll ();
|
2010-07-04 10:39:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Changes the image that is viewed
|
2010-07-13 18:23:59 +00:00
|
|
|
public void SetImage (Image image)
|
|
|
|
{
|
2010-07-04 10:39:16 +00:00
|
|
|
|
|
|
|
Image = image;
|
2010-07-13 18:23:59 +00:00
|
|
|
Viewport.Remove (Viewport.Child);
|
|
|
|
Viewport.Add (Image);
|
|
|
|
ToggleButton.Active = false;
|
2010-07-04 10:39:16 +00:00
|
|
|
ShowAll ();
|
|
|
|
|
|
|
|
}
|
2010-07-13 18:23:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Returns the image that is currently viewed
|
2010-07-07 17:03:23 +00:00
|
|
|
public Image GetImage ()
|
|
|
|
{
|
2010-07-05 13:15:22 +00:00
|
|
|
return Image;
|
2010-07-07 17:03:23 +00:00
|
|
|
}
|
2010-07-13 18:23:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Selects an item by number
|
|
|
|
public bool SetSelected (int i)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (i > -1 && i <= Count) {
|
2010-07-14 15:28:33 +00:00
|
|
|
Selected = i;
|
2010-07-13 18:23:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the number of the currently selected item
|
|
|
|
public int GetSelected ()
|
|
|
|
{
|
|
|
|
return Selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Looks up an icon from the system's theme
|
|
|
|
public Gdk.Pixbuf GetIcon (string name, int size)
|
|
|
|
{
|
|
|
|
IconTheme icon_theme = new IconTheme ();
|
|
|
|
icon_theme.AppendSearchPath (System.IO.Path.Combine ("/usr/share/sparkleshare", "icons"));
|
|
|
|
return icon_theme.LoadIcon (name, size, IconLookupFlags.GenericFallback);
|
|
|
|
}
|
2010-07-07 17:03:23 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Derived class for the image view on the left
|
2010-07-13 18:23:59 +00:00
|
|
|
public class LeftRevisionView : RevisionView
|
|
|
|
{
|
|
|
|
|
|
|
|
public LeftRevisionView () : base ()
|
|
|
|
{
|
2010-07-07 17:03:23 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
// Select the second revision
|
2010-07-13 19:19:11 +00:00
|
|
|
Selected = 1;
|
2010-07-07 17:03:23 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
// Take reading direction for time into account
|
2010-07-07 17:03:23 +00:00
|
|
|
if (Direction == Gtk.TextDirection.Ltr)
|
|
|
|
ScrolledWindow.Placement = CornerType.TopRight;
|
|
|
|
else
|
|
|
|
ScrolledWindow.Placement = CornerType.TopLeft;
|
2010-07-05 13:15:22 +00:00
|
|
|
|
|
|
|
}
|
2010-07-07 17:03:23 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Derived class for the image view on the right
|
2010-07-13 18:23:59 +00:00
|
|
|
public class RightRevisionView : RevisionView
|
|
|
|
{
|
|
|
|
|
|
|
|
public RightRevisionView () : base ()
|
|
|
|
{
|
2010-07-04 10:39:16 +00:00
|
|
|
|
2010-07-13 18:23:59 +00:00
|
|
|
// Take reading direction for time into account
|
2010-07-07 17:03:23 +00:00
|
|
|
if (Direction == Gtk.TextDirection.Ltr)
|
|
|
|
ScrolledWindow.Placement = CornerType.TopLeft;
|
|
|
|
else
|
|
|
|
ScrolledWindow.Placement = CornerType.TopRight;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-04 10:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|