public MainWindow()
        {
            InitializeComponent();
            TextBlock block = new TextBlock();

            block.Text = "Lorem";
            StackPanel panel = new StackPanel();

            panel.Children.Add(block);

            Button b = new Button();

            b.Content    = "Szia";
            b.Background = Brushes.LightSkyBlue;
            Button b2 = new Button();

            b2.Content = "Dolgozo Hozzáadása";
            b2.Name    = "btn2";
            b2.Click  += formMegnyitasa;

            Grid grid = new Grid();

            grid.Width         = 500;
            grid.Background    = Brushes.Beige;
            grid.Margin        = Thickness.Parse("20,10,20,10");
            grid.ShowGridLines = true;
            ColumnDefinition column1 = new ColumnDefinition(GridLength.Parse("2*"));
            ColumnDefinition column2 = new ColumnDefinition(GridLength.Parse("*"));

            grid.ColumnDefinitions.Add(column1);
            grid.ColumnDefinitions.Add(column2);
            RowDefinition row = new RowDefinition();

            grid.RowDefinitions.Add(row);
            Grid.SetColumn(b, 0);
            Grid.SetColumn(b2, 1);
            grid.Children.Add(b);
            grid.Children.Add(b2);

            panel.Children.Add(grid);
            WrapPanel root = this.Find <WrapPanel>("wrappanel");

            root.Orientation = Orientation.Vertical;
            root.Children.Add(panel);
            NameScope scope = new NameScope();

            b2.RegisterInNameScope(scope);
            root.RegisterInNameScope(scope);
            Button sayhibutton = this.Find <Button>("sayhibutton");

            sayhibutton.RegisterInNameScope(scope);
            sayhibutton.Click += sayhi;
            NameScope.SetNameScope(this, scope);
        }
Exemplo n.º 2
0
        public static void Load(Control control, LayoutConfiguration layout)
        {
            foreach (var gridLayout in layout.GridLayouts)
            {
                var grid = control.FindControl <Grid>(gridLayout.Name);
                if (grid != null)
                {
                    if (grid.RowDefinitions.Count == gridLayout.Rows.Count)
                    {
                        for (int i = 0; i < grid.RowDefinitions.Count; i++)
                        {
                            grid.RowDefinitions[i].Height = GridLength.Parse(gridLayout.Rows[i].Height);
                        }
                    }

                    if (grid.ColumnDefinitions.Count == gridLayout.Columns.Count)
                    {
                        for (int i = 0; i < grid.ColumnDefinitions.Count; i++)
                        {
                            grid.ColumnDefinitions[i].Width = GridLength.Parse(gridLayout.Columns[i].Width);
                        }
                    }
                }
            }

            foreach (var tabLayout in layout.TabLayouts)
            {
                var tabControl = control.FindControl <TabControl>(tabLayout.Name);
                if (tabControl != null)
                {
                    if (tabControl.Items is AvaloniaList <object> tabItems && tabItems.Count == tabLayout.Tabs.Count)
                    {
                        for (int i = 0; i < tabLayout.Tabs.Count; i++)
                        {
                            for (int j = 0; j < tabItems.Count; j++)
                            {
                                if (tabItems[j] is TabItem tabItem)
                                {
                                    if (tabItem.Name == tabLayout.Tabs[i].Name)
                                    {
                                        if (i != j)
                                        {
                                            tabItems.Move(j, i);
                                        }
                                    }
                                }
                            }
                        }

                        tabControl.SelectedIndex = tabLayout.SelectedTab;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static void Build(MainWindow window)
        {
            // maxRow y maxCol deberían estar definidas en el ViewModel...
            int  maxRow  = 9;
            int  maxCol  = 5;
            int  i       = 0;
            Grid grdMain = window.FindControl <Grid>("grdMain");

            for (int row = 0; row < maxRow; row++)
            {
                grdMain.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Parse("*", CultureInfo.InstalledUICulture)
                });
            }
            for (int col = 0; col < maxCol; col++)
            {
                grdMain.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = GridLength.Parse("1*", CultureInfo.InstalledUICulture)
                });
            }
            for (int row = 0; row < maxRow; row++)
            {
                for (int col = 0; col < maxCol; col++)
                {
                    ButtonT b          = new ButtonT("Boton Nro: " + i.ToString(), i);
                    var     stackPanel = new Avalonia.Controls.StackPanel();
                    var     textBlock  = new Avalonia.Controls.TextBlock
                    {
                        [!TextBlock.TextProperty] = new Binding("Name")
                    };
                    stackPanel.Children.Add(textBlock);
                    var btn = new Avalonia.Controls.Button
                    {
                        Background = b.ButtonColor,
                        [!Button.BackgroundProperty] = b.ToBinding <SolidColorBrush>(),
                        [Grid.RowProperty]           = row,
                        [Grid.ColumnProperty]        = col,
                        // window.DataContext es null, por eso uso la instancia global del viewmodel :( )
                        Command          = ReactiveCommand.Create <ButtonT>(MainWindowViewModel.Instance.RunTheThing),
                        CommandParameter = b,
                        Content          = stackPanel,
                        DataContext      = b
                    };

                    i++;
                    grdMain.Children.Add(btn);
                }
            }
        }
