Skip to content

Commit

Permalink
add events DIFF_RENDER and DIFF_TYPES
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfromearth authored and peterfromearth committed Nov 13, 2021
1 parent 89c597e commit 1c9523b
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions inc/Ui/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Diff extends Ui
protected $text;
protected $showIntro;
protected $difftype;
protected $difftypes;

/**
* Diff Ui constructor
Expand All @@ -27,8 +28,16 @@ class Diff extends Ui
*/
public function __construct($text = '', $showIntro = true, $difftype = null)
{
global $lang;

$this->text = $text;
$this->showIntro = $showIntro;

$this->difftypes = [
'sidebyside' => $lang['diff_side'],
'inline' => $lang['diff_inline']
];
Event::createAndTrigger('DIFF_TYPES', $this->difftypes);

// determine diff view type
if (isset($difftype)) {
Expand All @@ -41,7 +50,8 @@ public function __construct($text = '', $showIntro = true, $difftype = null)
$this->difftype = 'inline';
}
}
if ($this->difftype !== 'inline') $this->difftype = 'sidebyside';
if (!isset($this->difftypes[$this->difftype])) $this->difftype = 'sidebyside';

}

/**
Expand Down Expand Up @@ -167,10 +177,7 @@ public function show()
$form->setHiddenField('rev2[0]', $l_rev);
$form->setHiddenField('rev2[1]', $r_rev);
$form->setHiddenField('do', 'diff');
$options = array(
'sidebyside' => $lang['diff_side'],
'inline' => $lang['diff_inline']
);
$options = $this->difftypes;
$input = $form->addDropdown('difftype', $options, $lang['diff_type'])
->val($this->difftype)->addClass('quickselect');
$input->useInput(false); // inhibit prefillInput() during toHTML() process
Expand Down Expand Up @@ -223,10 +230,24 @@ public function show()
. '<th colspan="2" '. $r_minor .'>'. $r_head .'</th>'
. '</tr>';
}

//diff view
print $this->insertSoftbreaks($diffformatter->format($diff));


$eventData = [
'difftype' => $this->difftype,
'diff' => $diff,
'diffformatter' => $diffformatter,
'l_text' => $l_text,
'r_text' => $r_text,
'l_rev' => $l_rev,
'r_rev' => $r_rev,
];
$diffEvent = new Event('DIFF_RENDER', $eventData);
if($diffEvent->advise_before()) {
//diff view
echo $this->insertSoftbreaks($diffformatter->format($diff));
}
$diffEvent->advise_after();
unset($diffEvent);

print '</table>';
print '</div>';
}
Expand Down

0 comments on commit 1c9523b

Please sign in to comment.