Skip to content

Commit

Permalink
[Fixes bug #892690] Show image previews in the Open File dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronwhite committed Nov 21, 2011
1 parent 4c4e4be commit 34fcb3b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Pinta.Core/Actions/LayerActions.cs
Expand Up @@ -158,6 +158,9 @@ private void HandlePintaCoreActionsLayersImportFromFileActivated (object sender,

fcd.SetCurrentFolder (PintaCore.System.LastDialogDirectory);
fcd.AlternativeButtonOrder = new int[] { (int) ResponseType.Ok, (int) ResponseType.Cancel };

fcd.AddImagePreview ();

int response = fcd.Run ();

if (response == (int)Gtk.ResponseType.Ok) {
Expand Down
30 changes: 30 additions & 0 deletions Pinta.Core/Extensions/GtkExtensions.cs
Expand Up @@ -132,5 +132,35 @@ public static Gtk.MenuItem CreateSubMenuItem (this Gtk.Action action)

return item;
}

/// <summary>
/// Initialize an image preview widget for the dialog
/// </summary>
public static void AddImagePreview (this FileChooserDialog dialog)
{
dialog.PreviewWidget = new Image ();
dialog.UpdatePreview += new EventHandler (OnUpdateImagePreview);
}

/// <summary>
/// Update the image preview widget of a FileChooserDialog
/// </summary>
/// <param name="sender"></param>
private static void OnUpdateImagePreview (object sender, EventArgs e)
{
FileChooserDialog dialog = (FileChooserDialog)sender;
Image preview = (Image)dialog.PreviewWidget;

try
{
preview.Pixbuf = new Gdk.Pixbuf (dialog.PreviewFilename, 256, 512, true);
dialog.PreviewWidgetActive = true;
}
catch (GLib.GException)
{
// if the image preview failed, don't show the preview widget
dialog.PreviewWidgetActive = false;
}
}
}
}
2 changes: 2 additions & 0 deletions Pinta/Actions/File/OpenDocumentAction.cs
Expand Up @@ -67,6 +67,8 @@ private void Activated (object sender, EventArgs e)
fcd.SetCurrentFolder (PintaCore.System.LastDialogDirectory);
fcd.SelectMultiple = true;

fcd.AddImagePreview ();

int response = fcd.Run ();

if (response == (int)Gtk.ResponseType.Ok) {
Expand Down

0 comments on commit 34fcb3b

Please sign in to comment.