/// <summary> /// Wraps the specified view. /// </summary> /// <param name="view">The view.</param> /// <param name="viewModelSource">The view model source containing the <c>ViewModel</c> property.</param> /// <param name="wrapOptions">The wrap options.</param> /// <returns>The <see cref="IViewModelWrapper" />.</returns> /// <exception cref="ArgumentNullException">The <paramref name="view" /> is <c>null</c>.</exception> public IViewModelWrapper Wrap(IView view, object viewModelSource, WrapOptions wrapOptions) { Argument.IsNotNull("view", view); Argument.IsNotNull("viewModelSource", viewModelSource); #if XAMARIN var viewModelWrapper = new ViewModelWrapper(view); return viewModelWrapper; #else return CreateViewModelGrid(view, viewModelSource, wrapOptions); #endif }
private IViewModelWrapper CreateViewModelGrid(IView view, object viewModelSource, WrapOptions wrapOptions) { var content = GetContent(view) as FrameworkElement; if (content == null) { return null; } object tempObj = null; if (_weakIsWrappingTable.TryGetValue(view, out tempObj)) { return null; } _weakIsWrappingTable.Add(view, new object()); var vmGrid = new Grid(); vmGrid.Name = InnerWrapperName.GetUniqueControlName(); vmGrid.SetBinding(FrameworkElement.DataContextProperty, new Binding { Path = new PropertyPath("ViewModel"), Source = viewModelSource }); #if NET || SL5 if (Enum<WrapOptions>.Flags.IsFlagSet(wrapOptions, WrapOptions.CreateWarningAndErrorValidatorForViewModel)) { var warningAndErrorValidator = new WarningAndErrorValidator(); warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding()); vmGrid.Children.Add(warningAndErrorValidator); } #endif if (Enum<WrapOptions>.Flags.IsFlagSet(wrapOptions, WrapOptions.TransferStylesAndTransitionsToViewModelGrid)) { content.TransferStylesAndTransitions(vmGrid); } SetContent(view, null); vmGrid.Children.Add(content); SetContent(view, vmGrid); Log.Debug("Created target control content wrapper grid for view model"); return new ViewModelWrapper(vmGrid); }
private IViewModelWrapper CreateViewModelGrid(IView view, object viewModelSource, WrapOptions wrapOptions) { var content = GetContent(view) as FrameworkElement; if (content == null) { return null; } object tempObj = null; if (_weakIsWrappingTable.TryGetValue(view, out tempObj)) { return null; } var viewTypeName = view.GetType().Name; _weakIsWrappingTable.Add(view, new object()); Grid vmGrid = null; var existingGrid = GetContent(view) as Grid; if (existingGrid != null) { if (existingGrid.Name.StartsWith(InnerWrapperName)) { Log.Debug($"No need to create content wrapper grid for view model for view '{viewTypeName}', custom grid with special name defined"); vmGrid = existingGrid; } } if (vmGrid == null) { Log.Debug($"Creating content wrapper grid for view model for view '{viewTypeName}'"); vmGrid = new Grid(); vmGrid.Name = InnerWrapperName.GetUniqueControlName(); #if NET || SL5 if (Enum<WrapOptions>.Flags.IsFlagSet(wrapOptions, WrapOptions.CreateWarningAndErrorValidatorForViewModel)) { var warningAndErrorValidator = new WarningAndErrorValidator(); warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding()); vmGrid.Children.Add(warningAndErrorValidator); } #endif if (Enum<WrapOptions>.Flags.IsFlagSet(wrapOptions, WrapOptions.TransferStylesAndTransitionsToViewModelGrid)) { content.TransferStylesAndTransitions(vmGrid); } SetContent(view, null); vmGrid.Children.Add(content); SetContent(view, vmGrid); Log.Debug($"Created content wrapper grid for view model for view '{viewTypeName}'"); } var binding = vmGrid.GetBindingExpression(FrameworkElement.DataContextProperty); if (binding == null) { vmGrid.SetBinding(FrameworkElement.DataContextProperty, new Binding { Path = new PropertyPath("ViewModel"), Source = viewModelSource }); } return new ViewModelWrapper(vmGrid); }
private IViewModelWrapper CreateViewModelGrid(IView view, object viewModelSource, WrapOptions wrapOptions) { var content = GetContent(view) as FrameworkElement; if (content is null) { return(null); } if (_weakIsWrappingTable.TryGetValue(view, out var tempObj)) { return(null); } var viewTypeName = view.GetType().Name; _weakIsWrappingTable.Add(view, new object()); Grid vmGrid = null; var existingGrid = GetContent(view) as Grid; if (existingGrid != null) { if (existingGrid.Name.StartsWith(InnerWrapperName)) { Log.Debug($"No need to create content wrapper grid for view model for view '{viewTypeName}', custom grid with special name defined"); vmGrid = existingGrid; } } if (vmGrid is null) { Log.Debug($"Creating content wrapper grid for view model for view '{viewTypeName}'"); vmGrid = new Grid(); vmGrid.Name = InnerWrapperName.GetUniqueControlName(); #if NET || NETCORE if (Enum <WrapOptions> .Flags.IsFlagSet(wrapOptions, WrapOptions.CreateWarningAndErrorValidatorForViewModel)) { var warningAndErrorValidator = new WarningAndErrorValidator(); warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding()); vmGrid.Children.Add(warningAndErrorValidator); } #endif SetContent(view, null); vmGrid.Children.Add(content); SetContent(view, vmGrid); Log.Debug($"Created content wrapper grid for view model for view '{viewTypeName}'"); } var binding = vmGrid.GetBindingExpression(FrameworkElement.DataContextProperty); if (binding is null) { vmGrid.SetBinding(FrameworkElement.DataContextProperty, new Binding { Path = new PropertyPath("ViewModel"), Source = viewModelSource }); } return(new ViewModelWrapper(vmGrid)); }
/// <summary> /// Gets a wrapped element mapped by the <paramref name="wrapOption"/>. /// </summary> /// <typeparam name="T">Type of the control to return.</typeparam> /// <param name="wrappedGrid">The wrapped grid.</param> /// <param name="wrapOption">The wrap option that is used, which will be mapped to the control. The value <see cref="WrapOptions.All"/> is not allowed and will throw an exception.</param> /// <returns> /// <see cref="FrameworkElement"/> or <c>null</c> if the element is not found. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="wrappedGrid"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException">The <paramref name="wrapOption"/> is <see cref="WrapOptions.All"/>.</exception> public static T GetWrappedElement <T>(Grid wrappedGrid, WrapOptions wrapOption) where T : FrameworkElement { return(GetWrappedElement(wrappedGrid, wrapOption) as T); }
/// <summary> /// Wraps the specified framework element. /// </summary> /// <param name="frameworkElement">The framework element.</param> /// <param name="wrapOptions">The wrap options.</param> /// <param name="buttons">The buttons to add.</param> /// <param name="parentContentControl">The parent content control.</param> /// <returns><see cref="Grid"/> that contains the wrapped content.</returns> /// <remarks> /// The framework element that is passed must be disconnected from the parent first. It is recommended to first check whether a /// framework element can be wrapped by using the <see cref="CanBeWrapped"/> method. /// This method will automatically handle the disconnecting of the framework element from the parent is the <paramref name="parentContentControl"/> /// is passed. /// </remarks> public static Grid Wrap(FrameworkElement frameworkElement, WrapOptions wrapOptions, DataWindowButton[] buttons, ContentControl parentContentControl) { Argument.IsNotNull("frameworkElement", frameworkElement); Argument.IsNotNull("buttons", buttons); if (string.Equals(frameworkElement.Name, MainContentHolderName)) { return((Grid)frameworkElement); } #if SILVERLIGHT // According to the documentation, no visual tree is garantueed in the Loaded event of the user control. // However, as a solution the documentation says you need to manually call ApplyTemplate, so let's do that. // For more info, see http://msdn.microsoft.com/en-us/library/ms596558(vs.95) var frameworkElementAsControl = frameworkElement as Control; if (frameworkElementAsControl != null) { frameworkElementAsControl.ApplyTemplate(); } #endif if (parentContentControl != null) { SetControlContent(parentContentControl, null); } var mainContent = frameworkElement; // Create the outside grid, so the inner grid is never the same as the main content holder var outsideGrid = new Grid(); outsideGrid.Name = MainContentHolderName; if (Application.Current != null) { #if SILVERLIGHT // TODO: Fix styles for silverlight #else outsideGrid.Resources.MergedDictionaries.Add(Application.Current.Resources); #endif } #region Generate buttons #if !NETFX_CORE if (buttons.Length > 0) { // Add wrappanel containing the buttons var buttonsWrapPanel = new WrapPanel(); buttonsWrapPanel.Name = ButtonsWrapPanelName; #if SILVERLIGHT buttonsWrapPanel.Style = Application.Current.Resources["DataWindowButtonContainerStyle"] as Style; #else buttonsWrapPanel.SetResourceReference(FrameworkElement.StyleProperty, "DataWindowButtonContainerStyle"); #endif foreach (var dataWindowButton in buttons) { var button = new Button(); if (dataWindowButton.CommandBindingPath != null) { button.SetBinding(ButtonBase.CommandProperty, new Binding(dataWindowButton.CommandBindingPath)); } else { button.Command = dataWindowButton.Command; } button.Content = dataWindowButton.Text; #if NET button.SetResourceReference(FrameworkElement.StyleProperty, "DataWindowButtonStyle"); button.IsDefault = dataWindowButton.IsDefault; button.IsCancel = dataWindowButton.IsCancel; #else button.Style = Application.Current.Resources["DataWindowButtonStyle"] as Style; #endif if (dataWindowButton.IsDefault) { button.Name = DefaultOkButtonName; } else if (dataWindowButton.IsCancel) { button.Name = DefaultCancelButtonName; } buttonsWrapPanel.Children.Add(button); } // Create dockpanel that will dock the buttons underneath the content var subDockPanel = new DockPanel(); subDockPanel.LastChildFill = true; DockPanel.SetDock(buttonsWrapPanel, Dock.Bottom); subDockPanel.Children.Add(buttonsWrapPanel); // Add actual content subDockPanel.Children.Add(frameworkElement); // The dockpanel is now the main content mainContent = subDockPanel; } #endif #endregion #region Generate internal grid // Create grid var internalGrid = new Grid(); internalGrid.Name = InternalGridName; internalGrid.Children.Add(mainContent); // Grid is now the main content mainContent = internalGrid; #endregion #region Generate WarningAndErrorValidator if (Enum <WrapOptions> .Flags.IsFlagSet(wrapOptions, WrapOptions.GenerateWarningAndErrorValidatorForDataContext)) { // Create warning and error validator var warningAndErrorValidator = new WarningAndErrorValidator(); warningAndErrorValidator.Name = WarningAndErrorValidatorName; warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding()); // Add to grid internalGrid.Children.Add(warningAndErrorValidator); } #endregion #region Generate InfoBarMessageControl #if !NETFX_CORE if (Enum <WrapOptions> .Flags.IsFlagSet(wrapOptions, WrapOptions.GenerateInlineInfoBarMessageControl) || Enum <WrapOptions> .Flags.IsFlagSet(wrapOptions, WrapOptions.GenerateOverlayInfoBarMessageControl)) { // Create info bar message control var infoBarMessageControl = new InfoBarMessageControl(); infoBarMessageControl.Name = InfoBarMessageControlName; infoBarMessageControl.Content = mainContent; if (Enum <WrapOptions> .Flags.IsFlagSet(wrapOptions, WrapOptions.GenerateOverlayInfoBarMessageControl)) { infoBarMessageControl.Mode = InfoBarMessageControlMode.Overlay; } // This is now the main content mainContent = infoBarMessageControl; } #endif #endregion // Set content of the outside grid outsideGrid.Children.Add(mainContent); if (parentContentControl != null) { SetControlContent(parentContentControl, outsideGrid); } return(outsideGrid); }
/// <summary> /// Wraps the specified framework element without any buttons. /// </summary> /// <param name="frameworkElement">The framework element.</param> /// <param name="wrapOptions">The wrap options.</param> /// <param name="parentContentControl">The parent content control.</param> /// <returns> /// <see cref="Grid"/> that contains the wrapped content. /// </returns> /// <remarks> /// The framework element that is passed must be disconnected from the parent first. It is recommended to first check whether a /// framework element can be wrapped by using the <see cref="CanBeWrapped"/> method. /// <para /> /// This method will automatically handle the disconnecting of the framework element from the parent is the <paramref name="parentContentControl"/> /// is passed. /// </remarks> public static Grid Wrap(FrameworkElement frameworkElement, WrapOptions wrapOptions, ContentControl parentContentControl = null) { return(Wrap(frameworkElement, wrapOptions, new DataWindowButton[] { }, parentContentControl)); }
/// <summary> /// Wraps the specified framework element. /// </summary> /// <param name="frameworkElement">The framework element.</param> /// <param name="wrapOptions">The wrap options.</param> /// <param name="buttons">The buttons to add.</param> /// <param name="parentContentControl">The parent content control.</param> /// <returns><see cref="Grid"/> that contains the wrapped content.</returns> /// <remarks> /// The framework element that is passed must be disconnected from the parent first. It is recommended to first check whether a /// framework element can be wrapped by using the <see cref="CanBeWrapped"/> method. /// This method will automatically handle the disconnecting of the framework element from the parent is the <paramref name="parentContentControl"/> /// is passed. /// </remarks> public static Grid Wrap(FrameworkElement frameworkElement, WrapOptions wrapOptions, DataWindowButton[] buttons, ContentControl parentContentControl) { Argument.IsNotNull("frameworkElement", frameworkElement); Argument.IsNotNull("buttons", buttons); if (!string.IsNullOrWhiteSpace(frameworkElement.Name)) { if (frameworkElement.Name.StartsWith(MainContentHolderName)) { return((Grid)frameworkElement); } } if (parentContentControl != null) { SetControlContent(parentContentControl, null); } var mainContent = frameworkElement; // Create the outside grid, so the inner grid is never the same as the main content holder var outsideGrid = new Grid(); outsideGrid.Name = MainContentHolderName.GetUniqueControlName(); if (Application.Current != null) { outsideGrid.Resources.MergedDictionaries.Add(Application.Current.Resources); } #region Generate buttons #if !NETFX_CORE if (buttons.Length > 0) { // Add wrappanel containing the buttons var buttonsWrapPanel = new WrapPanel(); buttonsWrapPanel.Name = ButtonsWrapPanelName; #if SILVERLIGHT buttonsWrapPanel.Style = Application.Current.Resources["DataWindowButtonContainerStyle"] as Style; #else buttonsWrapPanel.SetResourceReference(FrameworkElement.StyleProperty, "DataWindowButtonContainerStyle"); #endif foreach (var dataWindowButton in buttons) { var button = new Button(); if (dataWindowButton.CommandBindingPath != null) { button.SetBinding(ButtonBase.CommandProperty, new Binding(dataWindowButton.CommandBindingPath)); } else { button.Command = dataWindowButton.Command; } if (dataWindowButton.ContentBindingPath != null) { Binding contentBinding = new Binding(dataWindowButton.ContentBindingPath); if (dataWindowButton.ContentValueConverter != null) { contentBinding.Converter = dataWindowButton.ContentValueConverter; } button.SetBinding(ButtonBase.ContentProperty, contentBinding); } else { button.Content = dataWindowButton.Text; } if (dataWindowButton.VisibilityBindingPath != null) { Binding visibilityBinding = new Binding(dataWindowButton.VisibilityBindingPath); if (dataWindowButton.VisibilityValueConverter != null) { visibilityBinding.Converter = dataWindowButton.VisibilityValueConverter; } button.SetBinding(ButtonBase.VisibilityProperty, visibilityBinding); } #if NET button.SetResourceReference(FrameworkElement.StyleProperty, "DataWindowButtonStyle"); button.IsDefault = dataWindowButton.IsDefault; button.IsCancel = dataWindowButton.IsCancel; #else button.Style = Application.Current.Resources["DataWindowButtonStyle"] as Style; #endif if (dataWindowButton.IsDefault) { button.Name = DefaultOkButtonName; } else if (dataWindowButton.IsCancel) { button.Name = DefaultCancelButtonName; } buttonsWrapPanel.Children.Add(button); } // Create dockpanel that will dock the buttons underneath the content var subDockPanel = new DockPanel(); subDockPanel.LastChildFill = true; DockPanel.SetDock(buttonsWrapPanel, Dock.Bottom); subDockPanel.Children.Add(buttonsWrapPanel); // Add actual content subDockPanel.Children.Add(frameworkElement); // The dockpanel is now the main content mainContent = subDockPanel; } #endif #endregion #region Generate internal grid // Create grid var internalGrid = new Grid(); internalGrid.Name = InternalGridName; internalGrid.Children.Add(mainContent); // Grid is now the main content mainContent = internalGrid; #endregion #region Generate WarningAndErrorValidator if (Enum <WrapOptions> .Flags.IsFlagSet(wrapOptions, WrapOptions.GenerateWarningAndErrorValidatorForDataContext)) { // Create warning and error validator var warningAndErrorValidator = new WarningAndErrorValidator(); warningAndErrorValidator.Name = WarningAndErrorValidatorName; warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding()); // Add to grid internalGrid.Children.Add(warningAndErrorValidator); } #endregion #region Generate InfoBarMessageControl #if !NETFX_CORE if (Enum <WrapOptions> .Flags.IsFlagSet(wrapOptions, WrapOptions.GenerateInlineInfoBarMessageControl) || Enum <WrapOptions> .Flags.IsFlagSet(wrapOptions, WrapOptions.GenerateOverlayInfoBarMessageControl)) { // Create info bar message control var infoBarMessageControl = new InfoBarMessageControl(); infoBarMessageControl.Name = InfoBarMessageControlName; infoBarMessageControl.Content = mainContent; if (Enum <WrapOptions> .Flags.IsFlagSet(wrapOptions, WrapOptions.GenerateOverlayInfoBarMessageControl)) { infoBarMessageControl.Mode = InfoBarMessageControlMode.Overlay; } // This is now the main content mainContent = infoBarMessageControl; } #endif #endregion // Set content of the outside grid outsideGrid.Children.Add(mainContent); if (parentContentControl != null) { SetControlContent(parentContentControl, outsideGrid); } return(outsideGrid); }
public static void configureASPrinter(ASPrettyPrinter printer, Settings settings) { Boolean useTabs = PluginBase.Settings.UseTabs; Int32 tabSize = PluginBase.Settings.TabWidth; Int32 spaceSize = PluginBase.Settings.IndentSize; Int32 braceStyle = PluginBase.Settings.CodingStyle == CodingStyle.BracesOnLine ? 4 : 5; printer.setIndentMultilineComments(settings.Pref_AS_IndentMultilineComments); printer.setBlankLinesBeforeFunction(settings.Pref_AS_BlankLinesBeforeFunctions); printer.setBlankLinesBeforeClass(settings.Pref_AS_BlankLinesBeforeClasses); printer.setBlankLinesBeforeControlStatement(settings.Pref_AS_BlankLinesBeforeControlStatements); printer.setBlankLinesBeforeImports(settings.Pref_AS_BlankLinesBeforeImportBlock); printer.setBlankLinesBeforeProperties(settings.Pref_AS_BlankLinesBeforeProperties); printer.setBlankLinesToStartFunctions(settings.Pref_AS_BlankLinesAtFunctionStart); printer.setBlankLinesToEndFunctions(settings.Pref_AS_BlankLinesAtFunctionEnd); printer.setBlockIndent(spaceSize); printer.setUseTabs(useTabs); printer.setTabSize(tabSize); printer.setSpacesAfterComma(settings.Pref_AS_SpacesAfterComma); printer.setSpacesBeforeComma(settings.Pref_AS_SpacesBeforeComma); printer.setCRBeforeOpenBrace(settings.Pref_AS_OpenBraceOnNewLine); printer.setCRBeforeCatch(settings.Pref_AS_CatchOnNewLine); printer.setCRBeforeElse(settings.Pref_AS_ElseOnNewLine); printer.setCRBeforeWhile(settings.Pref_AS_WhileOnNewLine); printer.setUseBraceStyleSetting(true); printer.setBraceStyleSetting(braceStyle); printer.setKeepBlankLines(settings.Pref_AS_KeepBlankLines); printer.setBlankLinesToKeep(settings.Pref_AS_BlankLinesToKeep); printer.setSpacesAroundAssignment(settings.Pref_AS_SpacesAroundAssignment); printer.setAdvancedSpacesAroundAssignmentInOptionalParameters(settings.Pref_AS_Tweak_SpacesAroundEqualsInOptionalParameters); printer.setUseAdvancedSpacesAroundAssignmentInOptionalParameters(settings.Pref_AS_Tweak_UseSpacesAroundEqualsInOptionalParameters); printer.setAdvancedSpacesAroundAssignmentInMetatags(settings.Pref_AS_Tweak_SpacesAroundEqualsInMetatags); printer.setUseAdvancedSpacesAroundAssignmentInMetatags(settings.Pref_AS_Tweak_UseSpacesAroundEqualsInMetatags); printer.setSpacesAroundColons(settings.Pref_AS_SpacesAroundColons); printer.setAdvancedSpacesAfterColonsInDeclarations(settings.Pref_AS_AdvancedSpacesAfterColonsInDeclarations); printer.setAdvancedSpacesBeforeColonsInDeclarations(settings.Pref_AS_AdvancedSpacesBeforeColonsInDeclarations); printer.setAdvancedSpacesAfterColonsInFunctionTypes(settings.Pref_AS_AdvancedSpacesAfterColonsInFunctionTypes); printer.setAdvancedSpacesBeforeColonsInFunctionTypes(settings.Pref_AS_AdvancedSpacesBeforeColonsInFunctionTypes); printer.setUseGlobalSpacesAroundColons(settings.Pref_AS_UseGlobalSpacesAroundColons); printer.setMaxLineLength(settings.Pref_AS_MaxLineLength); printer.setExpressionSpacesAroundSymbolicOperators(settings.Pref_AS_SpacesAroundSymbolicOperator); printer.setKeepElseIfOnSameLine(settings.Pref_AS_ElseIfOnSameLine); printer.setKeepSingleLineCommentsAtColumn1(settings.Pref_AS_KeepSLCommentsOnColumn1); printer.setUseLineCommentWrapping(settings.Pref_AS_UseLineCommentWrapping); printer.setUseMLCommentWrapping(settings.Pref_AS_UseMLCommentWrapping); printer.setMLCommentCollapseLines(settings.Pref_AS_MLCommentReflow); printer.setDocCommentCollapseLines(settings.Pref_AS_DocCommentReflow); printer.setMLTextOnNewLines(settings.Pref_AS_MLCommentHeaderOnSeparateLine); printer.setMLAsteriskMode((Int32)settings.Pref_AS_MLCommentAsteriskMode); printer.setUseDocCommentWrapping(settings.Pref_AS_UseDocCommentWrapping); printer.setDocCommentHangingIndentTabs(settings.Pref_AS_DocCommentHangingIndentTabs); printer.setDocCommentKeepBlankLines(settings.Pref_AS_DocCommentKeepBlankLines); printer.setMLCommentKeepBlankLines(settings.Pref_AS_MLCommentKeepBlankLines); printer.setKeepSingleLineFunctions(settings.Pref_AS_LeaveSingleLineFunctions); printer.setNoIndentForTerminators(settings.Pref_AS_UnindentExpressionTerminators); printer.setNoCRBeforeBreak(settings.Pref_AS_NoNewCRsBeforeBreak); printer.setNoCRBeforeContinue(settings.Pref_AS_NoNewCRsBeforeContinue); printer.setNoCRBeforeReturn(settings.Pref_AS_NoNewCRsBeforeReturn); printer.setNoCRBeforeThrow(settings.Pref_AS_NoNewCRsBeforeThrow); printer.setNoCRBeforeExpressions(settings.Pref_AS_NoNewCRsBeforeExpression); printer.setKeepRelativeCommentIndent(settings.Pref_AS_KeepRelativeIndentInDocComments); printer.setSpacesInsideParensEtc(settings.Pref_AS_SpacesInsideParens); printer.setUseSpacesInsideParensEtc(settings.Pref_AS_UseGlobalSpacesInsideParens); printer.setHangingIndentTabs(settings.Pref_AS_TabsInHangingIndent); printer.setAdvancedSpacesInsideArrayDeclBrackets(settings.Pref_AS_AdvancedSpacesInsideArrayDeclBrackets); printer.setAdvancedSpacesInsideArrayReferenceBrackets(settings.Pref_AS_AdvancedSpacesInsideArrayRefBrackets); printer.setAdvancedSpacesInsideObjectBraces(settings.Pref_AS_AdvancedSpacesInsideLiteralBraces); printer.setAdvancedSpacesInsideParensInOtherPlaces(settings.Pref_AS_AdvancedSpacesInsideParensInOtherPlaces); printer.setAdvancedSpacesInsideParensInParameterLists(settings.Pref_AS_AdvancedSpacesInsideParensInParameterLists); printer.setAdvancedSpacesInsideParensInArgumentLists(settings.Pref_AS_AdvancedSpacesInsideParensInArgumentLists); printer.setSpacesBetweenControlKeywordsAndParens(settings.Pref_AS_SpacesBeforeOpenControlParen); printer.setSpacesBeforeFormalParameters(settings.Pref_AS_SpacesBeforeFormalParameters); printer.setSpacesBeforeArguments(settings.Pref_AS_SpacesBeforeArguments); printer.setAlwaysGenerateIndent(settings.Pref_AS_AlwaysGenerateIndent); printer.setUseGNUBraceIndent(settings.Pref_AS_UseGnuBraceIndent); printer.setLoopBraceMode(settings.Pref_AS_EnsureLoopsHaveBraces ? ASPrettyPrinter.Braces_AddIfMissing : ASPrettyPrinter.Braces_NoModify); printer.setLoopBraceMode(settings.Pref_AS_AddBracesToLoops); printer.setSwitchBraceMode(settings.Pref_AS_EnsureSwitchCasesHaveBraces ? ASPrettyPrinter.Braces_AddIfMissing : ASPrettyPrinter.Braces_NoModify); printer.setSwitchBraceMode(settings.Pref_AS_AddBracesToCases); printer.setConditionalBraceMode(settings.Pref_AS_EnsureConditionalsHaveBraces ? ASPrettyPrinter.Braces_AddIfMissing : ASPrettyPrinter.Braces_NoModify); printer.setConditionalBraceMode(settings.Pref_AS_AddBracesToConditionals); printer.setIndentAtPackageLevel(!settings.Pref_AS_DontIndentPackageItems); printer.setIndentSwitchCases(!settings.Pref_AS_DontIndentSwitchCases); printer.setKeepingExcessDeclWhitespace(settings.Pref_AS_LeaveExtraWhitespaceAroundVarDecls); printer.setAlignDeclEquals(settings.Pref_AS_AlignDeclEquals); printer.setAlignDeclMode((Int32)settings.Pref_AS_AlignDeclMode); printer.setKeepSpacesBeforeLineComments(settings.Pref_AS_KeepSpacesBeforeLineComments); printer.setLineCommentColumn(settings.Pref_AS_AlignLineCommentsAtColumn); printer.setUseGlobalNewlineBeforeBraceSetting(settings.Pref_AS_UseGlobalCRBeforeBrace); printer.setAdvancedNewlineBeforeBraceSettings(settings.Pref_AS_AdvancedCRBeforeBraceSettings); printer.setCollapseSpaceForAdjacentParens(settings.Pref_AS_CollapseSpacesForAdjacentParens); //printer.setNewlineAfterBindable(settings.Pref_AS_NewlineAfterBindable); printer.setNewlineBeforeBindableFunction(settings.Pref_AS_NewlineBeforeBindableFunction); printer.setNewlineBeforeBindableProperty(settings.Pref_AS_NewlineBeforeBindableProperty); List <String> tags = new List <String>(); tags.AddRange(settings.Pref_AS_MetaTagsOnSameLineAsTargetFunction.Split(',')); printer.setMetaTagsToKeepOnSameLineAsFunction(tags); tags.Clear(); tags.AddRange(settings.Pref_AS_MetaTagsOnSameLineAsTargetProperty.Split(',')); printer.setMetaTagsToKeepOnSameLineAsProperty(tags); printer.setTrimTrailingWS(settings.Pref_AS_TrimTrailingWhitespace); printer.setSpacesAfterLabel(settings.Pref_AS_SpacesAfterLabel); printer.setEmptyStatementsOnNewLine(settings.Pref_AS_PutEmptyStatementsOnNewLine); printer.setUseAdvancedWrapping(settings.Pref_AS_UseAdvancedWrapping); printer.setAdvancedWrappingElements(settings.Pref_AS_AdvancedWrappingElements); printer.setAdvancedWrappingEnforceMax(settings.Pref_AS_AdvancedWrappingEnforceMax); printer.setWrapAllArgumentsIfAny(settings.Pref_AS_AdvancedWrappingAllArgs); printer.setWrapAllParametersIfAny(settings.Pref_AS_AdvancedWrappingAllParms); printer.setWrapFirstArgument(settings.Pref_AS_AdvancedWrappingFirstArg); printer.setWrapFirstParameter(settings.Pref_AS_AdvancedWrappingFirstParm); printer.setWrapFirstArrayItem(settings.Pref_AS_AdvancedWrappingFirstArrayItem); printer.setWrapFirstObjectItem(settings.Pref_AS_AdvancedWrappingFirstObjectItem); printer.setWrapAllArrayItemsIfAny(settings.Pref_AS_AdvancedWrappingAllArrayItems); printer.setWrapAllObjectItemsIfAny(settings.Pref_AS_AdvancedWrappingAllObjectItems); printer.setWrapArrayItemsAlignStart(settings.Pref_AS_AdvancedWrappingAlignArrayItems); printer.setWrapObjectItemsAlignStart(settings.Pref_AS_AdvancedWrappingAlignObjectItems); printer.setAdvancedWrappingGraceColumns(settings.Pref_AS_AdvancedWrappingGraceColumns); printer.setAdvancedWrappingPreservePhrases(settings.Pref_AS_AdvancedWrappingPreservePhrases); bool breakBeforeComma = settings.Pref_AS_BreakLinesBeforeComma; bool breakBeforeArithmetic = settings.Pref_AS_BreakLinesBeforeArithmetic; bool breakBeforeLogical = settings.Pref_AS_BreakLinesBeforeLogical; bool breakBeforeAssign = settings.Pref_AS_BreakLinesBeforeAssignment; int wrapIndentStyle = (Int32)settings.Pref_AS_WrapIndentStyle; WrapOptions options = new WrapOptions((Int32)settings.Pref_AS_WrapArrayDeclMode); options.setBeforeSeparator(breakBeforeComma); options.setBeforeArithmeticOperator(breakBeforeArithmetic); options.setBeforeLogicalOperator(breakBeforeLogical); options.setBeforeAssignmentOperator(breakBeforeAssign); options.setIndentStyle(wrapIndentStyle); printer.setArrayInitWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapMethodCallMode); options.setBeforeSeparator(breakBeforeComma); options.setBeforeArithmeticOperator(breakBeforeArithmetic); options.setBeforeLogicalOperator(breakBeforeLogical); options.setBeforeAssignmentOperator(breakBeforeAssign); options.setIndentStyle(wrapIndentStyle); printer.setMethodCallWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapMethodDeclMode); options.setBeforeSeparator(breakBeforeComma); options.setIndentStyle(wrapIndentStyle); printer.setMethodDeclWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapExpressionMode); options.setBeforeSeparator(breakBeforeComma); options.setBeforeArithmeticOperator(breakBeforeArithmetic); options.setBeforeLogicalOperator(breakBeforeLogical); options.setBeforeAssignmentOperator(breakBeforeAssign); options.setIndentStyle(wrapIndentStyle); printer.setExpressionWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapXMLMode); options.setBeforeSeparator(breakBeforeComma); options.setBeforeArithmeticOperator(breakBeforeArithmetic); options.setBeforeLogicalOperator(breakBeforeLogical); options.setBeforeAssignmentOperator(breakBeforeAssign); options.setIndentStyle(wrapIndentStyle); printer.setXMLWrapOptions(options); }
/// <summary> /// Wraps the specified r. /// </summary> /// <param name="r">The r.</param> /// <param name="options">The options.</param> /// <returns></returns> public static TextReader Wrap(TextReader r, WrapOptions options) { var rAsWrap = (r as WrapTextReader); return (rAsWrap != null && rAsWrap.Options == options ? r : new WrapTextReader(r, options)); }
/// <summary> /// Initializes a new instance of the <see cref="WrapTextReader"/> class. /// </summary> /// <param name="r">The r.</param> /// <param name="options">The options.</param> protected WrapTextReader(TextReader r, WrapOptions options) { R = r; Options = options; }
/// <summary> /// Wraps the specified framework element without any buttons. /// </summary> /// <param name="frameworkElement">The framework element.</param> /// <param name="wrapOptions">The wrap options.</param> /// <param name="parentContentControl">The parent content control.</param> /// <returns> /// <see cref="Grid"/> that contains the wrapped content. /// </returns> /// <remarks> /// The framework element that is passed must be disconnected from the parent first. It is recommended to first check whether a /// framework element can be wrapped by using the <see cref="CanBeWrapped"/> method. /// <para /> /// This method will automatically handle the disconnecting of the framework element from the parent is the <paramref name="parentContentControl"/> /// is passed. /// </remarks> public static Grid Wrap(FrameworkElement frameworkElement, WrapOptions wrapOptions, ContentControl parentContentControl = null) { return(Wrap(frameworkElement, wrapOptions, ArrayShim.Empty <DataWindowButton>(), parentContentControl)); }
public static TextReader Wrap(TextReader r, WrapOptions options) { var rAsWrap = (r as WrapTextReader); return(rAsWrap != null && rAsWrap.Options == options ? r : new WrapTextReader(r, options)); }
protected WrapTextReader(TextReader r, WrapOptions options) { R = r; Options = options; }
private IViewModelWrapper CreateViewModelGrid(IView view, object viewModelSource, WrapOptions wrapOptions) { var content = GetContent(view) as FrameworkElement; if (content == null) { return(null); } object tempObj = null; if (_weakIsWrappingTable.TryGetValue(view, out tempObj)) { return(null); } _weakIsWrappingTable.Add(view, new object()); var vmGrid = new Grid(); vmGrid.Name = InnerWrapperName; vmGrid.SetBinding(FrameworkElement.DataContextProperty, new Binding { Path = new PropertyPath("ViewModel"), Source = viewModelSource }); #if NET || SL5 if (Enum <WrapOptions> .Flags.IsFlagSet(wrapOptions, WrapOptions.CreateWarningAndErrorValidatorForViewModel)) { var warningAndErrorValidator = new WarningAndErrorValidator(); warningAndErrorValidator.SetBinding(WarningAndErrorValidator.SourceProperty, new Binding()); vmGrid.Children.Add(warningAndErrorValidator); } #endif if (Enum <WrapOptions> .Flags.IsFlagSet(wrapOptions, WrapOptions.TransferStylesAndTransitionsToViewModelGrid)) { content.TransferStylesAndTransitions(vmGrid); } SetContent(view, null); vmGrid.Children.Add(content); SetContent(view, vmGrid); Log.Debug("Created target control content wrapper grid for view model"); return(new ViewModelWrapper(vmGrid)); }
public static void ConfigureASPrinter(ASPrettyPrinter printer, Settings settings, int tabSize) { printer.SetIndentMultilineComments(settings.Pref_AS_IndentMultilineComments); printer.SetBlankLinesBeforeFunction(settings.Pref_AS_BlankLinesBeforeFunctions); printer.SetBlankLinesBeforeClass(settings.Pref_AS_BlankLinesBeforeClasses); printer.SetBlankLinesBeforeControlStatement(settings.Pref_AS_BlankLinesBeforeControlStatements); printer.SetBlankLinesBeforeProperties(settings.Pref_AS_BlankLinesBeforeProperties); printer.SetBlockIndent(tabSize); printer.SetUseTabs(settings.Pref_Flex_UseTabs); printer.SetTabSize(tabSize); printer.SetSpacesAfterComma(settings.Pref_AS_SpacesAfterComma); printer.SetSpacesBeforeComma(settings.Pref_AS_SpacesBeforeComma); printer.SetCRBeforeOpenBrace(settings.Pref_AS_OpenBraceOnNewLine); printer.SetCRBeforeCatch(settings.Pref_AS_CatchOnNewLine); printer.SetCRBeforeElse(settings.Pref_AS_ElseOnNewLine); printer.SetUseBraceStyleSetting(settings.Pref_AS_UseBraceStyle); printer.SetBraceStyleSetting((Int32)settings.Pref_AS_BraceStyle); printer.SetKeepBlankLines(settings.Pref_AS_KeepBlankLines); printer.SetBlankLinesToKeep(settings.Pref_AS_BlankLinesToKeep); printer.SetSpacesAroundAssignment(settings.Pref_AS_SpacesAroundAssignment); printer.SetAdvancedSpacesAroundAssignmentInOptionalParameters(settings.Pref_AS_Tweak_SpacesAroundEqualsInOptionalParameters); printer.SetUseAdvancedSpacesAroundAssignmentInOptionalParameters(settings.Pref_AS_Tweak_UseSpacesAroundEqualsInOptionalParameters); printer.SetSpacesAroundColons(settings.Pref_AS_SpacesAroundColons); printer.SetAdvancedSpacesAfterColons(settings.Pref_AS_AdvancedSpacesAfterColons); printer.SetAdvancedSpacesBeforeColons(settings.Pref_AS_AdvancedSpacesBeforeColons); printer.SetUseGlobalSpacesAroundColons(settings.Pref_AS_UseGlobalSpacesAroundColons); printer.SetMaxLineLength(settings.Pref_AS_MaxLineLength); printer.SetExpressionSpacesAroundSymbolicOperators(settings.Pref_AS_SpacesAroundSymbolicOperator); printer.SetKeepElseIfOnSameLine(settings.Pref_AS_ElseIfOnSameLine); printer.SetKeepSingleLineCommentsAtColumn1(settings.Pref_AS_KeepSLCommentsOnColumn1); printer.SetSpacesInsideParensEtc(settings.Pref_AS_SpacesInsideParens); printer.SetUseSpacesInsideParensEtc(settings.Pref_AS_UseGlobalSpacesInsideParens); printer.SetAdvancedSpacesInsideArrayDeclBrackets(settings.Pref_AS_AdvancedSpacesInsideArrayDeclBrackets); printer.SetAdvancedSpacesInsideArrayReferenceBrackets(settings.Pref_AS_AdvancedSpacesInsideArrayRefBrackets); printer.SetAdvancedSpacesInsideObjectBraces(settings.Pref_AS_AdvancedSpacesInsideLiteralBraces); printer.SetAdvancedSpacesInsideParens(settings.Pref_AS_AdvancedSpacesInsideParens); printer.SetSpacesBetweenControlKeywordsAndParens(settings.Pref_AS_SpacesBeforeOpenControlParen); printer.SetAlwaysGenerateIndent(settings.Pref_AS_AlwaysGenerateIndent); printer.SetIndentAtPackageLevel(!settings.Pref_AS_DontIndentPackageItems); printer.SetKeepingExcessDeclWhitespace(settings.Pref_AS_LeaveExtraWhitespaceAroundVarDecls); printer.SetCollapseSpaceForAdjacentParens(settings.Pref_AS_CollapseSpacesForAdjacentParens); printer.SetNewlineAfterBindable(settings.Pref_AS_NewlineAfterBindable); printer.SetTrimTrailingWS(settings.Pref_AS_TrimTrailingWhitespace); printer.SetSpacesAfterLabel(settings.Pref_AS_SpacesAfterLabel); printer.SetEmptyStatementsOnNewLine(settings.Pref_AS_PutEmptyStatementsOnNewLine); bool breakBeforeComma = settings.Pref_AS_BreakLinesBeforeComma; int wrapIndentStyle = (Int32)settings.Pref_AS_WrapIndentStyle; WrapOptions options = new WrapOptions((Int32)settings.Pref_AS_WrapArrayDeclMode); options.BeforeSeparator = breakBeforeComma; options.IndentStyle = wrapIndentStyle; printer.SetArrayInitWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapMethodCallMode); options.BeforeSeparator = breakBeforeComma; options.IndentStyle = wrapIndentStyle; printer.SetMethodCallWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapMethodDeclMode); options.BeforeSeparator = breakBeforeComma; options.IndentStyle = wrapIndentStyle; printer.SetMethodDeclWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapExpressionMode); options.BeforeSeparator = breakBeforeComma; options.IndentStyle = wrapIndentStyle; printer.SetExpressionWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapXMLMode); options.BeforeSeparator = breakBeforeComma; options.IndentStyle = wrapIndentStyle; printer.SetXMLWrapOptions(options); }