/// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            IStoryBoardService storyBoardService             = Ioc.GetOrCreate <IStoryBoardService>();
            SerializeableCloudStorageCredentials credentials = storyBoardService.ActiveStory.LoadFromSession <SerializeableCloudStorageCredentials>(SynchronizationStorySessionKey.CloudStorageCredentials);

            _viewModel = new CloudStorageAccountViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                storyBoardService,
                Ioc.GetOrCreate <IFeedbackService>(),
                Ioc.GetOrCreate <ICloudStorageClientFactory>(),
                credentials);

            Bindings.BindCommand("GoBack", _viewModel.GoBackCommand);
            Bindings.BindCommand("OkCommand", _viewModel.OkCommand);
            Bindings.BindCommand("CancelCommand", _viewModel.CancelCommand);
            Bindings.BindText("Url", null, (v) => _viewModel.Url           = v, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindText("Username", null, (v) => _viewModel.Username = v, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindText("Password", () => SecureStringExtensions.SecureStringToString(_viewModel.Password), (v) => _viewModel.Password = SecureStringExtensions.StringToSecureString(v), _viewModel, nameof(_viewModel.Password), HtmlViewBindingMode.TwoWayPlusOneTimeToView);
            Bindings.BindCheckbox("Secure", null, (v) => _viewModel.Secure = v, null, null, HtmlViewBindingMode.OneWayToViewmodel);

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
Example #2
0
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables)
        {
            base.ShowInView(htmlView, variables);
            _viewModel = new SettingsViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <ISettingsService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IStoryBoardService>());

            Bindings.BindCommand("GoBack", _viewModel.GoBackCommand);
            Bindings.BindCommand("ChangeCloudSettingsCommand", _viewModel.ChangeCloudSettingsCommand);
            Bindings.BindCommand("ClearCloudSettingsCommand", _viewModel.ClearCloudSettingsCommand);
            Bindings.BindDropdown("SelectedEncryptionAlgorithm", null, SetEncryptionAlgorithmToViewmodel, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindCheckbox("AdoptCloudEncryptionAlgorithm", null, (value) => _viewModel.AdoptCloudEncryptionAlgorithm = value, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindDropdown("SelectedAutoSyncMode", null, (string value) => _viewModel.SelectedAutoSyncMode            = value, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindText("CloudStorageSettings", () => _viewModel.AccountSummary, null, _viewModel, nameof(_viewModel.AccountSummary), HtmlViewBindingMode.OneWayToView);
            Bindings.BindCheckbox("ShowCursorArrowKeys", null, (value) => _viewModel.ShowCursorArrowKeys = value, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindBackgroundImage("SelectedTheme", () => _viewModel.SelectedTheme.Image, _viewModel, nameof(_viewModel.SelectedTheme), HtmlViewBindingMode.OneWayToView);
            Bindings.UnhandledViewBindingEvent += UnhandledViewBindingEventHandler;

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
Example #3
0
 public PreviewMode(IHtmlView html, ITestService service, Test test)
     : base(Mode.Preview)
 {
     _html    = html;
     _service = service;
     _test    = test;
 }
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            IStoryBoardService storyBoardService             = Ioc.GetOrCreate <IStoryBoardService>();
            SerializeableCloudStorageCredentials credentials = storyBoardService.ActiveStory.LoadFromSession <SerializeableCloudStorageCredentials>(SynchronizationStorySessionKey.CloudStorageCredentials);

            _viewModel = new CloudStorageAccountViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                storyBoardService,
                Ioc.GetOrCreate <IFeedbackService>(),
                Ioc.GetOrCreate <ICloudStorageClientFactory>(),
                credentials);

            VueBindingShortcut[] shortcuts = new[]
            {
                new VueBindingShortcut(VueBindingShortcut.KeyEscape, nameof(CloudStorageAccountViewModel.CancelCommand)),
                new VueBindingShortcut(VueBindingShortcut.KeyEnter, nameof(CloudStorageAccountViewModel.OkCommand)),
            };
            VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
            _viewModel.VueDataBindingScript = VueBindings.BuildVueScript();
            VueBindings.StartListening();

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            _viewModel = new OpenSafeViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <IFeedbackService>(),
                Ioc.GetOrCreate <ICryptoRandomService>(),
                Ioc.GetOrCreate <ISettingsService>(),
                Ioc.GetOrCreate <IRepositoryStorageService>(),
                RedirectedFrom);

            VueBindingShortcut[] shortcuts = new[]
            {
                new VueBindingShortcut(VueBindingShortcut.KeyEscape, nameof(OpenSafeViewModel.GoBackCommand)),
                new VueBindingShortcut(VueBindingShortcut.KeyEnter, nameof(OpenSafeViewModel.OkCommand)),
            };
            VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
            _viewModel.VueDataBindingScript = VueBindings.BuildVueScript();
            VueBindings.StartListening();

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
Example #6
0
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            _viewModel = new SettingsViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <ISettingsService>(),
                Ioc.GetOrCreate <IStoryBoardService>(),
                Ioc.GetOrCreate <IFeedbackService>(),
                Ioc.GetOrCreate <ICloudStorageClientFactory>(),
                Ioc.GetOrCreate <IFilePickerService>());

            VueBindingShortcut[] shortcuts = new[]
            {
                new VueBindingShortcut(VueBindingShortcut.KeyEscape, nameof(SettingsViewModel.GoBackCommand)),
            };
            VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
            _viewModel.VueDataBindingScript = VueBindings.BuildVueScript();
            VueBindings.StartListening();

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
Example #7
0
 /// <inheritdoc/>
 protected override void SetHtmlViewBackgroundColor(IHtmlView htmlView)
 {
     if (_viewModel != null)
     {
         htmlView.SetBackgroundColor(ColorExtensions.HexToColor(_viewModel.BackgroundColorHex));
     }
 }
Example #8
0
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            _viewModel = new SettingsViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <ISettingsService>(),
                Ioc.GetOrCreate <IStoryBoardService>());

            Bindings.BindCommand("GoBack", _viewModel.GoBackCommand);
            Bindings.BindCommand("ChangeCloudSettingsCommand", _viewModel.ChangeCloudSettingsCommand);
            Bindings.BindCommand("ClearCloudSettingsCommand", _viewModel.ClearCloudSettingsCommand);
            Bindings.BindDropdown("SelectedEncryptionAlgorithm", null, SetEncryptionAlgorithmToViewmodel, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindDropdown("SelectedAutoSyncMode", null, (string value) => _viewModel.SelectedAutoSyncMode = value, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindText("CloudStorageSettings", () => _viewModel.AccountSummary, null, _viewModel, nameof(_viewModel.AccountSummary), HtmlViewBindingMode.OneWayToView);
            Bindings.BindBackgroundImage("SelectedTheme", () => _viewModel.SelectedTheme.Image, _viewModel, nameof(_viewModel.SelectedTheme), HtmlViewBindingMode.OneWayToView);
            Bindings.BindCheckbox("UseSolidColorTheme", null, (bool value) => _viewModel.UseSolidColorTheme                       = value, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindText("ColorForSolidThemeHex", null, (string value) => _viewModel.ColorForSolidThemeHex                   = value, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindDropdown("SelectedThemeMode", null, (string value) => _viewModel.SelectedThemeMode                       = value, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindDropdown("SelectedNoteInsertionMode", null, (string value) => _viewModel.SelectedNoteInsertionMode       = value, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindCheckbox("UseColorForAllNotesInDarkMode", null, (bool value) => _viewModel.UseColorForAllNotesInDarkMode = value, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindText("ColorForAllNotesInDarkModeHex", null, (string value) => _viewModel.ColorForAllNotesInDarkModeHex   = value, null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.UnhandledViewBindingEvent += UnhandledViewBindingEventHandler;

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            _viewModel = new RecycleBinViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <IFeedbackService>(),
                Ioc.GetOrCreate <ISettingsService>(),
                Ioc.GetOrCreate <ICryptoRandomService>(),
                Ioc.GetOrCreate <IRepositoryStorageService>());

            Bindings.BindCommand("GoBack", _viewModel.GoBackCommand);
            Bindings.BindCommand("EmptyRecycleBin", _viewModel.EmptyRecycleBinCommand);
            Bindings.BindGeneric <object>(
                NotesChangedEventHandler,
                null,
                null,
                null,
                new HtmlViewBindingViewmodelNotifier(_viewModel, "Notes"),
                HtmlViewBindingMode.OneWayToViewPlusOneTimeToView);
            Bindings.UnhandledViewBindingEvent += BindingsEventHandler;

            string html = _viewService.GenerateHtml(_viewModel);

            htmlView.LoadHtml(html);
        }
Example #10
0
        /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
        /// <param name="node">The HTML node.</param>
        /// <param name="htmlView">The HTML view.</param>
        /// <returns>The UI elements.</returns>
        public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView)
        {
            var controls = new List<Grid>();
            foreach (var child in node.Children.OfType<HtmlTagNode>().Where(c => c.Name == "li"))
            {
                var grid = new Grid();
                grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(20)});
                grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });

                var textBlock = CreateBulletSymbol(htmlView);
                                grid.Children.Add(textBlock);
                Grid.SetColumn(textBlock, 0);

                var panel = new StackPanel();

                child.WrapWithHtmlTag();
                foreach (var c in child.GetChildControls(htmlView).OfType<UIElement>())
                {
                    var frameworkElement = c as FrameworkElement;
                    if (frameworkElement != null)
                        frameworkElement.HorizontalAlignment = HorizontalAlignment.Stretch;

                    panel.Children.Add(c);
                }

                grid.Children.Add(panel);
                Grid.SetColumn(panel, 1);

                controls.Add(grid);
            }

            AdjustMargins(htmlView, controls);
            return controls.OfType<DependencyObject>().ToArray();
        }
Example #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VueDataBinding"/> class.
        /// </summary>
        /// <param name="dotnetViewModel">A C# viewmodel, which must support the <see cref="INotifyPropertyChanged"/>
        /// interface.</param>
        /// <param name="htmlView">A html view interface.</param>
        /// <param name="shortcuts">Optional enumeration of keyboard shortcuts.</param>
        public VueDataBinding(object dotnetViewModel, IHtmlView htmlView, IEnumerable <VueBindingShortcut> shortcuts = null)
        {
            if (dotnetViewModel == null)
            {
                throw new ArgumentNullException(nameof(dotnetViewModel));
            }
            if (htmlView == null)
            {
                throw new ArgumentNullException(nameof(htmlView));
            }
            _suppressedViewmodelPropertyChangedEvent = null;

            _dotnetViewModel   = dotnetViewModel;
            _viewModelNotifier = dotnetViewModel as INotifyPropertyChanged;
            if (_viewModelNotifier == null)
            {
                throw new ArgumentException("The parameter must support the interface INotifyPropertyChanged.", nameof(dotnetViewModel));
            }
            _htmlView = htmlView;

            // Search for properties which require data binding
            _bindingDescriptions  = new VueBindingDescriptions(DetectMarkedViewmodelAttributes(_dotnetViewModel));
            _bindingShortcuts     = shortcuts != null ? new List <VueBindingShortcut>(shortcuts) : null;
            _additionalVueDatas   = new List <KeyValuePair <string, string> >();
            _additionalVueMethods = new List <KeyValuePair <string, string> >();
        }
Example #12
0
 public PreviewMode(IHtmlView html, ITestService service, Test test)
     : base(Mode.Preview)
 {
     _html = html;
     _service = service;
     _test = test;
 }
Example #13
0
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            _viewModel = new OpenSafeViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <IFeedbackService>(),
                Ioc.GetOrCreate <ICryptoRandomService>(),
                Ioc.GetOrCreate <ISettingsService>(),
                Ioc.GetOrCreate <IRepositoryStorageService>(),
                RedirectedFrom);

            Bindings.BindCommand("GoBack", _viewModel.GoBackCommand);
            Bindings.BindCommand("OkCommand", _viewModel.OkCommand);
            Bindings.BindCommand("CancelCommand", _viewModel.CancelCommand);
            Bindings.BindCommand("ResetSafeCommand", _viewModel.ResetSafeCommand);
            Bindings.BindText("Password", null, (v) => _viewModel.Password = SecureStringExtensions.StringToSecureString(v), null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindText("PasswordConfirmation", null, (v) => _viewModel.PasswordConfirmation = SecureStringExtensions.StringToSecureString(v), null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindInvalid("Password", () => _viewModel.InvalidPasswordError, _viewModel, nameof(_viewModel.InvalidPasswordError), HtmlViewBindingMode.OneWayToView);
            Bindings.BindInvalid("PasswordConfirmation", () => _viewModel.InvalidPasswordConfirmationError, _viewModel, nameof(_viewModel.InvalidPasswordConfirmationError), HtmlViewBindingMode.OneWayToView);

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
Example #14
0
        /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
        /// <param name="node">The HTML node.</param>
        /// <param name="textBlock">The HTML view.</param>
        /// <returns>The UI elements.</returns>
        public DependencyObject[] CreateControls(HtmlNode node, IHtmlView textBlock)
        {
            var leaves = node.GetChildControls(textBlock);

            if (leaves.Length == 1 && leaves[0] is Panel)
            {
                leaves = new[] { leaves[0] }
            }
            ;

            if (leaves.Length > 0)
            {
                var element = leaves.First() as FrameworkElement;
                if (element != null)
                {
                    element.Margin = new Thickness(element.Margin.Left, 0, element.Margin.Right, element.Margin.Bottom);
                }

                element = leaves.Last() as FrameworkElement;
                if (element != null)
                {
                    element.Margin = new Thickness(element.Margin.Left, element.Margin.Top, element.Margin.Right, 0);
                }
            }

            return(leaves);
        }
    }
Example #15
0
        /// <exception cref="InvalidOperationException">Control generator returned null.</exception>
        public static DependencyObject[] GetControls(this HtmlNode node, IHtmlView textBlock)
        {
            if (node.Data == null)
            {
                var value = node is HtmlTextNode ? "text" : ((HtmlTagNode)node).Name;

                var generator = textBlock.Generators.ContainsKey(value) ? textBlock.Generators[value] :
                                (textBlock.Generators.ContainsKey("unknown") ? textBlock.Generators["unknown"] : null);

                if (generator != null)
                {
                    node.Data = generator.CreateControls(node, textBlock);
                    if (node.Data == null)
                    {
                        node.Data = new DependencyObject[] { }
                    }
                    ;
                }
                else
                {
                    node.Data = node.GetChildControls(textBlock);
                }
            }

            return((DependencyObject[])node.Data);
        }
    }
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HtmlViewBindings"/> class.
 /// </summary>
 /// <param name="htmlView">View which contains the WebView to bind to.</param>
 public HtmlViewBindings(IHtmlView htmlView)
 {
     _bindings                      = new List <IHtmlViewBinding>();
     _htmlView                      = htmlView;
     _htmlView.Navigating          += NavigatingEventHandler;
     _htmlView.NavigationCompleted += NavigationCompletedEventHandler;
 }
Example #17
0
 public EditMode(Test test, ITestStateManager testState, IHtmlView view, ITestEditorBuilder editorBuilder)
     : base(Mode.Edit)
 {
     _test          = test;
     _testState     = testState;
     _view          = view;
     _editorBuilder = editorBuilder;
 }
        /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
        /// <param name="node">The HTML node.</param>
        /// <param name="htmlView">The HTML view.</param>
        /// <returns>The UI elements.</returns>
        public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView)
        {
            var control = CreateControl(node, htmlView);
            if (control != null)
                return new [] { control };

            return new DependencyObject[] { };
        }
Example #19
0
 /// <inheritdoc/>
 public virtual void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
 {
     View           = htmlView;
     RedirectedFrom = redirectedFrom;
     SetHtmlViewBackgroundColor(htmlView);
     VueBindings?.Dispose();
     VueBindings = null;
 }
Example #20
0
 public EditMode(Test test, ITestStateManager testState, IHtmlView view, ITestEditorBuilder editorBuilder)
     : base(Mode.Edit)
 {
     _test = test;
     _testState = testState;
     _view = view;
     _editorBuilder = editorBuilder;
 }
Example #21
0
 /// <summary>Creates the action to open the link after the user clicked on it.</summary>
 /// <param name="hyperlink">The hyperlink.</param>
 /// <param name="link">The link.</param>
 /// <param name="textBlock">The text block.</param>
 /// <returns>The action</returns>
 protected virtual Action CreateLinkAction(Hyperlink hyperlink, string link, IHtmlView textBlock)
 {
     if (link.StartsWith("mailto:"))
     {
         return () => new EmailComposeTask {
                    To = link.Substring(7)
         }
     }
Example #22
0
        /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
        /// <param name="node">The HTML node.</param>
        /// <param name="htmlView">The HTML view.</param>
        /// <returns>The UI elements.</returns>
        public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView)
        {
            try
            {
                var link = node.Attributes["href"];
                var hyperlink = new Hyperlink();

                if (Foreground != null)
                    hyperlink.Foreground = Foreground;

#if !WINRT
                hyperlink.MouseOverForeground = htmlView.Foreground;
                hyperlink.TextDecorations = TextDecorations.Underline;
#endif                
                foreach (var child in node.Children)
                {
                    var leaves = child.GetControls(htmlView).ToArray();
                    if (leaves.Length > 0)
                    {
                        foreach (var item in leaves)
                        {
                            if (item is Inline)
                                hyperlink.Inlines.Add((Inline)item);
                            else
                                hyperlink.Inlines.Add(new InlineUIContainer { Child = (UIElement) item });
                        }
                    }
                    else if (child is HtmlTextNode && !string.IsNullOrEmpty(((HtmlTextNode)child).Text))
                        hyperlink.Inlines.Add(new Run { Text = ((HtmlTextNode)child).Text });
                }

#if WINRT

                var action = CreateLinkAction(hyperlink, link, htmlView);
                hyperlink.Click += (sender, e) =>
                {
                    action();
                    ((Control)htmlView).Focus(FocusState.Programmatic);
                };

#else

                var action = CreateLinkAction(hyperlink, link, htmlView);
                hyperlink.Command = new RelayCommand(delegate
                {
                    if (!PhoneApplication.IsNavigating)
                        action();
                });

#endif
                
                return new DependencyObject[] { hyperlink };
            }
            catch
            {
                return node.GetChildControls(htmlView); // suppress link 
            }
        }
Example #23
0
        /// <summary>
        /// Sets the default background color of the webview, this is the color shown while loading
        /// an HTML page or when the css background color is transparent. This method is called as
        /// early as possible, to avoid the white flicker when using dark themes, which is visible
        /// until the html page has finished loading.
        /// </summary>
        /// <param name="htmlView">The interface to the webview.</param>
        protected virtual void SetHtmlViewBackgroundColor(IHtmlView htmlView)
        {
            IThemeService themeService           = Ioc.GetOrCreate <IThemeService>();
            Color         defaultBackgroundColor = themeService.DarkMode
                ? Color.FromArgb(255, 18, 18, 18)
                : Color.FromArgb(255, 240, 240, 240);

            htmlView.SetBackgroundColor(defaultBackgroundColor);
        }
Example #24
0
 private TextBlock CreateBulletSymbol(IHtmlView htmlView)
 {
     var textBlock = new TextBlock();
     textBlock.Foreground = htmlView.Foreground;
     textBlock.FontSize = htmlView.FontSize;
     textBlock.FontFamily = htmlView.FontFamily;
     textBlock.Margin = new Thickness();
     textBlock.Text = BulletSymbol;
     return textBlock;
 }
Example #25
0
        private TextBlock CreateBulletSymbol(IHtmlView htmlView)
        {
            var textBlock = new TextBlock();

            textBlock.Foreground = htmlView.Foreground;
            textBlock.FontSize   = htmlView.FontSize;
            textBlock.FontFamily = htmlView.FontFamily;
            textBlock.Margin     = new Thickness();
            textBlock.Text       = BulletSymbol;
            return(textBlock);
        }
