From b002706d0aa2d9514f1666fa81898c1157dc2d12 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 29 Jun 2010 11:20:58 +0100 Subject: [PATCH] Continue cleaning up SparkleDiff code --- SparkleShare/SparkleDiff.cs | 112 ++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 61 deletions(-) diff --git a/SparkleShare/SparkleDiff.cs b/SparkleShare/SparkleDiff.cs index 3372d72d..e9a7a36e 100644 --- a/SparkleShare/SparkleDiff.cs +++ b/SparkleShare/SparkleDiff.cs @@ -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) { @@ -240,63 +233,65 @@ namespace SparkleShare { revision_combobox.AppendText (hash); } } - + if (position.Equals ("Left")) revision_combobox.Active = 1; else if (position.Equals ("Right")) 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); @@ -330,32 +325,27 @@ 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; ShowAll (); } - - - 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; @@ -364,7 +354,7 @@ namespace SparkleShare { ButtonNext.State = StateType.Insensitive; } - + }