private bool SaveAsProject() { using (var dialog = new SaveFileDialog()) { if (!string.IsNullOrEmpty(Project.Current.FileName)) { dialog.FileName = Project.Current.FileName; } else { dialog.InitialDirectory = PathHelper.SafeGetDirectoryName(Settings.LastProjectFileName); } dialog.Filter = string.Format("{0}|All Files|*.*||", Project.FilterString); if (dialog.ShowDialog() == DialogResult.OK) { Settings.LastProjectFileName = dialog.FileName; Project.Current.FileName = dialog.FileName; if (Project.Current.Save()) { Settings.RecentProjects.Add(Project.Current.FileName); return(true); } } } return(false); }
private bool ExportCode <T>(ref string lastExportFileName) where T : CodeExporter, new() { using (var exporter = new T()) { using (var dialog = new SaveFileDialog()) { // compose filter string for file dialog var filterString = string.Empty; var filters = exporter.FileDialogFilters; foreach (var filter in filters) { if (!string.IsNullOrEmpty(filterString)) { filterString += "|"; } filterString += string.Format("{0}|*{1}", filter.Key, filter.Value); } if (!string.IsNullOrEmpty(filterString)) { filterString += "|"; } filterString += "All Files|*.*||"; dialog.Filter = filterString; // set default filter by extension var extension = PathHelper.SafeGetExtension(lastExportFileName); for (var filterIndex = 0; filterIndex < filters.Count; ++filterIndex) { if (StringComparer.InvariantCultureIgnoreCase.Compare(extension, filters[filterIndex].Value) == 0) { dialog.FilterIndex = filterIndex + 1; // 1 based index break; } } // show dialog dialog.Title = exporter.FileDialogTitle; dialog.InitialDirectory = PathHelper.SafeGetDirectoryName(lastExportFileName); if (dialog.ShowDialog() == DialogResult.OK) { try { // export source code exporter.Export(dialog.FileName); lastExportFileName = dialog.FileName; return(true); } catch (Exception ex) { MessageBox.Show(Program.MainForm, string.Format("There was a problem exporting the map:\n\n{0}", ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } return(false); }
private void BrowseButton_Click(object sender, EventArgs e) { using (var dialog = new OpenFileDialog()) { dialog.Filter = "All Files|*.*||"; dialog.Title = "Open Transcript"; dialog.FileName = m_textBox.Text; dialog.InitialDirectory = PathHelper.SafeGetDirectoryName(m_textBox.Text); if (dialog.ShowDialog() == DialogResult.OK) { m_textBox.Text = dialog.FileName; } } }
private void FileExportImageMenuItem_Click(object sender, EventArgs e) { using (var dialog = new SaveFileDialog()) { dialog.Filter = "PNG Images|*.png|JPEG Images|*.jpg|BMP Images|*.bmp|Enhanced Metafiles (EMF)|*.emf|All Files|*.*||"; dialog.Title = "Export Image"; dialog.DefaultExt = getExtensionForDefaultImageType(); dialog.InitialDirectory = PathHelper.SafeGetDirectoryName(Settings.LastExportImageFileName); if (dialog.ShowDialog() == DialogResult.OK) { Settings.LastExportImageFileName = Path.GetDirectoryName(dialog.FileName) + @"\"; saveImage(dialog.FileName); } } }
private string exportPDF() { var folder = PathHelper.SafeGetDirectoryName(Project.Current.FileName); var fileName = PathHelper.SafeGetFilenameWithoutExtension(Project.Current.FileName); var pdfFile = Path.Combine(folder, fileName + ".pdf"); try { savePDF(pdfFile); } catch (Exception) { return(string.Empty); } return(pdfFile); }
private void FileExportPDFMenuItem_Click(object sender, EventArgs e) { using (var dialog = new SaveFileDialog()) { dialog.Filter = "PDF Files|*.pdf|All Files|*.*||"; dialog.Title = "Export PDF"; dialog.InitialDirectory = PathHelper.SafeGetDirectoryName(Settings.LastExportImageFileName); if (dialog.ShowDialog() == DialogResult.OK) { try { savePDF(dialog.FileName); } catch (Exception ex) { MessageBox.Show(Program.MainForm, string.Format("There was a problem exporting the map:\n\n{0}", ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private string exportImage() { var folder = PathHelper.SafeGetDirectoryName(Project.Current.FileName); var fileName = PathHelper.SafeGetFilenameWithoutExtension(Project.Current.FileName); var extension = getExtensionForDefaultImageType(); var imageFile = Path.Combine(folder, fileName + extension); try { saveImage(imageFile); } catch (Exception) { return(string.Empty); } return(imageFile); }
private bool OpenProject() { if (!CheckLoseProject()) { return(false); } using (var dialog = new OpenFileDialog()) { dialog.InitialDirectory = PathHelper.SafeGetDirectoryName(Settings.LastProjectFileName); dialog.Filter = string.Format("{0}|All Files|*.*||", Project.FilterString); if (dialog.ShowDialog() == DialogResult.OK) { Settings.LastProjectFileName = dialog.FileName; return(OpenProject(dialog.FileName)); } } return(false); }
private void FileExportPDFMenuItem_Click(object sender, EventArgs e) { using (var dialog = new SaveFileDialog()) { dialog.Filter = "PDF Files|*.pdf|All Files|*.*||"; dialog.Title = "Export PDF"; dialog.InitialDirectory = PathHelper.SafeGetDirectoryName(Settings.LastExportImageFileName); if (dialog.ShowDialog() == DialogResult.OK) { try { Settings.LastExportImageFileName = dialog.FileName; var doc = new PdfDocument(); doc.Info.Title = Project.Current.Title; doc.Info.Author = Project.Current.Author; doc.Info.Creator = Application.ProductName; doc.Info.CreationDate = DateTime.Now; doc.Info.Subject = Project.Current.Description; var page = doc.AddPage(); var size = m_canvas.ComputeCanvasBounds(true).Size; page.Width = new XUnit(size.X); page.Height = new XUnit(size.Y); using (var graphics = XGraphics.FromPdfPage(page)) { m_canvas.Draw(graphics, true, size.X, size.Y); } doc.Save(dialog.FileName); } catch (Exception ex) { MessageBox.Show(Program.MainForm, string.Format("There was a problem exporting the map:\n\n{0}", ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void FileExportImageMenuItem_Click(object sender, EventArgs e) { using (var dialog = new SaveFileDialog()) { dialog.Filter = "PNG Images|*.png|JPEG Images|*.jpg|BMP Images|*.bmp|Enhanced Metafiles (EMF)|*.emf|All Files|*.*||"; dialog.Title = "Export Image"; dialog.InitialDirectory = PathHelper.SafeGetDirectoryName(Settings.LastExportImageFileName); if (dialog.ShowDialog() == DialogResult.OK) { Settings.LastExportImageFileName = dialog.InitialDirectory; var format = ImageFormat.Png; var ext = Path.GetExtension(dialog.FileName); if (StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".jpg") == 0 || StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".jpeg") == 0) { format = ImageFormat.Jpeg; } else if (StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".bmp") == 0) { format = ImageFormat.Bmp; } else if (StringComparer.InvariantCultureIgnoreCase.Compare(ext, ".emf") == 0) { format = ImageFormat.Emf; } var size = m_canvas.ComputeCanvasBounds(true).Size *m_canvas.ZoomFactor; size.X = Numeric.Clamp(size.X, 16, 8192); size.Y = Numeric.Clamp(size.Y, 16, 8192); try { if (format == ImageFormat.Emf) { // export as a metafile using (var nativeGraphics = Graphics.FromHwnd(m_canvas.Handle)) { using (var stream = new MemoryStream()) { try { var dc = nativeGraphics.GetHdc(); using (var metafile = new Metafile(stream, dc)) { using (var imageGraphics = Graphics.FromImage(metafile)) { using (var graphics = XGraphics.FromGraphics(imageGraphics, new XSize(size.X, size.Y))) { m_canvas.Draw(graphics, true, size.X, size.Y); } } var handle = metafile.GetHenhmetafile(); var copy = CopyEnhMetaFile(handle, dialog.FileName); DeleteEnhMetaFile(copy); } } finally { nativeGraphics.ReleaseHdc(); } } } } else { // export as an image using (var bitmap = new Bitmap((int)Math.Ceiling(size.X), (int)Math.Ceiling(size.Y))) { using (var imageGraphics = Graphics.FromImage(bitmap)) { using (var graphics = XGraphics.FromGraphics(imageGraphics, new XSize(size.X, size.Y))) { m_canvas.Draw(graphics, true, size.X, size.Y); } } bitmap.Save(dialog.FileName, format); } } } catch (Exception ex) { MessageBox.Show(Program.MainForm, string.Format("There was a problem exporting the map:\n\n{0}", ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }