Skip to content

SplitItemBuilder should reference menu styles #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/Builder/CliMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,15 @@ private function processIndividualShortcut(MenuItemInterface $item, callable $ca
public function addSplitItem(\Closure $callback) : self
{
$builder = new SplitItemBuilder($this->menu);
$builder->setCheckboxStyle(clone $this->menu->getCheckboxStyle())
->setRadioStyle(clone $this->menu->getRadioStyle());

if ($this->autoShortcuts) {
$builder->enableAutoShortcuts($this->autoShortcutsRegex);
}

$callback($builder);

if (!$builder->getCheckboxStyle()->hasChangedFromDefaults()) {
$builder->setCheckboxStyle(clone $this->menu->getCheckboxStyle());
}

if (!$builder->getRadioStyle()->hasChangedFromDefaults()) {
$builder->setRadioStyle(clone $this->menu->getRadioStyle());
}

$this->menu->addItem($splitItem = $builder->build());

$this->processSplitItemShortcuts($splitItem);
Expand Down
21 changes: 4 additions & 17 deletions src/Builder/SplitItemBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,10 @@ class SplitItemBuilder
*/
private $autoShortcutsRegex = '/\[(.)\]/';

/**
* @var CheckboxStyle
*/
private $checkboxStyle;

/**
* @var RadioStyle
*/
private $radioStyle;

public function __construct(CliMenu $menu)
{
$this->menu = $menu;
$this->splitItem = new SplitItem();

$this->checkboxStyle = new CheckboxStyle();
$this->radioStyle = new RadioStyle();
}

public function addItem(
Expand Down Expand Up @@ -171,12 +158,12 @@ public function build() : SplitItem

public function getCheckboxStyle() : CheckboxStyle
{
return $this->checkboxStyle;
return $this->menu->getCheckboxStyle();
}

public function setCheckboxStyle(CheckboxStyle $style) : self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop the setters?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry and the modify* methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SplitItemBuilder::setCheckboxStyle() is called from CliMenuBuilder::addSplitItem() so the split item can inherit the parent styles.

{
$this->checkboxStyle = $style;
$this->menu->setCheckboxStyle($style);

return $this;
}
Expand All @@ -190,12 +177,12 @@ public function modifyCheckboxStyle(callable $itemCallable) : self

public function getRadioStyle() : RadioStyle
{
return $this->radioStyle;
return $this->menu->getRadioStyle();
}

public function setRadioStyle(RadioStyle $style) : self
{
$this->radioStyle = $style;
$this->menu->setRadioStyle($style);

return $this;
}
Expand Down