static string GetPath() { string path = Properties.Settings.Default.DaggerfallPath; int check; while ((check = CheckPath(ref path)) != 1) { if (check < 0) { return(null); } var chooser = new Gtk.FileChooserDialog("Select the path Daggerfall is in.", null, FileChooserAction.SelectFolder, "Select", ResponseType.Accept, "Cancel", ResponseType.Cancel); chooser.Show(); if (chooser.Run() == (int)ResponseType.Accept) { path = chooser.Filename; } else { return(null); } chooser.Destroy(); } Properties.Settings.Default.DaggerfallPath = path; Properties.Settings.Default.Save(); return(path); }
protected void OnButtonFileChooserClicked(object sender, EventArgs e) { FileChooserDialog fc = new FileChooserDialog ("Укажите файл резервной копии", this, FileChooserAction.Save, "Отмена", ResponseType.Cancel, "Сохранить", ResponseType.Accept); fc.SetFilename (entryFileName.Text); fc.Show (); if (fc.Run () == (int)ResponseType.Accept) { entryFileName.Text = fc.Filename; } fc.Destroy (); }
protected void OnSaveAsActionActivated(object sender, EventArgs e) { if(DocTemplate == null) return; FileChooserDialog fc= new FileChooserDialog("Укажите файл для сохранения шаблона...", this, FileChooserAction.Save, "Отмена",ResponseType.Cancel, "Сохранить",ResponseType.Accept); //FileFilter filter = new FileFilter(); fc.CurrentName = DocTemplate.Name + ".xml"; fc.Show(); if(fc.Run() == (int) ResponseType.Accept) { fc.Hide(); FileStream fs = new FileStream(fc.Filename, FileMode.Create, FileAccess.Write); DocTemplate.SaveToStream(fs); fs.Close(); } fc.Destroy(); }
private void LoadFile(object sender, EventArgs e) { //show the file browser FileChooserDialog dialogBox = new FileChooserDialog ("Choose the file to open", this, FileChooserAction.Open, "Cancel",ResponseType.Cancel, "Open",ResponseType.Accept); dialogBox.Show (); if (dialogBox.Run() == (int)ResponseType.Accept) { Console.WriteLine ("accept response from dialog box"); //check to make sure the file is valid //if it is not notify the user to try again if (!FileParser.FileParser.ParseFileGrammar (dialogBox.Filename, true)) { Console.WriteLine ("bad file grammar"); InvalidFilePopup badFilePrompt = new InvalidFilePopup (); badFilePrompt.makeAppear (); } //else all is well else { Console.WriteLine ("We will repaint the home window with the" + "new data given."); parentWindow.Repaint (); } dialogBox.Destroy(); this.Destroy (); } }
protected void OnButtonSavePhotoClicked(object sender, EventArgs e) { FileChooserDialog fc = new FileChooserDialog ("Укажите файл для сохранения фотографии", (Window)this.Toplevel, FileChooserAction.Save, "Отмена", ResponseType.Cancel, "Сохранить", ResponseType.Accept); fc.CurrentName = (GetSaveFileName != null ? GetSaveFileName() : "фото") + ".jpg"; fc.Show (); if (fc.Run () == (int)ResponseType.Accept) { fc.Hide (); FileStream fs = new FileStream (fc.Filename, FileMode.Create, FileAccess.Write); fs.Write (ImageFile, 0, ImageFile.Length); fs.Close (); } fc.Destroy (); }
public DialogResult ShowDialog(IWin32Window owner) { var oldDirectory = Directory.GetCurrentDirectory(); try { m_dlg = CreateFileChooserDialog(); m_dlg.Show(); Gtk.Application.Run(); return DialogResult; } finally { if (RestoreDirectory) Directory.SetCurrentDirectory(oldDirectory); } }
private void btnRunClicked(object o, EventArgs args) { const string sampleText = "Lorem ipsum dolor sit amet"; string cmd = txtCommand.Text; if (cmd == "click button1") { button1.Activate(); } else if (cmd == "set textbox3 text") { textBox3.Buffer.Text = sampleText; } else if (cmd == "set textBox3 long text") { textBox3.Buffer.Text = "very very very very very very very very long text to enable the horizontal scroll bar"; } else if (cmd.StartsWith("set textbox3 to ")) { textBox3.Buffer.Text = cmd.Substring(16). Replace("\\n", "\n"). Replace("\\r", "\r"); } else if (cmd == "select textbox3") { if (textBox3.Buffer.Text.Length < 4) { textBox3.Buffer.Text = sampleText; } Gtk.TextIter startIter, endIter; textBox3.Buffer.GetSelectionBounds(out startIter, out endIter); int start, end; start = startIter.Offset; end = endIter.Offset; end = (end - start == 3? 4: 3); start = 0; startIter = textBox3.Buffer.GetIterAtOffset(start); endIter = textBox3.Buffer.GetIterAtOffset(end); textBox3.Buffer.MoveMark("selection_bound", startIter); textBox3.Buffer.MoveMark("insert", endIter); } else if (cmd == "add table row") { Gtk.TreeIter iter; iter = tableStore.AppendNode(); tableStore.SetValues(iter, "true", "Mallory", "40"); } else if (cmd == "add table column") { AddTreeViewColumn(treeView2, 3, "more"); } else if (cmd == "enable multiselect") { listView1.Selection.Mode = Gtk.SelectionMode.Multiple; } else if (cmd == "disable multiselect") { listView1.Selection.Mode = Gtk.SelectionMode.Single; } else if (cmd == "change button3 name") { button3.Accessible.Name = "xyzzy"; } else if (cmd == "change button3 helptext") { button3.Accessible.Description = "plugh"; } else if (cmd == "enable button3") { button3.Sensitive = true; } else if (cmd == "disable button3") { button3.Sensitive = false; } else if (cmd == "focus textBox3") { textBox3.GrabFocus(); } else if (cmd == "focus button2") { button2.GrabFocus(); } else if (cmd.StartsWith("change title:")) { window.Title = cmd.Substring(cmd.IndexOf(':') + 1); } else if (cmd == "open FileChooser" && chooser == null) { chooser = new Gtk.FileChooserDialog("FileChooser", window, FileChooserAction.Open, "data", 0); chooser.Show(); } else if (cmd == "close FileChooser" && chooser != null) { chooser.Destroy(); chooser = null; } }
protected void OnButtonSaveClicked(object sender, EventArgs e) { TreePath sel = iconviewFiles.SelectedItems [0]; TreeIter iter; FilesStore.GetIter (out iter, sel); FileChooserDialog fc = new FileChooserDialog ("Укажите путь для сохранения файла", (Gtk.Window)this.Toplevel, FileChooserAction.Save, "Отмена", ResponseType.Cancel, "Сохранить", ResponseType.Accept); fc.CurrentName = (string)FilesStore.GetValue (iter, (int)FilesCol.name); fc.Show (); if (fc.Run () == (int)ResponseType.Accept) { fc.Hide (); logger.Info ("Сохраняем файл на диск..."); byte[] file = (byte[])FilesStore.GetValue (iter, (int)FilesCol.file); if (file == null) { file = LoadFileFromDB ((int)FilesStore.GetValue (iter, (int)FilesCol.id)); } System.IO.File.WriteAllBytes (fc.Filename, file); } fc.Destroy (); logger.Info ("Ок"); }
void Save(System.Action after) { if (_lang == null) { return; } if (string.IsNullOrWhiteSpace(_lang.Filename)) { var sf = new FileChooserDialog("Save As", this, FileChooserAction.Save); sf.AddFilter(langFileFilter); sf.AddButton("Save", ResponseType.Accept); sf.AddButton("Cancel", ResponseType.Cancel); sf.Response += (o, args) => { switch (args.ResponseId) { case ResponseType.Yes: case ResponseType.Accept: case ResponseType.Apply: case ResponseType.Ok: _lang.Filename = sf.Filename; Save(after); break; default: break; } sf.Destroy(); }; sf.Show(); } else { if (string.IsNullOrWhiteSpace(_lang.Name)) { _lang.Name = System.IO.Path.GetFileNameWithoutExtension(_lang.Filename); } string json = JsonConvert.SerializeObject(_lang, Formatting.Indented); File.WriteAllText(_lang.Filename, json); _dirty = false; statusbar1.Push(0, string.Format("Saved as {0}", _lang.Filename)); if (after != null) { after(); } } }
protected void OnOpenActionActivated(object sender, EventArgs e) { SaveIfDirtyThen(() => { var fd = new FileChooserDialog("Open language", this, FileChooserAction.Open); fd.AddButton("Open", ResponseType.Accept); fd.AddButton("Cancel", ResponseType.Cancel); fd.AddFilter(langFileFilter); fd.Response += (o, args) => { var filename = fd.Filename; fd.Destroy(); if (args.ResponseId == ResponseType.Accept) { OpenLang(filename); } }; fd.Show(); }); }
private void btnRunClicked (object o, EventArgs args) { const string sampleText = "Lorem ipsum dolor sit amet"; string cmd = txtCommand.Text; if (cmd == "click button1") button1.Activate (); else if (cmd == "set textbox3 text") textBox3.Buffer.Text = sampleText; else if (cmd == "set textBox3 long text") textBox3.Buffer.Text = "very very very very very very very very long text to enable the horizontal scroll bar"; else if (cmd.StartsWith ("set textbox3 to ")) textBox3.Buffer.Text = cmd.Substring (16). Replace ("\\n", "\n"). Replace ("\\r", "\r"); else if (cmd == "select textbox3") { if (textBox3.Buffer.Text.Length < 4) textBox3.Buffer.Text = sampleText; Gtk.TextIter startIter, endIter; textBox3.Buffer.GetSelectionBounds (out startIter, out endIter); int start, end; start = startIter.Offset; end = endIter.Offset; end = (end-start == 3? 4: 3); start = 0; startIter = textBox3.Buffer.GetIterAtOffset (start); endIter = textBox3.Buffer.GetIterAtOffset (end); textBox3.Buffer.MoveMark ("selection_bound", startIter); textBox3.Buffer.MoveMark ("insert", endIter); } else if (cmd == "add table row") { Gtk.TreeIter iter; iter = tableStore.AppendNode (); tableStore.SetValues (iter, "true", "Mallory", "40"); } else if (cmd == "add table column") AddTreeViewColumn (treeView2, 3, "more"); else if (cmd == "enable multiselect") listView1.Selection.Mode = Gtk.SelectionMode.Multiple; else if (cmd == "disable multiselect") listView1.Selection.Mode = Gtk.SelectionMode.Single; else if (cmd == "change button3 name") button3.Accessible.Name = "xyzzy"; else if (cmd == "change button3 helptext") button3.Accessible.Description = "plugh"; else if (cmd == "enable button3") button3.Sensitive = true; else if (cmd == "disable button3") button3.Sensitive = false; else if (cmd == "focus textBox3") textBox3.GrabFocus (); else if (cmd == "focus button2") button2.GrabFocus (); else if (cmd.StartsWith ("change title:")) window.Title = cmd.Substring (cmd.IndexOf (':') + 1); else if (cmd == "open FileChooser" && chooser == null) { chooser = new Gtk.FileChooserDialog ("FileChooser", window, FileChooserAction.Open, "data", 0); chooser.Show (); } else if (cmd == "close FileChooser" && chooser != null) { chooser.Destroy (); chooser = null; } }
protected void OnBtnFileClicked(object sender, EventArgs e) { try { FileName = ""; if (RecordMode == true) { Gtk.FileChooserDialog filechooser = null; try { filechooser = new Gtk.FileChooserDialog("Choose the file to save", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept); } catch (Exception ex) { logger.Error(ex, "Choose receive File"); } AddFilters(ref filechooser); FileName = ""; string dir = ConfigurationManager.AppSettings["DataDirectory"]; if (!string.IsNullOrEmpty(dir) && Directory.Exists(dir)) { filechooser.SetCurrentFolder(dir); } filechooser.Show(); if (filechooser.Run() == (int)ResponseType.Accept) { FileName = filechooser.Filename; } filechooser.Destroy(); string FileOnly = System.IO.Path.GetFileName(FileName); string path = System.IO.Path.GetDirectoryName(FileName); string FileWithoutExt = System.IO.Path.GetFileNameWithoutExtension(FileName); string[] FileList = System.IO.Directory.GetFiles(path, FileWithoutExt + "*", System.IO.SearchOption.TopDirectoryOnly); bool Fexist = false; if (FileList.Length > 0) { Fexist = true; } if (Fexist) { MessageDialog msdSame = new MessageDialog(this, DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, "File Exists. Overwrite?"); msdSame.Title = "File Exists"; ResponseType tp = (Gtk.ResponseType)msdSame.Run(); msdSame.Destroy(); if (tp.ToString() == "No") { return; } } } else { Gtk.FileChooserDialog filechooser = null; try { filechooser = new Gtk.FileChooserDialog("Choose the file to transmit", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept); } catch (Exception ex) { logger.Error(ex, "Choose transmit File"); } AddFilters(ref filechooser); FileName = ""; string dir = ConfigurationManager.AppSettings["DataDirectory"]; if (!string.IsNullOrEmpty(dir) && Directory.Exists(dir)) { filechooser.SetCurrentFolder(dir); } filechooser.Show(); if (filechooser.Run() == (int)ResponseType.Accept) { FileName = filechooser.Filename; } filechooser.Destroy(); } txtFilename.Text = FileName; } catch (Exception ex) { logger.Error(ex, "Error while choosing file"); } }
/** * Wil open a file browser to locate a file on the system * */ private void OpenFileTree(object sender, EventArgs e) { bool openedSuccessfully = false; Console.WriteLine ("Opening a file tree"); //show the file browser dialogBox = new FileChooserDialog ("Choose the file to open", this, FileChooserAction.Open, "Cancel",ResponseType.Cancel, "Open",ResponseType.Accept); dialogBox.Show (); if (dialogBox.Run () == (int)ResponseType.Accept) { Console.WriteLine ("accept response from dialog box"); //check to make sure the file is valid //if it is not notify the user to try again if (!FileParser.FileParser.ParseFileGrammar (dialogBox.Filename, false)) { Console.WriteLine ("bad file grammar"); InvalidFilePopup badFilePrompt = new InvalidFilePopup (); badFilePrompt.makeAppear (); } //else all is well else { Console.WriteLine ("going to main window"); MainWindow homeScreen = new MainWindow (); homeScreen.makeAppear (); openedSuccessfully = true; } dialogBox.Destroy (); if (openedSuccessfully) this.Destroy (); } else dialogBox.Destroy (); }
protected void OnImagePopupSave(object sender, EventArgs Arg) { FileChooserDialog fc= new FileChooserDialog("Укажите файл для сохранения картинки", this, FileChooserAction.Save, "Отмена",ResponseType.Cancel, "Сохранить",ResponseType.Accept); //FileFilter filter = new FileFilter(); fc.CurrentName = DocInfo.TypeName + " " + entryNumber.Text + ".jpg"; fc.Show(); if(fc.Run() == (int) ResponseType.Accept) { fc.Hide(); foreach(DocumentImage img in Images) { if(img.id == PopupImageId) { FileStream fs = new FileStream(fc.Filename, FileMode.Create, FileAccess.Write); fs.Write(img.file, 0, (int)img.size); fs.Close(); } } } fc.Destroy(); }
protected void OnButtonPDFClicked(object sender, EventArgs e) { FileChooserDialog fc= new FileChooserDialog("Укажите файл для сохранения документа", this, FileChooserAction.Save, "Отмена",ResponseType.Cancel, "Сохранить",ResponseType.Accept); fc.CurrentName = DocInfo.TypeName + " " + entryNumber.Text + ".pdf"; fc.Show(); if(fc.Run() == (int) ResponseType.Accept) { fc.Hide(); iTextSharp.text.Document document = new iTextSharp.text.Document(); using (var stream = new FileStream(fc.Filename, FileMode.Create, FileAccess.Write, FileShare.None)) { iTextSharp.text.pdf.PdfWriter.GetInstance(document, stream); document.Open(); foreach(DocumentImage img in Images) { if(img.Image.Width > img.Image.Height) document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); else document.SetPageSize(iTextSharp.text.PageSize.A4); document.NewPage(); var image = iTextSharp.text.Image.GetInstance(img.file); image.SetAbsolutePosition(0,0); image.ScaleToFit(document.PageSize.Width, document.PageSize.Height); document.Add(image); } document.Close(); } } fc.Destroy(); }