Ejemplo n.º 1
0
 private void m_btnBrowse_Click(object sender, EventArgs e)
 {
     if (m_openFileDlg == null)
     {
         m_openFileDlg = new OpenFileDialogAdapter();
         m_openFileDlg.CheckFileExists  = true;
         m_openFileDlg.InitialDirectory = FwDirectoryFinder.DefaultBackupDirectory;
         m_openFileDlg.RestoreDirectory = true;
         m_openFileDlg.Title            = FwCoreDlgs.ksFindBackupFileDialogTitle;
         m_openFileDlg.ValidateNames    = true;
         m_openFileDlg.Multiselect      = false;
         m_openFileDlg.Filter           = ResourceHelper.BuildFileFilter(FileFilterType.FieldWorksAllBackupFiles,
                                                                         FileFilterType.XML);
     }
     if (m_openFileDlg.ShowDialog(this) == DialogResult.OK)
     {
         //In the presentation layer:
         //1) Verify that the file selected for restore is a valid FieldWorks backup file
         //and take appropriate action.
         //1a) if not then inform the user they need to select another file.
         //1b) if it is valid then we need to set the various other controls in this dialog to be active
         //and give the user the option of selecting things they can restore optionally. If something like SupportingFiles
         //was not included in the backup then we grey out that control and uncheck it.
         BackupZipFile = m_openFileDlg.FileName;
         m_openFileDlg.InitialDirectory = Path.GetDirectoryName(m_openFileDlg.FileName);
     }
 }
Ejemplo n.º 2
0
        protected override void OnLoad(EventArgs e)
        {
            var      menu = new MainMenu();
            MenuItem open = new MenuItem("Open", (s, a) =>
            {
                using (var dialog = new OpenFileDialogAdapter())
                {
                    dialog.InitialDirectory = "/tmp";
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        m_datafile = new FileInfo(dialog.FileName);
                        m_painted  = false;
                    }
                }
            });

            MenuItem refresh = new MenuItem("Refresh", (s, a) =>
            {
                m_painted = false;
                this.Invalidate();
            });

            base.OnLoad(e);

            menu.MenuItems.Add(open);
            menu.MenuItems.Add(refresh);
            Menu = menu;
        }
Ejemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void cmnuScanFile_Click(object sender, EventArgs e)
        {
            // Use an open file dialog to let the user specify a file to scan.
            m_openFileDialog.CheckFileExists = true;
            m_openFileDialog.Filter          = ResourceHelper.FileFilter(FileFilterType.AllFiles);

            if (m_openFileDialog.ShowDialog() == DialogResult.OK)
            {
                GetTokensSubStrings(m_openFileDialog.FileName);
            }
        }
Ejemplo n.º 4
0
        private void chooseDb4o_Click(object sender, EventArgs e)
        {
            Db4oFile.ShowDialog();
            db4o.Text = Db4oFile.FileName;
            if (Db4oFile.FileName != "")
            {
                string path = System.IO.Path.ChangeExtension(Db4oFile.FileName, ".fwdata");

                XmlFile.FileName = path;
                xml.Text         = path;
            }
        }
Ejemplo n.º 5
0
 private void btnChooseFiles_Click(object sender, System.EventArgs e)
 {
     using (var dlg = new OpenFileDialogAdapter())
     {
         dlg.Multiselect = true;
         dlg.Filter      = ResourceHelper.FileFilter(FileFilterType.Text);
         if (DialogResult.OK == dlg.ShowDialog(this))
         {
             tbFileNames.Lines = dlg.FileNames;
             m_paths           = dlg.FileNames;
         }
     }
 }
Ejemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Show the file chooser dialog for opening an image file.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private DialogResult ShowChoosePictureDlg()
        {
            DialogResult dialogResult = DialogResult.None;

            using (var dlg = new OpenFileDialogAdapter())
            {
                dlg.InitialDirectory = (m_grpFileLocOptions.Visible) ? m_txtDestination.Text :
                                       s_defaultPicturesFolder;
                dlg.Filter           = ResourceHelper.BuildFileFilter(FileFilterType.AllImage, FileFilterType.AllFiles);
                dlg.FilterIndex      = 1;
                dlg.Title            = FwCoreDlgs.kstidInsertPictureChooseFileCaption;
                dlg.RestoreDirectory = true;
                dlg.CheckFileExists  = true;
                dlg.CheckPathExists  = true;

                while (dialogResult != DialogResult.OK && dialogResult != DialogResult.Cancel)
                {
                    dialogResult = dlg.ShowDialog(m_app == null ? null : m_app.ActiveMainWindow);
                    if (dialogResult == DialogResult.OK)
                    {
                        string file = dlg.FileName;
                        if (String.IsNullOrEmpty(file))
                        {
                            return(DialogResult.Cancel);
                        }
                        Image image;
                        try
                        {
                            image = Image.FromFile(FileUtils.ActualFilePath(file));
                        }
                        catch (OutOfMemoryException)                         // unsupported image format
                        {
                            MessageBoxUtils.Show(FwCoreDlgs.kstidInsertPictureReadError,
                                                 FwCoreDlgs.kstidInsertPictureReadErrorCaption);
                            dialogResult = DialogResult.None;
                            continue;
                        }
                        m_filePath     = file;
                        m_currentImage = image;
                        UpdatePicInformation();
                        if (m_grpFileLocOptions.Visible)
                        {
                            ApplyDefaultFileLocationChoice();
                        }
                    }
                }
            }
            return(dialogResult);
        }
