@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Split Diffusion "view" preference into blame and color preferences

Summary:
We have this silly "view" preference which has a variety of silly values: "plain", "plainblame", "highlighted", and "blame", and then also "raw", which is magical. This is really just two flags: color on/off, and blame on/off (plus a separate mode for raw).

Express the code in terms of the flags and, e.g., get rid of the state transition tables we had before.

Test Plan: Viewed code in all four modes.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7046

+127 -116
+1 -1
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 82 82 id(new PhabricatorActionView()) 83 83 ->setName(pht('View History')) 84 84 ->setHref($history_uri) 85 - ->setIcon('perflab')); 85 + ->setIcon('history')); 86 86 87 87 $behind_head = $drequest->getRawCommit(); 88 88 $head_uri = $drequest->generateURI(
+124 -114
src/applications/diffusion/controller/DiffusionBrowseFileController.php
··· 18 18 19 19 $path = $drequest->getPath(); 20 20 21 - $selected = $request->getStr('view'); 22 21 $preferences = $request->getUser()->loadPreferences(); 23 - if (!$selected) { 24 - $selected = $preferences->getPreference( 25 - PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW, 26 - 'highlighted'); 27 - } else if ($request->isFormPost() && $selected != 'raw') { 22 + 23 + $show_blame = $request->getBool( 24 + 'blame', 25 + $preferences->getPreference( 26 + PhabricatorUserPreferences::PREFERENCE_DIFFUSION_BLAME, 27 + false)); 28 + $show_color = $request->getBool( 29 + 'color', 30 + $preferences->getPreference( 31 + PhabricatorUserPreferences::PREFERENCE_DIFFUSION_COLOR, 32 + true)); 33 + 34 + $view = $request->getStr('view'); 35 + if ($request->isFormPost() && $view != 'raw') { 36 + $preferences->setPreference( 37 + PhabricatorUserPreferences::PREFERENCE_DIFFUSION_BLAME, 38 + $show_blame); 28 39 $preferences->setPreference( 29 - PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW, 30 - $selected); 40 + PhabricatorUserPreferences::PREFERENCE_DIFFUSION_COLOR, 41 + $show_color); 31 42 $preferences->save(); 32 43 33 - return id(new AphrontRedirectResponse()) 34 - ->setURI($request->getRequestURI()->alter('view', $selected)); 35 - } 44 + $uri = $request->getRequestURI() 45 + ->alter('blame', null) 46 + ->alter('color', null); 36 47 37 - $needs_blame = ($selected == 'plainblame'); 38 - if ($selected == 'blame' && $request->isAjax()) { 39 - $needs_blame = true; 48 + return id(new AphrontRedirectResponse())->setURI($uri); 40 49 } 41 50 51 + // We need the blame information if blame is on and we're building plain 52 + // text, or blame is on and this is an Ajax request. If blame is on and 53 + // this is a colorized request, we don't show blame at first (we ajax it 54 + // in afterward) so we don't need to query for it. 55 + $needs_blame = ($show_blame && !$show_color) || 56 + ($show_blame && $request->isAjax()); 57 + 42 58 $file_content = DiffusionFileContent::newFromConduit( 43 59 $this->callConduitWithDiffusionRequest( 44 60 'diffusion.filecontentquery', ··· 49 65 ))); 50 66 $data = $file_content->getCorpus(); 51 67 52 - if ($selected === 'raw') { 68 + if ($view === 'raw') { 53 69 return $this->buildRawResponse($path, $data); 54 70 } 55 71 ··· 57 73 58 74 // Build the content of the file. 59 75 $corpus = $this->buildCorpus( 60 - $selected, 76 + $show_blame, 77 + $show_color, 61 78 $file_content, 62 79 $needs_blame, 63 80 $drequest, ··· 75 92 76 93 $content[] = $this->buildHeaderView($drequest); 77 94 $view = $this->buildActionView($drequest); 78 - $content[] = $this->enrichActionView($view, $drequest, $selected); 95 + $content[] = $this->enrichActionView( 96 + $view, 97 + $drequest, 98 + $show_blame, 99 + $show_color); 79 100 $content[] = $this->buildPropertyView($drequest); 80 101 81 102 $follow = $request->getStr('follow'); ··· 161 182 } 162 183 163 184 private function buildCorpus( 164 - $selected, 185 + $show_blame, 186 + $show_color, 165 187 DiffusionFileContent $file_content, 166 188 $needs_blame, 167 189 DiffusionRequest $drequest, ··· 181 203 } 182 204 } 183 205 184 - switch ($selected) { 185 - case 'plain': 186 - $style = 187 - "margin: 1em 2em; width: 90%; height: 80em; font-family: monospace"; 206 + if (!$show_color) { 207 + $style = 208 + "margin: 1em 2em; width: 90%; height: 80em; font-family: monospace"; 209 + if (!$show_blame) { 188 210 $corpus = phutil_tag( 189 211 'textarea', 190 212 array( 191 213 'style' => $style, 192 214 ), 193 215 $file_content->getCorpus()); 194 - 195 - break; 196 - 197 - case 'plainblame': 198 - $style = 199 - "margin: 1em 2em; width: 90%; height: 80em; font-family: monospace"; 216 + } else { 200 217 $text_list = $file_content->getTextList(); 201 218 $rev_list = $file_content->getRevList(); 202 219 $blame_dict = $file_content->getBlameDict(); ··· 215 232 'style' => $style, 216 233 ), 217 234 implode("\n", $rows)); 218 - break; 235 + } 236 + } else { 237 + require_celerity_resource('syntax-highlighting-css'); 238 + $text_list = $file_content->getTextList(); 239 + $rev_list = $file_content->getRevList(); 240 + $blame_dict = $file_content->getBlameDict(); 219 241 220 - case 'highlighted': 221 - case 'blame': 222 - default: 223 - require_celerity_resource('syntax-highlighting-css'); 224 - $text_list = $file_content->getTextList(); 225 - $rev_list = $file_content->getRevList(); 226 - $blame_dict = $file_content->getBlameDict(); 242 + $text_list = implode("\n", $text_list); 243 + $text_list = PhabricatorSyntaxHighlighter::highlightWithFilename( 244 + $path, 245 + $text_list); 246 + $text_list = explode("\n", $text_list); 227 247 228 - $text_list = implode("\n", $text_list); 229 - $text_list = PhabricatorSyntaxHighlighter::highlightWithFilename( 230 - $path, 231 - $text_list); 232 - $text_list = explode("\n", $text_list); 248 + $rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict, 249 + $needs_blame, $drequest, $show_blame, $show_color); 233 250 234 - $rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict, 235 - $needs_blame, $drequest, $selected); 236 - 237 - $corpus_table = javelin_tag( 238 - 'table', 239 - array( 240 - 'class' => "diffusion-source remarkup-code PhabricatorMonospaced", 241 - 'sigil' => 'phabricator-source', 242 - ), 243 - $rows); 251 + $corpus_table = javelin_tag( 252 + 'table', 253 + array( 254 + 'class' => "diffusion-source remarkup-code PhabricatorMonospaced", 255 + 'sigil' => 'phabricator-source', 256 + ), 257 + $rows); 244 258 245 - if ($this->getRequest()->isAjax()) { 246 - return $corpus_table; 247 - } 259 + if ($this->getRequest()->isAjax()) { 260 + return $corpus_table; 261 + } 248 262 249 - $id = celerity_generate_unique_node_id(); 263 + $id = celerity_generate_unique_node_id(); 250 264 251 - $projects = $drequest->loadArcanistProjects(); 252 - $langs = array(); 253 - foreach ($projects as $project) { 254 - $ls = $project->getSymbolIndexLanguages(); 255 - if (!$ls) { 256 - continue; 257 - } 258 - $dep_projects = $project->getSymbolIndexProjects(); 259 - $dep_projects[] = $project->getPHID(); 260 - foreach ($ls as $lang) { 261 - if (!isset($langs[$lang])) { 262 - $langs[$lang] = array(); 263 - } 264 - $langs[$lang] += $dep_projects + array($project); 265 + $projects = $drequest->loadArcanistProjects(); 266 + $langs = array(); 267 + foreach ($projects as $project) { 268 + $ls = $project->getSymbolIndexLanguages(); 269 + if (!$ls) { 270 + continue; 271 + } 272 + $dep_projects = $project->getSymbolIndexProjects(); 273 + $dep_projects[] = $project->getPHID(); 274 + foreach ($ls as $lang) { 275 + if (!isset($langs[$lang])) { 276 + $langs[$lang] = array(); 265 277 } 278 + $langs[$lang] += $dep_projects + array($project); 266 279 } 267 - 268 - $lang = last(explode('.', $drequest->getPath())); 280 + } 269 281 270 - if (isset($langs[$lang])) { 271 - Javelin::initBehavior( 272 - 'repository-crossreference', 273 - array( 274 - 'container' => $id, 275 - 'lang' => $lang, 276 - 'projects' => $langs[$lang], 277 - )); 278 - } 282 + $lang = last(explode('.', $drequest->getPath())); 279 283 280 - $corpus = phutil_tag( 281 - 'div', 284 + if (isset($langs[$lang])) { 285 + Javelin::initBehavior( 286 + 'repository-crossreference', 282 287 array( 283 - 'style' => 'padding: 0 2em;', 284 - 'id' => $id, 285 - ), 286 - $corpus_table); 288 + 'container' => $id, 289 + 'lang' => $lang, 290 + 'projects' => $langs[$lang], 291 + )); 292 + } 287 293 288 - Javelin::initBehavior('load-blame', array('id' => $id)); 294 + $corpus = phutil_tag( 295 + 'div', 296 + array( 297 + 'style' => 'padding: 0 2em;', 298 + 'id' => $id, 299 + ), 300 + $corpus_table); 289 301 290 - break; 302 + Javelin::initBehavior('load-blame', array('id' => $id)); 291 303 } 292 304 293 305 return $corpus; ··· 296 308 private function enrichActionView( 297 309 PhabricatorActionListView $view, 298 310 DiffusionRequest $drequest, 299 - $selected) { 311 + $show_blame, 312 + $show_color) { 300 313 301 314 $viewer = $this->getRequest()->getUser(); 302 315 $base_uri = $this->getRequest()->getRequestURI(); 303 316 304 - $toggle_blame = array( 305 - 'highlighted' => 'blame', 306 - 'blame' => 'highlighted', 307 - 'plain' => 'plainblame', 308 - 'plainblame' => 'plain', 309 - 'raw' => 'raw', // not a real case. 310 - ); 317 + $view->addAction( 318 + id(new PhabricatorActionView()) 319 + ->setName(pht('Show Last Change')) 320 + ->setHref( 321 + $drequest->generateURI( 322 + array( 323 + 'action' => 'change', 324 + ))) 325 + ->setIcon('new')); 311 326 312 - $toggle_highlight = array( 313 - 'highlighted' => 'plain', 314 - 'blame' => 'plainblame', 315 - 'plain' => 'highlighted', 316 - 'plainblame' => 'blame', 317 - 'raw' => 'raw', // not a real case. 318 - ); 319 - 320 - $blame_on = ($selected == 'blame' || $selected == 'plainblame'); 321 - if ($blame_on) { 327 + if ($show_blame) { 322 328 $blame_text = pht('Disable Blame'); 323 329 $blame_icon = 'blame-grey'; 330 + $blame_value = 0; 324 331 } else { 325 332 $blame_text = pht('Enable Blame'); 326 333 $blame_icon = 'blame'; 334 + $blame_value = 1; 327 335 } 328 336 329 337 $view->addAction( 330 338 id(new PhabricatorActionView()) 331 339 ->setName($blame_text) 332 - ->setHref($base_uri->alter('view', $toggle_blame[$selected])) 340 + ->setHref($base_uri->alter('blame', $blame_value)) 333 341 ->setIcon($blame_icon) 334 342 ->setUser($viewer) 335 343 ->setRenderAsForm(true)); 336 344 337 345 338 - $highlight_on = ($selected == 'blame' || $selected == 'highlighted'); 339 - if ($highlight_on) { 346 + if ($show_color) { 340 347 $highlight_text = pht('Disable Highlighting'); 341 348 $highlight_icon = 'highlight-grey'; 349 + $highlight_value = 0; 342 350 } else { 343 351 $highlight_text = pht('Enable Highlighting'); 344 352 $highlight_icon = 'highlight'; 353 + $highlight_value = 1; 345 354 } 346 355 347 356 $view->addAction( 348 357 id(new PhabricatorActionView()) 349 358 ->setName($highlight_text) 350 - ->setHref($base_uri->alter('view', $toggle_highlight[$selected])) 359 + ->setHref($base_uri->alter('color', $highlight_value)) 351 360 ->setIcon($highlight_icon) 352 361 ->setUser($viewer) 353 362 ->setRenderAsForm(true)); ··· 417 426 array $blame_dict, 418 427 $needs_blame, 419 428 DiffusionRequest $drequest, 420 - $selected) { 429 + $show_blame, 430 + $show_color) { 421 431 422 432 $handles = array(); 423 433 if ($blame_dict) { ··· 464 474 'data' => $line, 465 475 ); 466 476 467 - if ($selected == 'blame') { 477 + if ($show_blame) { 468 478 // If the line's rev is same as the line above, show empty content 469 479 // with same color; otherwise generate blame info. The newer a change 470 480 // is, the more saturated the color. ··· 574 584 575 585 $rows = $this->renderInlines( 576 586 idx($inlines, 0, array()), 577 - ($selected == 'blame'), 587 + ($show_blame), 578 588 $engine); 579 589 580 590 foreach ($display as $line) { ··· 764 774 765 775 $rows = array_merge($rows, $this->renderInlines( 766 776 idx($inlines, $line['line'], array()), 767 - ($selected == 'blame'), 777 + ($show_blame), 768 778 $engine)); 769 779 } 770 780
+2 -1
src/applications/settings/storage/PhabricatorUserPreferences.php
··· 18 18 const PREFERENCE_SEARCHBAR_JUMP = 'searchbar-jump'; 19 19 const PREFERENCE_SEARCH_SHORTCUT = 'search-shortcut'; 20 20 21 - const PREFERENCE_DIFFUSION_VIEW = 'diffusion-view'; 21 + const PREFERENCE_DIFFUSION_BLAME = 'diffusion-blame'; 22 + const PREFERENCE_DIFFUSION_COLOR = 'diffusion-color'; 22 23 23 24 const PREFERENCE_NAV_COLLAPSED = 'nav-collapsed'; 24 25 const PREFERENCE_NAV_WIDTH = 'nav-width';