Exemplo n.º 1
0
        private void InitializeComponent()
        {
            var theme = new DefaultTheme();

            theme.FindResource("Button");
            AvaloniaXamlLoader.Load(this);
        }
Exemplo n.º 2
0
 public App()
 {
     RegisterServices();
     InitializeSubsystems(GetPlatformId());
     Styles = new DefaultTheme();
     InitializeComponent();
 }
Exemplo n.º 3
0
 public XamlTestApp()
 {
     RegisterServices();
     RegisterPlatform();
     Styles = new DefaultTheme();
     InitializeComponent();
 }
Exemplo n.º 4
0
 public App()
 {
     RegisterServices();
     InitializeSubsystems((int)Environment.OSVersion.Platform);
     Styles = new DefaultTheme();
     Styles.Add(new SampleTabStyle());
 }
Exemplo n.º 5
0
        /// <summary>
        /// Disposer. Release resources and cleanup.
        /// </summary>
        /// <param name="disposing">true to dispose managed resources</param>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!_disposed)
            {
                Log.Debug();

                if (disposing)
                {
                    if (DefaultTheme != null)
                    {
                        DefaultTheme.Dispose();
                    }

                    if (_activeTheme != null)
                    {
                        _activeTheme.Dispose();
                    }
                }

                // Release unmanaged resources.
            }

            _disposed = true;
        }
Exemplo n.º 6
0
        private void RegisterServices()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var formattedText   = fixture.Create <IFormattedTextImpl>();
            var globalStyles    = new Mock <IGlobalStyles>();
            var renderInterface = fixture.Create <IPlatformRenderInterface>();
            var renderManager   = fixture.Create <IRenderQueueManager>();
            var windowImpl      = new Mock <IWindowImpl>();

            windowImpl.SetupProperty(x => x.ClientSize);
            windowImpl.Setup(x => x.MaxClientSize).Returns(new Size(1024, 1024));

            PerspexLocator.CurrentMutable
            .Bind <IAssetLoader>().ToConstant(new AssetLoader())
            .Bind <IInputManager>().ToConstant(new Mock <IInputManager>().Object)
            .Bind <IGlobalStyles>().ToConstant(globalStyles.Object)
            .Bind <ILayoutManager>().ToConstant(new LayoutManager())
            .Bind <IPclPlatformWrapper>().ToConstant(new PclPlatformWrapper())
            .Bind <IPlatformRenderInterface>().ToConstant(renderInterface)
            .Bind <IRenderQueueManager>().ToConstant(renderManager)
            .Bind <IStyler>().ToConstant(new Styler())
            .Bind <IWindowImpl>().ToConstant(windowImpl.Object);

            var theme = new DefaultTheme();

            globalStyles.Setup(x => x.Styles).Returns(theme);
        }
Exemplo n.º 7
0
        private void RegisterServices()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var formattedText   = fixture.Create <IFormattedTextImpl>();
            var globalStyles    = new Mock <IGlobalStyles>();
            var renderInterface = fixture.Create <IPlatformRenderInterface>();
            var windowImpl      = new Mock <IWindowImpl>();

            windowImpl.SetupProperty(x => x.ClientSize);
            windowImpl.Setup(x => x.MaxClientSize).Returns(new Size(1024, 1024));
            windowImpl.SetupGet(x => x.Scaling).Returns(1);

            AvaloniaLocator.CurrentMutable
            .Bind <IAssetLoader>().ToConstant(new AssetLoader())
            .Bind <IInputManager>().ToConstant(new Mock <IInputManager>().Object)
            .Bind <IGlobalStyles>().ToConstant(globalStyles.Object)
            .Bind <ILayoutManager>().ToConstant(new LayoutManager())
            .Bind <IRuntimePlatform>().ToConstant(new AppBuilder().RuntimePlatform)
            .Bind <IPlatformRenderInterface>().ToConstant(renderInterface)
            .Bind <IStyler>().ToConstant(new Styler())
            .Bind <IWindowingPlatform>().ToConstant(new WindowingPlatformMock(() => windowImpl.Object));

            var theme = new DefaultTheme();

            globalStyles.Setup(x => x.Styles).Returns(theme);
        }
