コード例 #1
3
ファイル: Form1.cs プロジェクト: Prashant-Jonny/phever
        private void saveFileButton_Click(object sender, EventArgs e)
        {
            // Initialize
            detailsListView.Items.Clear();
            pictureBox1.Image = null;

            // Show a CommonSaveFileDialog with couple of file filters.
            // Also show some properties (specific to the filter selected) 
            // that the user can update from the dialog itself.
            CommonSaveFileDialog saveCFD = new CommonSaveFileDialog();
            saveCFD.AlwaysAppendDefaultExtension = true;
            saveCFD.DefaultExtension = ".docx";

            // When the file type changes, we will add the specific properties
            // to be collected from the dialog (refer to the saveCFD_FileTypeChanged event handler)
            saveCFD.FileTypeChanged += new EventHandler(saveCFD_FileTypeChanged);

            saveCFD.Filters.Add(new CommonFileDialogFilter("Word Documents", "*.docx"));
            saveCFD.Filters.Add(new CommonFileDialogFilter("JPEG Files", "*.jpg"));

            if (saveCFD.ShowDialog() == CommonFileDialogResult.OK)
            {
                // Get the selected file (this is what we'll save...)
                // Save it to disk, so we can read/write properties for it

                // Because we can't really create a Office file or Picture file, just copying
                // an existing file to show the properties
                if (saveCFD.SelectedFileTypeIndex == 1)
                    File.Copy(Path.Combine(Directory.GetCurrentDirectory(), "sample files\\test.docx"), saveCFD.FileName, true);
                else
                    File.Copy(Path.Combine(Directory.GetCurrentDirectory(), "sample files\\test.jpg"), saveCFD.FileName, true);

                // Get the ShellObject for this file
                ShellObject selectedSO = ShellFile.FromFilePath(saveCFD.FileName);

                // Get the properties from the dialog (user might have updated the properties)
                ShellPropertyCollection propColl = saveCFD.CollectedProperties;

                // Write the properties on our shell object
                using (ShellPropertyWriter propertyWriter = selectedSO.Properties.GetPropertyWriter())
                {
                    if (propColl.Contains(SystemProperties.System.Title))
                        propertyWriter.WriteProperty(SystemProperties.System.Title, propColl[SystemProperties.System.Title].ValueAsObject);

                    if (propColl.Contains(SystemProperties.System.Author))
                        propertyWriter.WriteProperty(SystemProperties.System.Author, propColl[SystemProperties.System.Author].ValueAsObject);

                    if (propColl.Contains(SystemProperties.System.Keywords))
                        propertyWriter.WriteProperty(SystemProperties.System.Keywords, propColl[SystemProperties.System.Keywords].ValueAsObject);

                    if (propColl.Contains(SystemProperties.System.Comment))
                        propertyWriter.WriteProperty(SystemProperties.System.Comment, propColl[SystemProperties.System.Comment].ValueAsObject);

                    if (propColl.Contains(SystemProperties.System.Category))
                        propertyWriter.WriteProperty(SystemProperties.System.Category, propColl[SystemProperties.System.Category].ValueAsObject);

                    if (propColl.Contains(SystemProperties.System.ContentStatus))
                        propertyWriter.WriteProperty(SystemProperties.System.Title, propColl[SystemProperties.System.Title].ValueAsObject);

                    if (propColl.Contains(SystemProperties.System.Photo.DateTaken))
                        propertyWriter.WriteProperty(SystemProperties.System.Photo.DateTaken, propColl[SystemProperties.System.Photo.DateTaken].ValueAsObject);

                    if (propColl.Contains(SystemProperties.System.Photo.CameraModel))
                        propertyWriter.WriteProperty(SystemProperties.System.Photo.CameraModel, propColl[SystemProperties.System.Photo.CameraModel].ValueAsObject);

                    if (propColl.Contains(SystemProperties.System.Rating))
                        propertyWriter.WriteProperty(SystemProperties.System.Rating, propColl[SystemProperties.System.Rating].ValueAsObject);
                }

                currentlySelected = selectedSO;
                DisplayProperties(selectedSO);

                showChildItemsButton.Enabled = selectedSO is ShellContainer ? true : false;
            }
        }
