public void InsertImage(TextIter iter, ImageInfo imageInfo, bool supportUndo) { Gdk.Pixbuf pixbuf = null; try { pixbuf = new Gdk.Pixbuf (imageInfo.FileContent); } catch { pixbuf = null; } if (pixbuf == null) { // TODO: Report the open image error. return; } if (imageInfo.DisplayWidth == 0) { imageInfo.DisplayWidth = pixbuf.Width; imageInfo.DisplayHeight = pixbuf.Height; } var imageWidget = new ImageWidget (pixbuf); imageWidget.ResizeImage (imageInfo.DisplayWidth, imageInfo.DisplayHeight); imageWidget.ShowAll (); InitImageWidgetContextMenu (imageWidget, imageInfo); imageWidget.Resized += imageWidget_Resized; if (supportUndo) Buffer.Undoer.FreezeUndo (); var anchorStart = iter; var anchor = Buffer.CreateChildAnchor (ref iter); var tag = new NoteTag ("dummy"); tag.CanUndo = false; Buffer.ApplyTag (tag, anchorStart, iter); Window.Editor.AddChildAtAnchor (imageWidget, anchor); imageInfo.SetInBufferInfo (Buffer, anchor, imageWidget); //imageWidget.Destroyed += (o, e) => //{ // if (!imageWidget.InsertUndone) { // imageInfoList.Remove (imageInfo); // } //}; if (supportUndo) { Buffer.Undoer.ThawUndo (); var action = new InsertImageAction (this, imageInfo, imageInfoList); Buffer.Undoer.AddUndoAction (action); } imageInfoList.Add (imageInfo); }
private void InitImageWidgetContextMenu(ImageWidget imageWidget, ImageInfo imageInfo) { Gtk.ImageMenuItem saveAs = new Gtk.ImageMenuItem (Catalog.GetString ("Save as...")); saveAs.Image = new Gtk.Image (Gtk.Stock.SaveAs, Gtk.IconSize.Menu); saveAs.Activated += (o, e) => SaveImage (Note.Window, imageInfo); imageWidget.ContextMenu.Append (saveAs); Gtk.ImageMenuItem prop = new Gtk.ImageMenuItem (Catalog.GetString ("Properties")); prop.Image = new Gtk.Image (Gtk.Stock.Properties, Gtk.IconSize.Menu); prop.Activated += (o, e) => ShowImageProperties (Note.Window, imageInfo); imageWidget.ContextMenu.Append (prop); imageWidget.ContextMenu.ShowAll (); }