[longomatch] Remind last directory for the file chooser
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Remind last directory for the file chooser
- Date: Tue, 31 Mar 2015 17:28:42 +0000 (UTC)
commit ea5453dbe8bc6da1afb5d84efc515333e79e30b8
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu Mar 19 10:55:06 2015 +0100
Remind last directory for the file chooser
LongoMatch.GUI.Helpers/FileChooserHelper.cs | 35 +++++++++++++++++----------
LongoMatch.GUI.Helpers/Misc.cs | 26 ++++---------------
2 files changed, 28 insertions(+), 33 deletions(-)
---
diff --git a/LongoMatch.GUI.Helpers/FileChooserHelper.cs b/LongoMatch.GUI.Helpers/FileChooserHelper.cs
index 8ccc461..0ce704a 100644
--- a/LongoMatch.GUI.Helpers/FileChooserHelper.cs
+++ b/LongoMatch.GUI.Helpers/FileChooserHelper.cs
@@ -24,6 +24,8 @@ namespace LongoMatch.Gui.Helpers
public class FileChooserHelper
{
+ static string lastDirectory = null;
+
static public string SaveFile (Widget parent, string title, string defaultName,
string defaultFolder, string filterName,
string[] extensions)
@@ -83,36 +85,43 @@ namespace LongoMatch.Gui.Helpers
else
button = "gtk-open";
- if(parent != null)
+ if (parent != null)
toplevel = parent.Toplevel as Window;
else
toplevel = null;
- fChooser = new FileChooserDialog(title, toplevel, action,
- "gtk-cancel",ResponseType.Cancel, button, ResponseType.Accept);
+ fChooser = new FileChooserDialog (title, toplevel, action,
+ "gtk-cancel", ResponseType.Cancel, button, ResponseType.Accept);
fChooser.SelectMultiple = allowMultiple;
- if (defaultFolder != null)
- fChooser.SetCurrentFolder(defaultFolder);
+ if (defaultFolder != null) {
+ fChooser.SetCurrentFolder (defaultFolder);
+ } else if (lastDirectory != null) {
+ fChooser.SetCurrentFolder (lastDirectory);
+ }
if (defaultName != null)
fChooser.CurrentName = defaultName;
if (filterName != null) {
- filter = new FileFilter();
+ filter = new FileFilter ();
filter.Name = filterName;
if (extensions != null) {
foreach (string p in extensions) {
- filter.AddPattern(p);
+ filter.AddPattern (p);
}
}
fChooser.Filter = filter;
}
- if (fChooser.Run() != (int)ResponseType.Accept)
- path = new List<string>();
- else
- path = new List<string>(fChooser.Filenames);
-
- fChooser.Destroy();
+ if (fChooser.Run () != (int)ResponseType.Accept) {
+ path = new List<string> ();
+ } else {
+ path = new List<string> (fChooser.Filenames);
+ if (defaultFolder == null && fChooser.Filenames.Length > 0) {
+ lastDirectory = System.IO.Path.GetDirectoryName (fChooser.Filenames
[0]);
+ }
+ }
+
+ fChooser.Destroy ();
return path;
}
}
diff --git a/LongoMatch.GUI.Helpers/Misc.cs b/LongoMatch.GUI.Helpers/Misc.cs
index bbd9ebd..f82090a 100644
--- a/LongoMatch.GUI.Helpers/Misc.cs
+++ b/LongoMatch.GUI.Helpers/Misc.cs
@@ -51,31 +51,18 @@ namespace LongoMatch.Gui.Helpers
public static Pixbuf OpenImage (Widget widget)
{
- Gtk.Window toplevel = widget.Toplevel as Gtk.Window;
Pixbuf pimage = null;
StreamReader file;
- FileChooserDialog fChooser;
- string lastDir;
-
- if (lastFilename != null) {
- lastDir = Path.GetDirectoryName (lastFilename);
- } else {
- lastDir = Config.HomeDir;
- }
-
- fChooser = new FileChooserDialog (Catalog.GetString ("Choose an image"),
- toplevel, FileChooserAction.Open,
- "gtk-cancel", ResponseType.Cancel,
- "gtk-open", ResponseType.Accept);
- fChooser.AddFilter (GetFileFilter ());
- fChooser.SetCurrentFolder (lastDir);
- if (fChooser.Run () == (int)ResponseType.Accept) {
+ string filename;
+
+ filename = Config.GUIToolkit.OpenFile (Catalog.GetString ("Choose an image"),
+ null, null, "Images", new string[] { "*.png", "*.jpg", "*.jpeg", "*.svg" });
+ if (filename != null) {
// For Win32 compatibility we need to open the image file
// using a StreamReader. Gdk.Pixbuf(string filePath) uses GLib to open the
// input file and doesn't support Win32 files path encoding
try {
- lastFilename = fChooser.Filename;
- file = new StreamReader (fChooser.Filename);
+ file = new StreamReader (filename);
pimage = new Gdk.Pixbuf (file.BaseStream);
file.Close ();
} catch (Exception ex) {
@@ -83,7 +70,6 @@ namespace LongoMatch.Gui.Helpers
Config.GUIToolkit.ErrorMessage (Catalog.GetString ("Image file format
not supported"), widget);
}
}
- fChooser.Destroy ();
return pimage;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]