コード例 #2
1
ファイル: Form1.cs プロジェクト: Prashant-Jonny/phever
        private void PromptForSave()
        {
            if (Form1.CurrentFile.IsDirty)
            {
                // ask the user to save.
                DialogResult dr = MessageBox.Show(this, "Current document has changed. Would you like to save?", "Save current document", MessageBoxButtons.YesNoCancel);

                if (dr == DialogResult.Cancel)
                    return;
                else if (dr == DialogResult.No)
                {
                    // don't do anything
                }
                else if (dr == DialogResult.Yes)
                {
                    // Does the current file have a name?
                    if (string.IsNullOrEmpty(Form1.CurrentFile.Filename))
                    {
                        CommonSaveFileDialog saveAsCFD = new CommonSaveFileDialog();
                        saveAsCFD.Filters.Add(new CommonFileDialogFilter("Text files", ".txt"));

                        if (saveAsCFD.ShowDialog() == CommonFileDialogResult.OK)
                        {
                            Form1.CurrentFile.Save(saveAsCFD.FileName);
                            UpdateAppTitle();
                        }
                        else
                            return;
                    }
                    else
                    {
                        // just save it
                        Form1.CurrentFile.Save(CurrentFile.Filename);
                        UpdateAppTitle();
                    }
                }
            }
        }
コード例 #3
0
 private void b_CompressArchive_Click(object sender, RoutedEventArgs e)
 {
     var dialog = new CommonSaveFileDialog();
     dialog.Title = "Select where to save the archive";
     if (dialog.ShowDialog() == CommonFileDialogResult.OK)
         tb_CompressArchive.Text = dialog.FileName;
 }
コード例 #4
0
        private void btnSave_Click( object sender, RoutedEventArgs e )
        {
            CommonSaveFileDialog saveDialog = new CommonSaveFileDialog();
              saveDialog.ShowPlacesList = true;
              saveDialog.AddToMostRecentlyUsedList = true;
              saveDialog.Filters.Add( new CommonFileDialogFilter( "PNG images", "*.png" ) );
              saveDialog.DefaultFileName = DateTime.Now.ToString( "yyyyMMddhhmmss" ) + ".png";
              if ( saveDialog.ShowDialog( this ) == CommonFileDialogResult.Ok ) {
            using ( FileStream newFileStream = new FileStream( saveDialog.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite ),
              oldFileStream = new FileStream( soureFilePath, FileMode.Open, FileAccess.Read ) ) {
            string semanticInfo = @"
            sky: blue sky.
            heart: cloud heart.
            Meaning: It means love|爱|❤.
                ";

              ////// Reference: http://code.google.com/p/pngcs/wiki/Overview

              // get decoder
              pngReader = new PngReader( oldFileStream );
              // create encoder
              pngWriter = new PngWriter( newFileStream, pngReader.ImgInfo );
              // copy
              int chunkBehav = Hjg.Pngcs.Chunks.ChunkCopyBehaviour.COPY_ALL; // tell to copy all 'safe' chunks
              pngWriter.CopyChunksFirst( pngReader, chunkBehav );          // copy some metadata from reader
              int channels = pngReader.ImgInfo.Channels;
              if ( channels < 3 )
            throw new Exception( "This example works only with RGB/RGBA images" );
              for ( int row = 0; row < pngReader.ImgInfo.Rows; row++ ) {
            ImageLine l1 = pngReader.ReadRow( row ); // format: RGBRGB... or RGBARGBA...
            pngWriter.WriteRow( l1, row );
              }
              pngWriter.CopyChunksLast( pngReader, chunkBehav ); // metadata after the image pixels? can happen

              // app info
              pngWriter.GetMetadata().SetText( Hjg.Pngcs.Chunks.PngChunkTextVar.KEY_Software, "Semantic Image" );
              // semantic info
              Hjg.Pngcs.Chunks.PngChunk chunk = pngWriter.GetMetadata().SetText( Key_SemanticInfo, semanticInfo, false, false );
              chunk.Priority = true;

              pngWriter.End(); // dont forget this
              pngReader.End();

              oldFileStream.Close();
              newFileStream.Close();
            }
              }
        }
コード例 #5
0
		public bool Run (SelectFileDialogData data)
		{
			var parent = data.TransientFor ?? MessageService.RootWindow;

			CommonFileDialog dialog;
			if (data.Action == FileChooserAction.Open || data.Action == FileChooserAction.SelectFolder)
				dialog = new CustomCommonOpenFileDialog ();
			else
				dialog = new CommonSaveFileDialog ();

			SetCommonFormProperties (data, dialog);

			if (!GdkWin32.RunModalWin32Dialog (dialog, parent))
				return false;

			GetCommonFormProperties (data, dialog);

			return true;
		}