Exemplo n.º 4
0
        private void InitializeComponent()
        {
            int maxRow = 3;
            int maxCol = 5;

            AvaloniaXamlLoader.Load(this);
            int i       = 0;
            var grdMain = this.FindControl <Grid>("grdMain");

            for (int row = 0; row < maxRow; row++)
            {
                grdMain.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Parse("*", CultureInfo.InstalledUICulture)
                });
            }
            for (int col = 0; col < maxCol; col++)
            {
                grdMain.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = GridLength.Parse("1*", CultureInfo.InstalledUICulture)
                });
            }
            for (int row = 0; row < maxRow; row++)
            {
                for (int col = 0; col < maxCol; col++)
                {
                    var btn = new Avalonia.Controls.Button
                    {
                        [Grid.RowProperty]    = row,
                        [Grid.ColumnProperty] = col,
                        //Fill = lstColores[i%lstColores.Count],
                        Command          = ReactiveCommand.Create <int>(RunTheThing),
                        CommandParameter = i,
                        Content          = i.ToString()
                    };
                    i++;
                    grdMain.Children.Add(btn);
                }
            }
        }
Exemplo n.º 5
0
        public void Parse_Should_Parse_Pixel_Value()
        {
            var result = GridLength.Parse("2");

            Assert.Equal(new GridLength(2, GridUnitType.Pixel), result);
        }
Exemplo n.º 6
0
        public void Parse_Should_Parse_Star_Value()
        {
            var result = GridLength.Parse("2*");

            Assert.Equal(new GridLength(2, GridUnitType.Star), result);
        }
Exemplo n.º 7
0
        public void Parse_Should_Parse_Auto_Lowercase()
        {
            var result = GridLength.Parse("auto");

            Assert.Equal(GridLength.Auto, result);
        }
        protected virtual Control CreateTextAndHexadecimalEditControl(
            ConfigurablePropertyMetadata property,
            IEnumerable <ConfigurablePropertyMetadata> allProperties)
        {
            var otherPropertyInfo = property.GetCustomAttribute <TextAndHexadecimalEditAttribute>();

            if (otherPropertyInfo == null)
            {
                throw new InvalidOperationException($"{nameof(TextAndHexadecimalEditAttribute)} not found on property {property.PropertyName}!");
            }

            var otherProperty = allProperties
                                .FirstOrDefault(actProperty => actProperty.PropertyName == otherPropertyInfo.EncodingWebNamePropertyName);

            if (otherProperty == null)
            {
                throw new InvalidOperationException($"Property {otherPropertyInfo.EncodingWebNamePropertyName} not found!");
            }

            var stackPanel = new StackPanel();

            stackPanel.Orientation = Orientation.Vertical;

            var ctrlTextBox1 = new TextBox();

            ctrlTextBox1[!TextBox.TextProperty] = new Binding(
                nameof(property.ValueAccessor),
                BindingMode.TwoWay);
            ctrlTextBox1.Width      = double.NaN;
            ctrlTextBox1.IsReadOnly = property.IsReadOnly;

            var hexTextBinding = new Binding(
                nameof(property.ValueAccessor),
                BindingMode.TwoWay)
            {
                Converter          = new TextToHexConverter(),
                ConverterParameter = new Func <string?>(() => otherProperty.ValueAccessor as string)
            };

            var ctrlTextBox2Container = new Grid();

            ctrlTextBox2Container.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto));
            ctrlTextBox2Container.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Parse("*")));

            var ctrlTextBox2Header = new TextBlock();

            ctrlTextBox2Header.Text = "HEX";
            ctrlTextBox2Header.SetValue(Grid.ColumnProperty, 0);
            ctrlTextBox2Container.Children.Add(ctrlTextBox2Header);

            var ctrlTextBox2 = new TextBox();

            ctrlTextBox2[!TextBox.TextProperty] = hexTextBinding;
            ctrlTextBox2.Width      = double.NaN;
            ctrlTextBox2.IsReadOnly = property.IsReadOnly;

            otherProperty.RegisterWeakPropertyChangedTarget(
                new WeakReference(ctrlTextBox2),
                (sender, eArgs) =>
            {
                ctrlTextBox2[!TextBox.TextProperty] = hexTextBinding;
            });

            ctrlTextBox2.SetValue(Grid.ColumnProperty, 1);
            ctrlTextBox2Container.Children.Add(ctrlTextBox2);

            stackPanel.Children.Add(ctrlTextBox1);
            stackPanel.Children.Add(ctrlTextBox2Container);

            return(stackPanel);
        }