Example #26
0
 /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
 /// <param name="node">The HTML node.</param>
 /// <param name="htmlView">The HTML view.</param>
 /// <returns>The UI elements.</returns>
 public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView)
 {
     var controls = node.GetChildControls(htmlView); 
     foreach (var leave in controls)
     {
         var element = leave as TextElement;
         if (element != null)
             element.FontWeight = FontWeights.Bold;
     }
     return controls;
 }
        /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
        /// <param name="node">The HTML node.</param>
        /// <param name="htmlView">The HTML view.</param>
        /// <returns>The UI elements.</returns>
        public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView)
        {
            var control = CreateControl(node, htmlView);

            if (control != null)
            {
                return new [] { control }
            }
            ;

            return(new DependencyObject[] { });
        }
Example #28
0
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            ISettingsService settingsService = Ioc.GetOrCreate <ISettingsService>();

            View.NavigationCompleted += NavigationCompletedEventHandler;
            _repositoryService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository);

            NoteModel note;

            _startedWithSendToSilentnotes = variables.ContainsKey(ControllerParameters.SendToSilentnotesText);
            if (_startedWithSendToSilentnotes)
            {
                // Create new note and update repository
                note = new NoteModel();
                note.BackgroundColorHex = settingsService.LoadSettingsOrDefault().DefaultNoteColorHex;
                noteRepository.Notes.Insert(0, note);
                _sendToSilentnotesText = variables[ControllerParameters.SendToSilentnotesText];
            }
            else
            {
                // Get the note from the repository
                Guid noteId = new Guid(variables[ControllerParameters.NoteId]);
                note = noteRepository.Notes.FindById(noteId);
            }

            ICryptor cryptor = new Cryptor(NoteModel.CryptorPackageName, Ioc.GetOrCreate <ICryptoRandomService>());

            _viewModel = new NoteViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                null,
                _repositoryService,
                Ioc.GetOrCreate <IFeedbackService>(),
                settingsService,
                cryptor,
                noteRepository.Safes,
                note);
            SetHtmlViewBackgroundColor(htmlView);

            Bindings.BindCommand("PullNoteFromOnlineStorage", _viewModel.PullNoteFromOnlineStorageCommand);
            Bindings.BindCommand("PushNoteToOnlineStorage", _viewModel.PushNoteToOnlineStorageCommand);
            Bindings.BindCommand("GoBack", _viewModel.GoBackCommand);
            Bindings.BindText("PrettyTimeAgo", () => _viewModel.PrettyTimeAgo, null, _viewModel, nameof(_viewModel.PrettyTimeAgo), HtmlViewBindingMode.OneWayToView);
            Bindings.UnhandledViewBindingEvent += UnhandledViewBindingEventHandler;

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
Example #29
0
        public static Stream Render(IHtmlView html, IResponseContext response, ChunkedMemoryStream stream)
        {
            stream.Reset();
            response.ContentType = "text/html; charset=UTF-8";
            var sw = stream.GetWriter();

            html.Render(sw);
            sw.Flush();
            response.ContentLength = stream.Position;
            stream.Position        = 0;
            return(stream);
        }
