Пример #1
0
 private void OnBrowseForFilePath(object sender, RoutedEventArgs e)
 {
     Microsoft.Win32.FileDialog filePathBrowser = (Microsoft.Win32.FileDialog)Resources["mFilePathBrowser"];
     filePathBrowser.InitialDirectory = mFilePathBox.Text;
     filePathBrowser.FileName         = "[Filename will be ignored]";
     if (filePathBrowser.ShowDialog(this).GetValueOrDefault())
     {
         mFilePathBox.Text = System.IO.Path.GetDirectoryName(filePathBrowser.FileName);
     }
 }
        private void btnFileDlg_Click(object sender, RoutedEventArgs e)
        {
            resetGUI(true);
            fileDlg = new Microsoft.Win32.OpenFileDialog();

            fileDlg.InitialDirectory = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"My Games\Rocket League\TAGame\Demos\");
            fileDlg.Filter = "RL-Replay Files (*.replay)|*.replay";
            if(fileDlg.ShowDialog() == true) {
                txtBoxFileName.Text = System.IO.Path.GetFileName(fileDlg.FileName);
                lblCreatedAt.Content = File.GetLastWriteTime(fileDlg.FileName).ToString();
            }
        }
Пример #3
0
        private void setFileDialogBox(object path)
        {
            // Ustawienie danych okna dialogowego
            fileDialog.Title       = Caption;
            fileDialog.Filter      = Filter;
            fileDialog.FilterIndex = FilterIndex;
            fileDialog.DefaultExt  = DefaultExtension;

            // Ścieżka do pliku
            string fileToPath = "";

            if (FilePath != null)
            {
                fileToPath = FilePath;
            }
            else
            {
                FilePath = "";
            }

            if (path != null)
            {
                fileToPath = (string)path;
            }

            if (!string.IsNullOrWhiteSpace(fileToPath))
            {
                // Katalog początkowy
                fileDialog.InitialDirectory =
                    System.IO.Path.GetDirectoryName(fileToPath);
                // Nazwa pliku
                fileDialog.FileName = System.IO.Path.GetFileName(fileToPath);
            }

            // Odpowiedź okna dialogowego
            FileDialogResult = fileDialog.ShowDialog();
            OnPropertyChanged("FileDialogResult");
            if (FileDialogResult.HasValue && FileDialogResult.Value)
            {
                FilePath = fileDialog.FileName;
                OnPropertyChanged("FilePath");
                object commandParameter = CommandParameter;
                // Jeśli parametr jest null, to ustalamy go jako ścieżka do pliku
                if (commandParameter == null)
                {
                    commandParameter = FilePath;
                }
                // Uruchamiamy polecenie CommandFileOk,
                // a jako parametr przekazujemy (domyślnie!) ściężkę do pliku
                executeCommand(CommandFileOk, commandParameter);
            }
        }
Пример #4
0
        private static bool TryGetFileName([NotNull] FileDialog dialog, out string file)
        {
            var result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                file = dialog.FileName;
                return(true);
            }

            file = null;
            return(false);
        }
Пример #5
0
        private void btnFileDlg_Click(object sender, RoutedEventArgs e)
        {
            resetGUI(true);
            fileDlg = new Microsoft.Win32.OpenFileDialog();

            fileDlg.InitialDirectory = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"My Games\Rocket League\TAGame\Demos\");
            fileDlg.Filter           = "RL-Replay Files (*.replay)|*.replay";
            if (fileDlg.ShowDialog() == true)
            {
                txtBoxFileName.Text  = System.IO.Path.GetFileName(fileDlg.FileName);
                lblCreatedAt.Content = File.GetLastWriteTime(fileDlg.FileName).ToString();
            }
        }
Пример #6
0
 public void PokazSaveDialog(string fileFilter)
 {
     fileDialog        = new Microsoft.Win32.SaveFileDialog();
     fileDialog.Filter = fileFilter;
     if (fileDialog.ShowDialog() == true)
     {
         List <string> adresyMailowe = new List <string>();
         foreach (var adres in ViewModels.Adres.ListaAdresow)
         {
             adresyMailowe.Add((adres.AdresMailowy).ToString());
             System.IO.File.WriteAllLines(fileDialog.FileName, adresyMailowe.ToArray());
         }
     }
 }