Ejemplo n.º 7
0
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK != openFileDialog1.ShowDialog())
            {
                return;
            }

            tbPath.Text = openFileDialog1.FileName;
            UpdateButtons();
            if (btnOK.Enabled)
            {
                m_mediator.PropertyTable.SetProperty(FilePropertyName, tbPath.Text);
                m_mediator.PropertyTable.SetPropertyPersistence(FilePropertyName, true);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Respond to Browse button by letting user pick a .zip file to import.
        /// </summary>
        public void OnBrowse()
        {
            using (var openDialog = new OpenFileDialogAdapter())
            {
                openDialog.Title            = xWorksStrings.kstidChooseFile;
                openDialog.Filter           = xWorksStrings.kstidZipFiles + "|*.zip";
                openDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                var result = openDialog.ShowDialog(_view);
                if (result != DialogResult.OK)
                {
                    return;
                }
                var importFilePath = openDialog.FileName;
                _view.importPathTextBox.Text = importFilePath;
            }
        }
Ejemplo n.º 9
0
 private void OpenFwDataProjectLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     // Use 'el cheapo' .Net dlg to find LangProj.
     using (var dlg = new OpenFileDialogAdapter())
     {
         Hide();
         dlg.CheckFileExists  = true;
         dlg.InitialDirectory = FwDirectoryFinder.ProjectsDirectory;
         dlg.RestoreDirectory = true;
         dlg.Title            = FwCoreDlgs.ksChooseLangProjectDialogTitle;
         dlg.ValidateNames    = true;
         dlg.Multiselect      = false;
         dlg.Filter           = ResourceHelper.FileFilter(FileFilterType.FieldWorksProjectFiles);
         DialogResult         = dlg.ShowDialog(Owner);
         Project = dlg.FileName;
     }
 }
Ejemplo n.º 10
0
        private void selectFileButton_Click(object sender, System.EventArgs e)
        {
            if (ofDlg.ShowDialog() == DialogResult.Cancel)
            {
                ofDlg.FileName = string.Empty;
            }
            else
            {
                txtInputFile.Text = ofDlg.FileName;
                toolTipInputFile.SetToolTip(txtInputFile, ofDlg.FileName);

                // the converter is used only to guess the input encoding. If the user hasn't
                // yet selected a mapping, just pass null.
//				IEncConverter converter = null;
//				if (m_mapname != null && m_mapname != "")
//					converter = (IEncConverter)m_encConverters[m_mapname];
                InputArgsChanged();
            }
        }
Ejemplo n.º 11
0
 private void m_btnBrowse_Click(object sender, EventArgs e)
 {
     using (var dlg = new OpenFileDialogAdapter())
     {
         dlg.DefaultExt      = "flextext";
         dlg.Filter          = ResourceHelper.BuildFileFilter(FileFilterType.FLExText, FileFilterType.XML, FileFilterType.AllFiles);
         dlg.FilterIndex     = 1;
         dlg.CheckFileExists = true;
         dlg.Multiselect     = false;
         if (!String.IsNullOrEmpty(m_tbFilename.Text) &&
             !String.IsNullOrEmpty(m_tbFilename.Text.Trim()))
         {
             dlg.FileName = m_tbFilename.Text;
         }
         DialogResult res = dlg.ShowDialog();
         if (res == DialogResult.OK)
         {
             m_tbFilename.Text = dlg.FileName;
         }
     }
 }
Ejemplo n.º 12
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void cmnuScanFile_Click(object sender, EventArgs e)
        {
            // Let the user specify a Paratext or Toolbox language file to scan.
            var languageFiles = ResourceHelper.GetResourceString("kstidToolboxLanguageFiles");
            var allFiles      = ResourceHelper.GetResourceString("kstidAllFiles");

            using (var openFileDialog = new OpenFileDialogAdapter
            {
                Title = FwCoreDlgs.kstidLanguageFileBrowser,
                InitialDirectory = ScriptureProvider.SettingsDirectory,
                CheckFileExists = true,
                Filter = FileUtils.FileDialogFilterCaseInsensitiveCombinations(
                    string.Format("{0} ({1})|{1}|{2} ({3})|{3}", languageFiles, "*.lds;*.lng", allFiles, "*.*"))
            })
            {
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    GetTokensSubStrings(openFileDialog.FileName);
                }
            }
        }