Example #30
0
        protected virtual RichTextBlock CreateTextBlock(HtmlNode node, IHtmlView htmlView)
        {
            var textBlock = new RichTextBlock();
#endif

            textBlock.FontSize   = htmlView.FontSize * FontSize;
            textBlock.Foreground = Foreground ?? htmlView.Foreground;
            textBlock.FontFamily = FontFamily ?? htmlView.FontFamily;
            textBlock.FontStyle  = FontStyle;
            textBlock.FontWeight = FontWeight;

            return(textBlock);
        }
 public static DependencyObject[] GetChildControls(this HtmlNode node, IHtmlView textBlock)
 {
     var list = new List<DependencyObject>();
     foreach (var c in node.Children)
     {
         var ctrl = c.GetControls(textBlock);
         if (ctrl != null)
             list.AddRange(ctrl);
         else
             list.AddRange(c.GetChildControls(textBlock));
     }
     return list.ToArray();
 }
Example #32
0
 /// <summary>Creates the action to open the link after the user clicked on it.</summary>
 /// <param name="hyperlink">The hyperlink.</param>
 /// <param name="link">The link.</param>
 /// <param name="textBlock">The text block.</param>
 /// <returns>The action</returns>
 protected virtual Action CreateLinkAction(Hyperlink hyperlink, string link, IHtmlView textBlock)
 {
     return(async() =>
     {
         try
         {
             await Launcher.LaunchUriAsync(new Uri(link));
         }
         catch
         {
             // Ignore malformed URIs.
         }
     });
 }
