/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handles the Click event of the m_btnBrowseProjectFolder control.
		/// It launches a FolderBrowserDialog with the initial directory being one of:
		/// - the folder specified in the text box, if it exists;
		/// - otherwise, the specified default path, if that folder exists
		/// - otherwise, My Computer (was C:\, but that won't work on Linux).
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void m_btnBrowseProjectFolder_Click(object sender, EventArgs e)
		{
			string defaultPath = FwDirectoryFinder.ProjectsDirectory;

			using (var fldrBrowse = new FolderBrowserDialogAdapter())
			{
				fldrBrowse.ShowNewFolderButton = true;
				fldrBrowse.Description = FwCoreDlgs.ksChooseProjectFolder;

				bool backupDirExists = FileUtils.DirectoryExists(m_tbProjectsFolder.Text);

				// if the directory exists which is typed in the text box...
				if (backupDirExists)
					fldrBrowse.SelectedPath = m_tbProjectsFolder.Text;
				else
				{
					// check the last directory used in the registry. If it exists, begin looking
					// here.
					if (FileUtils.DirectoryExists(defaultPath))
						fldrBrowse.SelectedPath = defaultPath;
					else
						// Otherwise, begin looking in My Computer
						fldrBrowse.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
				}

				// if directory selected, set path to it.
				if (fldrBrowse.ShowDialog() == DialogResult.OK)
					m_tbProjectsFolder.Text = fldrBrowse.SelectedPath;
			}
		}