Ejemplo n.º 13
0
        private void btn_LinguaLinksXmlBrowse_Click(object sender, System.EventArgs e)
        {
            string currentFile = m_LinguaLinksXmlFileName.Text;

            openFileDialog.Filter          = ResourceHelper.BuildFileFilter(FileFilterType.XML, FileFilterType.AllFiles);
            openFileDialog.FilterIndex     = 1;
            openFileDialog.CheckFileExists = true;
            openFileDialog.Multiselect     = false;

            if (currentFile != null)
            {
                openFileDialog.InitialDirectory = currentFile;
                openFileDialog.FileName         = currentFile;
            }

            openFileDialog.Title = ITextStrings.ksSelectLLXMLFile;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                m_LinguaLinksXmlFileName.Text = openFileDialog.FileName;
                UpdateLanguageCodes();
            }
        }
        private string GetFile(string currentFile, string pathForInitialDirectory,
                               FileFilterType[] types, bool checkFileExists, string title, Func <string, bool> isValidFile)
        {
            using (var openFileDialog = new OpenFileDialogAdapter())
            {
                openFileDialog.Filter          = ResourceHelper.BuildFileFilter(types);
                openFileDialog.CheckFileExists = checkFileExists;
                openFileDialog.Multiselect     = false;

                bool done = false;
                while (!done)
                {
                    // LT-6620 : putting in an invalid path was causing an exception in the openFileDialog.ShowDialog()
                    // Now we make sure parts are valid before setting the values in the openfile dialog.
                    string dir = string.Empty;
                    try
                    {
                        dir = Path.GetDirectoryName(pathForInitialDirectory);
                    }
                    catch
                    {
                    }
                    if (Directory.Exists(dir))
                    {
                        openFileDialog.InitialDirectory = dir;
                    }
                    if (File.Exists(currentFile))
                    {
                        openFileDialog.FileName = currentFile;
                    }
                    else
                    {
                        openFileDialog.FileName = "";
                    }

                    openFileDialog.Title = title;
                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        if (!(isValidFile(openFileDialog.FileName)))
                        {
                            string msg = String.Format(ITextStrings.ksInvalidFileAreYouSure,
                                                       openFileDialog.FileName);
                            DialogResult dr = MessageBox.Show(this, msg,
                                                              ITextStrings.ksPossibleInvalidFile,
                                                              MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                            if (dr == DialogResult.Yes)
                            {
                                return(openFileDialog.FileName);
                            }
                            else if (dr == DialogResult.No)
                            {
                                continue;
                            }
                            else
                            {
                                break;                                          // exit with current still
                            }
                        }
                        return(openFileDialog.FileName);
                    }
                    else
                    {
                        done = true;
                    }
                }
                return(currentFile);
            }
        }
        private string GetFiles(string currentFiles)
        {
            using (var openFileDialog = new OpenFileDialogAdapter())
            {
                openFileDialog.Filter = ResourceHelper.BuildFileFilter(FileFilterType.InterlinearSfm,
                                                                       FileFilterType.AllFiles);
                openFileDialog.CheckFileExists = true;
                openFileDialog.Multiselect     = true;             // can import multiple files

                var    files           = currentFiles.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                string dir             = string.Empty;
                string initialFileName = string.Empty;
                openFileDialog.FileName = "";
                if (files.Length > 0)
                {
                    var firstFilePath = files[0].Trim();
                    // LT-6620 : putting in an invalid path was causing an exception in the openFileDialog.ShowDialog()
                    // Now we make sure parts are valid before setting the values in the openfile dialog.
                    try
                    {
                        dir = Path.GetDirectoryName(firstFilePath);
                        if (File.Exists(firstFilePath))
                        {
                            initialFileName = Path.GetFileName(firstFilePath);
                        }
                    }
                    catch
                    {
                    }
                }
                if (Directory.Exists(dir))
                {
                    openFileDialog.InitialDirectory = dir;
                }
                // It doesn't seem to be possible to open the dialog with more than one file selected.
                // However there will often be only one so that's at least somewhat helpful.
                openFileDialog.FileName = initialFileName;
                openFileDialog.Title    = ITextStrings.ksSelectInterlinFile;
                while (true)                 // loop until approved set of files or cancel
                {
                    if (openFileDialog.ShowDialog() != DialogResult.OK)
                    {
                        return(currentFiles);
                    }
                    var badFiles = new List <string>();
                    foreach (var fileName in openFileDialog.FileNames)
                    {
                        if (!new Sfm2Xml.IsSfmFile(fileName).IsValid)
                        {
                            badFiles.Add(fileName);
                        }
                    }
                    if (badFiles.Count > 0)
                    {
                        string msg = String.Format(ITextStrings.ksInvalidInterlinearFiles,
                                                   string.Join(", ", badFiles.ToArray()));
                        DialogResult dr = MessageBox.Show(this, msg,
                                                          ITextStrings.ksPossibleInvalidFile,
                                                          MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                        if (dr == DialogResult.Yes)
                        {
                            return(string.Join(", ", openFileDialog.FileNames));
                        }
                        if (dr == DialogResult.No)
                        {
                            continue;                  // loop and show dialog again...hopefully same files selected.
                        }
                        break;                         // user must have chosen cancel, break out of loop
                    }
                    return(string.Join(", ", openFileDialog.FileNames));
                }
                return(currentFiles);                // leave things unchanged.
            }
        }