@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 159 lines 3.6 kB view raw
1<?php 2 3final class DifferentialFileTreeEngine 4 extends Phobject { 5 6 private $viewer; 7 private $changesets; 8 private $disabled; 9 private $ownedChangesets; 10 11 public function setViewer($viewer) { 12 $this->viewer = $viewer; 13 return $this; 14 } 15 16 public function getViewer() { 17 return $this->viewer; 18 } 19 20 public function getIsVisible() { 21 return (bool)$this->getSetting($this->getVisibleSettingKey()); 22 } 23 24 public function setDisabled($disabled) { 25 $this->disabled = $disabled; 26 return $this; 27 } 28 29 public function getDisabled() { 30 return $this->disabled; 31 } 32 33 public function setChangesets(array $changesets) { 34 $this->changesets = $changesets; 35 return $this; 36 } 37 38 public function getChangesets() { 39 return $this->changesets; 40 } 41 42 public function newView($content) { 43 if ($this->getDisabled()) { 44 return $content; 45 } 46 47 require_celerity_resource('diff-tree-view-css'); 48 49 $width = $this->getWidth(); 50 $is_visible = $this->getIsVisible(); 51 52 $formation_view = new PHUIFormationView(); 53 54 $flank_view = $formation_view->newFlankColumn() 55 ->setHeaderText(pht('Paths')) 56 ->setIsResizable(true) 57 ->setIsFixed(true) 58 ->setIsVisible($is_visible) 59 ->setIsDesktopOnly(true) 60 ->setWidth($width) 61 ->setMinimumWidth($this->getMinimumWidth()) 62 ->setMaximumWidth($this->getMaximumWidth()); 63 64 $viewer = $this->getViewer(); 65 if ($viewer->isLoggedIn()) { 66 $flank_view 67 ->setExpanderTooltip(pht('Show Paths Panel')) 68 ->setVisibleSettingKey($this->getVisibleSettingKey()) 69 ->setWidthSettingKey($this->getWidthSettingKey()); 70 } 71 72 $head_view = id(new PHUIListView()) 73 ->addMenuItem( 74 id(new PHUIListItemView()) 75 ->setIcon('fa-list') 76 ->setName(pht('Table of Contents')) 77 ->setKeyCommand('t') 78 ->setHref('#')); 79 $flank_view->setHead($head_view); 80 81 $tail_view = new PHUIListView(); 82 83 if ($viewer->isLoggedIn()) { 84 $tail_view->addMenuItem( 85 id(new PHUIListItemView()) 86 ->setIcon('fa-comment-o') 87 ->setName(pht('Add Comment')) 88 ->setKeyCommand('x') 89 ->setHref('#')); 90 } 91 92 $tail_view 93 ->addMenuItem( 94 id(new PHUIListItemView()) 95 ->setIcon('fa-chevron-left') 96 ->setName(pht('Hide Panel')) 97 ->setKeyCommand('f') 98 ->setHref('#')) 99 ->addMenuItem( 100 id(new PHUIListItemView()) 101 ->setIcon('fa-keyboard-o') 102 ->setName(pht('Keyboard Reference')) 103 ->setKeyCommand('?') 104 ->setHref('#')); 105 $flank_view->setTail($tail_view); 106 107 $main_column = $formation_view->newContentColumn() 108 ->appendChild($content); 109 110 return $formation_view; 111 } 112 113 private function getVisibleSettingKey() { 114 return PhabricatorFiletreeVisibleSetting::SETTINGKEY; 115 } 116 117 private function getWidthSettingKey() { 118 return PhabricatorFiletreeWidthSetting::SETTINGKEY; 119 } 120 121 private function getWidth() { 122 $width = (int)$this->getSetting($this->getWidthSettingKey()); 123 124 if (!$width) { 125 $width = $this->getDefaultWidth(); 126 } 127 128 $min = $this->getMinimumWidth(); 129 if ($width < $min) { 130 $width = $min; 131 } 132 133 $max = $this->getMaximumWidth(); 134 if ($width > $max) { 135 $width = $max; 136 } 137 138 return $width; 139 } 140 141 private function getDefaultWidth() { 142 return 240; 143 } 144 145 private function getMinimumWidth() { 146 return 150; 147 } 148 149 private function getMaximumWidth() { 150 return 512; 151 } 152 153 private function getSetting($key) { 154 $viewer = $this->getViewer(); 155 return $viewer->getUserSetting($key); 156 } 157 158 159}