Example #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handle the Folder browse button to locate a folder to write to.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected virtual void btnFolderBrowse_Click(object sender, System.EventArgs e)
		{
			using (var dlg = new FolderBrowserDialogAdapter())
			{
				dlg.SelectedPath = BaseOutputFolder;
				dlg.Description = TeResourceHelper.GetResourceString(StidExportDlgFolderBrowserPrompt);
				dlg.ShowNewFolderButton = true;
				if (dlg.ShowDialog() == DialogResult.OK)
				{
					BaseOutputFolder = dlg.SelectedPath;
					m_fUserModifiedFolder = true;
				}
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// LinkedFiles Browse
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// ------------------------------------------------------------------------------------
		private void btnLinkedFilesBrowse_Click(object sender, EventArgs e)
		{
			using (var folderBrowserDlg = new FolderBrowserDialogAdapter())
			{
				folderBrowserDlg.Description = FwCoreDlgs.folderBrowserDlgDescription;
				folderBrowserDlg.RootFolder = Environment.SpecialFolder.Desktop;
				if (!Directory.Exists(txtExtLnkEdit.Text))
				{
					string msg = String.Format(FwCoreDlgs.ksLinkedFilesFolderIsUnavailable, txtExtLnkEdit.Text);
					MessageBox.Show(msg, FwCoreDlgs.ksLinkedFilesFolderUnavailable);
					folderBrowserDlg.SelectedPath = m_defaultLinkedFilesFolder;
				}
				else
				{
					folderBrowserDlg.SelectedPath = txtExtLnkEdit.Text;
				}

				if (folderBrowserDlg.ShowDialog() == DialogResult.OK)
				{
					txtExtLnkEdit.Text = folderBrowserDlg.SelectedPath;
				}
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handles the Click event of the m_btnBrowseDest control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		/// ------------------------------------------------------------------------------------
		private void m_btnBrowseDest_Click(object sender, EventArgs e)
		{
			Logger.WriteEvent("Browsing for destination folder in 'Picture Properties' dialog");
			using (var dlg = new FolderBrowserDialogAdapter())
			{
				dlg.SelectedPath = m_txtDestination.Text;
				dlg.Description = String.Format(FwCoreDlgs.kstidSelectLinkedFilesSubFolder,
					s_defaultPicturesFolder);
				dlg.ShowNewFolderButton = true;

				if (dlg.ShowDialog() == DialogResult.OK)
				{
					if (ValidateDestinationFolder(dlg.SelectedPath))
						m_txtDestination.Text = dlg.SelectedPath;
				}
			}
		}
Example #5
0
		private void m_browse_Click(object sender, EventArgs e)
		{
			using (var dlg = new FolderBrowserDialogAdapter())
			{
				dlg.Description = String.Format(FwCoreDlgs.ksDirectoryLocationForBackup);
				dlg.ShowNewFolderButton = true;

				if (String.IsNullOrEmpty(DestinationFolder) || !Directory.Exists(DestinationFolder))
				{
					dlg.SelectedPath = FwDirectoryFinder.DefaultBackupDirectory;
				}
				else
				{
					dlg.SelectedPath = DestinationFolder;
				}

				if (dlg.ShowDialog(this) == DialogResult.OK)
				{
					DestinationFolder = dlg.SelectedPath;
				}
			}
		}
Example #6
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (m_exportList.SelectedItems.Count == 0)
                return;

            //if (ItemDisabled((string)m_exportList.SelectedItems[0].Tag))
            //    return;
            m_exportItems.Clear();
            foreach (ListViewItem sel in m_exportList.SelectedItems)
                m_exportItems.Add(sel);
            var mainControl = EnsureViewInfo();
            try
            {

                if (!PrepareForExport())
                    return;

                bool fLiftExport = m_exportItems[0].SubItems[2].Text == "lift";
                string sFileName;
                string sDirectory;
                if (fLiftExport)
                {
                    using (var dlg = new FolderBrowserDialogAdapter())
                    {
                        dlg.Tag = xWorksStrings.ksChooseLIFTFolderTitle; // can't set title !!??
                        dlg.Description = String.Format(xWorksStrings.ksChooseLIFTExportFolder,
                            m_exportItems[0].SubItems[1].Text);
                        dlg.ShowNewFolderButton = true;
                        dlg.RootFolder = Environment.SpecialFolder.Desktop;
                        dlg.SelectedPath = m_mediator.PropertyTable.GetStringProperty("ExportDir",
                            Environment.GetFolderPath(Environment.SpecialFolder.Personal));
                        if (dlg.ShowDialog(this) != DialogResult.OK)
                            return;
                        sDirectory = dlg.SelectedPath;
                    }
                    string sFile = Path.GetFileName(sDirectory);
                    sFileName = Path.Combine(sDirectory, sFile + FwFileExtensions.ksLexiconInterchangeFormat);
                    string sMsg = null;
                    MessageBoxButtons btns = MessageBoxButtons.OKCancel;
                    if (File.Exists(sFileName))
                    {
                        sMsg = xWorksStrings.ksLIFTAlreadyExists;
                        btns = MessageBoxButtons.OKCancel;
                    }
                    else
                    {
                        string[] rgfiles = Directory.GetFiles(sDirectory);
                        if (rgfiles.Length > 0)
                        {
                            sMsg = xWorksStrings.ksLIFTFolderNotEmpty;
                            btns = MessageBoxButtons.YesNo;
                        }
                    }
                    if (!String.IsNullOrEmpty(sMsg))
                    {
                        using (LiftExportMessageDlg dlg = new LiftExportMessageDlg(sMsg, btns))
                        {
                            if (dlg.ShowDialog(this) != DialogResult.OK)
                                return;
                        }
                    }
                }
                else
                {
                    FxtType ft;
                    // Note that DiscourseExportDialog doesn't add anything to m_rgFxtTypes.
                    // See FWR-2506.
                    if (m_rgFxtTypes.Count > 0)
                    {
                        string fxtPath = (string) m_exportItems[0].Tag;
                        ft = m_rgFxtTypes[FxtIndex(fxtPath)];
                    }
                    else
                    {
                        // Choose a dummy value that will take the default branch of merely choosing
                        // an output file.
                        ft.m_ft = FxtTypes.kftConfigured;
                    }
                    switch (ft.m_ft)
                    {
                        case FxtTypes.kftTranslatedLists:
                            using (var dlg = new ExportTranslatedListsDlg())
                            {
                                dlg.Initialize(m_mediator, m_cache,
                                    m_exportItems[0].SubItems[1].Text,
                                    m_exportItems[0].SubItems[2].Text,
                                    m_exportItems[0].SubItems[3].Text);
                                if (dlg.ShowDialog(this) != DialogResult.OK)
                                    return;
                                sFileName = dlg.FileName;
                                sDirectory = Path.GetDirectoryName(sFileName);
                                m_translationWritingSystems = dlg.SelectedWritingSystems;
                                m_translatedLists = dlg.SelectedLists;
                            }
                            break;
                        case FxtTypes.kftSemanticDomains:
                            using (var dlg = new ExportSemanticDomainsDlg())
                            {
                                dlg.Initialize(m_cache);
                                if (dlg.ShowDialog(this) != DialogResult.OK)
                                    return;
                                m_translationWritingSystems = new List<int>();
                                m_translationWritingSystems.Add(dlg.SelectedWs);
                                m_allQuestions = dlg.AllQuestions;
                            }
                            goto default;
                        case FxtTypes.kftPathway:
                            ProcessPathwayExport();
                            return;
                        default:
                            using (var dlg = new SaveFileDialogAdapter())
                            {
                                dlg.AddExtension = true;
                                dlg.DefaultExt = m_exportItems[0].SubItems[2].Text;
                                dlg.Filter = m_exportItems[0].SubItems[3].Text;
                                dlg.Title = String.Format(xWorksStrings.ExportTo0, m_exportItems[0].SubItems[1].Text);
                                dlg.InitialDirectory = m_mediator.PropertyTable.GetStringProperty("ExportDir",
                                    Environment.GetFolderPath(Environment.SpecialFolder.Personal));
                                if (dlg.ShowDialog(this) != DialogResult.OK)
                                    return;
                                sFileName = dlg.FileName;
                                sDirectory = Path.GetDirectoryName(sFileName);
                            }
                            break;
                    }
                }
                if (sDirectory != null)
                {
                    m_mediator.PropertyTable.SetProperty("ExportDir", sDirectory);
                    m_mediator.PropertyTable.SetPropertyPersistence("ExportDir", true);
                }
                if (fLiftExport) // Fixes LT-9437 Crash exporting a discourse chart (or interlinear too!)
                {
                    DoExport(sFileName, true);
                }
                else
                {
                    DoExport(sFileName); // Musn't use the 2 parameter version here or overrides get messed up.
                }
                if (m_chkShowInFolder.Checked)
                {
                    OpenExportFolder(sDirectory, sFileName);
                    m_mediator.PropertyTable.SetProperty("ExportDlgShowInFolder", "true");
                    m_mediator.PropertyTable.SetPropertyPersistence("ExportDlgShowInFolder", true);
                }
                else
                {
                    m_mediator.PropertyTable.SetProperty("ExportDlgShowInFolder", "false");
                    m_mediator.PropertyTable.SetPropertyPersistence("ExportDlgShowInFolder", true);
                }
            }
            finally
            {
                if (mainControl != null)
                    mainControl.Dispose();
            }
        }
Example #7
0
		/// <summary>
		/// Ensure a valid folder for LangProject.LinkedFilesRootDir.  When moving projects
		/// between systems, the stored value may become hopelessly invalid.  See FWNX-1005
		/// for an example of the havoc than can ensue.
		/// </summary>
		/// <remarks>This method gets called when we open the FDO cache.</remarks>
		private static void EnsureValidLinkedFilesFolder(FdoCache cache)
		{
			// If the location of the LinkedFilesRootDir was changed when this project was restored just now;
			// overwrite the location that was restored from the fwdata file.
			if (!String.IsNullOrEmpty(s_LinkDirChangedTo) && !cache.LangProject.LinkedFilesRootDir.Equals(s_LinkDirChangedTo))
			{
				NonUndoableUnitOfWorkHelper.Do(cache.ActionHandlerAccessor,
					() => cache.LangProject.LinkedFilesRootDir = s_LinkDirChangedTo);
			}

			if (MiscUtils.RunningTests)
				return;

			var linkedFilesFolder = cache.LangProject.LinkedFilesRootDir;
			var defaultFolder = FdoFileHelper.GetDefaultLinkedFilesDir(cache.ProjectId.ProjectFolder);
			EnsureValidLinkedFilesFolderCore(linkedFilesFolder, defaultFolder);

			if (!Directory.Exists(linkedFilesFolder))
			{
				MessageBox.Show(String.Format(Properties.Resources.ksInvalidLinkedFilesFolder, linkedFilesFolder), Properties.Resources.ksErrorCaption);
				using (var folderBrowserDlg = new FolderBrowserDialogAdapter())
				{
					folderBrowserDlg.Description = Properties.Resources.ksLinkedFilesFolder;
					folderBrowserDlg.RootFolder = Environment.SpecialFolder.Desktop;
					folderBrowserDlg.SelectedPath = Directory.Exists(defaultFolder) ? defaultFolder : cache.ProjectId.ProjectFolder;
					if (folderBrowserDlg.ShowDialog() == DialogResult.OK)
						linkedFilesFolder = folderBrowserDlg.SelectedPath;
					else
					{
						FileUtils.EnsureDirectoryExists(defaultFolder);
						linkedFilesFolder = defaultFolder;
					}
				}
				NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(cache.ActionHandlerAccessor, () =>
					{ cache.LangProject.LinkedFilesRootDir = linkedFilesFolder; });
			}
		}
Example #8
0
 private void OnTargetClick(object sender, EventArgs e)
 {
     using (var folderBrowserDialog = new FolderBrowserDialogAdapter())
     {
         folderBrowserDialog.SelectedPath = edtTargetPath.Text.Length > 0 && edtSourceFile.Text.Length > 0 ? Path.GetDirectoryName(edtSourceFile.Text) : edtTargetPath.Text.Length > 0 ? edtTargetPath.Text : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
         folderBrowserDialog.Description = "Zielverzeichnis ausw\u00e4hlen";
         if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
         {
             edtTargetPath.Text = folderBrowserDialog.SelectedPath;
         }
     }
 }