public static void ApplyNewLevelStyle(OutlinerNote note, int newLevel) { // нолевой уровень - корень if (newLevel <= 0) { return; } UndoLevelStyle undoLevelStyle = new UndoLevelStyle(note); if (note.LastStyleApplied != null) { note.LastStyleApplied.UnapplyStyle(note); } LevelStyle levelStyle = note.Document.Styles.GetStyleForLevel(newLevel); LevelStyle wholeDocumentStyle = note.Document.Styles.WholeDocumentStyle; wholeDocumentStyle.ApplyToNote(note); levelStyle.ApplyToNote(note); note.LastStyleApplied = levelStyle; undoLevelStyle.StyleApplied(note); note.Document.UndoManager.PushUndoAction(undoLevelStyle); }
internal void UpdateStyle(BaseStyle activeStyle, StylePropertyType stylePropertyType, object value) { LevelStyle levelStyle = activeStyle as LevelStyle; InlineNoteStyle inlineStyle = activeStyle as InlineNoteStyle; WalkRecursively(__FakeRootNote, delegate(OutlinerNote note, out bool shouldWalkSubnotes, out bool shouldContinue) { shouldContinue = true; shouldWalkSubnotes = true; if (activeStyle.StyleType == StyleType.Inline) { if (!note.HasInlineNote) { return; } TextRange range = new TextRange(note.InlineNoteDocument.ContentStart, note.InlineNoteDocument.ContentEnd); UndoManager.PushUndoAction(new Undo.UndoFlowDocumentFormatting(note, 0, true, false)); LevelStyle.ApplyPropertyToRange(range, stylePropertyType, value); LevelStyle.ApplyPropertyToFlowDocument(note.InlineNoteDocument, stylePropertyType, value); } else // if (activeStyle.StyleType == StyleType.Level) { if (note.Level == levelStyle.Level || levelStyle.Level == -1) { ApplyStylePropertyForAllColumns(stylePropertyType, value, levelStyle, note); } } }); }
public OutlinerStyles() { __LevelStyles = new List <LevelStyle>(); __WholeDocumentStyle = new LevelStyle(-1); __WholeDocumentStyle.StyleChanged += new EventHandler(OnStyleChanged); Add(__WholeDocumentStyle); __InlineNoteStyle = new InlineNoteStyle(); __InlineNoteStyle.AddProperty(StylePropertyType.FontSize, Math.Floor(Settings.DefaultFontSize / 1.2)); __InlineNoteStyle.AddProperty(StylePropertyType.FontColor, new SolidColorBrush(Color.FromRgb(0x77, 0x77, 0x77))); __InlineNoteStyle.StyleChanged += new EventHandler(OnStyleChanged); Add(__InlineNoteStyle); GetStyleForLevel(5); // Create styles for the first 5 levels }
// level - starts from zero internal LevelStyle GetStyleForLevel(int level) { if (level == -1) { return(__WholeDocumentStyle); } while (__LevelStyles.Count <= level) { var levelStyle = new LevelStyle(__LevelStyles.Count + 1); levelStyle.StyleChanged += new EventHandler(OnStyleChanged); __LevelStyles.Add(levelStyle); Add(levelStyle); } return(__LevelStyles[level - 1]); }
public static void ApplyLevelStyleForEdit(OutlinerNote note, MyEdit myEdit) { // нолевой уровень - корень if (note.Level == -1) { return; } int level = note.Level; LevelStyle levelStyle = note.Document.Styles.GetStyleForLevel(level); LevelStyle wholeDocumentStyle = note.Document.Styles.WholeDocumentStyle; if (myEdit != null) { wholeDocumentStyle.ApplyToMyEdit(myEdit); wholeDocumentStyle.ApplyToRange(myEdit.Selection); levelStyle.ApplyToMyEdit(myEdit); levelStyle.ApplyToRange(myEdit.Selection); //UpdateFontSettings(myEdit.Selection); } }
private void ApplyStylePropertyForAllColumns(StylePropertyType stylePropertyType, object value, LevelStyle levelStyle, OutlinerNote note) { for (int i = 0; i < note.Columns.Count; i++) { if (note.Columns[i].DataType != ColumnDataType.RichText) { continue; } FlowDocument flowDocument = (FlowDocument)note.Columns[i].ColumnData; TextRange range = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd); UndoManager.PushUndoAction(new Undo.UndoFlowDocumentFormatting(note, i, false, false)); LevelStyle.ApplyPropertyToRange(range, stylePropertyType, value); LevelStyle.ApplyPropertyToFlowDocument(flowDocument, stylePropertyType, value); // If document style gets modified, level style should be applied afterwards if (levelStyle.Level == -1) { LevelStyle currentLevelStyle = note.Document.Styles.GetStyleForLevel(note.Level); for (int si = 0; si < currentLevelStyle.Properties.Count; si++) { if (currentLevelStyle.Properties[si].PropertyType == stylePropertyType) { LevelStyle.ApplyPropertyToRange(range, stylePropertyType, currentLevelStyle.Properties[si].Value); LevelStyle.ApplyPropertyToFlowDocument( flowDocument, stylePropertyType, currentLevelStyle.Properties[si].Value); } } } } }