Example #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);
     }
 }
Example #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;
        }
Example #3
0
        /// <summary></summary>
        public ConverterTest()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();
            ofDlg            = new OpenFileDialogAdapter();
            ofDlg.DefaultExt = "txt";
            ofDlg.Filter     = FileUtils.FileDialogFilterCaseInsensitiveCombinations(FwCoreDlgs.ofDlg_Filter);

            saveFileDialog                  = new SaveFileDialogAdapter();
            saveFileDialog.DefaultExt       = "txt";
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.Filter           = ofDlg.Filter;

            if (DesignMode)
            {
                return;
            }

            InputArgsChanged();                 // set the initial state of the Convert button

            // Set view properties.
            m_fHasOutput = false;
            m_svOutput   = new SampleView();
            m_svOutput.WritingSystemFactory = FwUtils.CreateWritingSystemManager();
            m_svOutput.Dock      = DockStyle.Fill;
            m_svOutput.Visible   = true;
            m_svOutput.Enabled   = false;
            m_svOutput.BackColor = OutputPanel.BackColor;
            m_svOutput.TabIndex  = 1;
            m_svOutput.TabStop   = true;
            OutputPanel.Controls.Add(m_svOutput);
        }
Example #4
0
 public LiftImportDlg()
 {
     openFileDialog1 = new OpenFileDialogAdapter();
     InitializeComponent();
     openFileDialog1.Title  = LexTextControls.openFileDialog1_Title;
     openFileDialog1.Filter = FileUtils.FileDialogFilterCaseInsensitiveCombinations(
         LexTextControls.openFileDialog1_Filter);
 }
Example #5
0
        /// <summary>
        /// Class to choose input, output files for Db4o to XML conversion
        /// </summary>
        public FileInOutChooser()
        {
            InitializeComponent();

            Db4oFile        = new OpenFileDialogAdapter();
            Db4oFile.Filter = "Db4o Files|*.fwdb|All Files|*.*";

            XmlFile            = new SaveFileDialogAdapter();
            XmlFile.DefaultExt = "fwxml";
        }
Example #6
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;
         }
     }
 }
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
Example #8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new instance of the CharContextCtrl.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public CharContextCtrl()
        {
            InitializeComponent();
            m_openFileDialog            = new OpenFileDialogAdapter();
            m_openFileDialog.DefaultExt = "lds";
            m_openFileDialog.Title      = FwCoreDlgs.kstidLanguageFileBrowser;

            gridContext.AutoGenerateColumns = false;
            colRef.MinimumWidth             = 2;
            colRef.Width = colRef.MinimumWidth;

            gridContext.GridColor = ColorHelper.CalculateColor(SystemColors.WindowText,
                                                               SystemColors.Window, 35);
            m_sInitialScanMsgLabel = lblScanMsg.Text;
        }
Example #9
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;
            }
        }
Example #10
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;
     }
 }
 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;
         }
     }
 }
Example #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);
                }
            }
        }
Example #13
0
        public LinguaLinksImportDlg()
        {
            InitializeComponent();
            openFileDialog = new OpenFileDialogAdapter();
            AccessibleName = GetType().Name;

            // Copied from the LexImportWizard dlg Init (LexImportWizard.cs)
            // Ensure that we have the default encoding converter (to/from MS Windows Code Page
            // for Western European languages)
            SilEncConverters40.EncConverters         encConv = new SilEncConverters40.EncConverters();
            System.Collections.IDictionaryEnumerator de      = encConv.GetEnumerator();
            string sEncConvName      = "Windows1252<>Unicode";          // REVIEW: SHOULD THIS NAME BE LOCALIZED?
            bool   fMustCreateEncCnv = true;

            while (de.MoveNext())
            {
                if ((string)de.Key != null && (string)de.Key == sEncConvName)
                {
                    fMustCreateEncCnv = false;
                    break;
                }
            }
            if (fMustCreateEncCnv)
            {
                try
                {
                    encConv.AddConversionMap(sEncConvName, "1252",
                                             ECInterfaces.ConvType.Legacy_to_from_Unicode, "cp", "", "",
                                             ECInterfaces.ProcessTypeFlags.CodePageConversion);
                }
                catch (SilEncConverters40.ECException exception)
                {
                    MessageBox.Show(exception.Message, ITextStrings.ksConvMapError,
                                    MessageBoxButtons.OK);
                }
            }
        }
        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.
            }
        }