mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-06-17 16:11:32 +00:00
Add custom KiCad autocomplete list settings (#1342)
* Add admin editor for KiCad autocomplete lists * Add custom KiCad autocomplete list settings * Ignore the footprints_custom.txt and symbols_custom.txt in git and create them on the fly if needed Otherwise it breaks the update mechanism * Added comments * Include kicad custom files in config backup command --------- Co-authored-by: Jan Böhmer <mail@jan-boehmer.de>
This commit is contained in:
parent
35dcb298e7
commit
58a34e3628
14 changed files with 665 additions and 3 deletions
|
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||
namespace App\Form\Part\EDA;
|
||||
|
||||
use App\Form\Type\StaticFileAutocompleteType;
|
||||
use App\Settings\MiscSettings\KiCadEDASettings;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
|
@ -39,6 +40,13 @@ class KicadFieldAutocompleteType extends AbstractType
|
|||
//Do not use a leading slash here! otherwise it will not work under prefixed reverse proxies
|
||||
public const FOOTPRINT_PATH = 'kicad/footprints.txt';
|
||||
public const SYMBOL_PATH = 'kicad/symbols.txt';
|
||||
public const CUSTOM_FOOTPRINT_PATH = 'kicad/footprints_custom.txt';
|
||||
public const CUSTOM_SYMBOL_PATH = 'kicad/symbols_custom.txt';
|
||||
|
||||
public function __construct(
|
||||
private readonly KiCadEDASettings $kiCadEDASettings,
|
||||
) {
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
|
|
@ -47,8 +55,8 @@ class KicadFieldAutocompleteType extends AbstractType
|
|||
|
||||
$resolver->setDefaults([
|
||||
'file' => fn(Options $options) => match ($options['type']) {
|
||||
self::TYPE_FOOTPRINT => self::FOOTPRINT_PATH,
|
||||
self::TYPE_SYMBOL => self::SYMBOL_PATH,
|
||||
self::TYPE_FOOTPRINT => $this->kiCadEDASettings->useCustomList ? self::CUSTOM_FOOTPRINT_PATH : self::FOOTPRINT_PATH,
|
||||
self::TYPE_SYMBOL => $this->kiCadEDASettings->useCustomList ? self::CUSTOM_SYMBOL_PATH : self::SYMBOL_PATH,
|
||||
default => throw new \InvalidArgumentException('Invalid type'),
|
||||
}
|
||||
]);
|
||||
|
|
@ -58,4 +66,4 @@ class KicadFieldAutocompleteType extends AbstractType
|
|||
{
|
||||
return StaticFileAutocompleteType::class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
103
src/Form/Settings/KicadListEditorType.php
Normal file
103
src/Form/Settings/KicadListEditorType.php
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Settings;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Form type for editing the custom KiCad footprints and symbols lists.
|
||||
*/
|
||||
final class KicadListEditorType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('useCustomList', CheckboxType::class, [
|
||||
'label' => 'settings.misc.kicad_eda.use_custom_list',
|
||||
'help' => 'settings.misc.kicad_eda.use_custom_list.help',
|
||||
'required' => false,
|
||||
])
|
||||
->add('customFootprints', TextareaType::class, [
|
||||
'label' => 'settings.misc.kicad_eda.editor.custom_footprints',
|
||||
'help' => 'settings.misc.kicad_eda.editor.footprints.help',
|
||||
'attr' => [
|
||||
'rows' => 16,
|
||||
'spellcheck' => 'false',
|
||||
'class' => 'font-monospace',
|
||||
],
|
||||
])
|
||||
->add('defaultFootprints', TextareaType::class, [
|
||||
'label' => 'settings.misc.kicad_eda.editor.default_footprints',
|
||||
'help' => 'settings.misc.kicad_eda.editor.default_files_help',
|
||||
'disabled' => true,
|
||||
'mapped' => false,
|
||||
'data' => $options['default_footprints'],
|
||||
'attr' => [
|
||||
'rows' => 16,
|
||||
'spellcheck' => 'false',
|
||||
'class' => 'font-monospace',
|
||||
'readonly' => 'readonly',
|
||||
],
|
||||
])
|
||||
->add('customSymbols', TextareaType::class, [
|
||||
'label' => 'settings.misc.kicad_eda.editor.custom_symbols',
|
||||
'help' => 'settings.misc.kicad_eda.editor.symbols.help',
|
||||
'attr' => [
|
||||
'rows' => 16,
|
||||
'spellcheck' => 'false',
|
||||
'class' => 'font-monospace',
|
||||
],
|
||||
])
|
||||
->add('defaultSymbols', TextareaType::class, [
|
||||
'label' => 'settings.misc.kicad_eda.editor.default_symbols',
|
||||
'help' => 'settings.misc.kicad_eda.editor.default_files_help',
|
||||
'disabled' => true,
|
||||
'mapped' => false,
|
||||
'data' => $options['default_symbols'],
|
||||
'attr' => [
|
||||
'rows' => 16,
|
||||
'spellcheck' => 'false',
|
||||
'class' => 'font-monospace',
|
||||
'readonly' => 'readonly',
|
||||
],
|
||||
])
|
||||
->add('save', SubmitType::class, [
|
||||
'label' => 'save',
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'default_footprints' => '',
|
||||
'default_symbols' => '',
|
||||
]);
|
||||
$resolver->setAllowedTypes('default_footprints', 'string');
|
||||
$resolver->setAllowedTypes('default_symbols', 'string');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue