Path: blob/master/src/applications/help/controller/PhabricatorHelpKeyboardShortcutController.php
12242 views
<?php12final class PhabricatorHelpKeyboardShortcutController3extends PhabricatorHelpController {45public function shouldAllowPublic() {6return true;7}89public function handleRequest(AphrontRequest $request) {10$viewer = $request->getViewer();1112$keys = $request->getStr('keys');13try {14$keys = phutil_json_decode($keys);15} catch (PhutilJSONParserException $ex) {16return new Aphront400Response();17}1819// There have been at least two users asking for a keyboard shortcut to20// close the dialog, so be explicit that escape works since it isn't21// terribly discoverable.22$keys[] = array(23'keys' => array('Esc'),24'description' => pht('Close any dialog, including this one.'),25'group' => 'global',26);2728$groups = array(29'default' => array(30'name' => pht('Page Shortcuts'),31'icon' => 'fa-keyboard-o',32),33'diff-nav' => array(34'name' => pht('Diff Navigation'),35'icon' => 'fa-arrows',36),37'diff-vis' => array(38'name' => pht('Hiding Content'),39'icon' => 'fa-eye-slash',40),41'inline' => array(42'name' => pht('Editing Inline Comments'),43'icon' => 'fa-pencil',44),45'xactions' => array(46'name' => pht('Comments'),47'icon' => 'fa-comments-o',48),49'global' => array(50'name' => pht('Global Shortcuts'),51'icon' => 'fa-globe',52),53);5455$stroke_map = array(56'left' => "\xE2\x86\x90",57'right' => "\xE2\x86\x92",58'up' => "\xE2\x86\x91",59'down' => "\xE2\x86\x93",60'return' => "\xE2\x8F\x8E",61'tab' => "\xE2\x87\xA5",62'delete' => "\xE2\x8C\xAB",63);6465$row_maps = array();66foreach ($keys as $shortcut) {67$keystrokes = array();68foreach ($shortcut['keys'] as $stroke) {69$stroke = idx($stroke_map, $stroke, $stroke);70$keystrokes[] = phutil_tag(71'span',72array(73'class' => 'keyboard-shortcut-key',74),75$stroke);76}77$keystrokes = phutil_implode_html(' or ', $keystrokes);7879$group_key = idx($shortcut, 'group');80if (!isset($groups[$group_key])) {81$group_key = 'default';82}8384$row = phutil_tag(85'tr',86array(),87array(88phutil_tag('th', array(), $keystrokes),89phutil_tag('td', array(), $shortcut['description']),90));9192$row_maps[$group_key][] = $row;93}9495$tab_group = id(new PHUITabGroupView())96->setVertical(true);9798foreach ($groups as $key => $group) {99$rows = idx($row_maps, $key);100if (!$rows) {101continue;102}103104$icon = id(new PHUIIconView())105->setIcon($group['icon']);106107$tab = id(new PHUITabView())108->setKey($key)109->setName($group['name'])110->setIcon($icon);111112$table = phutil_tag(113'table',114array('class' => 'keyboard-shortcut-help'),115$rows);116117$tab->appendChild($table);118119$tab_group->addTab($tab);120}121122return $this->newDialog()123->setTitle(pht('Keyboard Shortcuts'))124->setWidth(AphrontDialogView::WIDTH_FULL)125->setFlush(true)126->appendChild($tab_group)127->addCancelButton('#', pht('Close'));128129}130131}132133134