/// ------------------------------------------------------------------------------------ /// <summary> /// Shows the Format Styles dialog. /// </summary> /// <param name="paraStyleName">Name of the initially selected paragraph style.</param> /// <param name="charStyleName">Name of the initially selected character style.</param> /// <returns> /// true if a refresh is needed to reload the cache /// </returns> /// ------------------------------------------------------------------------------------ public bool ShowStylesDialog(string paraStyleName, string charStyleName) { StVc vc = null; IVwRootSite activeViewSite = null; if (ActiveView != null) { vc = ActiveView.EditingHelper.ViewConstructor as StVc; activeViewSite = ActiveView.CastAsIVwRootSite(); } using (FwStylesDlg stylesDlg = new FwStylesDlg(activeViewSite, Cache, StyleSheet, (vc == null) ? false : vc.RightToLeft, Cache.ProjectIncludesRightToLeftWs, StyleSheet.GetDefaultBasedOnStyleName(), MaxStyleLevelToShow, FwApp.MeasurementSystem, paraStyleName, charStyleName, HvoAppRootObject, FwApp.App, FwApp.App)) { stylesDlg.StylesRenamedOrDeleted += new FwStylesDlg.StylesRenOrDelDelegate(m_callbacks.OnStylesRenamedOrDeleted); stylesDlg.AllowSelectStyleTypes = m_callbacks.ShowSelectStylesComboInStylesDialog; stylesDlg.CanSelectParagraphBackgroundColor = m_callbacks.CanSelectParagraphBackgroundColor; return(stylesDlg.ShowDialog(m_callbacks) == DialogResult.OK && ((stylesDlg.ChangeType & StyleChangeType.DefChanged) > 0 || (stylesDlg.ChangeType & StyleChangeType.Added) > 0)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Shows the Format Apply Style dialog. Apply the results to the selection of the active /// view if the user clicks OK. /// </summary> /// <param name="paraStyleName">Name of the para style.</param> /// <param name="charStyleName">Name of the char style.</param> /// <param name="maxStyleLevel">The maximum style level that will be shown in this /// dialog. (apps that do not use style levels in their stylesheets can pass 0)</param> /// ------------------------------------------------------------------------------------ public void ShowApplyStyleDialog(string paraStyleName, string charStyleName, int maxStyleLevel) { SimpleRootSite rootsite = (ActiveView as SimpleRootSite); try { if (rootsite != null) { rootsite.ShowRangeSelAfterLostFocus = true; } int hvoRoot, frag; IVwViewConstructor vc; IVwStylesheet ss; ActiveView.CastAsIVwRootSite().RootBox.GetRootObject(out hvoRoot, out vc, out frag, out ss); using (FwApplyStyleDlg applyStyleDlg = new FwApplyStyleDlg(ActiveView.CastAsIVwRootSite(), Cache, StyleSheet.RootObjectHvo, StyleSheetOwningFlid, StyleSheet.GetDefaultBasedOnStyleName(), maxStyleLevel, paraStyleName, charStyleName, hvoRoot, FwApp.App, FwApp.App)) { if (FwEditingHelper != null) { if (FwEditingHelper.ApplicableStyleContexts != null) { applyStyleDlg.ApplicableStyleContexts = FwEditingHelper.ApplicableStyleContexts; } } else if (FwApp.App != null) { // Window doesn't have an editing helper, go with whole-app default if (FwApp.App.DefaultStyleContexts != null) { applyStyleDlg.ApplicableStyleContexts = FwApp.App.DefaultStyleContexts; } } applyStyleDlg.AllowSelectStyleTypes = m_callbacks.ShowSelectStylesComboInStylesDialog; IVwSelection sel = EditingHelper.CurrentSelection.Selection; applyStyleDlg.CanApplyCharacterStyle = sel.CanFormatChar; applyStyleDlg.CanApplyParagraphStyle = sel.CanFormatPara; if (applyStyleDlg.ShowDialog(m_callbacks) == DialogResult.OK) { EditingHelper.ApplyStyle(applyStyleDlg.StyleChosen); } } } finally { if (rootsite != null) { rootsite.ShowRangeSelAfterLostFocus = false; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Shows the Format Styles dialog. /// </summary> /// <param name="paraStyleName">Name of the initially selected paragraph style.</param> /// <param name="charStyleName">Name of the initially selected character style.</param> /// <param name="setPropsToFactorySettings">Delegate to set style info properties back /// to the default facotry settings</param> /// <returns> /// true if a refresh is needed to reload the cache /// </returns> /// ------------------------------------------------------------------------------------ public bool ShowStylesDialog(string paraStyleName, string charStyleName, Action <StyleInfo> setPropsToFactorySettings) { StVc vc = null; IVwRootSite activeViewSite = null; if (EditingHelper == null) // If the calling location doesn't provide this just bring up the dialog with normal selected { paraStyleName = "Normal"; } if (ActiveView != null) { vc = ActiveView.EditingHelper.ViewConstructor as StVc; activeViewSite = ActiveView.CastAsIVwRootSite(); } if (paraStyleName == null && charStyleName == null && EditingHelper.CurrentSelection != null && EditingHelper.CurrentSelection.Selection != null) { // If the caller didn't know the default style, try to figure it out from // the selection. GetStyleNames(ActiveView as SimpleRootSite, EditingHelper.CurrentSelection.Selection, ref paraStyleName, ref charStyleName); } using (FwStylesDlg stylesDlg = new FwStylesDlg(activeViewSite, Cache, ActiveStyleSheet, (vc == null) ? false : vc.RightToLeft, Cache.ServiceLocator.WritingSystems.AllWritingSystems.Any(ws => ws.RightToLeftScript), ActiveStyleSheet.GetDefaultBasedOnStyleName(), MaxStyleLevelToShow, m_app.MeasurementSystem, paraStyleName, charStyleName, HvoAppRootObject, m_app, m_app)) { stylesDlg.SetPropsToFactorySettings = setPropsToFactorySettings; stylesDlg.StylesRenamedOrDeleted += m_callbacks.OnStylesRenamedOrDeleted; stylesDlg.AllowSelectStyleTypes = true; stylesDlg.ShowTEStyleTypes = m_callbacks.ShowTEStylesComboInStylesDialog; stylesDlg.CanSelectParagraphBackgroundColor = m_callbacks.CanSelectParagraphBackgroundColor; return(stylesDlg.ShowDialog(m_callbacks) == DialogResult.OK && ((stylesDlg.ChangeType & StyleChangeType.DefChanged) > 0 || (stylesDlg.ChangeType & StyleChangeType.Added) > 0)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Shows the Format Apply Style dialog. Apply the results to the selection of the active /// view if the user clicks OK. /// </summary> /// <param name="paraStyleName">Name of the para style.</param> /// <param name="charStyleName">Name of the char style.</param> /// <param name="maxStyleLevel">The maximum style level that will be shown in this /// dialog. (apps that do not use style levels in their stylesheets can pass 0)</param> /// ------------------------------------------------------------------------------------ public void ShowApplyStyleDialog(string paraStyleName, string charStyleName, int maxStyleLevel) { SimpleRootSite rootsite = (ActiveView as SimpleRootSite); try { if (rootsite != null) { rootsite.ShowRangeSelAfterLostFocus = true; } IVwSelection sel = EditingHelper.CurrentSelection.Selection; if (paraStyleName == null && charStyleName == null) { // If the caller didn't know the default style, try to figure it out from // the selection. GetStyleNames(rootsite, sel, ref paraStyleName, ref charStyleName); } int hvoRoot, frag; IVwViewConstructor vc; IVwStylesheet ss; ActiveView.CastAsIVwRootSite().RootBox.GetRootObject(out hvoRoot, out vc, out frag, out ss); using (FwApplyStyleDlg applyStyleDlg = new FwApplyStyleDlg(ActiveView.CastAsIVwRootSite(), Cache, ActiveStyleSheet.RootObjectHvo, StyleSheetOwningFlid, ActiveStyleSheet.GetDefaultBasedOnStyleName(), maxStyleLevel, paraStyleName, charStyleName, hvoRoot, m_app, m_app)) { if (FwEditingHelper != null) { if (FwEditingHelper.ApplicableStyleContexts != null) { applyStyleDlg.ApplicableStyleContexts = FwEditingHelper.ApplicableStyleContexts; } } else if (m_app != null) { // Window doesn't have an editing helper, go with whole-app default if (m_app.DefaultStyleContexts != null) { applyStyleDlg.ApplicableStyleContexts = m_app.DefaultStyleContexts; } } applyStyleDlg.AllowSelectStyleTypes = m_callbacks.ShowTEStylesComboInStylesDialog; applyStyleDlg.CanApplyCharacterStyle = sel.CanFormatChar; applyStyleDlg.CanApplyParagraphStyle = sel.CanFormatPara; if (applyStyleDlg.ShowDialog(m_callbacks) == DialogResult.OK) { string sUndo, sRedo; ResourceHelper.MakeUndoRedoLabels("kstidUndoApplyStyle", out sUndo, out sRedo); using (UndoTaskHelper helper = new UndoTaskHelper(Cache.ActionHandlerAccessor, ActiveView.CastAsIVwRootSite(), sUndo, sRedo)) { EditingHelper.ApplyStyle(applyStyleDlg.StyleChosen); helper.RollBack = false; } } } } finally { if (rootsite != null) { rootsite.ShowRangeSelAfterLostFocus = false; } } }