Example #1
0
		/// <summary>
		/// Opens a file dialog with the given settings.
		/// </summary>
		public bool FileDialog(FileDialogDef def)
		{
			// decide which action to use
			gtk.FileChooserAction action = gtk.FileChooserAction.Save;
			string accept = "";
			if (def.Type == FileDialogType.Open)
			{
				action = gtk.FileChooserAction.Open;
				accept = "Open";
			}
			else if (def.Type == FileDialogType.SaveAs)
			{
				action = gtk.FileChooserAction.Save;
				accept = "Save";
			}
			
			var dialog = new gtk.FileChooserDialog(def.Title, 
							this.Toplevel as gtk.Window, action,
							"Cancel", gtk.ResponseType.Cancel,
                            accept, gtk.ResponseType.Accept);
			if (def.FileName != null)
				dialog.SetFilename(def.FileName);
			
			// assemble the filters
			foreach (var ext in def.Extensions)
			{
				var filter = new gtk.FileFilter();
				var pattern = "*." + ext;
				filter.AddPattern(pattern);
				filter.Name = def.GetDescription(ext) + " (" + pattern + ")";
				dialog.AddFilter(filter);
			}
			
			var ret = dialog.Run() == (int)gtk.ResponseType.Accept;
			def.FileName = dialog.Filename;
			dialog.Destroy();
			return ret;
		}
Example #2
0
		/// <summary>
		/// Has the adapater open a new file dialog based on the given definition. 
		/// </summary>
		public bool FileDialog(FileDialogDef def)
		{
			return adapter.FileDialog(def);
		}
Example #3
0
		/// <summary>
		/// Creates a file dialog.
		/// </summary>
		public bool FileDialog(FileDialogDef dialogDef)
		{
			Microsoft.Win32.FileDialog dialog = null;

			// create the dialog
			if (dialogDef.Type == FileDialogType.Open)
				dialog = new Microsoft.Win32.OpenFileDialog();
			else if (dialogDef.Type == FileDialogType.SaveAs)
				dialog = new Microsoft.Win32.SaveFileDialog();

			// set the options from the def
			if (dialogDef.FileName != null)
				dialog.FileName = "Document"; // Default file name
			foreach (var ext in dialogDef.Extensions)
			{
				dialog.Filter = String.Format("{0} (.{1})|*.{1}", dialogDef.GetDescription(ext), ext);
			}
			if (dialogDef.Extensions.Count > 0)
				dialog.DefaultExt = "." + dialogDef.Extensions[0]; // Default file extension

			// Show the dialog
			Nullable<bool> result = dialog.ShowDialog();
			var success = result != null && (bool)result;
			if (success)
				dialogDef.FileName = dialog.FileName;
			return success;
		}
Example #4
0
		/// <summary>
		/// Prompts the user for a file name, then exports to that file.
		/// </summary>
		public void Export()
		{
			FileDialogDef dialogDef = new FileDialogDef() {Type = FileDialogType.SaveAs};
			dialogDef.Extensions.Add("png");
			if (FileDialog(dialogDef))
				adapter.Export(dialogDef.FileName);
		}
Example #5
0
		public bool FileDialog(FileDialogDef dialog)
		{
			throw new System.NotImplementedException();
		}