Exemplo n.º 9
0
        public MainWindowViewModel(Window w)
        {
            window             = w;
            window.WindowState = Settings.WindowState;
            if (Settings.Width > 0)
            {
                window.Width = Settings.Width;
            }
            if (Settings.Height > 0)
            {
                window.Height = Settings.Height;
            }
            if (Settings.Left != -1 && Settings.Top != -1)
            {
                window.Position = new Point(Settings.Left, Settings.Top);
            }

            patternsPanelColumn     = window.Find <Grid>("MainGrid").ColumnDefinitions[0];
            sourceCodeTextBox       = window.Find <TextBox>("SourceCode");
            sourceCodeErrorsListBox = window.Find <ListBox>("SourceCodeErrors");
            matchingResultListBox   = window.Find <ListBox>("MatchingResult");
            logger = window.Find <TextBox>("Logger");

            patternsPanelColumn.Width             = GridLength.Parse(Settings.PatternsPanelWidth.ToString(), CultureInfo.InvariantCulture);
            sourceCodeErrorsListBox.DoubleTapped += (object sender, Avalonia.Interactivity.RoutedEventArgs e) =>
            {
                GuiHelpers.ProcessErrorOnDoubleClick(sourceCodeErrorsListBox, sourceCodeTextBox);
            };
            matchingResultListBox.DoubleTapped += MatchingResultListBox_DoubleTapped;

            sourceCodeLogger = new GuiLogger(SourceCodeErrors)
            {
                LogPatternErrors = false
            };
            languageDetector.Logger = sourceCodeLogger;

            OpenSourceCodeFile.Subscribe(async _ =>
            {
                var dialog         = new OpenFileDialog();
                string[] fileNames = await dialog.ShowAsync(window);
                if (fileNames != null)
                {
                    string fileName        = fileNames.Single();
                    OpenedFileName         = fileName;
                    fileOpened             = true;
                    sourceCodeTextBox.Text = File.ReadAllText(sourceCodeFileName);
                }
            });

            SaveSourceCodeFile.Subscribe(_ =>
            {
                if (!string.IsNullOrEmpty(sourceCodeFileName))
                {
                    File.WriteAllText(sourceCodeFileName, sourceCodeTextBox.Text);
                }
            });

            ReloadFile.Subscribe(_ =>
            {
                if (!string.IsNullOrEmpty(sourceCodeFileName))
                {
                    sourceCodeTextBox.Text = File.ReadAllText(sourceCodeFileName);
                }
            });

            Reset.Subscribe(_ =>
            {
                OpenedFileName         = "";
                sourceCodeTextBox.Text = "";
            });

            if (string.IsNullOrEmpty(Settings.SourceCodeFile) || !File.Exists(Settings.SourceCodeFile))
            {
                fileOpened             = false;
                sourceCodeFileName     = "";
                sourceCodeTextBox.Text = Settings.SourceCode;
            }
            else
            {
                fileOpened             = true;
                sourceCodeFileName     = Settings.SourceCodeFile;
                sourceCodeTextBox.Text = File.ReadAllText(Settings.SourceCodeFile);
            }

            CheckSourceCode();

            this.RaisePropertyChanged(nameof(SelectedLanguageInfo));
            this.RaisePropertyChanged(nameof(OpenedFileName));

            sourceCodeTextBox.GetObservable(TextBox.CaretIndexProperty)
            .Subscribe(UpdateSourceCodeCaretIndex);
            sourceCodeTextBox.GetObservable(TextBox.SelectionStartProperty)
            .Subscribe(selectionStart =>
            {
                if (sourceCodeTextBox.IsFocused)
                {
                    sourceCodeSelectionStart = selectionStart;
                }
            });
            sourceCodeTextBox.GetObservable(TextBox.SelectionEndProperty)
            .Subscribe(selectionEnd =>
            {
                if (sourceCodeTextBox.IsFocused)
                {
                    sourceCodeSelectionEnd = selectionEnd;
                }
            });

            sourceCodeTextBox.GetObservable(TextBox.TextProperty)
            .Throttle(TimeSpan.FromMilliseconds(500))
            .Subscribe(str => CheckSourceCode());

            SetupWindowSubscriptions();

            this.RaisePropertyChanged(nameof(IsErrorsExpanded));
            this.RaisePropertyChanged(nameof(IsTokensExpanded));
            this.RaisePropertyChanged(nameof(IsParseTreeExpanded));
            this.RaisePropertyChanged(nameof(IsUstExpanded));
            this.RaisePropertyChanged(nameof(IsMatchingsExpanded));
        }
        public static bool TryConvert(AstTransformationContext context, IXamlAstValueNode node, string text, IXamlType type, AvaloniaXamlIlWellKnownTypes types, out IXamlAstValueNode result)
        {
            if (type.FullName == "System.TimeSpan")
            {
                var tsText = text.Trim();

                if (!TimeSpan.TryParse(tsText, CultureInfo.InvariantCulture, out var timeSpan))
                {
                    // // shorthand seconds format (ie. "0.25")
                    if (!tsText.Contains(":") && double.TryParse(tsText,
                                                                 NumberStyles.Float | NumberStyles.AllowThousands,
                                                                 CultureInfo.InvariantCulture, out var seconds))
                    {
                        timeSpan = TimeSpan.FromSeconds(seconds);
                    }
                    else
                    {
                        throw new XamlX.XamlLoadException($"Unable to parse {text} as a time span", node);
                    }
                }

                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.FindMethod("FromTicks", type, false, types.Long),
                                                                      new[] { new XamlConstantNode(node, types.Long, timeSpan.Ticks) });
                return(true);
            }

            if (type.Equals(types.FontFamily))
            {
                result = new AvaloniaXamlIlFontFamilyAstNode(types, text, node);
                return(true);
            }

            if (type.Equals(types.Thickness))
            {
                try
                {
                    var thickness = Thickness.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Thickness, types.ThicknessFullConstructor,
                                                                         new[] { thickness.Left, thickness.Top, thickness.Right, thickness.Bottom });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a thickness", node);
                }
            }

            if (type.Equals(types.Point))
            {
                try
                {
                    var point = Point.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Point, types.PointFullConstructor,
                                                                         new[] { point.X, point.Y });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a point", node);
                }
            }

            if (type.Equals(types.Vector))
            {
                try
                {
                    var vector = Vector.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Vector, types.VectorFullConstructor,
                                                                         new[] { vector.X, vector.Y });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a vector", node);
                }
            }

            if (type.Equals(types.Size))
            {
                try
                {
                    var size = Size.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Size, types.SizeFullConstructor,
                                                                         new[] { size.Width, size.Height });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a size", node);
                }
            }

            if (type.Equals(types.Matrix))
            {
                try
                {
                    var matrix = Matrix.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Matrix, types.MatrixFullConstructor,
                                                                         new[] { matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.M31, matrix.M32 });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a matrix", node);
                }
            }

            if (type.Equals(types.CornerRadius))
            {
                try
                {
                    var cornerRadius = CornerRadius.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.CornerRadius, types.CornerRadiusFullConstructor,
                                                                         new[] { cornerRadius.TopLeft, cornerRadius.TopRight, cornerRadius.BottomRight, cornerRadius.BottomLeft });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a corner radius", node);
                }
            }

            if (type.Equals(types.Color))
            {
                if (!Color.TryParse(text, out Color color))
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a color", node);
                }

                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.GetMethod(
                                                                          new FindMethodMethodSignature("FromUInt32", type, types.UInt)
                {
                    IsStatic = true
                }),
                                                                      new[] { new XamlConstantNode(node, types.UInt, color.ToUint32()) });

                return(true);
            }

            if (type.Equals(types.GridLength))
            {
                try
                {
                    var gridLength = GridLength.Parse(text);

                    result = new AvaloniaXamlIlGridLengthAstNode(node, types, gridLength);

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a grid length", node);
                }
            }

            if (type.Equals(types.Cursor))
            {
                if (TypeSystemHelpers.TryGetEnumValueNode(types.StandardCursorType, text, node, out var enumConstantNode))
                {
                    var cursorTypeRef = new XamlAstClrTypeReference(node, types.Cursor, false);

                    result = new XamlAstNewClrObjectNode(node, cursorTypeRef, types.CursorTypeConstructor, new List <IXamlAstValueNode> {
                        enumConstantNode
                    });

                    return(true);
                }
            }

            if (type.Equals(types.ColumnDefinitions))
            {
                return(ConvertDefinitionList(node, text, types, types.ColumnDefinitions, types.ColumnDefinition, "column definitions", out result));
            }

            if (type.Equals(types.RowDefinitions))
            {
                return(ConvertDefinitionList(node, text, types, types.RowDefinitions, types.RowDefinition, "row definitions", out result));
            }

            if (type.Equals(types.Classes))
            {
                var classes    = text.Split(' ');
                var classNodes = classes.Select(c => new XamlAstTextNode(node, c, types.XamlIlTypes.String)).ToArray();

                result = new AvaloniaXamlIlAvaloniaListConstantAstNode(node, types, types.Classes, types.XamlIlTypes.String, classNodes);
                return(true);
            }

            result = null;
            return(false);
        }
