public void showProperties() { CheckDisposed(); CmPicture pic = (CmPicture) this.Object; using (PicturePropertiesDialog dlg = new PicturePropertiesDialog(m_cache, pic, FwApp.App, true)) { if (dlg.Initialize()) { if (dlg.ShowDialog() == DialogResult.OK) { string strLocalPictures = SIL.FieldWorks.Common.RootSites.EditingHelper.DefaultPictureFolder; pic.UpdatePicture(dlg.CurrentFile, dlg.Caption, strLocalPictures, pic.Cache.DefaultAnalWs); InstallPicture(m_picBox); m_lastSize = new Size(0, 0); // forces OnSizeChanged to do something (we need to adjust to new aspect ratio). OnSizeChanged(new EventArgs()); } } } }
public void showProperties() { CheckDisposed(); var pic = (ICmPicture)Object; var app = (IApp)m_mediator.PropertyTable.GetValue("App"); using (var dlg = new PicturePropertiesDialog(m_cache, pic, m_mediator.HelpTopicProvider, app, true)) { if (dlg.Initialize()) { var stylesheet = FontHeightAdjuster.StyleSheetFromMediator(m_mediator); dlg.UseMultiStringCaption(m_cache, WritingSystemServices.kwsVernAnals, stylesheet); dlg.SetMultilingualCaptionValues(pic.Caption); if (dlg.ShowDialog() == DialogResult.OK) { UndoableUnitOfWorkHelper.Do(DetailControlsStrings.ksUndoUpdatePicture, DetailControlsStrings.ksRedoUpdatePicture, m_obj, () => { string strLocalPictures = CmFolderTags.DefaultPictureFolder; dlg.GetMultilingualCaptionValues(pic.Caption); pic.UpdatePicture(dlg.CurrentFile, null, strLocalPictures, 0); }); InstallPicture(m_picBox); m_lastSize = new Size(0, 0); // forces OnSizeChanged to do something (we need to adjust to new aspect ratio). OnSizeChanged(new EventArgs()); } } } }
/// <summary> /// Called by reflection based on menu item InsertPicture. /// </summary> /// <param name="cmd"></param> /// <returns></returns> public bool OnInsertPicture(object cmd) { int flid; if (!CanInsertPictureOrMediaFile(cmd, out flid)) return false; // should not happen, but play safe var obj = m_dataEntryForm.CurrentSlice.Object; int chvo = obj.Cache.DomainDataByFlid.get_VecSize(obj.Hvo, flid); IApp app = (IApp)m_mediator.PropertyTable.GetValue("App"); using (PicturePropertiesDialog dlg = new PicturePropertiesDialog(obj.Cache, null, m_mediator.HelpTopicProvider, app, true)) { if (dlg.Initialize()) { var stylesheet = FontHeightAdjuster.StyleSheetFromMediator(m_mediator); dlg.UseMultiStringCaption(obj.Cache, WritingSystemServices.kwsVernAnals, stylesheet); if (dlg.ShowDialog() == DialogResult.OK) { UndoableUnitOfWorkHelper.Do(xWorksStrings.ksUndoInsertPicture, xWorksStrings.ksRedoInsertPicture, obj, () => { string strLocalPictures = CmFolderTags.DefaultPictureFolder; int hvoPic = obj.Cache.DomainDataByFlid.MakeNewObject(CmPictureTags.kClassId, obj.Hvo, flid, chvo); var picture = Cache.ServiceLocator.GetInstance<ICmPictureRepository>().GetObject(hvoPic); dlg.GetMultilingualCaptionValues(picture.Caption); picture.UpdatePicture(dlg.CurrentFile, null, strLocalPictures, 0); }); } } } return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the clicking on the "Picture Properties" context menu. /// </summary> /// <param name="args"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected bool OnPictureProperties(object args) { if (ActiveEditingHelper == null || !ActiveEditingHelper.IsPictureSelected) return false; ICmPicture pic = ActiveEditingHelper.Picture; using (PicturePropertiesDialog dlg = new PicturePropertiesDialog(m_cache, pic, m_app, m_app)) { if (dlg.Initialize()) { if (dlg.ShowDialog() == DialogResult.OK) InsertThePicture(pic, dlg); } } return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Displays the insert picture dialog. /// </summary> /// <param name="args"></param> /// <returns><c>true</c> if we handle this</returns> /// ------------------------------------------------------------------------------------ protected bool OnInsertPictureDialog(object args) { Debug.Assert(m_cache != null); FwEditingHelper editHelper = ActiveEditingHelper; if (editHelper == null) return false; if (editHelper.IsBackTranslation) { SelectionHelper helper = editHelper.CurrentSelection; ICmPictureRepository repo = Cache.ServiceLocator.GetInstance<ICmPictureRepository>(); SelLevInfo info; ISegment segment; if (helper.GetLevelInfoForTag(StTxtParaTags.kflidSegments, out info)) segment = m_cache.ServiceLocator.GetInstance<ISegmentRepository>().GetObject(info.hvo); else { SelLevInfo paraLevInfo; helper.GetLevelInfoForTag(StTextTags.kflidParagraphs, out paraLevInfo); IStTxtPara para = Cache.ServiceLocator.GetInstance<IStTxtParaRepository>().GetObject(paraLevInfo.hvo); segment = para.GetSegmentForOffsetInFreeTranslation(helper.GetIch(SelectionHelper.SelLimitType.Top), helper.Ws); } ITsString tssVernSegment = segment.BaselineText; Guid guidNextPicNotInBt = tssVernSegment.GetAllEmbeddedObjectGuids(FwObjDataTypes.kodtGuidMoveableObjDisp).FirstOrDefault(g => !segment.FreeTranslation.get_String(helper.Ws).GetAllEmbeddedObjectGuids(FwObjDataTypes.kodtGuidMoveableObjDisp).Contains(g)); if (guidNextPicNotInBt == Guid.Empty) return false; ICmPicture pict = repo.GetObject(guidNextPicNotInBt); string undo; string redo; TeResourceHelper.MakeUndoRedoLabels("kstidInsertPicture", out undo, out redo); using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor, editHelper.EditedRootBox.Site, undo, redo)) { editHelper.InsertPicture(pict); undoTaskHelper.RollBack = false; } } else { using (PicturePropertiesDialog dlg = new PicturePropertiesDialog(m_cache, null, m_app, m_app)) { // Don't allow inserting an empty picture, so don't check for result of Initialize() if (dlg.Initialize()) { if (dlg.ShowDialog() == DialogResult.OK) InsertThePicture(null, dlg); } } } return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Displays the insert picture dialog. /// </summary> /// <param name="args"></param> /// <returns><c>true</c> if we handle this</returns> /// ------------------------------------------------------------------------------------ protected bool OnInsertPictureDialog(object args) { Debug.Assert(m_cache != null); if (ActiveEditingHelper == null) return false; using (PicturePropertiesDialog dlg = new PicturePropertiesDialog(m_cache, null, FwApp.App)) { // Don't allow inserting an empty picture, so don't check for result of Initialize() if (dlg.Initialize()) { if (dlg.ShowDialog() == DialogResult.OK) InsertThePicture(null, dlg); } } return true; }