コード例 #6
0
        public static string GetPath(this CommonSaveFileDialog dialog)
        {
            var result = dialog.ShowDialog();

            if (result == CommonFileDialogResult.Ok)
            {
                var index      = dialog.SelectedFileTypeIndex - 1;
                var extensions = dialog.Filters[index].Extensions;
                var fileName   = dialog.FileName;
                foreach (var exe in extensions)
                {
                    if (Path.GetExtension(fileName).ToUpper() == $".{exe}".ToUpper())
                    {
                        return(fileName);
                    }
                }
                return($"{fileName}.{extensions[0]}");
            }
            return(null);
        }
コード例 #7
0
ファイル: UiPatcherPrepareButton.cs プロジェクト: kidaa/Pulse
        protected override async Task DoAction()
        {
            Label = PreparationLabel;
            try
            {
                string securityKey = await ((MainWindow)this.GetRootElement()).GetSecurityKeyAsync(false);
                if (CancelEvent.IsSet())
                    return;

                string root, targetPath;
                using (CommonOpenFileDialog dlg = new CommonOpenFileDialog("Выберите каталог..."))
                {
                    dlg.IsFolderPicker = true;
                    if (dlg.ShowDialog() != CommonFileDialogResult.Ok)
                        return;

                    root = dlg.FileName;
                    if (CancelEvent.IsSet())
                        return;
                }

                using (CommonSaveFileDialog dlg = new CommonSaveFileDialog("Сохранить как..."))
                {
                    dlg.DefaultFileName = "FF13TranslationAlpha.ecp";
                    if (dlg.ShowDialog() != CommonFileDialogResult.Ok)
                        return;

                    targetPath = dlg.FileName;
                    if (CancelEvent.IsSet())
                        return;
                }

                await Pack(root, securityKey, targetPath);

            }
            finally
            {
                Label = PrepareLabel;
            }
        }
コード例 #8
0
ファイル: FileService.cs プロジェクト: modulexcite/nvmsharp
        public Task<string> ShowSaveFileDialogAsync(string title, string defaultExtension, params Tuple<string, string>[] extensions)
        {
            var tcs = new TaskCompletionSource<string>();

            _dispatcherService.CurrentDispatcher.BeginInvoke(new Action(() =>
            {
                var result = string.Empty;

                // Create a CommonSaveFileDialog to select destination file
                var sfd = new CommonSaveFileDialog
                {
                    EnsureReadOnly = true,
                    EnsurePathExists = true,
                    DefaultExtension = defaultExtension,
                    Title = title ?? "Save File",
                };

                if ((extensions != null) && (extensions.Any()))
                {
                    foreach (var ext in extensions)
                    {
                        sfd.Filters.Add(new CommonFileDialogFilter(ext.Item1, ext.Item2));
                    }
                }

                if (sfd.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    ShellObject selectedObj = null;

                    try
                    {
                        // Try to get the selected item 
                        selectedObj = sfd.FileAsShellObject;
                    }
                    catch
                    {
                        //MessageBox.Show("Could not create a ShellObject from the selected item");
                    }

                    if (selectedObj != null)
                    {
                        // Get the file name
                        result = selectedObj.ParsingName;
                    }
                }

                tcs.SetResult(result);
            }));

            return tcs.Task;
        }
コード例 #9
0
        private void SetFileName(object sender, RoutedEventArgs e)
        {
            OutputFileRecord outFileRec = (OutputFileRecord)OutputFileNamesGrid.SelectedItem;
            if (outFileRec == null)
                return;

            CommonSaveFileDialog cofd = new CommonSaveFileDialog("Save as file name");
            cofd.InitialDirectory = System.IO.Path.GetDirectoryName(outFileRec.FileName);
            cofd.DefaultFileName = outFileRec.FileName;
            cofd.DefaultDirectory = System.IO.Path.GetDirectoryName(outFileRec.FileName);
            cofd.Filters.Add(new CommonFileDialogFilter("PDF File", ".pdf"));
            CommonFileDialogResult result = cofd.ShowDialog(this);
            if (result == CommonFileDialogResult.Ok)
            {
                outFileRec.FileName = cofd.FileName;
            }
        }