Exemplo n.º 11
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     return(GridLength.Parse((string)value, culture));
 }
Exemplo n.º 12
0
 public void Parse_Should_Throw_FormatException_For_Invalid_String()
 {
     Assert.Throws <FormatException>(() => GridLength.Parse("2x", CultureInfo.InvariantCulture));
 }
Exemplo n.º 13
0
        public void Parse_Should_Parse_Star()
        {
            var result = GridLength.Parse("*", CultureInfo.InvariantCulture);

            Assert.Equal(new GridLength(1, GridUnitType.Star), result);
        }
Exemplo n.º 14
0
        public void Parse_Should_Parse_Auto_Lowercase()
        {
            var result = GridLength.Parse("auto", CultureInfo.InvariantCulture);

            Assert.Equal(GridLength.Auto, result);
        }
Exemplo n.º 15
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var width = System.Convert.ToString(value);

            return(GridLength.Parse(width));
        }
Exemplo n.º 16
0
 public void Parse_Should_Throw_FormatException_For_Invalid_String()
 {
     Assert.Throws <FormatException>(() => GridLength.Parse("2x"));
 }
Exemplo n.º 17
0
        public static bool CustomValueConverter(AstTransformationContext context,
                                                IXamlAstValueNode node, IXamlType type, out IXamlAstValueNode result)
        {
            if (!(node is XamlAstTextNode textNode))
            {
                result = null;
                return(false);
            }

            var text = textNode.Text;

            var types = context.GetAvaloniaTypes();

            if (type.FullName == "System.TimeSpan")
            {
                var tsText = text.Trim();

                if (!TimeSpan.TryParse(tsText, CultureInfo.InvariantCulture, out var timeSpan))
                {
                    // // shorthand seconds format (ie. "0.25")
                    if (!tsText.Contains(":") && double.TryParse(tsText,
                                                                 NumberStyles.Float | NumberStyles.AllowThousands,
                                                                 CultureInfo.InvariantCulture, out var seconds))
                    {
                        timeSpan = TimeSpan.FromSeconds(seconds);
                    }
                    else
                    {
                        throw new XamlX.XamlLoadException($"Unable to parse {text} as a time span", node);
                    }
                }


                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.FindMethod("FromTicks", type, false, types.Long),
                                                                      new[] { new XamlConstantNode(node, types.Long, timeSpan.Ticks) });
                return(true);
            }

            if (type.Equals(types.FontFamily))
            {
                result = new AvaloniaXamlIlFontFamilyAstNode(types, text, node);
                return(true);
            }

            if (type.Equals(types.Thickness))
            {
                try
                {
                    var thickness = Thickness.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Thickness, types.ThicknessFullConstructor,
                                                                         new[] { thickness.Left, thickness.Top, thickness.Right, thickness.Bottom });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a thickness", node);
                }
            }

            if (type.Equals(types.Point))
            {
                try
                {
                    var point = Point.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Point, types.PointFullConstructor,
                                                                         new[] { point.X, point.Y });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a point", node);
                }
            }

            if (type.Equals(types.Vector))
            {
                try
                {
                    var vector = Vector.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Vector, types.VectorFullConstructor,
                                                                         new[] { vector.X, vector.Y });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a vector", node);
                }
            }

            if (type.Equals(types.Size))
            {
                try
                {
                    var size = Size.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Size, types.SizeFullConstructor,
                                                                         new[] { size.Width, size.Height });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a size", node);
                }
            }

            if (type.Equals(types.Matrix))
            {
                try
                {
                    var matrix = Matrix.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Matrix, types.MatrixFullConstructor,
                                                                         new[] { matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.M31, matrix.M32 });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a matrix", node);
                }
            }

            if (type.Equals(types.CornerRadius))
            {
                try
                {
                    var cornerRadius = CornerRadius.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.CornerRadius, types.CornerRadiusFullConstructor,
                                                                         new[] { cornerRadius.TopLeft, cornerRadius.TopRight, cornerRadius.BottomRight, cornerRadius.BottomLeft });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a corner radius", node);
                }
            }

            if (type.Equals(types.Color))
            {
                if (!Color.TryParse(text, out Color color))
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a color", node);
                }

                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.GetMethod(
                                                                          new FindMethodMethodSignature("FromUInt32", type, types.UInt)
                {
                    IsStatic = true
                }),
                                                                      new[] { new XamlConstantNode(node, types.UInt, color.ToUint32()) });

                return(true);
            }

            if (type.Equals(types.GridLength))
            {
                try
                {
                    var gridLength = GridLength.Parse(text);

                    result = new AvaloniaXamlIlGridLengthAstNode(node, types, gridLength);

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a grid length", node);
                }
            }

            if (type.Equals(types.Cursor))
            {
                if (TypeSystemHelpers.TryGetEnumValueNode(types.StandardCursorType, text, node, out var enumConstantNode))
                {
                    var cursorTypeRef = new XamlAstClrTypeReference(node, types.Cursor, false);

                    result = new XamlAstNewClrObjectNode(node, cursorTypeRef, types.CursorTypeConstructor, new List <IXamlAstValueNode> {
                        enumConstantNode
                    });

                    return(true);
                }
            }

            if (type.FullName == "Avalonia.AvaloniaProperty")
            {
                var scope = context.ParentNodes().OfType <AvaloniaXamlIlTargetTypeMetadataNode>().FirstOrDefault();
                if (scope == null)
                {
                    throw new XamlX.XamlLoadException("Unable to find the parent scope for AvaloniaProperty lookup", node);
                }

                result = XamlIlAvaloniaPropertyHelper.CreateNode(context, text, scope.TargetType, node);
                return(true);
            }

            result = null;
            return(false);
        }
