public DeviceLayoutViewModel(LayoutEditModel model, DeviceLayoutEditorViewModel editorViewModel, IWindowManager windowManager)
        {
            _windowManager = windowManager;

            Model           = model;
            DeviceLayout    = model.DeviceLayout;
            EditorViewModel = editorViewModel;
        }
Exemplo n.º 2
0
        public DeviceLayoutEditorViewModel(LayoutEditModel model, ShellViewModel shellViewModel, IWindowManager windowManager)
        {
            _shellViewModel = shellViewModel;
            _windowManager  = windowManager;

            Model        = model;
            DeviceLayout = model.DeviceLayout;
            DeviceLayout.CustomData ??= new LayoutCustomDeviceData();
            DeviceLayoutViewModel = new DeviceLayoutViewModel(Model, this, windowManager);
            DeviceLayoutViewModel.ConductWith(this);

            LogicalLayouts = new ObservableCollection <string> {
                "Empty"
            };
            foreach (var led in DeviceLayout.Leds)
            {
                if (led.CustomData == null)
                {
                    continue;
                }

                var customLedData = (LayoutCustomLedData)led.CustomData;
                foreach (var ledDataLogicalLayout in customLedData.LogicalLayouts)
                {
                    if (ledDataLogicalLayout.Name != null && !LogicalLayouts.Contains(ledDataLogicalLayout.Name))
                    {
                        LogicalLayouts.Add(ledDataLogicalLayout.Name);
                    }
                }
            }

            SelectedLogicalLayout = LogicalLayouts.FirstOrDefault();

            // Lame but works
            if (Model.FilePath.EndsWith("ABNT.xml"))
            {
                Model.PhysicalLayout = KeyboardLayoutType.ABNT;
            }
            else if (Model.FilePath.EndsWith("ANSI.xml"))
            {
                Model.PhysicalLayout = KeyboardLayoutType.ANSI;
            }
            else if (Model.FilePath.EndsWith("ISO.xml"))
            {
                Model.PhysicalLayout = KeyboardLayoutType.ISO;
            }
            else if (Model.FilePath.EndsWith("JIS.xml"))
            {
                Model.PhysicalLayout = KeyboardLayoutType.JIS;
            }
            else if (Model.FilePath.EndsWith("KS.xml"))
            {
                Model.PhysicalLayout = KeyboardLayoutType.KS;
            }

            UpdateDeviceImage();
        }
        public void CreateNew()
        {
            var model = new LayoutEditModel();

            model.FilePath     = Path.Combine(Path.GetTempPath(), "New layout.xml");
            model.DeviceLayout = new DeviceLayout {
                CustomData = new LayoutCustomDeviceData()
            };

            _shellViewModel.Start(model);
        }
        public LedViewModel(LayoutEditModel model, DeviceLayoutViewModel layoutViewModel, IWindowManager windowManager, LedLayout ledLayout)
        {
            _layoutViewModel = layoutViewModel;
            _windowManager   = windowManager;

            Model           = model;
            LedLayout       = ledLayout;
            AvailableLedIds = new BindableCollection <string>();
            LedCursor       = Cursors.Hand;

            ApplyLogicalLayout();
        }
Exemplo n.º 5
0
        public LedViewModel(LayoutEditModel model, DeviceLayoutViewModel layoutViewModel, IWindowManager windowManager, LedLayout ledLayout)
        {
            _layoutViewModel = layoutViewModel;
            _windowManager   = windowManager;

            Model           = model;
            LedLayout       = ledLayout;
            AvailableLedIds = new BindableCollection <string>();
            LedCursor       = Cursors.Hand;

            this.PropertyChanged           += OnPropertyChanged;
            FileChangedWatcher.FileChanged += FileChangedWatcherOnFileChanged;

            UpdateImageSource();
        }
        public async Task <IActionResult> Put([FromBody] LayoutEditModel model)
        {
            var mapping = new Func <Layout, Task <Layout> >(async(entity) =>
            {
                entity.Name        = model.Name;
                entity.Description = model.Description;
                if (!string.IsNullOrWhiteSpace(model.IconAssetId))
                {
                    entity.Icon = model.IconAssetId;
                }
                entity.CategoryId = model.CategoryId;
                entity.Data       = model.Data;
                entity.Color      = model.Color;
                return(await Task.FromResult(entity));
            });

            return(await _PutRequest(model.Id, mapping));
        }