コード例 #10
0
        /// <summary>
        /// Executes the browse destination execute
        /// </summary>
        private void BrowseDestinationExecute()
        {
            var dlg = new CommonSaveFileDialog();
            dlg.Filters.Add(new CommonFileDialogFilter("XML file", "*.xml"));
            dlg.DefaultFileName = "Stringtable.xml";

            if (!string.IsNullOrWhiteSpace(this.SourcePath)) dlg.DefaultDirectory = this.SourcePath;

            if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
            {
                this.DestinationPath = dlg.FileName;
            }
        }
コード例 #11
0
        private bool PromptForSave()
        {
            if (!CurrentFile.IsDirty)
            {
                return true;
            }

            // ask the user to save.
            DialogResult dr = MessageBox.Show(this, "Current document has changed. Would you like to save?", "Save current document", MessageBoxButtons.YesNoCancel);

            if (dr == DialogResult.Cancel)
            {
                return false;
            }

            if (dr == DialogResult.Yes)
            {
                // Does the current file have a name?
                if (string.IsNullOrEmpty(Form1.CurrentFile.Filename))
                {
                    CommonSaveFileDialog saveAsCFD = new CommonSaveFileDialog();
                    saveAsCFD.Filters.Add(new CommonFileDialogFilter("Text files", ".txt"));
                    saveAsCFD.AlwaysAppendDefaultExtension = true;

                    if (saveAsCFD.ShowDialog() == CommonFileDialogResult.Ok)
                    {
                        Form1.CurrentFile.Save(saveAsCFD.FileName);
                        UpdateAppTitle();
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    // just save it
                    Form1.CurrentFile.Save(CurrentFile.Filename);
                    UpdateAppTitle();
                }
            }

            return true;
        }
コード例 #12
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Does the current file have a name?
            if (string.IsNullOrEmpty(Form1.CurrentFile.Filename))
            {
                CommonSaveFileDialog saveAsCFD = new CommonSaveFileDialog();
                saveAsCFD.Filters.Add(new CommonFileDialogFilter("Text files", ".txt"));

                if (saveAsCFD.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    Form1.CurrentFile.Save(saveAsCFD.FileName);
                    UpdateAppTitle();
                }
                else
                    return;
            }
            else
            {
                // just save it
                Form1.CurrentFile.Save(Form1.CurrentFile.Filename);
                UpdateAppTitle();
            }
        }
コード例 #13
0
 internal FileSaveModalDialog(Dispatcher dispatcher, Window parentWindow)
     : base(dispatcher, parentWindow)
 {
     Dialog = new CommonSaveFileDialog();
     Filters = new List<FileDialogFilter>();
 }
コード例 #14
0
ファイル: Dialogs.cs プロジェクト: logue/MabiPack
        public string OutputFile(string OutputFile = "")
        {
            string caption = Properties.Resources.ChooseUnpackFile;
            if (this.isVista)
            {
                CommonSaveFileDialog dOutputFile = new CommonSaveFileDialog();
                dOutputFile.Title = caption;
                dOutputFile.DefaultExtension = ".pack";
                dOutputFile.Filters.Add(new CommonFileDialogFilter(Properties.Resources.PackFileDesc, "*.pack"));
                dOutputFile.InitialDirectory = MabiDir + "\\Package\\";

                if (dOutputFile.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    OutputFile = dOutputFile.FileName;
                }
            }
            else
            {
                SaveFileDialog dOutputFile = new SaveFileDialog();
                dOutputFile.InitialDirectory = OutputFile;
                dOutputFile.Title = caption;
                dOutputFile.DefaultExt = ".pack";
                dOutputFile.Filter = Properties.Resources.PackFileDesc +  "|(*.pack)";
                if (dOutputFile.ShowDialog() == DialogResult.OK)
                {
                    OutputFile = dOutputFile.FileName;
                }

            }
            return OutputFile;
        }
