//------------------------------------------------------------------------------------------ /// <summary> /// Initializes user-interface components over the provided shell. /// </summary> public static void InitializeUserInterface() { PaletteProject = new WidgetPalette("PaletteProject", "Project", EShellVisualContentType.PaletteContent, "book_open.png"); //PaletteProject.PaletteTab.Width = 300; // Ugly: PaletteProject.PaletteTab.FlowDirection = FlowDirection.RightToLeft; // To let space for the quickbar on the left. PaletteEdition = new WidgetPalette("PaletteEdition", "Compose", EShellVisualContentType.PaletteContent, "wand.png"); PaletteGeneral = new WidgetPalette("PaletteGeneral", "General", EShellVisualContentType.PaletteContent, "world.png"); PopulateMenuPalette(PaletteProject, CompositionDirector, EShellCommandCategory.Document, EShellCommandCategory.Global); PopulateMenuPalette(PaletteProject, DomainDirector, EShellCommandCategory.Document, EShellCommandCategory.Global); PopulateMenuPalette(PaletteEdition, CompositionDirector, EShellCommandCategory.Edition); PopulateMenuPalette(PaletteGeneral, CompositionDirector, EShellCommandCategory.Extra); // Let the "Recent" tab at end var Tabs = new List <object>(); foreach (var Tab in PaletteProject.PaletteTab.Items) { Tabs.Add(Tab); } Tabs.SwapItemsAt(1, 2); PaletteProject.PaletteTab.Items.Clear(); Tabs.ForEach(tab => PaletteProject.PaletteTab.Items.Add(tab)); // ---------------------------------------------------------------------------------------------------------------------------------------- EditorPropertiesControl = new WidgetPropertyPanel(); EditorProperties = new EntitledPanel("EditorProperties", "Properties", EShellVisualContentType.NavigationContent, EditorPropertiesControl); //POSTPONED: NavigatorMapControl = new WidgetNavMap(); //POSTPONED: NavigatorMap = new EntitledPanel("NavigatorMap", "Map", EShellVisualContentType.NavigationContent, NavigatorMapControl); // ---------------------------------------------------------------------------------------------------------------------------------------- ContentTreeControl = new WidgetNavTree(WorkspaceDirector); ContentTree = new EntitledPanel("ContentTree", "Content", EShellVisualContentType.NavigationContent, ContentTreeControl); // ---------------------------------------------------------------------------------------------------------------------------------------- DocumentArea = new DocumentPanel("DocumentVisualizer", DocumentVisualizerControl); DocumentArea.Height = double.NaN; DocumentArea.Width = double.NaN; // ---------------------------------------------------------------------------------------------------------------------------------------- var MessengerConsole = new WidgetMessenger(); MessengerConsolePublisher = new ConsoleRollPublisher(MessengerConsole.MessagePublisher, AppExec.GetConfiguration <int>("Application", "ConsoleOutputMaxLines", ConsoleRollPublisher.DEF_MAXLINES)); Console.SetOut(MessengerConsolePublisher); /* Messages and Results... * var TabItemConsole = new TabItem(); * TabItemConsole.Header = "Console"; * TabItemConsole.Content = MessengerConsole; * * var MessengerResults = new WidgetMessenger(); * var TabItemResults = new TabItem(); * TabItemResults.Header = "Results"; * TabItemResults.Content = MessengerResults; * * var TabMessenger = new TabControl(); * TabMessenger.TabStripPlacement = Dock.Bottom; * TabMessenger.Items.Add(TabItemConsole); * TabMessenger.Items.Add(TabItemResults); * TabMessenger.Height = double.NaN; * TabMessenger.Width = double.NaN; */ Messenger = new EntitledPanel("Messenger", "Messaging", EShellVisualContentType.MessagingContent, MessengerConsole /* TabMessenger */); Messenger.ShowTitle = false; // ---------------------------------------------------------------------------------------------------------------------------------------- var IdeaScroller = new ScrollViewer(); IdeaScroller.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; IdeaScroller.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; // For nice wrapping IdeaScroller.Content = IdeaPaletteControl; EditorIdeaPalette = new EntitledPanel("EditorIdeaPalette", "Ideas", EShellVisualContentType.EditingContent, IdeaScroller); // ---------------------------------------------------------------------------------------------------------------------------------------- var ComplementScroller = new ScrollViewer(); ComplementScroller.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; ComplementScroller.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; // For nice wrapping ComplementScroller.Content = ComplementPaletteControl; EditorComplementPalette = new EntitledPanel("EditorComplementPalette", "Complements", EShellVisualContentType.EditingContent, ComplementScroller); // ---------------------------------------------------------------------------------------------------------------------------------------- var MarkerScroller = new ScrollViewer(); MarkerScroller.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; MarkerScroller.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; // For nice wrapping MarkerScroller.Content = MarkerPaletteControl; EditorMarkerPalette = new EntitledPanel("EditorMarkerPalette", "Markers", EShellVisualContentType.EditingContent, MarkerScroller); // ---------------------------------------------------------------------------------------------------------------------------------------- StatusBarControl = new WidgetStatusBar(); StatusArea = new EntitledPanel("StatusMessage", "Status", EShellVisualContentType.StatusContent, StatusBarControl, false); StatusArea.Background = Brushes.Transparent; ShellHost.MainSelector = StatusBarControl.DocumentSelector; // ---------------------------------------------------------------------------------------------------------------------------------------- ShellHost.PutVisualContent(PaletteProject); ShellHost.PutVisualContent(PaletteEdition); //POSTPONED: ShellHost.PutVisualContent(PaletteGeneral); ShellHost.PutVisualContent(EShellVisualContentType.QuickPaletteContent, CompositionDirector.QuickExposedCommands.Select( (expo) => { var NewButton = new PaletteButton(expo); NewButton.ButtonText = ""; // Only show the icon NewButton.ToolTip = expo.Name; return(NewButton); })); ShellHost.PutVisualContent(ContentTree); ShellHost.PutVisualContent(EditorProperties); //POSTPONED: ShellHost.PutVisualContent(NavigatorMap); ShellHost.PutVisualContent(DocumentArea); ShellHost.PutVisualContent(Messenger); ShellHost.PutVisualContent(EditorIdeaPalette, 0); ShellHost.PutVisualContent(EditorMarkerPalette, 1); ShellHost.PutVisualContent(EditorComplementPalette, 2); ShellHost.PutVisualContent(StatusArea); ShellHost.MainSelector.ItemsSource = WorkspaceDirector.Documents; ShellHost.MainSelector.SelectionChanged += new SelectionChangedEventHandler(MainDocumentSelector_SelectionChanged); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // VERY IMPORTANT! // Do not mess with the next Action<T> nor Lambdas. // They are entangled into serialized content (Still don't know from where) WorkspaceDirector.PreDocumentDeactivation = (workspace, document) => { OnDocumentDiscard(workspace, document); document.DocumentEditEngine.LastOpenedViews = DocumentVisualizerControl.GetAllViews(document).ToList(); document.DocumentEditEngine.Visualizer.DiscardAllViews(); }; WorkspaceDirector.PostDocumentActivation = (workspace, document) => { if (ShellHost.MainSelector.SelectedItem != document) { ShellHost.RefreshSelection(document); } OnDocumentChange(workspace, document); document.DocumentEditEngine.Show(); document.DocumentEditEngine.LastOpenedViews = null; }; WorkspaceDirector.PostDocumentStatusChange = (workspace, document) => { OnDocumentChange(workspace, document); }; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! EntitleApplication(); ShowAssistance(); }
// ------------------------------------------------------------------------------------------------------------- /********************************************************************************* * //! CRITICAL CODE: Do not rename nor move. * // This part is entangled with predefined Domains, thru some * // serialized event-handlers with Action<T>, Func<T> and lambdas. *********************************************************************************/ public static void PopulateMenuPalette(WidgetPalette Palette, WorkSphere Sphere, params EShellCommandCategory[] AssignableCommandCategories) { var GroupingHeaderBrush = Display.GetResource <Brush, EntitledPanel>("HeaderBrush"); // PanelTextBrush also looks good var GroupingBodyBrush = new SolidColorBrush(Color.FromRgb(242, 246, 248)); // Display.GetGradientBrush(Color.FromRgb(252, 252, 252), Color.FromRgb(247, 247, 247)); //Display.GetResource<Brush, EntitledPanel>("PanelBrush"); // Adds the required tab items if these already does not exists in the palette's tab control. foreach (var Area in Sphere.CommandAreas) { Panel TargetAreaPanel = null; bool TabExists = false; bool MenuItemExposed = false; // Determines whether the current Area is already exposed as a TabItem. foreach (TabItem Item in Palette.PaletteTab.Items) { if (Item.Name == Area.TechName) { TargetAreaPanel = Item.Content as Panel; TabExists = true; break; } } // Creates a new Panel if no TabItem was found. if (!TabExists) { var WrappingPanel = new WrapPanel(); WrappingPanel.Orientation = Orientation.Horizontal; TargetAreaPanel = WrappingPanel; } // Create Groups foreach (var Group in Sphere.CommandGroups[Area.TechName]) { StackPanel TargetGroupContainer = null; WrapPanel TargetGroupingPanel = null; // Determines whether the current Group is already exposed as a GroupBox. foreach (var Element in TargetAreaPanel.Children) { if (Element is GroupBox && ((StackPanel)Element).Tag.ToString() == Group.TechName) { TargetGroupContainer = Element as StackPanel; var Body = (Border)TargetGroupContainer.Children[1]; // Children[0] is the Header TargetGroupingPanel = (WrapPanel)Body.Child; break; } } // Creates a new Panel if no TabItem was found. if (TargetGroupContainer == null) { TargetGroupContainer = new StackPanel(); TargetGroupContainer.Tag = Group.TechName; TargetGroupContainer.Orientation = Orientation.Horizontal; TargetGroupContainer.VerticalAlignment = VerticalAlignment.Stretch; TargetGroupContainer.Margin = new Thickness(1, 0, 1, 0); var GroupingHeader = new Border(); GroupingHeader.CornerRadius = new CornerRadius(3.0, 0, 0, 3.0); GroupingHeader.Background = GroupingHeaderBrush; GroupingHeader.Padding = new Thickness(0, 4, 1, 4); GroupingHeader.ToolTip = Group.Name; var GroupingTitle = new TextBlock(); GroupingTitle.Text = Group.Name; GroupingTitle.FontFamily = new FontFamily("Arial"); // new FontFamily("Verdana"); GroupingTitle.FontSize = 11; // GroupingTitle.FontWeight = FontWeights.Thin; GroupingTitle.Foreground = Brushes.White; GroupingTitle.TextAlignment = TextAlignment.Right; GroupingTitle.HorizontalAlignment = HorizontalAlignment.Stretch; GroupingTitle.LayoutTransform = new RotateTransform(-90.0); GroupingHeader.Child = GroupingTitle; TargetGroupContainer.Children.Add(GroupingHeader); var GroupingBody = new Border(); GroupingBody.CornerRadius = new CornerRadius(0, 3.0, 3.0, 0); GroupingBody.Background = GroupingBodyBrush; GroupingBody.BorderThickness = new Thickness(0); // GroupingBody.BorderBrush = Brushes.LightGray; // GroupingBody.BorderThickness = new Thickness(0,1,1,1); /* Rarely needed * GroupingHeader.MouseLeftButtonDown += * ((sender, mevargs) => GroupingBody.SetVisible(!GroupingBody.IsVisible.IsTrue())); */ TargetGroupContainer.Children.Add(GroupingBody); TargetGroupingPanel = new WrapPanel(); TargetGroupingPanel.Orientation = Orientation.Vertical; GroupingBody.Child = TargetGroupingPanel; } TargetAreaPanel.Children.Add(TargetGroupContainer); // Populates the GroupBox with the associated Command Expositors. foreach (KeyValuePair <string, WorkCommandExpositor> ExpositorReg in Sphere.CommandExpositors) { var Expositor = ExpositorReg; if (Expositor.Value.AreaKey == Area.TechName && Expositor.Value.GroupKey == Group.TechName && AssignableCommandCategories.Contains(Expositor.Value.Category)) { Control NewControl = null; var Options = (Expositor.Value.OptionsGetter == null ? null : Expositor.Value.OptionsGetter()); if (Expositor.Value.SwitchInitializer != null) { var SwitchChecker = new CheckBox(); SwitchChecker.Content = Expositor.Value.Name; SwitchChecker.ToolTip = Expositor.Value.Summary; SwitchChecker.Margin = new Thickness(2, 4, 2, 4); SwitchChecker.FontSize = 10.0; /* WPF still has minor problems with fonts over shadow * var Shadow = new DropShadowEffect(); * Shadow.Color = Colors.Gray; * Shadow.Opacity = 0.2; * SwitchChecker.Effect = Shadow; */ SwitchChecker.Command = ExpositorReg.Value.Command; // Important to pass as parameter instead of negating model property // (which, after undos/redos, can be incoherent with the check-box state shown) Expositor.Value.CommandParameterExtractor = (() => SwitchChecker.IsChecked); /* var Switcher = new RoutedEventHandler((sender, evargs) => * { * var CanExec = Expositor.Value.Command.CanExecute(null); * if (CanExec) * Expositor.Value.Command.Execute(SwitchChecker.IsChecked); * }); * * SwitchChecker.Checked += Switcher; * SwitchChecker.Unchecked += Switcher; */ NewControl = SwitchChecker; MenuToolbarControlsUpdater.AddOrReplace(Area.TechName + "." + Group.TechName + "." + ExpositorReg.Key, () => { SwitchChecker.IsChecked = Expositor.Value.SwitchInitializer(WorkspaceDirector.ActiveDocumentEngine); }); } else if (Expositor.Value.OptionsGetter == null) { NewControl = new PaletteButton(Expositor.Value); } else if (Expositor.Value.ShowOptionsAsComboBox) { var SelectorButton = new ComboBox(); SelectorButton.ToolTip = Expositor.Value.Name; SelectorButton.HorizontalContentAlignment = HorizontalAlignment.Stretch; //? SelectorCombo.MaxWidth = ApplicationShell.MainWindow.PREDEF_INITIAL_TOOLTAB_WIDTH - 48; SelectorButton.BorderBrush = Brushes.Transparent; SelectorButton.Background = Brushes.Transparent; SelectorButton.Height = 22; SelectorButton.Padding = new Thickness(1, 1, 1, 1); ScrollViewer.SetVerticalScrollBarVisibility(SelectorButton, ScrollBarVisibility.Visible); ScrollViewer.SetHorizontalScrollBarVisibility(SelectorButton, ScrollBarVisibility.Disabled); var FirstOption = Options.FirstOrDefault(); if (FirstOption == null || typeof(FormalPresentationElement).IsAssignableFrom(FirstOption.GetType())) { SelectorButton.ItemTemplate = Display.GetResource <DataTemplate>("TplFormalPresentationElement"); } else if (typeof(SimplePresentationElement).IsAssignableFrom(FirstOption.GetType())) { SelectorButton.ItemTemplate = Display.GetResource <DataTemplate>("TplSimplePresentationElement"); } SelectorButton.Loaded += ((sender, args) => { var Items = Expositor.Value.OptionsGetter(); SelectorButton.ItemsSource = Items; if (Items.Length > 0) { SelectorButton.SelectedItem = Items[0]; } SelectorButton.Tag = true; // Indicates ready for selection }); SelectorButton.SelectionChanged += ((sender, selargs) => { if (Expositor.Value.Command.CanExecute(null) && SelectorButton.Tag != null) { Expositor.Value.Command.Execute(selargs.AddedItems != null && selargs.AddedItems.Count > 0 ? selargs.AddedItems[0] : null); } }); NewControl = SelectorButton; } else { var SelectorList = new ListBox(); SelectorList.HorizontalContentAlignment = HorizontalAlignment.Stretch; SelectorList.Width = ApplicationShell.MainWindow.PREDEF_INITIAL_TOOLTAB_WIDTH - 48; SelectorList.BorderBrush = Brushes.Transparent; SelectorList.FontSize = 11; SelectorList.Margin = new Thickness(0, -2, 0, 0); SelectorList.Cursor = Cursors.Hand; ScrollViewer.SetVerticalScrollBarVisibility(SelectorList, ScrollBarVisibility.Visible); ScrollViewer.SetHorizontalScrollBarVisibility(SelectorList, ScrollBarVisibility.Disabled); SelectorList.Loaded += ((sender, args) => { SelectorList.ItemsSource = Expositor.Value.OptionsGetter(); }); SelectorList.SelectionChanged += ((sender, selargs) => { if ((Mouse.LeftButton == MouseButtonState.Pressed || Keyboard.IsKeyDown(Key.Enter)) && Expositor.Value.Command.CanExecute(null)) { Expositor.Value.Command.Execute(selargs.AddedItems != null && selargs.AddedItems.Count > 0 ? selargs.AddedItems[0] : null); if (Expositor.Value.GoesToRootAfterExecute) { Palette.PaletteTab.PostCall(ptab => ptab.SelectedIndex = 0); } } }); SelectorList.KeyDown += ((sender, keyargs) => { if (Keyboard.IsKeyDown(Key.Enter) && Expositor.Value.Command.CanExecute(null)) { Expositor.Value.Command.Execute(SelectorList.SelectedItem); } }); /* Looks bad (hides some lines) * SelectorList.MouseMove += * ((sender, args) => * { * // var Position = Mouse.GetPosition(sender as IInputElement); * var Container = Display.GetNearestVisualDominantOfType<ListBoxItem>(args.OriginalSource as DependencyObject); * if (Container == LastRecentDocContainer) * return; * * LastRecentDocContainer = Container; * if (LastRecentDocContainer == null) * ToolTipService.SetToolTip(SelectorList, null); * else * { * // PENDING: Make this work as supposed to be. * ToolTipService.SetToolTip(SelectorList, LastRecentDocContainer.Content); * ToolTipService.SetPlacementTarget(SelectorList, LastRecentDocContainer); * ToolTipService.SetPlacement(SelectorList, PlacementMode.Relative); * ToolTipService.SetVerticalOffset(SelectorList, 0); * ToolTipService.SetHorizontalOffset(SelectorList, 0); * ToolTipService.SetInitialShowDelay(SelectorList, 1); * ToolTipService.SetBetweenShowDelay(SelectorList, 1); * ToolTipService.SetShowDuration(SelectorList, 30000); * } * }); */ NewControl = SelectorList; } TargetGroupingPanel.Children.Add(NewControl); MenuItemExposed = true; } } } // For possible assigned commands invocators creates a new TabItem, if no one was found related to the current Area. if (!TabExists && MenuItemExposed) { var NewTab = new TabItem(); NewTab.Name = Area.TechName; NewTab.Header = Area.Name; NewTab.Content = TargetAreaPanel; Palette.PaletteTab.Items.Add(NewTab); } } }