Ejemplo n.º 1
1
		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.º 2
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.º 3
0
		/// <summary>
		/// Handle the InsertLinkToFile command
		/// </summary>
		public bool OnInsertLinkToFile(object arg)
		{
			CheckDisposed();

			RootSiteEditingHelper helper = EditingHelper as RootSiteEditingHelper;
			if (helper == null || !helper.CanInsertLinkToFile())
				return false;
			string pathname = null;
			using (var fileDialog = new OpenFileDialogAdapter())
			{
				fileDialog.Filter = ResourceHelper.FileFilter(FileFilterType.AllFiles);
				fileDialog.RestoreDirectory = true;
				if (fileDialog.ShowDialog() != DialogResult.OK)
					return false;
				pathname = fileDialog.FileName;
			}
			if (string.IsNullOrEmpty(pathname))
				return false;
			pathname = MoveOrCopyFilesController.MoveCopyOrLeaveExternalFile(pathname,
				Cache.LangProject.LinkedFilesRootDir, m_mediator.HelpTopicProvider,  Cache.ProjectId.IsLocal);
			if (String.IsNullOrEmpty(pathname))
				return false;
			// JohnT: don't use m_StyleSheet, no guarantee it has been created (see LT-7034)
			helper.ConvertSelToLink(pathname, StyleSheet);
			return true;
		}
Ejemplo n.º 4
0
		/// <summary>
		/// Import a file contained translated strings for one or more lists.
		/// </summary>
		/// <remarks>See FWR-1739.</remarks>
		public bool OnImportTranslatedLists(object commandObject)
		{
			string filename = null;
			// ActiveForm can go null (see FWNX-731), so cache its value, and check whether
			// we need to use 'this' instead (which might be a better idea anyway).
			var form = ActiveForm;
			if (form == null)
				form = this;
			using (var dlg = new OpenFileDialogAdapter())
			{
				dlg.CheckFileExists = true;
				dlg.RestoreDirectory = true;
				dlg.Title = ResourceHelper.GetResourceString("kstidOpenTranslatedLists");
				dlg.ValidateNames = true;
				dlg.Multiselect = false;
				dlg.Filter = ResourceHelper.FileFilter(FileFilterType.FieldWorksTranslatedLists);
				if (dlg.ShowDialog(form) != DialogResult.OK)
					return true;
				filename = dlg.FileName;
			}
#if DEBUG
			var dtBegin = DateTime.Now;
#endif
			using (new WaitCursor(form, true))
			{
				NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(Cache.ActionHandlerAccessor,
					() => ImportTranslatedLists(filename));
			}
#if DEBUG
			var dtEnd = DateTime.Now;
			var span = new TimeSpan(dtEnd.Ticks - dtBegin.Ticks);
			Debug.WriteLine(String.Format("Total elapsed time for loading translated list(s) from {0} and handling PropChanges = {1}",
				filename, span));
#endif
			return true;
		}
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;
		}
		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 = SplitPaths(currentFiles);
				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 JoinPaths(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 JoinPaths(openFileDialog.FileNames);
				}
				return currentFiles; // leave things unchanged.
			}
		}
Ejemplo n.º 9
0
		private bool InsertMediaFile(object cmd, string filter, string keyCaption, string defaultCaption)
		{
			ICmObject obj;
			int flid;
			bool fOnPronunciationSlice = CanInsertPictureOrMediaFile(cmd, out flid);
			if (fOnPronunciationSlice)
			{
				obj = m_dataEntryForm.CurrentSlice.Object;
			}
			else
			{
				// Find the first pronunciation object on the current entry, creating it if
				// necessary.
				var le = m_dataEntryForm.Root as ILexEntry;
				if (le == null)
					return false;
				if (le.PronunciationsOS.Count == 0)
				{
					// Ensure that the pronunciation writing systems have been initialized.
					// Otherwise, the crash reported in FWR-2086 can happen!
					int wsPron = Cache.DefaultPronunciationWs;
					UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Undo Create Pronuciation",
						"Redo Create Pronunciation", Cache.ActionHandlerAccessor, () =>
						{
							le.PronunciationsOS.Add(Cache.ServiceLocator.GetInstance<ILexPronunciationFactory>().Create());
						});
				}
				obj = le.PronunciationsOS[0];
				flid = LexPronunciationTags.kflidMediaFiles;
			}
			using (var dlg = new OpenFileDialogAdapter())
			{
				dlg.InitialDirectory = Cache.LangProject.LinkedFilesRootDir;
				dlg.Filter = filter;
				dlg.FilterIndex = 1;
				if (m_mediator != null && m_mediator.HasStringTable)
					dlg.Title = m_mediator.StringTbl.GetString(keyCaption);
				if (string.IsNullOrEmpty(dlg.Title) || dlg.Title == "*" + keyCaption + "*")
					dlg.Title = defaultCaption;
				dlg.RestoreDirectory = true;
				dlg.CheckFileExists = true;
				dlg.CheckPathExists = true;

				DialogResult dialogResult = DialogResult.None;
				while (dialogResult != DialogResult.OK && dialogResult != DialogResult.Cancel)
				{
					dialogResult = dlg.ShowDialog();
					if (dialogResult == DialogResult.OK)
					{
						string file = MoveOrCopyFilesDlg.MoveCopyOrLeaveMediaFile(dlg.FileName,
							Cache.LangProject.LinkedFilesRootDir, m_mediator.HelpTopicProvider, Cache.ProjectId.IsLocal);
						if (String.IsNullOrEmpty(file))
							return true;
						string sFolderName = null;
						if (m_mediator != null && m_mediator.HasStringTable)
							sFolderName = m_mediator.StringTbl.GetString("kstidMediaFolder");
						if (sFolderName == null || sFolderName.Length == 0 || sFolderName == "*kstidMediaFolder*")
							sFolderName = CmFolderTags.LocalMedia;
						if (!obj.IsValidObject)
							return true; // Probably some other client deleted it while we were choosing the file.
						int chvo = obj.Cache.DomainDataByFlid.get_VecSize(obj.Hvo, flid);
						UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(
							xWorksStrings.ksUndoInsertMedia, xWorksStrings.ksRedoInsertMedia,
							Cache.ActionHandlerAccessor, () =>
							{
								int hvo = obj.Cache.DomainDataByFlid.MakeNewObject(CmMediaTags.kClassId, obj.Hvo, flid, chvo);
								var media = Cache.ServiceLocator.GetInstance<ICmMediaRepository>().GetObject(hvo);
								var folder = DomainObjectServices.FindOrCreateFolder(obj.Cache, LangProjectTags.kflidMedia, sFolderName);
								media.MediaFileRA = DomainObjectServices.FindOrCreateFile(folder, file);
							});
					}
				}
			}
			return true;
		}
Ejemplo n.º 10
0
 private void OnSourceClick(object sender, EventArgs e)
 {
     using (var openFileDialog = new OpenFileDialogAdapter())
     {
         openFileDialog.Filter = "RTF Dateien|*.rtf|Alle Dateien|*.*";
         openFileDialog.Title = "Projektabrechnung ausw\u00e4hlen";
         openFileDialog.FileName = edtSourceFile.Text;
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             edtSourceFile.Text = openFileDialog.FileName;
             if (edtTargetPath.Text.Length == 0)
             {
                 edtTargetPath.Text = Path.GetDirectoryName(openFileDialog.FileName);
             }
         }
     }
 }
Ejemplo n.º 11
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;
			}
		}