コード例 #15
0
		public bool Run (OpenFileDialogData data)
		{
			var parent = data.TransientFor ?? MessageService.RootWindow;
			CommonFileDialog dialog;
			if (data.Action == FileChooserAction.Open)
				dialog = new CustomCommonOpenFileDialog ();
			else
				dialog = new CommonSaveFileDialog ();

			SelectFileDialogHandler.SetCommonFormProperties (data, dialog);

			CustomCommonFileDialogComboBox encodingCombo = null;
			if (data.ShowEncodingSelector) {
				var group = new CommonFileDialogGroupBox ("encoding", "Encoding:");
				encodingCombo = new CustomCommonFileDialogComboBox ();

				BuildEncodingsCombo (encodingCombo, data.Action != FileChooserAction.Save, data.Encoding);
				group.Items.Add (encodingCombo);
				dialog.Controls.Add (group);

				encodingCombo.SelectedIndexChanged += (sender, e) => {
					if (encodingCombo.SelectedIndex == encodingCombo.Items.Count - 1) {
						var dlg = new System.Windows.Window {
							Title = "Choose encodings",
							Content = new SelectEncodingControl(),
							SizeToContent = SizeToContent.WidthAndHeight
						};
						if (dlg.ShowDialog ().Value) {
							BuildEncodingsCombo (encodingCombo, data.Action != FileChooserAction.Save, data.Encoding);
							dialog.ApplyControlPropertyChange ("Items", encodingCombo);
						}
					}
				};
			}

			CustomCommonFileDialogComboBox viewerCombo = null;
			CommonFileDialogCheckBox closeSolution = null;
			if (data.ShowViewerSelector && data.Action == FileChooserAction.Open) {
				var group = new CommonFileDialogGroupBox ("openWith", "Open with:");

				viewerCombo = new CustomCommonFileDialogComboBox {
					Enabled = false
				};
				group.Items.Add (viewerCombo);
				dialog.Controls.Add (group);

				if (IdeApp.Workspace.IsOpen) {
					var group2 = new CommonFileDialogGroupBox ();

					// "Close current workspace" is too long and splits the text on 2 lines.
					closeSolution = new CommonFileDialogCheckBox ("Close workspace", true) {
						Visible = false
					};
					group2.Items.Add (closeSolution);
					dialog.Controls.Add (group2);
				}

				dialog.SelectionChanged += (sender, e) => {
					try {
						var files = GetSelectedItems (dialog);
						var file = files.Count == 0 ? null : files[0];
						bool hasBench = FillViewers (viewerCombo, file);
						if (closeSolution != null)
							closeSolution.Visible = hasBench;
						dialog.ApplyControlPropertyChange ("Items", viewerCombo);
					} catch (Exception ex) {
						LoggingService.LogError (e.ToString ());
					}
				};
			}

			if (!GdkWin32.RunModalWin32Dialog (dialog, parent))
				return false;

			SelectFileDialogHandler.GetCommonFormProperties (data, dialog);
			if (encodingCombo != null)
				data.Encoding = ((EncodingComboItem)encodingCombo.Items [encodingCombo.SelectedIndex]).Encoding;

			if (viewerCombo != null) {
				if (closeSolution != null)
					data.CloseCurrentWorkspace = closeSolution.Visible && closeSolution.IsChecked;
				data.SelectedViewer = ((ViewerComboItem)viewerCombo.Items [viewerCombo.SelectedIndex]).Viewer;
			}

			return true;
		}
コード例 #16
0
ファイル: Worker.cs プロジェクト: logue/MabiPack
        /// <summary>
        /// Unpacking file
        /// </summary>
        /// <param name="Res">PackResource </param>
        public bool UnpackFile(PackResource Res)
        {
            Console.WriteLine("Unpack");

            String InternalName = Res.GetName();
            CommonSaveFileDialog dSaveAs = new CommonSaveFileDialog();
            dSaveAs.DefaultFileName = Path.GetFileName(InternalName);
            if (dSaveAs.ShowDialog() == CommonFileDialogResult.Ok)
            {
                if (!isCLI)
                {
                    this.pd.ShowDialog(ProgressDialog.PROGDLG.Normal);
                    this.pd.Caption = Properties.Resources.Str_Unpack;
                }
                try
                {
                    // loading file content.
                    byte[] buffer = new byte[Res.GetSize()];
                    Res.GetData(buffer);
                    Res.Close();
                    // Delete old
                    if (File.Exists(dSaveAs.FileName))
                    {
                        File.Delete(dSaveAs.FileName);
                    }
                    // Write to file.
                    FileStream fs = new FileStream(dSaveAs.FileName, System.IO.FileMode.Create);
                    fs.Write(buffer, 0, buffer.Length);
                    fs.Close();
                    // Modify File time
                    File.SetCreationTime(dSaveAs.FileName, Res.GetCreated());
                    File.SetLastAccessTime(dSaveAs.FileName, Res.GetAccessed());
                    File.SetLastWriteTime(dSaveAs.FileName, Res.GetModified());
                }
                catch (Exception)
                {
                    return false;
                }
                finally
                {
                    Res.Close();
                    this.pd.CloseDialog();
                    Console.WriteLine("Finish.");
                }
                return true;
            }
            return false;
        }