Example #33
0
        /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
        /// <param name="node">The HTML node.</param>
        /// <param name="htmlView">The HTML view.</param>
        /// <returns>The UI elements.</returns>
        public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView)
        {
            var controls = node.GetChildControls(htmlView);

            foreach (var leave in controls)
            {
                var element = leave as TextElement;
                if (element != null)
                {
                    element.FontWeight = FontWeights.Bold;
                }
            }
            return(controls);
        }
Example #34
0
        /// <summary>Creates a single UI element for the given HTML node and HTML view.</summary>
        /// <param name="node">The node.</param>
        /// <param name="htmlView">The text block.</param>
        /// <returns>The UI element.</returns>
        public override DependencyObject CreateControl(HtmlNode node, IHtmlView htmlView)
        {
            try
            {
                var imageUri = node.Attributes["src"];

                var height = 0;
                if (node.Attributes.ContainsKey("height"))
                    int.TryParse(node.Attributes["height"], out height);

                var width = 0;
                if (node.Attributes.ContainsKey("width"))
                    int.TryParse(node.Attributes["width"], out width);

                if (height == 1 && width == 1)
                    return null;

                var image = new Image();
                image.Width = 0;
                image.Height = 0;

                var bitmapImage = new BitmapImage(new Uri(imageUri));

                var imageBlock = new ImageBlock
                {
                    Image = image,
                    UserHeight = height,
                    UserWidth = width,
                    Source = bitmapImage
                };

                bitmapImage.ImageOpened += delegate { imageBlock.Update(htmlView.ActualWidth); };

                image.HorizontalAlignment = HorizontalAlignment.Left;
                image.Source = bitmapImage;
                image.Margin = new Thickness(0, htmlView.ParagraphMargin, 0, htmlView.ParagraphMargin);

                if (width > 0)
                    image.Width = width;
                if (height > 0)
                    image.Height = height;

                htmlView.SizeDependentControls.Add(imageBlock);
                return new ContentPresenter { Content = image };
            }
            catch
            {
                return null;
            }
        }
Example #35
0
        private void AdjustMargins(IHtmlView htmlView, List <Grid> controls)
        {
            var firstControl = controls.FirstOrDefault();

            if (firstControl != null)
            {
                firstControl.Margin = new Thickness(0, htmlView.ParagraphMargin, 0, 0);
            }

            var lastControl = controls.LastOrDefault();

            if (lastControl != null)
            {
                lastControl.Margin = new Thickness(0, 0, 0, htmlView.ParagraphMargin);
            }
        }
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables)
        {
            base.ShowInView(htmlView, variables);
            _viewModel = new CloudStorageOauthWaitingViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <IStoryBoardService>(),
                Ioc.GetOrCreate <IFeedbackService>());

            Bindings.BindCommand("GoBack", _viewModel.GoBackCommand);

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
Example #37
0
        /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
        /// <param name="node">The HTML node.</param>
        /// <param name="htmlView">The HTML view.</param>
        /// <returns>The UI elements.</returns>
        public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView)
        {
            var controls = node.GetChildControls(htmlView);
            foreach (var leave in controls)
            {
                var element = leave as TextElement;
                if (element != null)
                {
#if WINRT
                    element.FontStyle = FontStyle.Italic;
#else
                    element.FontStyle = FontStyles.Italic;
#endif
                }
            }
            return controls;
        }
Example #38
0
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            _viewModel = new FirstTimeSyncViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <IStoryBoardService>());

            Bindings.BindCommand("GoBack", _viewModel.GoBackCommand);
            Bindings.BindCommand("Continue", _viewModel.ContinueCommand);

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
Example #39
0
        public static DependencyObject[] GetChildControls(this HtmlNode node, IHtmlView textBlock)
        {
            var list = new List <DependencyObject>();

            foreach (var c in node.Children)
            {
                var ctrl = c.GetControls(textBlock);
                if (ctrl != null)
                {
                    list.AddRange(ctrl);
                }
                else
                {
                    list.AddRange(c.GetChildControls(textBlock));
                }
            }
            return(list.ToArray());
        }
Example #40
0
        /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
        /// <param name="node">The HTML node.</param>
        /// <param name="htmlView">The HTML view.</param>
        /// <returns>The UI elements.</returns>
        public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView)
        {
            var controls = node.GetChildControls(htmlView);

            foreach (var leave in controls)
            {
                var element = leave as TextElement;
                if (element != null)
                {
#if WINRT
                    element.FontStyle = FontStyle.Italic;
#else
                    element.FontStyle = FontStyles.Italic;
#endif
                }
            }
            return(controls);
        }
