From ec6ba69666867ed1e1dd2da2ce44447a9db44ac6 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Tue, 30 Jul 2024 19:24:31 +0200 Subject: [PATCH] Add Copy file path button to file header bar in Differential/Diffusion Summary: When looking at a commit/revision, allow to copy the path of a file to the clipboard, so you can quickly open that file in your local code checkout from the command line. Closes T15897 Test Plan: Open a proposed commit in Differential or a merged commit in Diffusion. Click the "Copy file path" button, paste that clipboard content. Change the width of the viewport and see that the button is not rendered when in phone mode. Run `./bin/celerity map` again and no changes. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15897 Differential Revision: https://we.phorge.it/D25757 --- resources/celerity/map.php | 12 ++++---- .../view/DifferentialChangesetDetailView.php | 29 +++++++++++++++++-- .../differential/changeset-view.css | 11 ++++++- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index c6c577aa3a..0911be5e57 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -12,7 +12,7 @@ return array( 'core.pkg.css' => 'ac619266', 'core.pkg.js' => '2eeda9e0', 'dark-console.pkg.js' => '187792c2', - 'differential.pkg.css' => '6d3700f0', + 'differential.pkg.css' => 'fda9518d', 'differential.pkg.js' => '46fcb3af', 'diffusion.pkg.css' => '354279ea', 'diffusion.pkg.js' => '78c9885d', @@ -63,7 +63,7 @@ return array( 'rsrc/css/application/diff/diff-tree-view.css' => 'e2d3e222', 'rsrc/css/application/diff/inline-comment-summary.css' => '81eb368d', 'rsrc/css/application/differential/add-comment.css' => '7e5900d9', - 'rsrc/css/application/differential/changeset-view.css' => '1b0476bc', + 'rsrc/css/application/differential/changeset-view.css' => '979e688c', 'rsrc/css/application/differential/core.css' => '7300a73e', 'rsrc/css/application/differential/phui-inline-comment.css' => '9863a85e', 'rsrc/css/application/differential/revision-comment.css' => '7dbc8d1d', @@ -560,7 +560,7 @@ return array( 'conpherence-transaction-css' => '3a3f5e7e', 'd3' => 'e97b4b78', 'diff-tree-view-css' => 'e2d3e222', - 'differential-changeset-view-css' => '1b0476bc', + 'differential-changeset-view-css' => '979e688c', 'differential-core-view-css' => '7300a73e', 'differential-revision-add-comment-css' => '7e5900d9', 'differential-revision-comment-css' => '7dbc8d1d', @@ -1056,9 +1056,6 @@ return array( 'javelin-util', 'phabricator-keyboard-shortcut-manager', ), - '1b0476bc' => array( - 'phui-inline-comment-view-css', - ), '1b6acc2a' => array( 'javelin-magical-init', 'javelin-util', @@ -1777,6 +1774,9 @@ return array( 'javelin-stratcom', 'phabricator-notification', ), + '979e688c' => array( + 'phui-inline-comment-view-css', + ), '98ef467f' => array( 'javelin-behavior', 'javelin-dom', diff --git a/src/applications/differential/view/DifferentialChangesetDetailView.php b/src/applications/differential/view/DifferentialChangesetDetailView.php index 9d04d081ac..8dfe71f2d3 100644 --- a/src/applications/differential/view/DifferentialChangesetDetailView.php +++ b/src/applications/differential/view/DifferentialChangesetDetailView.php @@ -233,6 +233,22 @@ final class DifferentialChangesetDetailView extends AphrontView { $show_directory_uri = phutil_string_cast($show_directory_uri); } + Javelin::initBehavior('phabricator-clipboard-copy'); + $path_copy_button = id(new PHUIButtonView()) + ->setTag('a') + ->setColor(PHUIButtonView::GREY) + ->setIcon('fa-clipboard') + ->setHref('#') + ->addSigil('clipboard-copy') + ->addSigil('has-tooltip') + ->setMetadata( + array( + 'tip' => pht('Copy file path'), + 'text' => $display_filename, + 'successMessage' => pht('File path copied.'), + 'errorMessage' => pht('Copy of file path failed.'), + )); + return javelin_tag( 'div', array( @@ -278,14 +294,23 @@ final class DifferentialChangesetDetailView extends AphrontView { 'sigil' => 'changeset-header', ), array( - $icon, + javelin_tag( + 'span', + array( + 'class' => 'differential-changeset-path-copy-button', + 'meta' => array( + 'selectID' => $display_filename, + 'once' => true, + ), + ), + $path_copy_button), javelin_tag( 'span', array( 'class' => 'differential-changeset-path-name', 'sigil' => 'changeset-header-path-name', ), - $display_filename), + $display_filename), )), javelin_tag( 'div', diff --git a/webroot/rsrc/css/application/differential/changeset-view.css b/webroot/rsrc/css/application/differential/changeset-view.css index a127d14648..f41bd8a167 100644 --- a/webroot/rsrc/css/application/differential/changeset-view.css +++ b/webroot/rsrc/css/application/differential/changeset-view.css @@ -340,7 +340,7 @@ td.cov-I { .differential-file-icon-header .phui-icon-view { display: inline-block; - margin: 0 6px 2px 0; + margin: 0 0 2px 0; vertical-align: middle; font-size: 14px; } @@ -349,6 +349,15 @@ td.cov-I { display: none; } +.differential-changeset-path-copy-button { + margin-right: 0; + padding-right: 10px; +} + +.device-phone .differential-changeset-path-copy-button { + display: none; +} + .differential-changeset-buttons { float: right; margin-top: 16px;