Exemplo n.º 18
0
        public override void Render(DrawingContext context)
        {
            if (_isTemplateApplied == false)
            {
                base.Render(context);
            }

            switch (TabStripPlacement)
            {
            case Dock.Left:
                Grid.SetColumn(_contentSite, 0);
                Grid.SetRow(_contentSite, 0);
                _bottomRow.Height  = GridLength.Auto;
                _leftColumn.Width  = GridLength.Parse("*");
                _rightColumn.Width = GridLength.Auto;
                _topRow.Height     = GridLength.Parse("*");
                break;

            case Dock.Top:
                Grid.SetColumn(_contentSite, 0);
                Grid.SetRow(_contentSite, 0);
                _bottomRow.Height  = GridLength.Auto;
                _leftColumn.Width  = GridLength.Parse("*");
                _rightColumn.Width = GridLength.Auto;
                _topRow.Height     = GridLength.Parse("*");
                break;

            case Dock.Right:
                Grid.SetColumn(_contentSite, 1);
                Grid.SetRow(_contentSite, 0);
                _bottomRow.Height  = GridLength.Auto;
                _leftColumn.Width  = GridLength.Auto;
                _rightColumn.Width = GridLength.Parse("*");
                _topRow.Height     = GridLength.Parse("*");
                break;

            case Dock.Bottom:
                Grid.SetColumn(_contentSite, 0);
                Grid.SetRow(_contentSite, 1);
                _bottomRow.Height  = GridLength.Parse("*");
                _leftColumn.Width  = GridLength.Parse("*");
                _rightColumn.Width = GridLength.Auto;
                _topRow.Height     = GridLength.Auto;
                break;
            }

            if (UnderlinePlacement == null)
            {
                switch (TabStripPlacement)
                {
                case Dock.Top:
                    Grid.SetColumn(_underline, 0);
                    Grid.SetRow(_underline, 1);
                    break;

                case Dock.Bottom:
                    Grid.SetColumn(_underline, 0);
                    Grid.SetRow(_underline, 0);
                    break;

                case Dock.Left:
                    Grid.SetColumn(_underline, 0);
                    Grid.SetRow(_underline, 0);
                    break;

                case Dock.Right:
                    Grid.SetColumn(_underline, 0);
                    Grid.SetRow(_underline, 0);
                    break;
                }
            }
            else
            {
                switch (UnderlinePlacement.Value)
                {
                case Dock.Top:
                    switch (TabStripPlacement)
                    {
                    case Dock.Top:
                        Grid.SetColumn(_underline, 0);
                        Grid.SetRow(_underline, 0);
                        break;

                    case Dock.Bottom:
                        Grid.SetColumn(_underline, 0);
                        Grid.SetRow(_underline, 0);
                        break;

                    case Dock.Left:
                        Grid.SetColumn(_underline, 0);
                        Grid.SetRow(_underline, 0);
                        break;

                    case Dock.Right:
                        Grid.SetColumn(_underline, 1);
                        Grid.SetRow(_underline, 0);
                        break;
                    }
                    break;

                case Dock.Bottom:
                    switch (TabStripPlacement)
                    {
                    case Dock.Top:
                        Grid.SetColumn(_underline, 0);
                        Grid.SetRow(_underline, 1);
                        break;

                    case Dock.Bottom:
                        Grid.SetColumn(_underline, 0);
                        Grid.SetRow(_underline, 1);
                        break;

                    case Dock.Left:
                        Grid.SetColumn(_underline, 0);
                        Grid.SetRow(_underline, 1);
                        break;

                    case Dock.Right:
                        Grid.SetColumn(_underline, 1);
                        Grid.SetRow(_underline, 1);
                        break;
                    }
                    break;

                case Dock.Left:
                    switch (TabStripPlacement)
                    {
                    case Dock.Top:
                        Grid.SetColumn(_underline, 0);
                        Grid.SetRow(_underline, 0);
                        break;

                    case Dock.Bottom:
                        Grid.SetColumn(_underline, 0);
                        Grid.SetRow(_underline, 1);
                        break;

                    case Dock.Left:
                        Grid.SetColumn(_underline, 0);
                        Grid.SetRow(_underline, 0);
                        break;

                    case Dock.Right:
                        Grid.SetColumn(_underline, 1);
                        Grid.SetRow(_underline, 0);
                        break;
                    }
                    break;

                case Dock.Right:
                    switch (TabStripPlacement)
                    {
                    case Dock.Top:
                        Grid.SetColumn(_underline, 0);
                        Grid.SetRow(_underline, 0);
                        break;

                    case Dock.Bottom:
                        Grid.SetColumn(_underline, 1);
                        Grid.SetRow(_underline, 1);
                        break;

                    case Dock.Left:
                        Grid.SetColumn(_underline, 0);
                        Grid.SetRow(_underline, 0);
                        break;

                    case Dock.Right:
                        Grid.SetColumn(_underline, 1);
                        Grid.SetRow(_underline, 0);
                        break;
                    }
                    break;
                }
            }



            base.Render(context);
        }