Пример #7
0
        private static string GetFileDialog(string initialDirectory = null, string fileName = null,
                                            string defaultExt       = null, string filter   = null, bool isOpenFile = true)
        {
            Microsoft.Win32.FileDialog dlg = isOpenFile
                ? new Microsoft.Win32.OpenFileDialog() as Microsoft.Win32.FileDialog
                : new Microsoft.Win32.SaveFileDialog() as Microsoft.Win32.FileDialog
            ;

            dlg.InitialDirectory = initialDirectory ?? CaminhoPadrao.GetPathSubPasta();
            dlg.FileName         = fileName ?? "Arquivo";                // Default file name
            dlg.DefaultExt       = defaultExt ?? ".txt";                 // Default file extension
            dlg.Filter           = filter ?? "Arquivo TXT (.txt)|*.txt"; // Filter files by extension

            return(dlg.ShowDialog() ?? false ? dlg.FileName : null);
        }
Пример #8
0
        public FileDialogBox()
        {
            execute = o =>
            {
                fileDialog.Title       = Caption;
                fileDialog.Filter      = Filter;
                fileDialog.FilterIndex = FilterIndex;
                fileDialog.DefaultExt  = DefaultExtension;

                string filePath = string.Empty;
                if (FilePath != null)
                {
                    filePath = FilePath;
                }
                else
                {
                    FilePath = string.Empty;
                }
                if (o != null)
                {
                    filePath = (string)o;
                }
                if (!string.IsNullOrWhiteSpace(filePath))
                {
                    fileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(filePath);
                    fileDialog.FileName         = System.IO.Path.GetFileName(filePath);
                }
                FileDialogResult = fileDialog.ShowDialog();
                NotifyPropertyChanged(nameof(FileDialogResult));
                if (FileDialogResult.HasValue && FileDialogResult.Value)
                {
                    FilePath = fileDialog.FileName;
                    NotifyPropertyChanged(nameof(FilePath));
                    object commandParameter = CommandParameter;
                    if (commandParameter == null)
                    {
                        commandParameter = FilePath;
                    }
                    if (CommandFileOk != null)
                    {
                        if (CommandFileOk.CanExecute(commandParameter))
                        {
                            CommandFileOk.Execute(commandParameter);
                        }
                    }
                }
            };
        }
Пример #9
0
        /// <summary>
        /// Displays given dialog and returns its result as a <c>string</c>.
        /// </summary>
        /// <param name="dialog">The dialog to show.</param>
        /// <param name="filter">File type filter string.</param>
        /// <returns>Path to selected file, or <c>null</c> if no file was selected.</returns>
        private static string ShowDialog(FileDialog dialog, string filter)
        {
            string fileName = null;

            dialog.Filter           = filter;
            dialog.RestoreDirectory = true;

            bool?result = dialog.ShowDialog();

            if (result == true)
            {
                fileName = dialog.FileName;
            }

            return(fileName);
        }
Пример #10
0
 public void PokazOpenDialog(string fileFilter)
 {
     fileDialog        = new Microsoft.Win32.OpenFileDialog(); //utworzenie instancji klasy OpenFileDialog
     fileDialog.Filter = fileFilter;
     if (fileDialog.ShowDialog() == true)
     {
         string     tekst      = "";
         FileStream fileStream = new FileStream(fileDialog.FileName,
                                                FileMode.Open);
         StreamReader streamReader = new StreamReader(fileStream, Encoding.Default);
         while ((tekst = streamReader.ReadLine()) != null)
         {
             ViewModels.Adres.ListaAdresow.Add(new AdresViewModel(tekst, true, false, true));
         }
         fileStream.Close();
     }
 }
Пример #11
0
        public void ZalacznikOpenDialog()
        {
            fileDialog = new Microsoft.Win32.OpenFileDialog(); //utworzenie instancji klasy OpenFileDialog
            if (fileDialog.ShowDialog() == true)
            {
                string nazwa = "";
                string adres = "";

                FileStream fileStream = new FileStream(fileDialog.FileName,
                                                       FileMode.Open);
                StreamReader streamReader = new StreamReader(fileStream, Encoding.Default);
                nazwa = fileDialog.SafeFileName; ///do zmiany
                adres = fileDialog.FileName;

                ViewModels.MainViewModel.ListaZalacznikow.Add(new ZalacznikViewModel(nazwa, adres));
                fileStream.Close();
            }
        }
Пример #12
0
    /// <summary>
    /// Open this file dialog on top of all other windows
    /// </summary>
    /// <param name="fileDialog"></param>
    /// <returns></returns>
    public static bool?Show(Microsoft.Win32.FileDialog fileDialog)
    {
        Window win = new Window();

        win.ResizeMode  = System.Windows.ResizeMode.NoResize;
        win.WindowStyle = System.Windows.WindowStyle.None;
        win.Topmost     = true;
        win.Visibility  = System.Windows.Visibility.Hidden;
        win.Content     = fileDialog;
        bool?result = false;

        win.Loaded += (s, e) =>
        {
            result = fileDialog.ShowDialog();
        };
        win.ShowDialog();
        return(result);
    }