Example #41
0
        /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
        /// <param name="node">The HTML node.</param>
        /// <param name="textBlock">The HTML view.</param>
        /// <returns>The UI elements.</returns>
        public DependencyObject[] CreateControls(HtmlNode node, IHtmlView textBlock)
        {
            var leaves = node.GetChildControls(textBlock);
            if (leaves.Length == 1 && leaves[0] is Panel)
                leaves = new[] { leaves[0] };

            if (leaves.Length > 0)
            {
                var element = leaves.First() as FrameworkElement;
                if (element != null)
                    element.Margin = new Thickness(element.Margin.Left, 0, element.Margin.Right, element.Margin.Bottom);

                element = leaves.Last() as FrameworkElement;
                if (element != null)
                    element.Margin = new Thickness(element.Margin.Left, element.Margin.Top, element.Margin.Right, 0);
            }

            return leaves;
        }
        /// <exception cref="InvalidOperationException">Control generator returned null.</exception>
        public static DependencyObject[] GetControls(this HtmlNode node, IHtmlView textBlock)
        {
            if (node.Data == null)
            {
                var value = node is HtmlTextNode ? "text" : ((HtmlTagNode)node).Name;

                var generator = textBlock.Generators.ContainsKey(value) ? textBlock.Generators[value] :
                    (textBlock.Generators.ContainsKey("unknown") ? textBlock.Generators["unknown"] : null);

                if (generator != null)
                {
                    node.Data = generator.CreateControls(node, textBlock);
                    if (node.Data == null)
                        node.Data = new DependencyObject[] { };
                }
                else
                    node.Data = node.GetChildControls(textBlock);
            }

            return (DependencyObject[]) node.Data;
        }
Example #43
0
 public static Stream Render(IHtmlView html, IResponseContext response, ChunkedMemoryStream stream)
 {
     stream.Reset();
     response.ContentType = "text/html; charset=UTF-8";
     var sw = stream.GetWriter();
     html.Render(sw);
     sw.Flush();
     response.ContentLength = stream.Position;
     stream.Position = 0;
     return stream;
 }
Example #44
0
 /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
 /// <param name="node">The HTML node.</param>
 /// <param name="textBlock">The HTML view.</param>
 /// <returns>The UI elements.</returns>
 public DependencyObject[] CreateControls(HtmlNode node, IHtmlView textBlock)
 {
     return new DependencyObject[] { };
 }
Example #45
0
 /// <summary>Creates the action to open the link after the user clicked on it.</summary>
 /// <param name="hyperlink">The hyperlink.</param>
 /// <param name="link">The link.</param>
 /// <param name="textBlock">The text block.</param>
 /// <returns>The action</returns>
 protected virtual Action CreateLinkAction(Hyperlink hyperlink, string link, IHtmlView textBlock)
 {
     return async () =>
     {
         try
         {
             await Launcher.LaunchUriAsync(new Uri(link));
         }
         catch
         {
             // Ignore malformed URIs. 
         }
     };
 }
 /// <summary>Creates a single UI element for the given HTML node and HTML view.</summary>
 /// <param name="node">The node.</param>
 /// <param name="htmlView">The HTML view.</param>
 /// <returns>The UI element.</returns>
 public abstract DependencyObject CreateControl(HtmlNode node, IHtmlView htmlView);
Example #47
0
        private void AdjustMargins(IHtmlView htmlView, List<Grid> controls)
        {
            var firstControl = controls.FirstOrDefault();
            if (firstControl != null)
                firstControl.Margin = new Thickness(0, htmlView.ParagraphMargin, 0, 0);

            var lastControl = controls.LastOrDefault();
            if (lastControl != null)
                lastControl.Margin = new Thickness(0, 0, 0, htmlView.ParagraphMargin);
        }
Example #48
0
        /// <summary>Creates the action to open the link after the user clicked on it.</summary>
        /// <param name="hyperlink">The hyperlink.</param>
        /// <param name="link">The link.</param>
        /// <param name="textBlock">The text block.</param>
        /// <returns>The action</returns>
        protected virtual Action CreateLinkAction(Hyperlink hyperlink, string link, IHtmlView textBlock)
        {
            if (link.StartsWith("mailto:"))
                return () => new EmailComposeTask {To = link.Substring(7)}.Show();
            
            // 'tel:' removed because it needs CAP_PHONEDIALER capability! Use PhoneLinkGenerator from "- Other" directory. 

            try
            {
                var uri = link.StartsWith("http://") || link.StartsWith("https://") ?
                    new Uri(link, UriKind.Absolute) : new Uri(textBlock.HtmlBaseUri, link);
                return () => new WebBrowserTask { Uri = uri }.Show();
            }
            catch (Exception)
            {

            }

            return () => { };
        }
Example #49
0
 /// <summary>Creates a single UI element for the given HTML node and HTML view.</summary>
 /// <param name="node">The node.</param>
 /// <param name="htmlView">The text block.</param>
 /// <returns>The UI element.</returns>
 public override DependencyObject CreateControl(HtmlNode node, IHtmlView htmlView)
 {
     return new Run { Text = ((HtmlTextNode)node).Text };
 }
