示例#1
0
 private string GenerateNewLayoutName()
 {
     for (int i = 0; i < 200; i++)
     {
         LayoutConfiguration found = AppContext.Configuration.Layouts.FirstOrDefault(l => l.Name.StartsWith("Layout " + (i + 1)));
         if (found == null)
         {
             return("Layout " + (i + 1));
         }
     }
     return("<<>>");
 }
        private void ApplyLayout(AppChooserUserControl chooser, int row, int col)
        {
            if (chooser.SelectedApp == null || !chooser.SelectedApp.IsActive)
            {
                return;
            }

            LayoutConfiguration layout = this.LayoutConfiguration; // AppContext.Configuration.Displays[0];

            layout.GridSize.UpdateCellSizes(gridApps);

            Rect bounds = layout.GetCorrectedCellBounds(row, col, chooser.SelectedApp.HWND);

            Logic.MoveWindow(chooser.SelectedApp.HWND, bounds.Left, bounds.Top, bounds.Width, bounds.Height);
        }
        private static void RebuildAppsGrid(Grid grid, int rows, int cols, LayoutConfiguration config, ViewModel vm)
        {
            //for splitters
            int newRows = rows * 2 - 1;
            int newCols = cols * 2 - 1;

            GridLength oneStar      = new GridLength(1, GridUnitType.Star);
            GridLength splitterSize = new GridLength(5, GridUnitType.Pixel);

            double[] widths = config.GridSize.RelativeColumnsWidths;

            grid.ColumnDefinitions.Clear();
            for (int col = 0; col < newCols; col++)
            {
                //every odd column for splitter
                GridLength width = (col % 2) != 0 ? splitterSize :
                                   new GridLength(config.GridSize.RelativeColumnsWidths[col / 2], GridUnitType.Star);

                grid.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = width
                });
            }

            grid.RowDefinitions.Clear(); //all but first
            for (int row = 0; row < newRows; row++)
            {
                //every odd row for splitter
                GridLength height = (row % 2) != 0 ? splitterSize :
                                    new GridLength(config.GridSize.RelativeRowsHeghts[row / 2], GridUnitType.Star);

                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = height
                });
            }

            foreach (UIElement ul in grid.Children)
            {
                if (ul is AppChooserUserControl app)
                {
                    app.Dispose();
                }
            }

            grid.Children.Clear();
            for (int row = 0; row < newRows; row++)
            {
                if ((row % 2) != 0) //create row splitter
                {
                    CreateGridSplitterH(grid, newRows, newCols, row, 0);
                }
                else
                {
                    for (int col = 0; col < newCols; col++)
                    {
                        if (row == 0 && (col % 2) != 0)
                        {
                            CreateGridSplitterV(grid, newRows, newCols, row, col);
                        }
                        else if ((col % 2) == 0)
                        {
                            AppChooserUserControl ctrl = new AppChooserUserControl();
                            ctrl.DisplayConfiguration = config;
                            ctrl.Init(row / 2, col / 2);

                            Grid.SetColumn(ctrl, col);
                            Grid.SetRow(ctrl, row);
                            grid.Children.Add(ctrl);
                        }
                    }
                }
            }
        }