Exemplo n.º 8
0
        private void RegisterServices()
        {
            var globalStyles    = new Mock <IGlobalStyles>();
            var renderInterface = new Mock <IPlatformRenderInterface>();

            renderInterface.Setup(x => x.CreateFormattedText(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <double>(), It.IsAny <FontStyle>(),
                                                             It.IsAny <TextAlignment>(), It.IsAny <FontWeight>(), It.IsAny <TextWrapping>()))
            .Returns(new FormattedTextMock("TEST"));

            var windowImpl = new Mock <IWindowImpl>();

            Size clientSize = default(Size);

            windowImpl.SetupGet(x => x.ClientSize).Returns(() => clientSize);
            windowImpl.Setup(x => x.Resize(It.IsAny <Size>())).Callback <Size>(s => clientSize = s);
            windowImpl.Setup(x => x.MaxClientSize).Returns(new Size(1024, 1024));
            windowImpl.SetupGet(x => x.Scaling).Returns(1);

            AvaloniaLocator.CurrentMutable
            .Bind <IAssetLoader>().ToConstant(new AssetLoader())
            .Bind <IInputManager>().ToConstant(new Mock <IInputManager>().Object)
            .Bind <IGlobalStyles>().ToConstant(globalStyles.Object)
            .Bind <ILayoutManager>().ToConstant(new LayoutManager())
            .Bind <IRuntimePlatform>().ToConstant(new AppBuilder().RuntimePlatform)
            .Bind <IPlatformRenderInterface>().ToConstant(renderInterface.Object)
            .Bind <IStyler>().ToConstant(new Styler())
            .Bind <IWindowingPlatform>().ToConstant(new Avalonia.Controls.UnitTests.WindowingPlatformMock(() => windowImpl.Object));

            var theme = new DefaultTheme();

            globalStyles.Setup(x => x.Styles).Returns(theme);
        }
Exemplo n.º 9
0
 public DesignerApp()
 {
     RegisterServices();
     //For now we only support windows
     InitializeSubsystems(2);
     Styles = new DefaultTheme();
 }
Exemplo n.º 10
0
        public void Attach(IResourceDictionary resources, Action <ThemeViewModel>?preview = null)
        {
            if (Themes == null)
            {
                CurrentTheme = DefaultTheme?.Clone();
                Themes       = new ObservableCollection <ThemeViewModel>();
                if (CurrentTheme != null)
                {
                    Themes.Add(CurrentTheme);
                }
            }
            else
            {
                CurrentTheme = Themes.FirstOrDefault();
            }

            if (CurrentTheme != null)
            {
                _themeObservable = ObserveTheme(resources, CurrentTheme, preview);

                _editorObservable = Changed.Subscribe(x =>
                {
                    if (x.PropertyName == nameof(CurrentTheme))
                    {
                        _themeObservable?.Dispose();
                        if (CurrentTheme != null)
                        {
                            _themeObservable = ObserveTheme(resources, CurrentTheme, preview);
                        }
                    }
                });
            }
        }
Exemplo n.º 11
0
 public App()
 {
     RegisterServices();
     InitializeSubsystems((int)Environment.OSVersion.Platform);
     Styles = new DefaultTheme();
     PerspexXamlLoader.Load(this);
 }