Пример #13
0
        protected FileDialogBox()
        {
            execute =
                argument =>
            {
                fileDialog.Title       = Caption;
                fileDialog.Filter      = Filter;
                fileDialog.FilterIndex = FilterIndex;
                fileDialog.DefaultExt  = DefaultExt;

                string path = "";
                if (FilePath != null)
                {
                    path = FilePath;
                }
                else
                {
                    FilePath = "";
                }
                if (argument != null)
                {
                    path = (string)argument;
                }

                if (!string.IsNullOrWhiteSpace(path))
                {
                    fileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(path);
                    fileDialog.FileName         = System.IO.Path.GetFileName(path);
                }

                FileDialogResult = fileDialog.ShowDialog();
                OnPropertyChanged("FileDialogResult");

                if (FileDialogResult.HasValue && FileDialogResult.Value)
                {
                    FilePath = fileDialog.FileName;
                    OnPropertyChanged("FilePath");
                    ExecuteCommand(CommandFileOK, CommandParameter);
                }
                ;
            };
        }
Пример #14
0
 protected Microsoft.Win32.FileDialog fileDialog = null; //wyzerowanie(?) ustawień dialogu
 protected FileDialogBox()                               //protected nie zezwala na dostęp z zewnątrz klasy
 {
     execute =                                           //definiuje metodę wezwaną, gdy komenda jest przywołana
               o =>                                      //parametr "o" wyrażenia lambda
     {
         fileDialog.Title       = Caption;               //z własności klasy, tytuł okna dialogowego, przekazany z widoku
         fileDialog.Filter      = Filter;                //przekazany z widoku
         fileDialog.FilterIndex = FilterIndex;           //przekazany z widoku
         fileDialog.DefaultExt  = DefaultExt;            //przekazany z widoku
         string ścieżkaPliku = "";                       //pusta ścieżka
         if (FilePath != null)
         {
             ścieżkaPliku = FilePath;
         }
         else
         {
             FilePath = "";                                                 //jeśli pusta ścieżka
         }
         if (o != null)
         {
             ścieżkaPliku = (string)o;                 //jeśli "o" różne od 0, to ścieżka jest stringiem z parametru "o"
         }
         if (!string.IsNullOrWhiteSpace(ścieżkaPliku)) //jeśli ścieżka pliku nie jest równa zero, to...
         {
             fileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(ścieżkaPliku);
             fileDialog.FileName         = System.IO.Path.GetFileName(ścieżkaPliku);
         }
         FileDialogResult = fileDialog.ShowDialog();
         OnPropertyChanged("FileDialogResult");
         if (FileDialogResult.HasValue && FileDialogResult.Value)
         {
             FilePath = fileDialog.FileName;
             OnPropertyChanged("FilePath");
             ExecuteCommand(CommandFileOk, FilePath);
         }
         ;
     };
 }
Пример #15
0
        private static void HandleFileDialog(IFileDialogInfo fileDialogInfo, FileDialog fileDialog)
        {
            fileDialog.AddExtension     = fileDialogInfo.AddExtension;
            fileDialog.CheckFileExists  = fileDialogInfo.CheckFileExists;
            fileDialog.CheckPathExists  = fileDialogInfo.CheckPathExists;
            fileDialog.CustomPlaces     = fileDialogInfo.CustomPlaces;
            fileDialog.DefaultExt       = fileDialogInfo.DefaultExt;
            fileDialog.DereferenceLinks = fileDialogInfo.DerefenenceLinks;
            fileDialog.Filter           = fileDialogInfo.Filter;
            fileDialog.FilterIndex      = fileDialogInfo.FilterIndex;
            fileDialog.InitialDirectory = fileDialogInfo.InitialDirectory;
            fileDialog.Title            = fileDialogInfo.Title;
            fileDialog.ValidateNames    = fileDialogInfo.ValidateNames;

            fileDialogInfo.Confirmed = fileDialog.ShowDialog() == true;

            if (!fileDialogInfo.Confirmed)
            {
                return;
            }

            fileDialogInfo.FileName  = fileDialog.FileName;
            fileDialogInfo.FileNames = fileDialog.FileNames;
        }
Пример #16
0
        static public string GetFileName(this Microsoft.Win32.FileDialog dialog)
        {
            bool?result = dialog.ShowDialog();

            return(result.HasValue && result.Value ? dialog.FileName : (string)null);
        }