Exemplo n.º 19
0
 public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
 {
     return(GridLength.Parse((string)value, culture));
 }
Exemplo n.º 20
0
        public MainWindowViewModel(Window w)
        {
            window             = w;
            window.WindowState = Settings.WindowState;
            if (Settings.Width > 0)
            {
                window.Width = Settings.Width;
            }

            if (Settings.Height > 0)
            {
                window.Height = Settings.Height;
            }

            if (Settings.Left != -1 && Settings.Top != -1)
            {
                window.Position = new Point(Settings.Left, Settings.Top);
            }

            patternsPanelColumn = window.Find <Grid>("MainGrid").ColumnDefinitions[0];
            sourceTextBox       = window.Find <TextEditor>("Source");
            sourceErrorsListBox = window.Find <ListBox>("SourceErrors");
            matchResultListBox  = window.Find <ListBox>("MatchingResult");

            patternsPanelColumn.Width         = GridLength.Parse(Settings.PatternsPanelWidth.ToString());
            sourceErrorsListBox.DoubleTapped += (sender, e) =>
            {
                GuiUtils.ProcessErrorOnDoubleClick(sourceErrorsListBox, sourceTextBox);
            };
            matchResultListBox.DoubleTapped += MatchingResultListBox_DoubleTapped;

            SourceLogger            = GuiLogger.CreateSourceLogger(SourceErrors, MatchingResults);
            languageDetector.Logger = SourceLogger;

            OpenSourceFile = ReactiveCommand.Create(async() =>
            {
                var dialog = new OpenFileDialog
                {
                    Title = "Open source code file"
                };
                string[] fileNames = await dialog.ShowAsync(window);
                if (fileNames?.Any() == true)
                {
                    OpenedFileName     = fileNames[0];
                    fileOpened         = true;
                    sourceTextBox.Text = FileExt.ReadAllText(sourceFileName);
                }
            });

            SaveSourceFile = ReactiveCommand.Create(() =>
            {
                if (!string.IsNullOrEmpty(sourceFileName))
                {
                    FileExt.WriteAllText(sourceFileName, sourceTextBox.Text);
                }
            });

            ReloadFile = ReactiveCommand.Create(() =>
            {
                if (!string.IsNullOrEmpty(sourceFileName))
                {
                    sourceTextBox.Text = FileExt.ReadAllText(sourceFileName);
                }
            });

            Reset = ReactiveCommand.Create(() =>
            {
                OpenedFileName     = "";
                sourceTextBox.Text = "";
            });

            OpenDumpDirectory = ReactiveCommand.Create(() =>
            {
                try
                {
                    GuiUtils.OpenDirectory(ServiceLocator.TempDirectory);
                }
                catch (Exception ex)
                {
                    new MessageBox($"Unable to open {ServiceLocator.TempDirectory} due to {ex}").ShowDialog();
                }
            });

            if (string.IsNullOrEmpty(Settings.SourceFile) || !FileExt.Exists(Settings.SourceFile))
            {
                fileOpened         = false;
                sourceFileName     = "";
                sourceTextBox.Text = Settings.Source;
            }
            else
            {
                fileOpened         = true;
                sourceFileName     = Settings.SourceFile;
                sourceTextBox.Text = FileExt.ReadAllText(Settings.SourceFile);
            }

            CheckSource();

            this.RaisePropertyChanged(nameof(SelectedLanguage));
            this.RaisePropertyChanged(nameof(OpenedFileName));

            highlightings.TryGetValue(SelectedLanguage, out string highlighting);
            sourceTextBox.SyntaxHighlighting = highlighting != null
                ? HighlightingManager.Instance.GetDefinition(highlighting)
                : null;

            Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(200), RxApp.MainThreadScheduler)
            .Subscribe(_ => UpdateSourceSelection());

            Observable.FromEventPattern <EventHandler, EventArgs>(
                h => sourceTextBox.TextChanged += h,
                h => sourceTextBox.TextChanged -= h)
            .Throttle(TimeSpan.FromMilliseconds(500))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(str => CheckSource());

            SetupWindowSubscriptions();

            this.RaisePropertyChanged(nameof(IsErrorsExpanded));
            this.RaisePropertyChanged(nameof(IsTokensExpanded));
            this.RaisePropertyChanged(nameof(IsParseTreeExpanded));
            this.RaisePropertyChanged(nameof(IsUstExpanded));
            this.RaisePropertyChanged(nameof(IsMatchingsExpanded));
        }