Exemplo n.º 12
0
        private void RegisterServices()
        {
            var globalStyles          = new Mock <IGlobalStyles>();
            var globalStylesResources = globalStyles.As <IResourceNode>();
            var outObj = (object)10;

            globalStylesResources.Setup(x => x.TryGetResource("FontSizeNormal", out outObj)).Returns(true);

            var renderInterface = new Mock <IPlatformRenderInterface>();

            renderInterface.Setup(x =>
                                  x.CreateFormattedText(
                                      It.IsAny <string>(),
                                      It.IsAny <Typeface>(),
                                      It.IsAny <double>(),
                                      It.IsAny <TextAlignment>(),
                                      It.IsAny <TextWrapping>(),
                                      It.IsAny <Size>(),
                                      It.IsAny <IReadOnlyList <FormattedTextStyleSpan> >()))
            .Returns(new FormattedTextMock("TEST"));

            var streamGeometry = new Mock <IStreamGeometryImpl>();

            streamGeometry.Setup(x =>
                                 x.Open())
            .Returns(new Mock <IStreamGeometryContextImpl>().Object);

            renderInterface.Setup(x =>
                                  x.CreateStreamGeometry())
            .Returns(streamGeometry.Object);

            var windowImpl = new Mock <IWindowImpl>();

            Size clientSize = default(Size);

            windowImpl.SetupGet(x => x.ClientSize).Returns(() => clientSize);
            windowImpl.Setup(x => x.Resize(It.IsAny <Size>())).Callback <Size>(s => clientSize = s);
            windowImpl.Setup(x => x.MaxClientSize).Returns(new Size(1024, 1024));
            windowImpl.SetupGet(x => x.Scaling).Returns(1);

            AvaloniaLocator.CurrentMutable
            .Bind <IStandardCursorFactory>().ToConstant(new CursorFactoryMock())
            .Bind <IAssetLoader>().ToConstant(new AssetLoader())
            .Bind <IInputManager>().ToConstant(new Mock <IInputManager>().Object)
            .Bind <IGlobalStyles>().ToConstant(globalStyles.Object)
            .Bind <IRuntimePlatform>().ToConstant(new AppBuilder().RuntimePlatform)
            .Bind <IPlatformRenderInterface>().ToConstant(renderInterface.Object)
            .Bind <IStyler>().ToConstant(new Styler())
            .Bind <IFontManagerImpl>().ToConstant(new MockFontManagerImpl())
            .Bind <ITextShaperImpl>().ToConstant(new MockTextShaperImpl())
            .Bind <IWindowingPlatform>().ToConstant(new Avalonia.Controls.UnitTests.WindowingPlatformMock(() => windowImpl.Object));

            var theme = new DefaultTheme();

            globalStyles.Setup(x => x.IsStylesInitialized).Returns(true);
            globalStyles.Setup(x => x.Styles).Returns(theme);
        }
Exemplo n.º 13
0
        public void ResetTheme()
        {
            var clone = DefaultTheme?.Clone();

            if (clone != null)
            {
                ResetTheme();
            }
        }
Exemplo n.º 14
0
        public void MicrodocumTests_Should_AnalizeDTO()
        {
            //Given
            var theme = new DefaultTheme();
            var a     = new AssemblyAnalizer <DefaultLinkStyle>(theme);
            var asm   = AppDomain.CurrentDomain.GetAssemblies();
            //When
            var c = a.Analize(asm, theme.GetAvailableThemeAttributes());

            //Then
            Assert.True(c.Nodes.Count > 0, "c.Nodes.Count > 0");
        }
Exemplo n.º 15
0
        public App()
        {
            RegisterServices();
            InitializeSubsystems((int)Environment.OSVersion.Platform);
            Styles = new DefaultTheme();

            Log.Logger = new LoggerConfiguration()
                         .Filter.ByIncludingOnly(Matching.WithProperty("Area", "Property"))
                         .Filter.ByIncludingOnly(Matching.WithProperty("Property", "Text"))
                         .MinimumLevel.Verbose()
                         .WriteTo.Trace(outputTemplate: "[{Id:X8}] [{SourceContext}] {Message}")
                         .CreateLogger();
        }