コード例 #17
0
        /// <summary>
        /// Execute the save as command
        /// </summary>
        private void SaveAsCommandExecute()
        {
            if (this.Projects.Count != 1)
            {
                return;
            }

            var prjct = this.Projects[0];

            var dlg = new CommonSaveFileDialog { DefaultFileName = "Stringtable.xml" };

            if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
            {
                XmlDeSerializer.WriteXml(prjct, dlg.FileName);
            }
        }
コード例 #18
0
ファイル: SaveFileDialog.cs プロジェクト: ruche7/MMDLipTools
        /// <summary>
        /// ダイアログを表示する。
        /// </summary>
        /// <param name="owner">オーナーウィンドウ。</param>
        /// <returns>選択が行われたならば true 。そうでなければ false 。</returns>
        public override bool Show(Window owner = null)
        {
            if (CommonSaveFileDialog.IsPlatformSupported)
            {
                using (var dialog = new CommonSaveFileDialog())
                {
                    dialog.Title = this.Title;
                    dialog.DefaultDirectory = this.DefaultDirectory;
                    dialog.EnsureFileExists = this.IsFileExistsRequired;
                    dialog.EnsurePathExists = this.IsPathExistsRequired;
                    dialog.EnsureValidNames = this.IsValidNameRequired;
                    dialog.EnsureReadOnly = !this.IsWritableRequired;
                    this.Filters
                        .ConvertAll(
                            f =>
                                new CommonFileDialogFilter(
                                    f.Description,
                                    string.Join(";", f.Extensions))
                                {
                                    ShowExtensions = false,
                                })
                        .ForEach(f => dialog.Filters.Add(f));
                    if (this.FilterIndex >= 0 && this.FilterIndex < this.Filters.Count)
                    {
                        var exts = this.Filters[this.FilterIndex].Extensions;
                        if (exts.Count > 0)
                        {
                            dialog.DefaultExtension = exts[0];
                        }
                    }
                    dialog.AlwaysAppendDefaultExtension = this.IsExtensionAppended;
                    dialog.OverwritePrompt = this.IsOverwriteConfirmed;

                    if (dialog.ShowDialog(owner) != CommonFileDialogResult.Ok)
                    {
                        return false;
                    }

                    this.FileName = dialog.FileName;
                    this.DefaultDirectory = dialog.DefaultDirectory;
                    this.FilterIndex = dialog.SelectedFileTypeIndex - 1;
                }
            }
            else
            {
                var dialog = new Microsoft.Win32.SaveFileDialog();
                dialog.Title = this.Title;
                dialog.InitialDirectory = this.DefaultDirectory;
                dialog.CheckFileExists = this.IsFileExistsRequired;
                dialog.CheckPathExists = this.IsPathExistsRequired;
                dialog.ValidateNames = this.IsValidNameRequired;
                dialog.Filter =
                    (this.Filters == null) ?
                        "" :
                        string.Join(
                            "|",
                            this.Filters.ConvertAll(
                                f =>
                                    f.Description + "|" +
                                    ((f.Extensions.Count > 0) ?
                                        string.Join(
                                            ";",
                                            f.Extensions.ConvertAll(ext => "*." + ext)) :
                                        "*.*")));
                dialog.FilterIndex = Math.Max(0, this.FilterIndex + 1);
                dialog.AddExtension = this.IsExtensionAppended;
                dialog.OverwritePrompt = this.IsOverwriteConfirmed;

                if (dialog.ShowDialog(owner) != true)
                {
                    return false;
                }

                this.FileName = dialog.FileName;
                this.DefaultDirectory = dialog.InitialDirectory;
                this.FilterIndex = dialog.FilterIndex - 1;
            }

            return true;
        }
コード例 #19
0
 internal FileSaveModalDialog(IDispatcherService dispatcher)
     : base(dispatcher)
 {
     Dialog = new CommonSaveFileDialog();
     Filters = new List<FileDialogFilter>();
 }
コード例 #20
0
        private void OutputFileButton_Click( object sender, RoutedEventArgs e )
        {
            var dialog = new CommonSaveFileDialog
            {
                EnsureReadOnly = true,
                DefaultDirectory = "C:\\",
                DefaultFileName = "MergedPdf.pdf",
                Title = "Output File Name"
            };

            if ( dialog.ShowDialog() == CommonFileDialogResult.Ok )
            {
                OutputFileTextBox.Text = dialog.FileName;
            }
        }
