From 52c68e12619b8d44364ecd84fe1fabd9cb1d19af Mon Sep 17 00:00:00 2001 From: Aviv Eyal Date: Wed, 3 Oct 2012 10:58:56 -0700 Subject: [PATCH] File view: Replace drop-down form with buttons for view options Summary: It always bothered me that adding/removing blame view takes two clicks. Showing it like this saves a click for almost all transformations, and I think it feels nicer too. I'm open to adding a user-setting for this (This form or the drop-down), but figured I'd ask first. Test Plan: Use buttons to switch modes - make sure text on button matches action. Repeate with lines highlighted. Reviewers: epriestley, vrana Reviewed By: epriestley CC: jungejason, Two9A, aran, Korvin Differential Revision: https://secure.phabricator.com/D3499 --- src/__celerity_resource_map__.php | 52 ++++---- .../DiffusionBrowseFileController.php | 113 ++++++++++++------ webroot/rsrc/css/aphront/crumbs-view.css | 4 + 3 files changed, 105 insertions(+), 64 deletions(-) diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index ed79b7158b..688a54ff2a 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -512,7 +512,7 @@ celerity_register_resource_map(array( ), 'aphront-crumbs-view-css' => array( - 'uri' => '/res/9009e6bd/rsrc/css/aphront/crumbs-view.css', + 'uri' => '/res/699be12a/rsrc/css/aphront/crumbs-view.css', 'type' => 'css', 'requires' => array( @@ -3003,7 +3003,7 @@ celerity_register_resource_map(array( ), array( 'packages' => array( - '19bef443' => + '782b1e3f' => array( 'name' => 'core.pkg.css', 'symbols' => @@ -3032,7 +3032,7 @@ celerity_register_resource_map(array( 21 => 'phabricator-flag-css', 22 => 'aphront-error-view-css', ), - 'uri' => '/res/pkg/19bef443/core.pkg.css', + 'uri' => '/res/pkg/782b1e3f/core.pkg.css', 'type' => 'css', ), '3a455e4f' => @@ -3199,20 +3199,20 @@ celerity_register_resource_map(array( 'reverse' => array( 'aphront-attached-file-view-css' => '7839ae2d', - 'aphront-crumbs-view-css' => '19bef443', - 'aphront-dialog-view-css' => '19bef443', - 'aphront-error-view-css' => '19bef443', - 'aphront-form-view-css' => '19bef443', + 'aphront-crumbs-view-css' => '782b1e3f', + 'aphront-dialog-view-css' => '782b1e3f', + 'aphront-error-view-css' => '782b1e3f', + 'aphront-form-view-css' => '782b1e3f', 'aphront-headsup-action-list-view-css' => '2ba14b3d', - 'aphront-headsup-view-css' => '19bef443', - 'aphront-list-filter-view-css' => '19bef443', - 'aphront-pager-view-css' => '19bef443', - 'aphront-panel-view-css' => '19bef443', - 'aphront-side-nav-view-css' => '19bef443', - 'aphront-table-view-css' => '19bef443', - 'aphront-tokenizer-control-css' => '19bef443', - 'aphront-tooltip-css' => '19bef443', - 'aphront-typeahead-control-css' => '19bef443', + 'aphront-headsup-view-css' => '782b1e3f', + 'aphront-list-filter-view-css' => '782b1e3f', + 'aphront-pager-view-css' => '782b1e3f', + 'aphront-panel-view-css' => '782b1e3f', + 'aphront-side-nav-view-css' => '782b1e3f', + 'aphront-table-view-css' => '782b1e3f', + 'aphront-tokenizer-control-css' => '782b1e3f', + 'aphront-tooltip-css' => '782b1e3f', + 'aphront-typeahead-control-css' => '782b1e3f', 'differential-changeset-view-css' => '2ba14b3d', 'differential-core-view-css' => '2ba14b3d', 'differential-inline-comment-editor' => 'd05e3c0f', @@ -3278,15 +3278,15 @@ celerity_register_resource_map(array( 'javelin-workflow' => '3a455e4f', 'maniphest-task-summary-css' => '7839ae2d', 'maniphest-transaction-detail-css' => '7839ae2d', - 'phabricator-app-buttons-css' => '19bef443', + 'phabricator-app-buttons-css' => '782b1e3f', 'phabricator-content-source-view-css' => '2ba14b3d', - 'phabricator-core-buttons-css' => '19bef443', - 'phabricator-core-css' => '19bef443', - 'phabricator-directory-css' => '19bef443', + 'phabricator-core-buttons-css' => '782b1e3f', + 'phabricator-core-css' => '782b1e3f', + 'phabricator-directory-css' => '782b1e3f', 'phabricator-drag-and-drop-file-upload' => 'd05e3c0f', 'phabricator-dropdown-menu' => '3a455e4f', - 'phabricator-flag-css' => '19bef443', - 'phabricator-jump-nav' => '19bef443', + 'phabricator-flag-css' => '782b1e3f', + 'phabricator-jump-nav' => '782b1e3f', 'phabricator-keyboard-shortcut' => '3a455e4f', 'phabricator-keyboard-shortcut-manager' => '3a455e4f', 'phabricator-menu-item' => '3a455e4f', @@ -3294,11 +3294,11 @@ celerity_register_resource_map(array( 'phabricator-paste-file-upload' => '3a455e4f', 'phabricator-prefab' => '3a455e4f', 'phabricator-project-tag-css' => '7839ae2d', - 'phabricator-remarkup-css' => '19bef443', + 'phabricator-remarkup-css' => '782b1e3f', 'phabricator-shaped-request' => 'd05e3c0f', - 'phabricator-standard-page-view' => '19bef443', + 'phabricator-standard-page-view' => '782b1e3f', 'phabricator-tooltip' => '3a455e4f', - 'phabricator-transaction-view-css' => '19bef443', - 'syntax-highlighting-css' => '19bef443', + 'phabricator-transaction-view-css' => '782b1e3f', + 'syntax-highlighting-css' => '782b1e3f', ), )); diff --git a/src/applications/diffusion/controller/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/DiffusionBrowseFileController.php index 12ddf2e6ca..c7b8000386 100644 --- a/src/applications/diffusion/controller/DiffusionBrowseFileController.php +++ b/src/applications/diffusion/controller/DiffusionBrowseFileController.php @@ -267,41 +267,80 @@ final class DiffusionBrowseFileController extends DiffusionController { } private function renderViewSelectPanel($selected) { + $toggle_blame = array( + 'highlighted' => 'blame', + 'blame' => 'highlighted', + 'plain' => 'plainblame', + 'plainblame' => 'plain', + 'raw' => 'raw', // not a real case. + ); + $toggle_highlight = array( + 'highlighted' => 'plain', + 'blame' => 'plainblame', + 'plain' => 'highlighted', + 'plainblame' => 'blame', + 'raw' => 'raw', // not a real case. + ); - $request = $this->getRequest(); + $user = $this->getRequest()->getUser(); - $select = AphrontFormSelectControl::renderSelectTag( - $selected, - array( - 'highlighted' => 'View as Highlighted Text', - 'blame' => 'View as Highlighted Text with Blame', - 'plain' => 'View as Plain Text', - 'plainblame' => 'View as Plain Text with Blame', - 'raw' => 'View as raw document', - ), - array( - 'name' => 'view', - )); + $blame_on = ($selected == 'blame' || $selected == 'plainblame'); + if ($blame_on) { + $blame_text = pht('Disable Blame'); + } else { + $blame_text = pht('Enable Blame'); + } - $view_select_panel = new AphrontPanelView(); - $view_select_form = phabricator_render_form( - $request->getUser(), - array( - 'action' => $request->getRequestURI()->alter('view', null), - 'method' => 'post', - 'class' => 'diffusion-browse-type-form', - ), - $select. - ' '. - $this->renderEditButton()); + $blame_button = $this->createViewAction( + $blame_text, + $toggle_blame[$selected], + $user); - $view_select_panel->appendChild($view_select_form); - $view_select_panel->appendChild('
'); - return $view_select_panel; + $highlight_on = ($selected == 'blame' || $selected == 'highlighted'); + if ($highlight_on) { + $highlight_text = pht('Disable Highlighting'); + } else { + $highlight_text = pht('Enable Highlighting'); + } + $highlight_button = $this->createViewAction( + $highlight_text, + $toggle_highlight[$selected], + $user); + + + $raw_button = $this->createViewAction( + pht('View Raw File'), + 'raw', + $user, + 'file'); + + $edit_button = $this->createEditAction(); + + return id(new PhabricatorActionListView()) + ->setUser($user) + ->addAction($blame_button) + ->addAction($highlight_button) + ->addAction($raw_button) + ->addAction($edit_button); } - private function renderEditButton() { + private function createViewAction( + $localized_text, + $view_mode, + $user, + $icon = null) { + + $base_uri = $this->getRequest()->getRequestURI(); + return id(new PhabricatorActionView()) + ->setName($localized_text) + ->setIcon($icon) + ->setUser($user) + ->setRenderAsForm(true) + ->setHref($base_uri->alter('view', $view_mode)); + } + + private function createEditAction() { $request = $this->getRequest(); $user = $request->getUser(); @@ -313,17 +352,15 @@ final class DiffusionBrowseFileController extends DiffusionController { $callsign = $repository->getCallsign(); $editor_link = $user->loadEditorLink($path, $line, $callsign); - if (!$editor_link) { - return null; - } - return phutil_render_tag( - 'a', - array( - 'href' => $editor_link, - 'class' => 'button', - ), - 'Edit'); + $action = id(new PhabricatorActionView()) + ->setName(pht('Open in Editor')) + ->setIcon('edit'); + + $action->setHref($editor_link); + $action->setDisabled(!$editor_link); + + return $action; } private function buildDisplayRows( diff --git a/webroot/rsrc/css/aphront/crumbs-view.css b/webroot/rsrc/css/aphront/crumbs-view.css index 34c5b0d398..af6076e5b5 100644 --- a/webroot/rsrc/css/aphront/crumbs-view.css +++ b/webroot/rsrc/css/aphront/crumbs-view.css @@ -16,3 +16,7 @@ padding: 0 .35em; color: #888888; } + +.device-desktop .aphront-crumbs-view { + width: 66%; +}