Exemplo n.º 7
0
        public void LoadFromXml()
        {
            var model = new LayoutEditModel();

            _windowManager.ShowMessageBox("First, select the base folder of the layout. All other paths will be relative to this folder.");

            // Select a base path
            var folderDialog = new CommonOpenFileDialog {
                IsFolderPicker = true
            };

            if (folderDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                model.BasePath = folderDialog.FileName;
            }
            else
            {
                return;
            }

            _windowManager.ShowMessageBox("Now select the layout file itself, it should be relative to the base folder.");

            // Select a XML file
            var fileDialog = new CommonOpenFileDialog {
                InitialDirectory = model.BasePath, Filters = { new CommonFileDialogFilter("Layout Files", "*.xml") }
            };

            if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                model.DeviceLayout       = DeviceLayout.Load(fileDialog.FileName);
                model.DeviceLayoutSource = fileDialog.FileName;
            }
            else
            {
                return;
            }

            _shellViewModel.Start(model);
        }
Exemplo n.º 8
0
        public DeviceLayoutEditorViewModel(LayoutEditModel model, ShellViewModel shellViewModel, IWindowManager windowManager)
        {
            _shellViewModel = shellViewModel;
            _windowManager  = windowManager;

            Model                 = model;
            DeviceLayout          = model.DeviceLayout;
            DeviceLayoutViewModel = new DeviceLayoutViewModel(Model, this, windowManager);

            ImageLayouts = new ObservableCollection <string>();
            foreach (var ledImage in DeviceLayout.LedImageLayouts)
            {
                if (!ImageLayouts.Contains(ledImage.Layout))
                {
                    ImageLayouts.Add(ledImage.Layout);
                }
            }

            SelectedImageLayout = ImageLayouts.FirstOrDefault();

            ImageBasePath = DeviceLayout.ImageBasePath;
            DeviceImage   = DeviceLayout.DeviceImage;
        }
        public DeviceLayoutViewModel(LayoutEditModel model, DeviceLayoutEditorViewModel editorViewModel, IWindowManager windowManager)
        {
            _windowManager = windowManager;

            Model           = model;
            DeviceLayout    = model.DeviceLayout;
            EditorViewModel = editorViewModel;
            LedViewModels   = new BindableCollection <LedViewModel>(DeviceLayout.Leds.Select(l => new LedViewModel(Model, this, _windowManager, l)));

            UpdateLeds();

            PropertyChanged += DeviceLayoutViewModelPropertyChanged;
            EditorViewModel.PropertyChanged += EditorViewModelOnPropertyChanged;


            var activeWindow = Application.Current.Windows.OfType <Window>().SingleOrDefault(x => x.IsActive);

            if (activeWindow != null)
            {
                activeWindow.KeyDown += KeyUpDown;
                activeWindow.KeyUp   += KeyUpDown;
            }
        }
Exemplo n.º 10
0
        public void CreateNew()
        {
            var model = new LayoutEditModel();

            _windowManager.ShowMessageBox("Select the base folder of the layout. All other paths will be relative to this folder.");

            // Select a base path
            var folderDialog = new CommonOpenFileDialog {
                IsFolderPicker = true
            };

            if (folderDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                model.BasePath = folderDialog.FileName;
            }
            else
            {
                return;
            }

            model.DeviceLayout = new DeviceLayout();

            _shellViewModel.Start(model);
        }
        public void LoadFromXml()
        {
            var model = new LayoutEditModel();

            // Select a XML file
            VistaOpenFileDialog fileDialog = new();

            fileDialog.Filter = "Layout files (*.xml)|*.xml";
            if (fileDialog.ShowDialog() == false)
            {
                return;
            }

            model.DeviceLayout = DeviceLayout.Load(fileDialog.FileName, typeof(LayoutCustomDeviceData), typeof(LayoutCustomLedData));
            model.FilePath     = fileDialog.FileName;

            if (model.DeviceLayout == null)
            {
                _windowManager.ShowMessageBox("Failed to load layout.", "", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            _shellViewModel.Start(model);
        }
Exemplo n.º 12
0
 public void Start(LayoutEditModel model)
 {
     ActiveItem = new DeviceLayoutEditorViewModel(model, this, _windowManager);
 }