Skip to content

Commit

Permalink
Add image preview to Images pad
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronwhite committed Nov 24, 2011
1 parent 304436d commit d24ddc1
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions Pinta.Gui.Widgets/Widgets/OpenImages/OpenImagesListWidget.cs
Expand Up @@ -37,6 +37,11 @@ public class OpenImagesListWidget : ScrolledWindow

private CellRendererPixbuf file_close_cell;
private TreeViewColumn file_name_column;
private TreeViewColumn file_preview_column;

private const int PreviewWidth = 60;
private const int PreviewHeight = 40;
private const int PreviewColumnWidth = 70;

private Gdk.Pixbuf close_icon = PintaCore.Resources.GetIcon (Stock.Close);

Expand All @@ -52,18 +57,24 @@ public OpenImagesListWidget ()
tree.Selection.Mode = SelectionMode.Single;
tree.Selection.SelectFunction = HandleDocumentSelected;

var file_preview_cell = new CellRendererSurface (PreviewWidth, PreviewHeight);
file_preview_column = new TreeViewColumn ("File Preview", file_preview_cell, "surface", 0);
file_preview_column.Sizing = TreeViewColumnSizing.Fixed;
file_preview_column.FixedWidth = PreviewColumnWidth;
tree.AppendColumn (file_preview_column);

file_name_column = new TreeViewColumn ();
CellRendererText file_name_cell = new CellRendererText ();
file_name_column.PackStart (file_name_cell, true);
file_name_column.AddAttribute (file_name_cell, "text", 0);
file_name_column.AddAttribute (file_name_cell, "text", 1);

file_close_cell = new CellRendererPixbuf ();
file_name_column.PackStart (file_close_cell, false);
file_name_column.AddAttribute (file_close_cell, "pixbuf", 1);
file_name_column.AddAttribute (file_close_cell, "pixbuf", 2);

tree.AppendColumn (file_name_column);

store = new ListStore (typeof (string), typeof (Gdk.Pixbuf));
store = new ListStore (typeof (Cairo.ImageSurface), typeof (string), typeof (Gdk.Pixbuf));
tree.Model = store;
tree.ButtonPressEvent += HandleTreeButtonPressEvent;

Expand All @@ -74,6 +85,17 @@ public OpenImagesListWidget ()
PintaCore.Workspace.DocumentClosed += HandleDocumentOpenedOrClosed;
PintaCore.Workspace.DocumentCreated += HandleDocumentOpenedOrClosed;
PintaCore.Workspace.ActiveDocumentChanged += HandleActiveDocumentChanged;

// update the thumbnails whenever the image is modified
PintaCore.History.HistoryItemAdded += HandleDocumentModified;
PintaCore.History.ActionRedone += HandleDocumentModified;
PintaCore.History.ActionUndone += HandleDocumentModified;
}

void HandleDocumentModified (object sender, EventArgs e)
{
RebuildDocumentList ();
UpdateSelectedDocument ();
}

/// <summary>
Expand All @@ -88,6 +110,8 @@ void HandleTreeButtonPressEvent (object o, ButtonPressEventArgs args)
int start_pos, width;
file_name_column.CellGetPosition (file_close_cell, out start_pos, out width);

start_pos += file_preview_column.Width;

// if the close button was clicked, find the row that was clicked and close that document
if (start_pos <= click_x && start_pos + width > click_x)
{
Expand All @@ -96,6 +120,7 @@ void HandleTreeButtonPressEvent (object o, ButtonPressEventArgs args)

PintaCore.Workspace.SetActiveDocument (path.Indices[0]);
PintaCore.Actions.File.Close.Activate ();
UpdateSelectedDocument ();
}
}

Expand Down Expand Up @@ -129,7 +154,7 @@ private void RebuildDocumentList ()
{
doc.Renamed -= HandleDocRenamed;
doc.Renamed += HandleDocRenamed;
store.AppendValues (doc.Filename, close_icon);
store.AppendValues (doc.GetFlattenedImage (), doc.Filename, close_icon);
}
}

Expand Down

0 comments on commit d24ddc1

Please sign in to comment.