コード例 #21
0
        private void SaveBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var saveDialog = new CommonSaveFileDialog()
            {
                DefaultExtension = "txt",
                DefaultFileName = "results",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
            };
            saveDialog.Filters.Add(new CommonFileDialogFilter("Text files", "*.txt"));
            saveDialog.Filters.Add(new CommonFileDialogFilter("All files", "*.*"));

            if (saveDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                var file = new StreamWriter(saveDialog.FileName);
                foreach (var item in _searcher.Results.Keys)
                {
                    file.WriteLine(item);
                    foreach (var occurrence in _searcher.ResultsContent[item])
                        file.WriteLine("\tLine " + occurrence.Key + ": " + occurrence.Value);
                    file.WriteLine();
                }
                file.Flush();
                file.Close();
            }
        }
コード例 #22
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CommonSaveFileDialog dialog = new CommonSaveFileDialog();
            dialog.Title = "Select where to save your file";
            dialog.Filters.Add(new CommonFileDialogFilter("Text files (*.txt)", "*.txt"));

            CommonFileDialogResult result = dialog.ShowDialog();

            if (result == CommonFileDialogResult.Ok)
                ReportUsage(dialog.FileName);
        }
コード例 #23
0
ファイル: BrowseControl.xaml.cs プロジェクト: markovcd/Mapper
        private CommonFileDialog CreateFileDialog()
        {
            var isDirectory = BrowseStyle.HasFlag(BrowseStyle.Directory);
            var isSave = BrowseStyle.HasFlag(BrowseStyle.Save);
            var isOpen = BrowseStyle.HasFlag(BrowseStyle.Open);

            if (isSave && isDirectory) throw new InvalidOperationException();
            CommonFileDialog d = null;

            if (isSave) d = new CommonSaveFileDialog
            {
                EnsureValidNames = true,
                AlwaysAppendDefaultExtension = true,
                DefaultExtension = DefaultExtension
            };
            if (isOpen) d = new CommonOpenFileDialog
            {
                IsFolderPicker = isDirectory,
                EnsureFileExists = true
            };

            if (d == null) throw new InvalidOperationException();

            d.Title = Title;
            d.NavigateToShortcut = true;
            d.ShowPlacesList = true;

            if (!isDirectory)
                foreach (var f in ParseFilters()) d.Filters.Add(f);

            return d;
        }
コード例 #24
0
        /// <summary>
        /// Execute the save command
        /// </summary>
        private void SaveCommandExecute()
        {
            var dlg = new CommonSaveFileDialog { DefaultFileName = "DocForgeSettings1.xml" };

            if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
            {
                var settings = new Settings();
                settings.Save(this, dlg.FileName);
            }
        }
コード例 #25
0
        public NewWindow()
        {
            InitializeComponent();
            ResourceService.CultureChanged += OnCultureChanged;

            foreach (var subview in ModuleHost.Instance.SubViews)
            {
                AddOrShowView(subview, false);
                var menuitem = new MenuItem
                {
                    Header = subview.GetTitle(ResourceService.CurrentCulture)
                };
                menuitem.Click += (_, __) => AddOrShowView(subview, true);
                ResourceService.CultureChanged += (_, e) => menuitem.Header = subview.GetTitle(e.NewValue);
                subviews.Items.Add(menuitem);
            }

            foreach (var subwindow in ModuleHost.Instance.SubWindows)
            {
                var menuitem = new MenuItem
                {
                    Header = subwindow.GetTitle(ResourceService.CurrentCulture)
                };
                var closure = new SubWindowClosure(menuitem, subwindow);
                menuitem.Click += closure.Click;
                ResourceService.CultureChanged += closure.OnCultureChanged;
                switch (subwindow.Category)
                {
                    case SubWindowCategory.Overview:
                        subwindowOverview.Items.Add(menuitem);
                        break;
                    case SubWindowCategory.Statistics:
                        subwindowStatistics.Items.Add(menuitem);
                        break;
                    case SubWindowCategory.Information:
                        subwindowInformation.Items.Add(menuitem);
                        break;
                }
            }

            ResourceService.CultureChanged += (_, __) => viewList[nameof(GameHost)].Title = StringTable.Browser;

            DockCommands = new Config.CommandSet
            {
                Save = new DelegateCommand(() => TrySaveLayout()),
                Load = new DelegateCommand(() => TryLoadLayout()),
                SaveAs = new DelegateCommand(() =>
                {
                    using (var filedialog = new CommonSaveFileDialog())
                    {
                        filedialog.InitialDirectory = Environment.CurrentDirectory;
                        filedialog.DefaultFileName = "config.xml";
                        filedialog.Filters.Add(new CommonFileDialogFilter("Xml Files", "*.xml"));
                        filedialog.Filters.Add(new CommonFileDialogFilter("All Files", "*"));
                        if (filedialog.ShowDialog() == CommonFileDialogResult.Ok)
                            TrySaveLayout(filedialog.FileName);
                    }
                }),
                LoadFrom = new DelegateCommand(() =>
                {
                    using (var filedialog = new CommonOpenFileDialog())
                    {
                        filedialog.InitialDirectory = Environment.CurrentDirectory;
                        filedialog.Filters.Add(new CommonFileDialogFilter("Xml Files", "*.xml"));
                        filedialog.Filters.Add(new CommonFileDialogFilter("All Files", "*"));
                        if (filedialog.ShowDialog() == CommonFileDialogResult.Ok)
                            TryLoadLayout(filedialog.FileName);
                    }
                })
            };
        }
