Beispiel #1
0
        private void ShowBaseTemplates([NotNull] object sender, [NotNull] RoutedEventArgs e)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(e, nameof(e));

            var hyperlink = sender as Hyperlink;

            if (hyperlink == null)
            {
                return;
            }

            hyperlink.ContextMenu = null;

            var contextMenu = new ContextMenu();

            var context = new ContentEditorContext(ContentEditor);

            var baseTemplates = new BaseTemplatesSubmenu();

            contextMenu.Build(baseTemplates.GetSubmenuCommands(this), context);

            var commands = baseTemplates.GetSubmenuCommands(context);

            contextMenu.Build(commands, context);
            if (contextMenu.Items.Count <= 0)
            {
                return;
            }

            hyperlink.ContextMenu = contextMenu;
            contextMenu.IsOpen    = true;
        }
Beispiel #2
0
        private HyperlinkBox RenderLanguage([NotNull] ContentEditorContext context, [NotNull] string name)
        {
            Debug.ArgumentNotNull(context, nameof(context));
            Debug.ArgumentNotNull(name, nameof(name));

            CultureInfo cultureInfo;

            try
            {
                cultureInfo = new CultureInfo(name);
            }
            catch
            {
                cultureInfo = CultureInfo.InvariantCulture;
            }

            var language = new Language(name);

            var command = new SetLanguage(language);

            var hyperlink = new HyperlinkBox
            {
                Text             = name,
                CommandParameter = context,
                Command          = command,
                ToolTip          = cultureInfo.NativeName + @" / " + cultureInfo.EnglishName
            };

            Languages.Inlines.Add(hyperlink);

            return(hyperlink);
        }
Beispiel #3
0
        private void RenderVersions([NotNull] Item item)
        {
            Debug.ArgumentNotNull(item, nameof(item));

            Versions.Inlines.Clear();

            var context  = new ContentEditorContext(ContentEditor);
            var versions = item.Versions;

            var count = versions.Count;

            if (count > 0)
            {
                var selectedVersion = item.Uri.Version;
                if (selectedVersion == Version.Latest)
                {
                    selectedVersion = new Version(item.Versions[count - 1]);
                }

                count = count > 3 ? 3 : count;

                for (var n = 0; n < count; n++)
                {
                    var version = new Version(versions[versions.Count - n - 1]);

                    var command = new SetVersion(version);

                    var hyperlink = new HyperlinkBox
                    {
                        Text             = version.ToString(),
                        IsSelected       = version == selectedVersion,
                        CommandParameter = context,
                        Command          = command,
                        ToolTip          = Rocks.Resources.QuickInfo_RenderVersions_Version + @" " + version
                    };

                    Versions.Inlines.Add(hyperlink);
                }
            }

            var more = new Hyperlink(new Run(@"..."))
            {
                Style = FindResource(@"HyperlinkValue") as Style
            };

            more.Click += VersionsClick;

            var border = new Border
            {
                Child  = new TextBlock(more),
                Margin = new Thickness(2)
            };

            Versions.Inlines.Add(border);
        }
Beispiel #4
0
        private void VersionsClick([NotNull] object sender, [NotNull] RoutedEventArgs routedEventArgs)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(routedEventArgs, nameof(routedEventArgs));

            var context = new ContentEditorContext(ContentEditor);

            var versions = new VersionsSubmenu();
            var commands = versions.GetSubmenuCommands(context);

            ShowContextMenu(sender, commands, context);
        }
Beispiel #5
0
        private void ChangeTemplate([NotNull] object sender, [NotNull] RoutedEventArgs e)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(e, nameof(e));

            var context = new ContentEditorContext(ContentEditor);

            var command = new ChangeTemplate();

            if (command.CanExecute(context))
            {
                AppHost.Usage.ReportCommand(command, context);
                command.Execute(context);
            }
        }
Beispiel #6
0
        private void RenderLanguages([NotNull] Item item)
        {
            Debug.ArgumentNotNull(item, nameof(item));

            Languages.Inlines.Clear();

            var context   = new ContentEditorContext(ContentEditor);
            var languages = item.Languages;

            if (languages.Count > 0)
            {
                var language = RenderLanguage(context, item.Uri.Language.Name);
                language.IsSelected = true;

                var n = 0;
                foreach (var name in languages)
                {
                    if (name == item.Uri.Language.Name)
                    {
                        continue;
                    }

                    RenderLanguage(context, name);

                    n++;
                    if (n >= 2)
                    {
                        break;
                    }
                }
            }

            var more = new Hyperlink(new Run(@"..."))
            {
                Style = FindResource(@"HyperlinkValue") as Style
            };

            more.Click += LanguagesClick;

            var border = new Border
            {
                Child  = new TextBlock(more),
                Margin = new Thickness(2)
            };

            Languages.Inlines.Add(border);
        }
Beispiel #7
0
        private void ControlLoaded([NotNull] object sender, [NotNull] RoutedEventArgs args)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(args, nameof(args));

            Loaded -= ControlLoaded;

            ShowRibbon();
            var context = new ContentEditorContext(this);

            Ribbon.Render(context);
            Editor.Focus();

            var contentModel = ContentModel;

            if (contentModel.IsEmpty)
            {
                ShowEmptyEditor();
            }
        }
Beispiel #8
0
        private void IconMouseDown([NotNull] object sender, [NotNull] MouseButtonEventArgs e)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(e, nameof(e));

            if (e.LeftButton != MouseButtonState.Pressed)
            {
                return;
            }

            var context = new ContentEditorContext(ContentEditor);

            var command = new SetIcon();

            if (command.CanExecute(context))
            {
                AppHost.Usage.ReportCommand(command, context);
                command.Execute(context);
            }
        }
Beispiel #9
0
        private void ShowContextMenu([NotNull] object sender, [NotNull] IEnumerable <Rocks.Commands.ICommand> commands, [NotNull] ContentEditorContext context)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(commands, nameof(commands));
            Debug.ArgumentNotNull(context, nameof(context));

            var hyperlink = sender as Hyperlink;

            if (hyperlink == null)
            {
                return;
            }

            hyperlink.ContextMenu = new ContextMenu();

            hyperlink.ContextMenu.Build(commands, context);

            hyperlink.ContextMenu.IsOpen = true;
        }