private void Activated(object sender, EventArgs e) { var fcd = new Gtk.FileChooserDialog(Catalog.GetString("Open Image File"), PintaCore.Chrome.MainWindow, FileChooserAction.Open, Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Ok); // Add image files filter FileFilter ff = new FileFilter(); foreach (var format in PintaCore.System.ImageFormats.Formats) { if (!format.IsWriteOnly()) { foreach (var ext in format.Extensions) { ff.AddPattern(string.Format("*.{0}", ext)); } } } ff.Name = Catalog.GetString("Image files"); fcd.AddFilter(ff); FileFilter ff2 = new FileFilter(); ff2.Name = Catalog.GetString("All files"); ff2.AddPattern("*.*"); fcd.AddFilter(ff2); fcd.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel }; fcd.SetCurrentFolder(PintaCore.System.GetDialogDirectory()); fcd.SelectMultiple = true; fcd.AddImagePreview(); int response = fcd.Run(); if (response == (int)Gtk.ResponseType.Ok) { PintaCore.System.LastDialogDirectory = fcd.CurrentFolder; foreach (var file in fcd.Filenames) { if (PintaCore.Workspace.OpenFile(file, fcd)) { RecentManager.Default.AddFull(fcd.Uri, PintaCore.System.RecentData); } } } fcd.Destroy(); }
private void HandlePintaCoreActionsLayersImportFromFileActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit(); var fcd = new Gtk.FileChooserDialog(Catalog.GetString("Open Image File"), PintaCore.Chrome.MainWindow, FileChooserAction.Open, Stock.Cancel, ResponseType.Cancel, Stock.Open, ResponseType.Ok); fcd.SetCurrentFolder(PintaCore.System.GetDialogDirectory()); fcd.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel }; fcd.AddImagePreview(); int response = fcd.Run(); if (response == (int)Gtk.ResponseType.Ok) { string file = fcd.Filename; PintaCore.System.LastDialogDirectory = fcd.CurrentFolder; // Open the image and add it to the layers Layer layer = doc.AddNewLayer(System.IO.Path.GetFileName(file)); using (var fs = new FileStream(file, FileMode.Open)) using (Pixbuf bg = new Pixbuf(fs)) using (Cairo.Context g = new Cairo.Context(layer.Surface)) { CairoHelper.SetSourcePixbuf(g, bg, 0, 0); g.Paint(); } doc.SetCurrentLayer(layer); AddLayerHistoryItem hist = new AddLayerHistoryItem("Menu.Layers.ImportFromFile.png", Catalog.GetString("Import From File"), doc.Layers.IndexOf(layer)); doc.History.PushNewItem(hist); doc.Workspace.Invalidate(); } fcd.Destroy(); }
private void Activated(object sender, EventArgs e) { var fcd = new Gtk.FileChooserDialog (Catalog.GetString ("Open Image File"), PintaCore.Chrome.MainWindow, FileChooserAction.Open, Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Ok); // Add image files filter FileFilter ff = new FileFilter (); foreach (var format in PintaCore.System.ImageFormats.Formats) { foreach (var ext in format.Extensions) { ff.AddPattern (string.Format("*.{0}", ext)); } } ff.Name = Catalog.GetString ("Image files"); fcd.AddFilter (ff); FileFilter ff2 = new FileFilter (); ff2.Name = Catalog.GetString ("All files"); ff2.AddPattern ("*.*"); fcd.AddFilter (ff2); fcd.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel }; fcd.SetCurrentFolder (PintaCore.System.GetDialogDirectory ()); fcd.SelectMultiple = true; fcd.AddImagePreview (); int response = fcd.Run (); if (response == (int)Gtk.ResponseType.Ok) { PintaCore.System.LastDialogDirectory = fcd.CurrentFolder; foreach (var file in fcd.Filenames) if (PintaCore.Workspace.OpenFile (file, fcd)) RecentManager.Default.AddFull (fcd.Uri, PintaCore.System.RecentData); } fcd.Destroy (); }
private void HandlePintaCoreActionsLayersImportFromFileActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit (); Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog (Catalog.GetString ("Open Image File"), null, FileChooserAction.Open, Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Ok); 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) { string file = fcd.Filename; PintaCore.System.LastDialogDirectory = fcd.CurrentFolder; // Open the image and add it to the layers Layer layer = doc.AddNewLayer (System.IO.Path.GetFileName (file)); using (var fs = new FileStream (file, FileMode.Open)) using (Pixbuf bg = new Pixbuf (fs)) using (Cairo.Context g = new Cairo.Context (layer.Surface)) { CairoHelper.SetSourcePixbuf (g, bg, 0, 0); g.Paint (); } doc.SetCurrentLayer (layer); AddLayerHistoryItem hist = new AddLayerHistoryItem ("Menu.Layers.ImportFromFile.png", Catalog.GetString ("Import From File"), doc.Layers.IndexOf (layer)); doc.History.PushNewItem (hist); doc.Workspace.Invalidate (); } fcd.Destroy (); }