Skip to content

Commit

Permalink
feat: add vscodeLink method
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Mar 30, 2023
1 parent 10ec384 commit aa0bdd8
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,41 +783,33 @@ public function ___getIcons($page, $opt)
}

if ($this->wire->user->isSuperuser()) {
$tracy = $this->wire->config->tracy;
if (is_array($tracy) and array_key_exists('localRootPath', $tracy))
$root = $tracy['localRootPath'];
else $root = $this->wire->config->paths->root;
$link = str_replace($this->wire->config->paths->root, $root, $opt->path);

// view file edit link
$icons[] = (object)[
'icon' => 'code',
'label' => $opt->path,
'href' => "vscode://file/$link",
'tooltip' => $link,
'href' => $this->vscodeLink($opt->path),
'tooltip' => $opt->path,
];

$ext = pathinfo($link, PATHINFO_EXTENSION);
$ext = pathinfo($opt->path, PATHINFO_EXTENSION);

// php file edit link
$php = substr($opt->path, 0, strlen($ext) * -1 - 1) . ".php";
if (is_file($php)) {
$php = str_replace($this->wire->config->paths->root, $root, $php);
$icons[] = (object)[
'icon' => 'php',
'label' => $php,
'href' => "vscode://file/$php",
'href' => $this->vscodeLink($php),
'tooltip' => $php,
];
}
// style edit link
$less = substr($opt->path, 0, strlen($ext) * -1 - 1) . ".less";
if (is_file($less)) {
$less = str_replace($this->wire->config->paths->root, $root, $less);
$icons[] = (object)[
'icon' => 'eye',
'label' => $less,
'href' => "vscode://file/$less",
'href' => $this->vscodeLink($less),
'tooltip' => $less,
];
}
Expand Down Expand Up @@ -1808,6 +1800,16 @@ public function svg($filename, $replacements = [])
return $this->html($svg);
}

public function vscodeLink($path)
{
$tracy = $this->wire->config->tracy;
if (is_array($tracy) and array_key_exists('localRootPath', $tracy))
$root = $tracy['localRootPath'];
else $root = $this->wire->config->paths->root;
$link = str_replace($this->wire->config->paths->root, $root, $path);
return "vscode://file/$link";
}

/** translation support in LATTE files */

public function _($str)
Expand Down

0 comments on commit aa0bdd8

Please sign in to comment.