Exemplo n.º 16
0
        public void Case1_Should_HaveTTLAttribute()
        {
            //Given
            var theme = new DefaultTheme();
            var a     = new AssemblyAnalizer <DefaultLinkStyle>(theme);
            var asm   = AppDomain.CurrentDomain.GetAssemblies();
            var c     = a.Analize(asm, theme.GetAvailableThemeAttributes(), t => t.FullName?.StartsWith(_classname) ?? false);
            //When
            var graphwizFileData = _gen.Generate(c);

            //Then
            StringAssert.Contains("33", graphwizFileData);
        }
Exemplo n.º 17
0
        public void Case1_Should_Have4Links()
        {
            //Given
            var theme = new DefaultTheme();
            var a     = new AssemblyAnalizer <DefaultLinkStyle>(theme);
            var asm   = AppDomain.CurrentDomain.GetAssemblies();
            var c     = a.Analize(asm, theme.GetAvailableThemeAttributes(), t => t.FullName?.StartsWith(_classname) ?? false);
            //When
            var graphwizFileData = _gen.Generate(c);

            //Then
            Assert.AreEqual(4, Regex.Matches(Regex.Escape(graphwizFileData), "->").Count);
        }
Exemplo n.º 18
0
        public void Case5_Should_SplitChains()
        {
            //Given
            var theme = new DefaultTheme();
            var a     = new AssemblyAnalizer <DefaultLinkStyle>(theme);
            var asm   = AppDomain.CurrentDomain.GetAssemblies();
            var c     = a.Analize(asm, theme.GetAvailableThemeAttributes(), t => t.FullName?.StartsWith(/*"MicroDocum.Analyzers.Tests.Case1+"*/ _classname) ?? false);
            //When
            var chains = c.SplitChains();

            //Then
            Assert.That(chains, Has.Count.EqualTo(3));
        }
Exemplo n.º 19
0
 private void EnableThemeToggling()
 {
     this.FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.T, null, () =>
     {
         if (Theme is DefaultTheme)
         {
             Theme = new DarkTheme();
         }
         else
         {
             Theme = new DefaultTheme();
         }
     }, this);
 }
Exemplo n.º 20
0
        /// <summary>
        ///     Initializes static members of the <see cref="ThemeManager" /> class.
        /// </summary>
        /// <param name="menu">
        ///     The menu.
        /// </param>
        public static void Initialize(Menu menu)
        {
            Events.OnLoad += (sender, args) =>
            {
                Menu = new Menu("thememanager", "Theme Manager");

                Menu.Add(
                    new MenuList <string>(
                        "themeID",
                        "Theme",
                        new[] { "Default", "Blue", "Blue 2", "Light", "Light 2", "Colored", "Tech" })).ValueChanged
                    += (o, eventArgs) =>
                    {
                    Notifications.Add(new Notification("Theme Manager", "Please reload Menu !"));
                    };

                menu.Add(Menu);

                switch (Menu["themeID"].GetValue <MenuList>().Index)
                {
                case 0:
                    Current = new DefaultTheme();
                    break;

                case 1:
                    Current = new BlueTheme();
                    break;

                case 2:
                    Current = new BlueTheme2();
                    break;

                case 3:
                    Current = new LightTheme();
                    break;

                case 4:
                    Current = new LightTheme2();
                    break;

                case 5:
                    Current = new ColoredTheme();
                    break;

                case 6:
                    Current = new TechTheme();
                    break;
                }
            };
        }
Exemplo n.º 21
0
 public App()
 {
     RegisterServices();
     InitializeSubsystems((int)Environment.OSVersion.Platform);
     Styles = new DefaultTheme();
     Styles.Add(new SampleTabStyle());
     DataTemplates = new DataTemplates
     {
         new FuncTreeDataTemplate <Node>(
             x => new TextBlock {
             Text = x.Name
         },
             x => x.Children),
     };
 }
