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 FilePath;
private string FileName; private string FileName;
private VBox ViewLeft; private RevisionView ViewLeft;
private VBox ViewRight; private RevisionView ViewRight;
private string [] RevisionHashes; private string [] RevisionHashes;
@ -80,8 +80,8 @@ namespace SparkleShare {
HBox layout_horizontal = new HBox (false, 12); HBox layout_horizontal = new HBox (false, 12);
ViewLeft = CreateRevisionView ("Left"); ViewLeft = new RevisionView ();
ViewRight = CreateRevisionView ("Right"); ViewRight = new RevisionView ();
layout_horizontal.PackStart (ViewLeft); layout_horizontal.PackStart (ViewLeft);
layout_horizontal.PackStart (ViewRight); layout_horizontal.PackStart (ViewRight);
@ -204,9 +204,6 @@ namespace SparkleShare {
private VBox CreateRevisionView (string position) private VBox CreateRevisionView (string position)
{ {
VBox layout_vertical = new VBox (false, 6);
ScrolledWindow scrolled_window = new ScrolledWindow ();
Process process = new Process (); Process process = new Process ();
process.EnableRaisingEvents = true; process.EnableRaisingEvents = true;
@ -221,16 +218,12 @@ namespace SparkleShare {
Gdk.Pixbuf pixbuf; Gdk.Pixbuf pixbuf;
pixbuf = new Gdk.Pixbuf ( (System.IO.Stream) process.StandardOutput.BaseStream); pixbuf = new Gdk.Pixbuf ( (System.IO.Stream) process.StandardOutput.BaseStream);
scrolled_window.AddWithViewport (new Image (pixbuf));
scrolled_window.Hadjustment.ValueChanged += SyncViewsHorizontally; ViewLeft.ScrolledWindow.Hadjustment.ValueChanged += SyncViewsHorizontally;
scrolled_window.Vadjustment.ValueChanged += SyncViewsVertically; 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) { foreach (string hash in RevisionHashes) {
Console.WriteLine (hash); Console.WriteLine (hash);
if (current_version) { if (current_version) {
@ -240,63 +233,65 @@ namespace SparkleShare {
revision_combobox.AppendText (hash); revision_combobox.AppendText (hash);
} }
} }
if (position.Equals ("Left")) if (position.Equals ("Left"))
revision_combobox.Active = 1; revision_combobox.Active = 1;
else if (position.Equals ("Right")) else if (position.Equals ("Right"))
revision_combobox.Active = 0; revision_combobox.Active = 0;
revision_combobox.Changed += UpdateViews; revision_combobox.Changed += UpdateViews;
*/return new VBox ();
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;
} }
} }
// 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 class RevisionView : VBox
{ {
public ScrolledWindow ScrolledWindow; public ScrolledWindow ScrolledWindow;
public ComboBox ComboBox; public ComboBox ComboBox;
public Button ButtonPrevious; public Button ButtonPrevious;
public Button ButtonNext; public Button ButtonNext;
private int ValueCount; private int ValueCount;
private Image Image; private Image Image;
public RevisionView () : base (false, 6) public RevisionView () : base (false, 6)
{ {
@ -320,7 +315,7 @@ namespace SparkleShare {
Image image_next = new Image (); Image image_next = new Image ();
image_next.IconName = "go-next"; image_next.IconName = "go-next";
ButtonNext = new Button (image_next); ButtonNext = new Button (image_next);
ButtonNext.Clicked += Next; //move outside this class ButtonNext.Clicked += Next;
controls.Add (ButtonPrevious); controls.Add (ButtonPrevious);
controls.Add (ComboBox); controls.Add (ComboBox);
@ -330,32 +325,27 @@ namespace SparkleShare {
} }
// Fills the widget's combobox with entries
public void FillComboBox (string [] values) { public void FillComboBox (string [] values) {
ValueCount = values.Length; ValueCount = values.Length;
ComboBox.Changed += Update; ComboBox.Changed += Update;
} }
// Changes the image that is viewed
public void SetImage (Image image) { public void SetImage (Image image) {
Image = image; Image = image;
ShowAll (); 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) if (ComboBox.Active == 0)
ButtonPrevious.State = StateType.Insensitive; ButtonPrevious.State = StateType.Insensitive;
@ -364,7 +354,7 @@ namespace SparkleShare {
ButtonNext.State = StateType.Insensitive; ButtonNext.State = StateType.Insensitive;
} }
} }