本文整理汇总了C#中Gtk.FileChooserDialog类的典型用法代码示例。如果您正苦于以下问题:C# FileChooserDialog类的具体用法?C# FileChooserDialog怎么用?C# FileChooserDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileChooserDialog类属于Gtk命名空间,在下文中一共展示了FileChooserDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Show
public override WindowResponse Show()
{
FileChooserAction fca = FileChooserAction.Open;
switch(DialogType)
{
case FileDialogType.OpenFile:
fca = FileChooserAction.Open;
break;
case FileDialogType.SelectFolder:
fca = FileChooserAction.SelectFolder;
break;
case FileDialogType.SaveFile:
fca = FileChooserAction.Save;
break;
}
fc = new FileChooserDialog(Title, null, fca, Message.GetString("Cancel"), ResponseType.Cancel, Message.GetString("Select"), ResponseType.Ok);
fc.SetCurrentFolder(InitialDirectory);
foreach(FileTypeFilter filter in FileTypeFilters)
{
FileFilter ft = new FileFilter();
ft.Name = filter.FilterName;
foreach(string pat in filter.Filter) ft.AddPattern("*." + pat);
fc.AddFilter(ft);
}
WindowResponse resp = GtkHelper.GetResponse((ResponseType)fc.Run());
SelectedPath = fc.Filename;
return resp;
}
示例2: SelectFileDialog
private string SelectFileDialog(Window parentWindow)
{
var fileChooserDialog = new Gtk.FileChooserDialog(Mono.Unix.Catalog.GetString ("Select file..."),
parentWindow,
FileChooserAction.Open,
Gtk.Stock.Cancel,
Gtk.ResponseType.Cancel,
Gtk.Stock.Open, Gtk.ResponseType.Ok);
fileChooserDialog.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel };
fileChooserDialog.SelectMultiple = false;
//add filter for all files
FileFilter allFilesFilter = new FileFilter();
allFilesFilter.Name = Mono.Unix.Catalog.GetString("All files");
allFilesFilter.AddPattern("*.*");
fileChooserDialog.AddFilter(allFilesFilter);
int response = fileChooserDialog.Run();
string filename = null;
if(response == (int)Gtk.ResponseType.Ok)
{
filename = fileChooserDialog.Filename;
}
fileChooserDialog.Destroy();
return filename;
}
示例3: ChooseDialog
// creates a custom choose dialog
static string[] ChooseDialog(FileChooserAction action, string title, bool many)
{
FileChooserDialog dialog = new FileChooserDialog (title, null, action);
if (last_folder != null)
dialog.SetCurrentFolder (last_folder);
if (many)
dialog.SelectMultiple = true;
dialog.AddButton (Stock.Cancel, ResponseType.Cancel);
dialog.AddButton (Stock.Ok, ResponseType.Ok);
int response = dialog.Run ();
string[] ret = null;
if ((ResponseType) response == ResponseType.Ok)
ret = dialog.Filenames;
if ((ResponseType) response == ResponseType.Cancel)
ret = null;
last_folder = dialog.CurrentFolder;
dialog.Destroy ();
if(ret != null && ret.Length == 0) ret = null;
return ret;
}
示例4: OnTargetNMMLFileButtonClicked
protected void OnTargetNMMLFileButtonClicked(object sender, System.EventArgs e)
{
Gtk.FileChooserDialog fc =
new Gtk.FileChooserDialog ("Target NMML file", this.Toplevel as Gtk.Window, FileChooserAction.Open,
"Cancel", ResponseType.Cancel,
"Select", ResponseType.Accept);
Gtk.FileFilter filter = new Gtk.FileFilter ();
filter.Name = "NMML files";
filter.AddPattern ("*.nmml");
fc.AddFilter (filter);
if (mProject.TargetNMMLFile != "")
{
fc.SetFilename (mProject.TargetNMMLFile);
}
else
{
fc.SetFilename (mProject.BaseDirectory);
}
if (fc.Run () == (int)ResponseType.Accept)
{
string path = PathHelper.ToRelativePath (fc.Filename, mProject.BaseDirectory);
TargetNMMLFileEntry.Text = path;
}
fc.Destroy ();
}
示例5: OpenExperimentDialog
internal static string OpenExperimentDialog(Window parentWindow)
{
var fileChooserDialog = new Gtk.FileChooserDialog(Mono.Unix.Catalog.GetString ("Open Experiment File"),
parentWindow,
FileChooserAction.Open,
Gtk.Stock.Cancel,
Gtk.ResponseType.Cancel,
Gtk.Stock.Open, Gtk.ResponseType.Ok);
fileChooserDialog.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel };
fileChooserDialog.SelectMultiple = false;
// HERZUM SPRINT 4 TLAB-214
fileChooserDialog.SetCurrentFolder(TraceLab.Core.Settings.Settings.GetSettings().DefaultExperimentsDirectory);
// END SPRINT HERZUM 4 HERZUM 4: TLAB-214
AddFilters(fileChooserDialog);
int response = fileChooserDialog.Run();
string filename = null;
if(response == (int)Gtk.ResponseType.Ok)
{
filename = fileChooserDialog.Filename;
}
fileChooserDialog.Destroy();
return filename;
}
示例6: loadBatchPoints
//Will load in multiple files, or a folder of files which will be matched against
//loaded templates
public static List<Tuple<string, List<PointD>>> loadBatchPoints()
{
List<Tuple<string,List<PointD>>> result = new List<Tuple<string,List<PointD>>> ();
//Setup of dialog and limiting it to only XML files
FileChooserDialog fileChooser = new FileChooserDialog ("Open Files", null, FileChooserAction.Open);
fileChooser.AddButton (Stock.Cancel, ResponseType.Cancel);
fileChooser.AddButton (Stock.Open, ResponseType.Ok);
fileChooser.Filter = new FileFilter ();
fileChooser.Filter.AddPattern ("*.xml");
string tmp = System.IO.Directory.GetCurrentDirectory();
string newTmp = tmp + "/../../Gestures/RecordedDataPoints/";
fileChooser.SetCurrentFolder (newTmp);
fileChooser.SelectMultiple = true;
ResponseType retVal = (ResponseType)fileChooser.Run ();
if (retVal == ResponseType.Ok) {
foreach (string file in fileChooser.Filenames) {
result.Add (XMLParser.BatchLoadPoints (file));
}
}
fileChooser.Destroy ();
return result;
}
示例7: Execute
public override bool Execute()
{
Image image = null;
if (File.Exists(_path))
{
image = Image.Load(RunMode.Noninteractive, _path, _path);
}
else
{
var choose = new FileChooserDialog("Open...",
null,
FileChooserAction.Open,
"Cancel", ResponseType.Cancel,
"Open", ResponseType.Accept);
if (choose.Run() == (int) ResponseType.Accept)
{
string fileName = choose.Filename;
image = Image.Load(RunMode.Noninteractive, fileName, fileName);
};
choose.Destroy();
}
if (image != null)
{
image.CleanAll();
ActiveDisplay = new Display(image);
ActiveImage = image;
return true;
}
return false;
}
示例8: OpenClicked
protected virtual void OpenClicked (object sender, System.EventArgs e)
{
FileChooserDialog dlg = new FileChooserDialog (
GettextCatalog.GetString ("Select Executable"), null, FileChooserAction.Open,
"gtk-cancel", ResponseType.Cancel,
"gtk-open", ResponseType.Accept
);
dlg.SelectMultiple = false;
dlg.LocalOnly = true;
dlg.Modal = true;
dlg.SetCurrentFolder (Environment.GetFolderPath (Environment.SpecialFolder.Personal));
FileFilter filterExe = new FileFilter ();
filterExe.AddPattern ("*.exe");
filterExe.Name = GettextCatalog.GetString ("Executables");
FileFilter filterAll = new FileFilter ();
filterAll.AddPattern ("*");
filterAll.Name = GettextCatalog.GetString ("All files");
dlg.AddFilter (filterExe);
dlg.AddFilter (filterAll);
if (dlg.Run () == (int)ResponseType.Accept)
entryExecutable.Text = dlg.Filename;
dlg.Destroy ();
}
示例9: OnButtonClicked
protected void OnButtonClicked(object sender, EventArgs e)
{
if (sender == button1)
{
Gtk.FileChooserDialog dialog = new Gtk.FileChooserDialog ("Choose item...", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Insert Spacer", ResponseType.None, "Add", ResponseType.Accept);
Gtk.Alignment align = new Alignment (1, 0, 0, 1);
Gtk.Frame frame = new Frame ("Position");
Gtk.HBox hbox = new HBox (false, 4);
RadioButton rbRight;
rbRight = new RadioButton ("Right");
hbox.PackEnd(rbRight, false, false, 1);
hbox.PackEnd(new RadioButton (rbRight, "Left"), false, false, 1);
frame.Add (hbox);
align.Add (frame);
align.ShowAll ();
dialog.ExtraWidget = align;
ResponseType response = (ResponseType)dialog.Run ();
if (response == ResponseType.Accept) {
RunCommand ("defaults write com.apple.dock " + GetAlign(dialog.ExtraWidget) + " -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" + dialog.Filename + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>' && /bin/sleep 1 &&/usr/bin/killall Dock");
} else if (response == ResponseType.None) {
RunCommand ("defaults write com.apple.dock " + GetAlign(dialog.ExtraWidget) + " -array-add '{tile-data={}; tile-type=\"spacer-tile\";}' && /bin/sleep 1 &&/usr/bin/killall Dock");
}
dialog.Destroy ();
}
}
示例10: ShowSaveAsDialog
internal static string ShowSaveAsDialog(Window parentWindow, string currentFilename = null)
{
var fileChooserDialog = new FileChooserDialog (Mono.Unix.Catalog.GetString ("Save Experiment File"),
parentWindow,
FileChooserAction.Save,
Gtk.Stock.Cancel,
Gtk.ResponseType.Cancel,
Gtk.Stock.Save, Gtk.ResponseType.Ok);
fileChooserDialog.DoOverwriteConfirmation = true;
fileChooserDialog.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel };
fileChooserDialog.SelectMultiple = false;
if (String.IsNullOrEmpty(currentFilename) == false)
{
fileChooserDialog.SetFilename(currentFilename);
}
AddFilters(fileChooserDialog);
int response = fileChooserDialog.Run();
string filename = null;
if(response == (int)Gtk.ResponseType.Ok)
{
filename = fileChooserDialog.Filename;
}
fileChooserDialog.Destroy();
return filename;
}
示例11: OnSaveButtonClicked
protected void OnSaveButtonClicked(object sender, EventArgs e)
{
try
{
FileChooserDialog fc = new FileChooserDialog("Save Filterset", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept);
FileFilter filter = new FileFilter();
filter.Name = "DeSERt Filterset";
filter.AddMimeType("Filterset/fis");
filter.AddPattern("*.fis");
fc.AddFilter(filter);
fc.DoOverwriteConfirmation = true;
fc.CurrentName = FiltersetnameEntry.Text.Replace(" ", "-");
if (Directory.Exists(MySettings.LastFilterDir)) { fc.SetCurrentFolder(MySettings.LastFilterDir); }
ResponseType res = (ResponseType)fc.Run();
if (res == ResponseType.Ok || res == ResponseType.Close)
{
string path;
if (!System.IO.Path.HasExtension(fc.Filename)) { path = fc.Filename + ".fis"; }
else { path = fc.Filename; }
MySettings.LastFilterDir = System.IO.Path.GetDirectoryName(fc.Filename);
MySettings.Save();
fst.Name = FiltersetnameEntry.Text;
Filterset.SaveFilterset(path, fst);
saved = true;
}
fc.Destroy();
if (res == ResponseType.Close) { this.Destroy(); }
}
catch (Exception ex) { ErrorReport.ReportError("Save Button (Create Filterset)", ex); }
}
示例12: GetTemplateFromDisk
public static byte[] GetTemplateFromDisk()
{
//Читаем файл документа
FileChooserDialog Chooser = new FileChooserDialog ("Выберите шаблон документа...",
null,
FileChooserAction.Open,
"Отмена", ResponseType.Cancel,
"Выбрать", ResponseType.Accept);
FileFilter Filter = new FileFilter ();
Filter.Name = "ODT документы и OTT шаблоны";
Filter.AddMimeType ("application/vnd.oasis.opendocument.text");
Filter.AddMimeType ("application/vnd.oasis.opendocument.text-template");
Filter.AddPattern ("*.odt");
Filter.AddPattern ("*.ott");
Chooser.AddFilter (Filter);
Filter = new FileFilter ();
Filter.Name = "Все файлы";
Filter.AddPattern ("*.*");
Chooser.AddFilter (Filter);
byte[] file = null;
if ((ResponseType)Chooser.Run () == ResponseType.Accept) {
Chooser.Hide ();
logger.Info ("Чтение файла...");
file = File.ReadAllBytes(Chooser.Filename);
logger.Info ("Ok");
}
Chooser.Destroy ();
return file;
}
示例13: Activated
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 ();
ff.AddPixbufFormats ();
ff.AddPattern ("*.ora");
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.LastDialogDirectory);
fcd.SelectMultiple = true;
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))
RecentManager.Default.AddFull (fcd.Uri, PintaCore.System.RecentData);
}
fcd.Destroy ();
}
示例14: AskForQuizFilePath
public string AskForQuizFilePath()
{
string output;
Gtk.FileChooserDialog fc =
new Gtk.FileChooserDialog("Choose the quiz to open",
this,
FileChooserAction.Open,
"Cancel",ResponseType.Cancel,
"Open",ResponseType.Accept);
if (fc.Run() == (int)ResponseType.Accept)
{
output = fc.Filename;
}
else
{
throw new ApplicationException("Could for some reason not read the wanted file: " + fc.Filename);
}
//Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
fc.Destroy();
return output;
}
示例15: OnBtnSelectFileClicked
/// <summary>
/// On click "..." button - select file
/// </summary>
protected virtual void OnBtnSelectFileClicked(object sender, System.EventArgs e)
{
Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog (
AddinManager.CurrentLocalizer.GetString ("Choose the file to open"), new Dialog(),
Gtk.FileChooserAction.Open,
AddinManager.CurrentLocalizer.GetString ("Cancel"), ResponseType.Cancel,
AddinManager.CurrentLocalizer.GetString ("Open"), ResponseType.Accept);
if (!string.IsNullOrEmpty (this.eCommand.Text)) {
fc.SetFilename(this.eCommand.Text);
}
if (fc.Run() == (int) ResponseType.Accept) {
// check
UnixFileInfo info = new UnixFileInfo (fc.Filename);
if ((info.FileAccessPermissions & FileAccessPermissions.UserExecute)
!= FileAccessPermissions.UserExecute) {
MessageDialog md = new MessageDialog (new Dialog(),
DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Close,
AddinManager.CurrentLocalizer.GetString ("Selected invalid file!\nShould be executable."));
md.Run ();
md.Destroy();
} else {
this.eCommand.Text = fc.Filename;
}
}
fc.Destroy();
}