Exemplo n.º 22
0
        static Theme()
        {
            if (!Platform.HasRenderAPI)
            {
                theme = new NullTheme();
                return;
            }

            PlatformTheme = Platform.PlatformTheme;
            theme         = PlatformTheme ?? DefaultTheme.Create();
            theme.Start();

            Menu.Menu.UpdateDecalSizes();
            Clock.UpdateSize();
        }
Exemplo n.º 23
0
        public void Case5_Should_FindMessageTypes()
        {
            //Given
            var theme = new DefaultTheme();
            var a     = new AssemblyAnalizer <DefaultLinkStyle>(theme);
            var asm   = AppDomain.CurrentDomain.GetAssemblies();
            //When
            var c = a.Analize(asm, theme.GetAvailableThemeAttributes(), t => t.FullName?.StartsWith(/*"MicroDocum.Analyzers.Tests.Case1+"*/ _classname) ?? false);

            //Then
            Assert.That(c.Nodes.Count, Is.EqualTo(10));
            Assert.That(c.Edges.Count, Is.EqualTo(8));
            Assert.That(c.GetSingles(), Has.Count.EqualTo(0), "GetSingles");
            Assert.That(c.GetHeads(), Has.Count.EqualTo(3), "GetHeads");
            Assert.That(c.GetLeafs(), Has.Count.EqualTo(3), "GetLeafs");
        }
Exemplo n.º 24
0
        public void AddTheme()
        {
            if (Themes != null)
            {
                var theme = Themes.Count == 0 || CurrentTheme == null?DefaultTheme?.Clone() : CurrentTheme?.Clone();

                if (theme != null)
                {
                    if (Themes.Count > 0 && Themes.Count(x => x.Name == theme.Name) > 0)
                    {
                        theme.Name += "-copy";
                    }
                    AddTheme(theme);
                }
            }
        }
Exemplo n.º 25
0
        public void Case2_Should_FindMessageTypes()
        {
            //Given
            var theme = new DefaultTheme();
            var a     = new AssemblyAnalizer <DefaultLinkStyle>(theme);
            var asm   = AppDomain.CurrentDomain.GetAssemblies();
            //When
            var c = a.Analize(asm, theme.GetAvailableThemeAttributes(), t => t.FullName?.StartsWith(_classname) ?? false);

            //Then
            Assert.That(c.Nodes, Has.Exactly(4).Items);
            Assert.That(c.Edges, Has.Count.EqualTo(1));
            Assert.That(c.GetSingles(), Has.Count.EqualTo(2), "GetSingles");
            Assert.That(c.GetHeads(), Has.Count.EqualTo(1), "GetHeads");
            Assert.That(c.GetLeafs(), Has.Count.EqualTo(1), "GetLeafs");
        }
Exemplo n.º 26
0
        public void Case1_Should_GenerateFile()
        {
            //Given
            var theme = new DefaultTheme();
            var a     = new AssemblyAnalizer <DefaultLinkStyle>(theme);
            var asm   = AppDomain.CurrentDomain.GetAssemblies();
            var c     = a.Analize(asm, theme.GetAvailableThemeAttributes(), t => t.FullName?.StartsWith(_classname) ?? false);

            Assume.That(c.Nodes, Has.Exactly(3).Items);
            Assume.That(c.Edges, Has.Count.AtLeast(4));
            Assume.That(c.GetSingles(), Has.Count.EqualTo(0), "GetSingles");
            Assume.That(c.GetHeads(), Has.Count.EqualTo(1), "GetHeads");
            Assume.That(c.GetLeafs(), Has.Count.EqualTo(0), "GetLeafs");
            //When
            var graphwizFileData = _gen.Generate(c);

            //Then
            DrawAnSave(graphwizFileData);
        }