Example #50
0
        private void CreateTextBox(List<DependencyObject> list, List<Inline> current, IHtmlView htmlView, bool addTopMargin, bool addBottomMargin)
        {
            if (current.Count > 0)
            {
                var p = new Paragraph();
                foreach (var r in current)
                    p.Inlines.Add(r);

#if !WINRT
                var textBlock = new RichTextBox();
                textBlock.Background = textBlock.Background;
                textBlock.Margin = new Thickness(-12, addTopMargin ? htmlView.ParagraphMargin : 0, -12, addBottomMargin ? htmlView.ParagraphMargin : 0);
#else
                var textBlock = new RichTextBlock();
                textBlock.IsTextSelectionEnabled = false; 
                textBlock.Margin = new Thickness(0, addTopMargin ? htmlView.ParagraphMargin : 0, 0, addBottomMargin ? htmlView.ParagraphMargin : 0);
#endif

                textBlock.Blocks.Add(p);
                textBlock.FontSize = htmlView.FontSize * FontSize;
                textBlock.Foreground = Foreground ?? htmlView.Foreground;
                textBlock.FontFamily = FontFamily ?? htmlView.FontFamily;
                textBlock.FontStyle = FontStyle;
                textBlock.FontWeight = FontWeight;
                
                list.Add(textBlock);
                current.Clear();
            }
        }
Example #51
0
        private void CreateTextBox(HtmlNode node, List<DependencyObject> list, List<Inline> current, IHtmlView htmlView, bool addTopMargin, bool addBottomMargin)
        {
            if (current.Count > 0)
            {
                var textBlock = CreateTextBlock(node, htmlView);

                var p = new Paragraph();
                foreach (var r in current)
                    p.Inlines.Add(r);

                textBlock.Blocks.Add(p);

#if !WINRT
                textBlock.Background = textBlock.Background;
                textBlock.Margin = new Thickness(-12, addTopMargin ? htmlView.ParagraphMargin : 0, -12, addBottomMargin ? htmlView.ParagraphMargin : 0);
#else
                textBlock.IsTextSelectionEnabled = false;
                textBlock.Margin = new Thickness(0, addTopMargin ? htmlView.ParagraphMargin : 0, 0, addBottomMargin ? htmlView.ParagraphMargin : 0);
#endif

                list.Add(textBlock);
                current.Clear();
            }
        }
Example #52
0
 public ResultsMode(IHtmlView view, Test test)
     : base(Mode.Results)
 {
     _view = view;
     _test = test;
 }
Example #53
0
        /// <summary>Creates a formatted text block.</summary>
        /// <param name="node">The node.</param>
        /// <param name="htmlView">The HTML view.</param>
#if !WINRT
        protected virtual RichTextBox CreateTextBlock(HtmlNode node, IHtmlView htmlView)
        {
            var textBlock = new RichTextBox();
Example #54
0
        protected virtual RichTextBlock CreateTextBlock(HtmlNode node, IHtmlView htmlView)
        {
            var textBlock = new RichTextBlock();
#endif

            textBlock.FontSize = htmlView.FontSize * FontSize;
            textBlock.Foreground = Foreground ?? htmlView.Foreground;
            textBlock.FontFamily = FontFamily ?? htmlView.FontFamily;
            textBlock.FontStyle = FontStyle;
            textBlock.FontWeight = FontWeight;

            return textBlock;
        }
Example #55
0
        /// <summary>Creates the UI elements for the given HTML node and HTML view.</summary>
        /// <param name="node">The HTML node.</param>
        /// <param name="htmlView">The HTML view.</param>
        /// <returns>The UI elements.</returns>
        public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView)
        {
            var list = new List<DependencyObject>();

            var isFirst = true; 
            var addTopMargin = true; 
            var current = new List<Inline>();

            foreach (var child in node.GetChildControls(htmlView))
            {
                if (isFirst)
                {
                    if (child is Run)
                    {
                        var run = (Run)child;
                        run.Text = run.Text.TrimStart(' ', '\t'); // TODO: Trim all white spaces
                    }
                    isFirst = false;
                }

                if (child is Run && UseTextSplitting && ((Run)child).Text.Contains("\n")) // used to avoid 2048px max control size
                {
                    // split text
                    var run = (Run) child;
                    var splits = run.Text.Split('\n');

                    // join some splits to avoid small junks 
                    var currentSplit = "";
                    var newSplits = new List<string>();
                    for (var i = 0; i < splits.Length; i++)
                    {
                        var split = splits[i];
                        if (i != 0 && currentSplit.Length + split.Length > 16)
                        {
                            newSplits.Add(currentSplit);
                            currentSplit = split;
                        }
                        else
                            currentSplit += (i != 0 ? "\n" : "") + split;
                    }
                    newSplits.Add(currentSplit);

                    // create multiple text blocks
                    splits = newSplits.ToArray();
                    for (var i = 0; i < splits.Length; i++)
                    {
                        var split = splits[i];
                        current.Add(new Run { Text = split });
                        if (i < splits.Length - 1) // dont create for last
                            CreateTextBox(node, list, current, htmlView, i == 0 && addTopMargin, false);
                    }
                    addTopMargin = list.Count == 0; 
                } else if (child is Inline)
                    current.Add((Inline)child);
                else
                {
                    CreateTextBox(node, list, current, htmlView, addTopMargin, true);
                    list.Add(child);
                    addTopMargin = true; 
                }
            }

            CreateTextBox(node, list, current, htmlView, addTopMargin, true);

            if (list.Count == 0)
                return null;

            return list.ToArray();
        }