예제 #1
0
        private static void Print(string fileName, string pdfPath)
        {
            var dialog = new CommonSaveFileDialog
            {
                Title            = Language.Current.Get("Dialog.Print.Title"),
                EnsurePathExists = true,
                DefaultExtension = "pdf",
                CreatePrompt     = true,
                DefaultFileName  = Path.GetFileNameWithoutExtension(fileName)
            };

            dialog.Filters.Add(new CommonFileDialogFilter("Portable Document Format", ".pdf"));

            if (dialog.ShowDialog(Application.Current.MainWindow) == CommonFileDialogResult.Ok)
            {
                try
                {
                    if (File.Exists(dialog.FileName))
                    {
                        File.Delete(dialog.FileName);
                    }
                    File.Copy(pdfPath, dialog.FileName);
                    AppViewModel.Instance.Messages.Success(Language.Current.Get("Message.File.Save.Success"));
                }
                catch
                {
                    AppViewModel.Instance.Messages.Error(Language.Current.Get("Message.File.Save.Error"));
                }
            }
            dialog.Dispose();
        }
        public override CommonFileDialog Create(ICommonSaveFileDialogSettings Settings)
        {
            CommonSaveFileDialog?Dialog = null;

            try
            {
                Dialog = new CommonSaveFileDialog
                {
                    AddToMostRecentlyUsedList    = Settings.AddToMostRecentlyUsedList,
                    AllowPropertyEditing         = Settings.AllowPropertyEditing,
                    AlwaysAppendDefaultExtension = Settings.AlwaysAppendDefaultExtension,
                    CreatePrompt       = Settings.CreatePrompt,
                    DefaultDirectory   = Settings.DefaultDirectory,
                    DefaultExtension   = Settings.DefaultExtension,
                    DefaultFileName    = Settings.DefaultFileName,
                    EnsureFileExists   = Settings.EnsureFileExists,
                    EnsurePathExists   = Settings.EnsurePathExists,
                    EnsureReadOnly     = Settings.EnsureReadOnly,
                    EnsureValidNames   = Settings.EnsureValidNames,
                    InitialDirectory   = Settings.InitialDirectory,
                    IsExpandedMode     = Settings.IsExpandedMode,
                    NavigateToShortcut = Settings.NavigateToShortcut,
                    OverwritePrompt    = Settings.OverwritePrompt,
                    ShowHiddenItems    = Settings.ShowHiddenItems,
                    Title = Settings.Title,
                };
                foreach (var(RowDisplayName, ExtensionsList) in Settings.Filters)
                {
                    Dialog.Filters.Add(new CommonFileDialogFilter(RowDisplayName, ExtensionsList));
                }
                return(Dialog);
            }
            catch (Exception)
            {
                if (Dialog is IDisposable)
                {
                    Dialog.Dispose();
                }
                throw;
            }
        }
예제 #3
0
        private void OnSaveFileDialogMessage(SaveFileDialogMessage message)
        {
            CommonSaveFileDialog csfd = new CommonSaveFileDialog
            {
                Title            = message.Title,
                EnsurePathExists = true,

                DefaultFileName  = message.DefaultFileName,
                DefaultExtension = message.DefaultFileExtension,
                EnsureValidNames = true
            };

            CommonFileDialogResult sResult = csfd.ShowDialog();

            csfd.Dispose();
            if (sResult == CommonFileDialogResult.Ok)
            {
                message.Callback?.Invoke(true, csfd.FileName);
            }
            else
            {
                message.Callback?.Invoke(false, null);
            }
        }
예제 #4
0
        private void Event1_1_Click(object sender, RoutedEventArgs e)
        {
            int    index = comboBox1.SelectedIndex;
            string newKey = null, directory = null;

            using (var sfd = new CommonSaveFileDialog())
            {
                sfd.Title            = Properties.Resources.Strings["ui_0:c_1_1"][0];
                sfd.InitialDirectory = conf.UserDirectory;
                sfd.DefaultFileName  = string.Format("configuration_{0}", conf.Configurations.Count);
                sfd.DefaultExtension = "config";
                sfd.Filters.Add(new CommonFileDialogFilter("Configuration Files", "*.config"));

                if (sfd.ShowDialog() == CommonFileDialogResult.Cancel)
                {
                    sfd.Dispose();
                    return;
                }

                newKey    = Path.GetFileNameWithoutExtension(sfd.FileName);
                directory = Path.GetDirectoryName(sfd.FileName);
                sfd.Dispose();
            }

            if (directory != conf.UserDirectory)
            {
                if (QueryOnSaveChanges())
                {
                    conf.UserDirectory = directory;
                    comboBox1.Items.Clear();
                }
                else
                {
                    return;
                }
            }

            Header header = new Header(newKey);

            header.PropertyChanged += Header_PropertyChanged;

            if (key1 != newKey)
            {
                key1 = newKey;

                conf.Configurations.Add(key1, header);
                conf.SetConfiguration(key1);

                comboBox1.Items.Add(key1);
                index = comboBox1.Items.Count - 1;
            }
            else
            {
                conf.Configurations[key1] = header;
                conf.SetConfiguration(key1);

                comboBox1.SelectedIndex = -1;
            }

            comboBox1.SelectedIndex = index;
        } // New configuration
예제 #5
0
        private void OnClickImageSave(object sender, EventArgs e)
        {
            if (imageListView.SelectedIndices.Count < 1)
            {
                MessageBox.Show(Resources.DialogSelectImage, Resources.DialogInfo);
                return;
            }

            CommonFileDialogCheckBox correctColorCb = new CommonFileDialogCheckBox("correctColorCb",
                                                                                   Resources.DialogCorrectColor, false);

            ImageFormat[] imageFormats =
            {
                ImageFormat.Png,
                ImageFormat.Jpeg
            };

            CommonSaveFileDialog fileDialog = new CommonSaveFileDialog(Resources.DialogSaveImage)
            {
                Filters =
                {
                    new CommonFileDialogFilter("PNG",  "*.png"),
                    new CommonFileDialogFilter("JPEG", "*.jpg;*.jpeg")
                },
                Controls =
                {
                    correctColorCb
                },
                RestoreDirectory = true
            };

            if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                string      filepath    = fileDialog.FileName;
                int         selected    = imageListView.SelectedIndices[0];
                byte[]      imageData   = originalImagesData[selected];
                ImageFormat saveFormat  = imageFormats[fileDialog.SelectedFileTypeIndex - 1];
                ImageFormat imageFormat = originalImageFormats[selected];

                if (!correctColorCb.IsChecked && saveFormat == imageFormat)
                {
                    File.WriteAllBytes(filepath, imageData);
                }
                else
                {
                    using (MemoryStream stream = new MemoryStream(imageData))
                    {
                        Image imageSave = Image.FromStream(stream);

                        if (correctColorCb.IsChecked)
                        {
                            ImageUtils.ReverseColorRB((Bitmap)imageSave);
                        }

                        imageSave.Save(filepath, saveFormat);
                        imageSave.Dispose();
                    }
                }
            }

            fileDialog.Dispose();
        }