From e5e4276494780293e98445a5c80e914a004b2751 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Mon, 5 Jul 2010 14:15:22 +0100 Subject: [PATCH] [sparklediff] Resize window to the size of the images displayed --- SparkleDiff/RevisionView.cs | 6 ++++++ SparkleDiff/SparkleDiffWindow.cs | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/SparkleDiff/RevisionView.cs b/SparkleDiff/RevisionView.cs index 1c900ba4..e645ac7d 100644 --- a/SparkleDiff/RevisionView.cs +++ b/SparkleDiff/RevisionView.cs @@ -145,6 +145,12 @@ namespace SparkleShare { ShowAll (); } + + public Image GetImage () { + + return Image; + + } } diff --git a/SparkleDiff/SparkleDiffWindow.cs b/SparkleDiff/SparkleDiffWindow.cs index 14f27c03..c2feb71e 100644 --- a/SparkleDiff/SparkleDiffWindow.cs +++ b/SparkleDiff/SparkleDiffWindow.cs @@ -48,8 +48,6 @@ namespace SparkleShare { string file_name = System.IO.Path.GetFileName (file_path); - // TODO: Adjust the size of the window to the images - SetSizeRequest (800, 540); SetPosition (WindowPosition.Center); BorderWidth = 12; @@ -138,6 +136,8 @@ namespace SparkleShare { layout_horizontal.PackStart (ViewLeft); layout_horizontal.PackStart (ViewRight); + ResizeToViews (); + // Order time view according to the user's reading direction if (Direction == Gtk.TextDirection.Rtl) // See Deejay1? I can do i18n too! :P layout_horizontal.ReorderChild (ViewLeft, 1); @@ -164,6 +164,23 @@ namespace SparkleShare { } + private void ResizeToViews () { + + int new_width = ViewLeft.GetImage ().Pixbuf.Width + ViewRight.GetImage ().Pixbuf.Width + 100; + int new_height = 200; + + if (ViewLeft.GetImage ().Pixbuf.Height > ViewRight.GetImage ().Pixbuf.Height) + new_height += ViewLeft.GetImage ().Pixbuf.Height; + else + new_height += ViewRight.GetImage ().Pixbuf.Height; + + if (new_width >= Screen.Width || new_height >= Screen.Height) + Maximize (); + else + SetSizeRequest (new_width, new_height); + + } + // Hooks up two views so their scrollbars will be kept in sync private void HookUpViews () {