Exemplo n.º 27
0
        private TestApp()
        {
            RegisterServices();

            var fixture            = new Fixture().Customize(new AutoMoqCustomization());
            var windowImpl         = new Mock <IWindowImpl>();
            var renderInterface    = fixture.Create <IPlatformRenderInterface>();
            var threadingInterface = Mock.Of <IPlatformThreadingInterface>(x =>
                                                                           x.CurrentThreadIsLoopThread == true);

            PerspexLocator.CurrentMutable
            .Bind <IAssetLoader>().ToConstant(new AssetLoader())
            .Bind <IPclPlatformWrapper>().ToConstant(new PclPlatformWrapper())
            .Bind <IPlatformRenderInterface>().ToConstant(renderInterface)
            .Bind <IPlatformThreadingInterface>().ToConstant(threadingInterface)
            .Bind <IStandardCursorFactory>().ToConstant(new Mock <IStandardCursorFactory>().Object)
            .Bind <IWindowingPlatform>().ToConstant(new WindowingPlatformMock(() => windowImpl.Object));

            Styles = new DefaultTheme();
        }
Exemplo n.º 28
0
        public static NodeRule <MessageInfo, DefaultLinkStyle> GetRule()
        {
            return(new NodeRule <MessageInfo, DefaultLinkStyle>((node, nodeRules, map) =>
            {
                var attr = node.Info.Node.Attributes.FirstOrDefault(x => CompilerUtils.AttributeIs(x, typeof(TagsAltAttribute)));
                if (attr != null)
                {
                    var a = (TagsAltAttribute)attr;
                    var tags = a._tags;

                    if (tags.Any())
                    {
                        var labelText = node.Attributes[GraphvizAttribute.Label.ToString()];
                        labelText = DefaultTheme.CheckAndWrapToHtmlTable(labelText);
                        var newRowText = $"<font color='gray' point-size='6'><i>{string.Join(", ", tags.Select(x => "#" + x).ToArray())}</i></font>";
                        labelText = DefaultTheme.AddNewRow(labelText, newRowText);
                        node.Attributes[GraphvizAttribute.Label.ToString()] = labelText;
                    }
                }
            }));
        }
Exemplo n.º 29
0
 public static NodeRule <MessageInfo, DefaultLinkStyle> GetRule()
 {
     return(new NodeRule <MessageInfo, DefaultLinkStyle>((node, nodeRules, map) =>
     {
         var attr = node.Info.Node.Attributes.FirstOrDefault(x => CompilerUtils.AttributeIs(x, typeof(TTLAttribute)));
         if (attr != null)
         {
             var a = (TTLAttribute)attr;
             var seconds = (double)a._seconds;
             var val = TimeSpan.FromSeconds(seconds);
             if (val.TotalMilliseconds >= 1)
             {
                 var labelText = node.Attributes[GraphvizAttribute.Label.ToString()];
                 labelText = DefaultTheme.CheckAndWrapToHtmlTable(labelText);
                 var newRowText = $"<font color='red' point-size='6'>TTL {val.TotalSeconds:F2} sec</font>";
                 labelText = DefaultTheme.AddNewRow(labelText, newRowText);
                 node.Attributes[GraphvizAttribute.Label.ToString()] = labelText;
             }
         }
     }));
 }
Exemplo n.º 30
0
        public void MicrodocumTests_Should_GenerateGraphwiz()
        {
            //Given
            var theme = new DefaultTheme();
            var a     = new AssemblyAnalizer <DefaultLinkStyle>(theme);
            var asm   = AppDomain.CurrentDomain.GetAssemblies();
            var c     = a.Analize(asm, theme.GetAvailableThemeAttributes());
            var gen   = new GraphvizDotGenerator <DefaultLinkStyle>(new DefaultTheme());
            //When
            var graphwizFileData = gen.Generate(c);

            //Then
            Assert.True(!string.IsNullOrWhiteSpace(graphwizFileData));
            var path = Directory.GetCurrentDirectory();

            path = Path.Combine(path, "DTO_routing.dot");
            using (var file = new StreamWriter(path, false))
            {
                file.Write(graphwizFileData);
                _outputHelper.WriteLine("saved to " + path);
            }
        }