コード例 #26
0
ファイル: MainWindow.xaml.cs プロジェクト: ppotapenko/Concat
        private void ButtonGetResult_Click(object sender, RoutedEventArgs e)
        {
            var dirPath = TextBoxDirPath.Text;
            if (string.IsNullOrWhiteSpace(dirPath))
            {
                MessageBox.Show(string.Format("Поле директория не может быть пустым"));
            }
            else if (!Directory.Exists(dirPath))
            {
                MessageBox.Show(string.Format("Директория не существует! Проверте указанный путь: \"{0}\"", dirPath));
            }
            else
            {
                try
                {
                    var dialog = new CommonSaveFileDialog
                    {
                        InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                        DefaultFileName = new DirectoryInfo(dirPath).Name,
                        AlwaysAppendDefaultExtension = true,
                        DefaultExtension = "txt"
                    };
                    dialog.AlwaysAppendDefaultExtension = true;
                    dialog.Filters.Add(CommonFileDialogStandardFilters.TextFiles);
                    var result = dialog.ShowDialog();
                    if (result == CommonFileDialogResult.Ok)
                    {
                        var ignoreFolders =
                            TextBoxIgnoreFolders.Text
                                .Trim()
                                .Replace("\r", String.Empty)
                                .Replace("\n", String.Empty)
                                .Replace(" ", String.Empty)
                                .TrimEnd(';')
                                .Split(';')
                                .ToList();

                        var globalIgnoreFolders =
                            TextBoxGlobalIgnorFolders.Text
                                .Trim()
                                .Replace("\r", String.Empty)
                                .Replace("\n", String.Empty)
                                .Replace(" ", String.Empty)
                                .TrimEnd(',')
                                .Split(',')
                                .ToList();

                        var fileCounter = new FileCounter(dirPath, TextBoxFilterExt.Text, ignoreFolders,
                            globalIgnoreFolders);
                        var progressWindow = new ProgressWindow(fileCounter, dialog.FileName, TextBoxFileTitle.Text)
                        {
                            ButtonStart = {Visibility = Visibility.Hidden}
                        };

                        //runs the progress operation upon window load
                        progressWindow.ShowDialog();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Произошла ошибка!\r\n{0}", ex.Message));
                }
            }
        }
コード例 #27
0
        private void ConvertToXlsx()
        {
            var dlg = new CommonSaveFileDialog();
            dlg.EnsureReadOnly = false;
            dlg.Filters.Add(new CommonFileDialogFilter("xlsx files", "*.xlsx"));
            dlg.DefaultExtension = ".xlsx";
            dlg.AlwaysAppendDefaultExtension = true;    // 必ずデフォルトの拡張子をつけるように制限

            var result = dlg.ShowDialog();
            if (result != CommonFileDialogResult.Ok)
            {
                return;
            }

            var path = dlg.FileName;

            // コンバーターを作り、変換する
            var srcConverter = new JsonConverter();
            var data = srcConverter.Read(this.SourcePath);


            var converter = new ExcelConverter();
            converter.Write(data, path);
        }