private void ProcessColorRule(ColorRulesViewModel colorRulesViewModel) { if (colorRulesViewModel.Selection == null) { return; } switch (colorRulesViewModel.Type) { case RuleTypes.Alternating: ProcessAlternatingRule(colorRulesViewModel); break; } }
private void OpenColorRules(ProjectViewModel projectViewModel) { Logger.Log.Debug("Opened"); ColorRulesView colorRulesView = new ColorRulesView(); var colorRulesViewModel = new ColorRulesViewModel(MainViewModel); colorRulesViewModel.Selection = projectViewModel.Selection; colorRulesView.DataContext = colorRulesViewModel; colorRulesView.WindowStartupLocation = WindowStartupLocation.CenterOwner; colorRulesView.Owner = Application.Current.MainWindow; colorRulesView.ShowDialog(); Logger.Log.Debug("Closed"); }
private object MaterializeSelection(ColorRulesViewModel colorRulesViewModel) { object selection = null; using (StreamWriter writer = new StreamWriter("temp.xaml")) { colorRulesViewModel.Selection.Save(writer.BaseStream, DataFormats.Xaml); writer.Close(); } using (StreamReader reader = new StreamReader("temp.xaml")) { selection = XamlReader.Load(reader.BaseStream); reader.Close(); } return(selection); }
public WindowManager(MainViewModel mainViewModel) { MainViewModel = mainViewModel; OptionsViewModel = new OptionsViewModel(MainViewModel); AboutViewModel = new AboutViewModel(MainViewModel); LibraryManagementViewModel = new LibraryManagementViewModel(MainViewModel); LibraryEditorViewModel = new LibraryEditorViewModel(MainViewModel); ColorRulesViewModel = new ColorRulesViewModel(MainViewModel); ColorAnalyzerViewModel = new ColorAnalyzerViewModel(MainViewModel); OpenOptionsCommand = new RelayCommand( () => OpenOptions(), () => CanOpenOptions()); OpenAboutCommand = new RelayCommand( () => OpenAbout(), () => CanOpenAbout()); OpenLibraryManagementCommand = new RelayCommand( () => OpenLibraryManagement(), () => CanOpenLibraryManagement()); OpenLibraryEditorCommand = new RelayCommand <LibraryViewModel>( (l) => OpenLibraryEditor(l), (l) => CanOpenLibraryEditor(l)); CloseLibraryEditorCommand = new RelayCommand <CancelEventArgs>( (e) => CloseLibraryEditor(e), (e) => CanCloseLibraryEditor(e)); OpenColorRulesCommand = new RelayCommand <ProjectViewModel>( (p) => OpenColorRules(p), (p) => CanOpenColorRules(p)); OpenColorAnalyzerCommand = new RelayCommand <ProjectViewModel>( (p) => OpenColorAnalyzer(p), (p) => CanOpenColorAnalyzer(p)); }
private void ProcessAlternatingRule(ColorRulesViewModel colorRulesViewModel) { var selection = MaterializeSelection(colorRulesViewModel); if (selection.GetType() == typeof(Section)) { // } else if (selection.GetType() == typeof(Span)) { // } else { MessageBox.Show(selection.GetType().ToString()); } StringBuilder stringBuilder = new StringBuilder(); if (selection.GetType() == typeof(Section)) { var section = selection as Section; foreach (Block block in section.Blocks) { var paragraph = block as Paragraph; foreach (Inline inline in paragraph.Inlines) { var run = inline as Run; if (run.Text.Length <= 0) { //stringBuilder.Append(Environment.NewLine); } stringBuilder.Append(run.Text); //stringBuilder.Append(Environment.NewLine); } } List <String> array = StringUtilities.SplitIntoParts(stringBuilder.ToString(), colorRulesViewModel.Interval).ToList <string>(); Section newSection = new Section(); Paragraph newParagraph = new Paragraph(); Queue <Brush> foregroundBrushes = new Queue <Brush>(); Queue <Brush> backgroundBrushes = new Queue <Brush>(); foreach (SwatchViewModel swatchViewModel in colorRulesViewModel.ForegroundColors) { foregroundBrushes.Enqueue(new SolidColorBrush(swatchViewModel.Color)); } foreach (SwatchViewModel swatchViewModel in colorRulesViewModel.BackgroundColors) { backgroundBrushes.Enqueue(new SolidColorBrush(swatchViewModel.Color)); } for (int i = 0; i < array.Count; i++) { Run run = new Run(); run.Text = array[i]; var foregorundBrush = foregroundBrushes.Dequeue(); var backgroundBrush = backgroundBrushes.Dequeue(); if (colorRulesViewModel.Scope == RuleScopes.Foreground) { run.Foreground = foregorundBrush; } else if (colorRulesViewModel.Scope == RuleScopes.Background) { run.Background = backgroundBrush; } else if (colorRulesViewModel.Scope == RuleScopes.Both) { run.Foreground = foregorundBrush; run.Background = backgroundBrush; } foregroundBrushes.Enqueue(foregorundBrush); backgroundBrushes.Enqueue(backgroundBrush); newParagraph.Inlines.Add(run); } newSection.Blocks.Add(newParagraph); using (StreamWriter writer = new StreamWriter("temp.xaml")) { XamlWriter.Save(newSection, writer.BaseStream); writer.Close(); } using (StreamReader reader = new StreamReader("temp.xaml")) { MainViewModel.ActiveProject.Selection.Load(reader.BaseStream, DataFormats.Xaml); reader.Close(); } } else { MessageBox.Show(selection.GetType().ToString()); } }
private bool CanProcessColorRule(ColorRulesViewModel colorRulesViewModel) { return(true); }