예제 #1
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;
			}
		}
예제 #2
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;
			}
		}