Continue cleaning up SparkleDiff code

This commit is contained in:
Hylke Bons 2010-06-29 11:20:58 +01:00
parent 06e1c07eb8
commit b002706d0a

View file

@ -55,8 +55,8 @@ namespace SparkleShare {
private string FilePath;
private string FileName;
private VBox ViewLeft;
private VBox ViewRight;
private RevisionView ViewLeft;
private RevisionView ViewRight;
private string [] RevisionHashes;
@ -80,8 +80,8 @@ namespace SparkleShare {
HBox layout_horizontal = new HBox (false, 12);
ViewLeft = CreateRevisionView ("Left");
ViewRight = CreateRevisionView ("Right");
ViewLeft = new RevisionView ();
ViewRight = new RevisionView ();
layout_horizontal.PackStart (ViewLeft);
layout_horizontal.PackStart (ViewRight);
@ -204,9 +204,6 @@ namespace SparkleShare {
private VBox CreateRevisionView (string position)
{
VBox layout_vertical = new VBox (false, 6);
ScrolledWindow scrolled_window = new ScrolledWindow ();
Process process = new Process ();
process.EnableRaisingEvents = true;
@ -221,16 +218,12 @@ namespace SparkleShare {
Gdk.Pixbuf pixbuf;
pixbuf = new Gdk.Pixbuf ( (System.IO.Stream) process.StandardOutput.BaseStream);
scrolled_window.AddWithViewport (new Image (pixbuf));
scrolled_window.Hadjustment.ValueChanged += SyncViewsHorizontally;
scrolled_window.Vadjustment.ValueChanged += SyncViewsVertically;
ViewLeft.ScrolledWindow.Hadjustment.ValueChanged += SyncViewsHorizontally;
ViewLeft.ScrolledWindow.Vadjustment.ValueChanged += SyncViewsVertically;
HBox controls = new HBox (false, 6);
ComboBox revision_combobox = ComboBox.NewText ();
bool current_version = true;
/* bool current_version = true;
foreach (string hash in RevisionHashes) {
Console.WriteLine (hash);
if (current_version) {
@ -247,56 +240,58 @@ namespace SparkleShare {
revision_combobox.Active = 0;
revision_combobox.Changed += UpdateViews;
Image icon_previous = new Image ();
icon_previous.IconName = "go-previous";
Button button_previous = new Button (icon_previous);
if (position.Equals ("Left") && RevisionHashes.Length == 2)
button_previous.State = StateType.Insensitive;
button_previous.Clicked += delegate {
if (revision_combobox.Active + 1 < RevisionHashes.Length)
revision_combobox.Active += 1;
ShowAll ();
};
Image icon_next = new Image ();
icon_next.IconName = "go-next";
Button button_next = new Button (icon_next);
if (position.Equals ("Right"))
button_next.State = StateType.Insensitive;
button_previous.Clicked += delegate {
if (revision_combobox.Active > 0)
revision_combobox.Active -= 1;
ShowAll ();
};
controls.PackStart (button_previous, false, false, 0);
controls.PackStart (revision_combobox, false, false, 0);
controls.PackStart (button_next, false, false, 0);
layout_vertical.PackStart (scrolled_window, true, true, 0);
layout_vertical.PackStart (controls, false, false, 0);
return layout_vertical;
*/return new VBox ();
}
}
// An image grabbed from a stream generated by Git
public class RevisionImage : Image
{
public string Revision;
public string FilePath;
public RevisionImage (string file_path, string revision) : base ()
{
Revision = revision;
FilePath = file_path;
Process process = new Process ();
process.EnableRaisingEvents = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (FilePath);
process.StartInfo.FileName = "git";
process.StartInfo.Arguments = "show " + revision + ":" + System.IO.Path.GetFileName (FilePath);
process.Start ();
Pixbuf = new Gdk.Pixbuf ((System.IO.Stream) process.StandardOutput.BaseStream);
}
}
// A custom widget containing an image view,
// previous/next buttons and a combobox
public class RevisionView : VBox
{
public ScrolledWindow ScrolledWindow;
public ComboBox ComboBox;
public Button ButtonPrevious;
public Button ButtonNext;
private int ValueCount;
private Image Image;
public RevisionView () : base (false, 6)
{
@ -320,7 +315,7 @@ namespace SparkleShare {
Image image_next = new Image ();
image_next.IconName = "go-next";
ButtonNext = new Button (image_next);
ButtonNext.Clicked += Next;
//move outside this class ButtonNext.Clicked += Next;
controls.Add (ButtonPrevious);
controls.Add (ComboBox);
@ -331,15 +326,16 @@ namespace SparkleShare {
}
// Fills the widget's combobox with entries
public void FillComboBox (string [] values) {
ValueCount = values.Length;
ComboBox.Changed += Update;
}
// Changes the image that is viewed
public void SetImage (Image image) {
Image = image;
@ -348,14 +344,8 @@ namespace SparkleShare {
}
public void Update (object o, EventArgs args) {
Update ();
}
public void Update () {
// Updates the buttons to be disabled or enabled when needed
public void UpdateControls () {
if (ComboBox.Active == 0)
ButtonPrevious.State = StateType.Insensitive;