Converted Paste language selection to a typeahead
Summary: Fixes T11532. The language selection for pastes is now a typeahead that is backed by `pygments.dropdown-choices`. There is still a bit of weirdness around making "auto-detection" the default state. To actually select a different language, you first need to remove the "auto detect" option that is pre-populated in a new paste. Other than that, it works as intended. Test Plan: Create a new paste with a file extension that can be auto-detected. Created a new paste and manually selected the language Edited a paste and changed the language. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley, yelirekim Maniphest Tasks: T11532 Differential Revision: https://secure.phabricator.com/D16463
This commit is contained in:
parent
60d1762a85
commit
9422596ebf
|
@ -0,0 +1,3 @@
|
||||||
|
/* Allow this column to be nullable (null means we'll try to autodetect) */
|
||||||
|
ALTER TABLE {$NAMESPACE}_pastebin.pastebin_paste MODIFY language VARCHAR(64)
|
||||||
|
COLLATE {$COLLATE_TEXT};
|
|
@ -0,0 +1,2 @@
|
||||||
|
UPDATE {$NAMESPACE}_pastebin.pastebin_paste SET language = NULL
|
||||||
|
WHERE language = '';
|
|
@ -1732,6 +1732,7 @@ phutil_register_library_map(array(
|
||||||
'PasteEditConduitAPIMethod' => 'applications/paste/conduit/PasteEditConduitAPIMethod.php',
|
'PasteEditConduitAPIMethod' => 'applications/paste/conduit/PasteEditConduitAPIMethod.php',
|
||||||
'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php',
|
'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php',
|
||||||
'PasteInfoConduitAPIMethod' => 'applications/paste/conduit/PasteInfoConduitAPIMethod.php',
|
'PasteInfoConduitAPIMethod' => 'applications/paste/conduit/PasteInfoConduitAPIMethod.php',
|
||||||
|
'PasteLanguageSelectDatasource' => 'applications/paste/typeahead/PasteLanguageSelectDatasource.php',
|
||||||
'PasteMailReceiver' => 'applications/paste/mail/PasteMailReceiver.php',
|
'PasteMailReceiver' => 'applications/paste/mail/PasteMailReceiver.php',
|
||||||
'PasteQueryConduitAPIMethod' => 'applications/paste/conduit/PasteQueryConduitAPIMethod.php',
|
'PasteQueryConduitAPIMethod' => 'applications/paste/conduit/PasteQueryConduitAPIMethod.php',
|
||||||
'PasteReplyHandler' => 'applications/paste/mail/PasteReplyHandler.php',
|
'PasteReplyHandler' => 'applications/paste/mail/PasteReplyHandler.php',
|
||||||
|
@ -6401,6 +6402,7 @@ phutil_register_library_map(array(
|
||||||
'PasteEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
|
'PasteEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
|
||||||
'PasteEmbedView' => 'AphrontView',
|
'PasteEmbedView' => 'AphrontView',
|
||||||
'PasteInfoConduitAPIMethod' => 'PasteConduitAPIMethod',
|
'PasteInfoConduitAPIMethod' => 'PasteConduitAPIMethod',
|
||||||
|
'PasteLanguageSelectDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||||
'PasteMailReceiver' => 'PhabricatorObjectMailReceiver',
|
'PasteMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||||
'PasteQueryConduitAPIMethod' => 'PasteConduitAPIMethod',
|
'PasteQueryConduitAPIMethod' => 'PasteConduitAPIMethod',
|
||||||
'PasteReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
'PasteReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
||||||
|
|
|
@ -63,10 +63,6 @@ final class PhabricatorPasteEditEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildCustomEditFields($object) {
|
protected function buildCustomEditFields($object) {
|
||||||
$langs = array(
|
|
||||||
'' => pht('(Detect From Filename in Title)'),
|
|
||||||
) + PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
id(new PhabricatorTextEditField())
|
id(new PhabricatorTextEditField())
|
||||||
->setKey('title')
|
->setKey('title')
|
||||||
|
@ -76,14 +72,14 @@ final class PhabricatorPasteEditEngine
|
||||||
->setConduitDescription(pht('Retitle the paste.'))
|
->setConduitDescription(pht('Retitle the paste.'))
|
||||||
->setConduitTypeDescription(pht('New paste title.'))
|
->setConduitTypeDescription(pht('New paste title.'))
|
||||||
->setValue($object->getTitle()),
|
->setValue($object->getTitle()),
|
||||||
id(new PhabricatorSelectEditField())
|
id(new PhabricatorDatasourceEditField())
|
||||||
->setKey('language')
|
->setKey('language')
|
||||||
->setLabel(pht('Language'))
|
->setLabel(pht('Language'))
|
||||||
->setTransactionType(
|
->setTransactionType(
|
||||||
PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE)
|
PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE)
|
||||||
->setAliases(array('lang'))
|
->setAliases(array('lang'))
|
||||||
->setIsCopyable(true)
|
->setIsCopyable(true)
|
||||||
->setOptions($langs)
|
->setDatasource(new PasteLanguageSelectDatasource())
|
||||||
->setDescription(
|
->setDescription(
|
||||||
pht(
|
pht(
|
||||||
'Language used for syntax highlighting. By default, inferred '.
|
'Language used for syntax highlighting. By default, inferred '.
|
||||||
|
@ -91,7 +87,7 @@ final class PhabricatorPasteEditEngine
|
||||||
->setConduitDescription(
|
->setConduitDescription(
|
||||||
pht('Change language used for syntax highlighting.'))
|
pht('Change language used for syntax highlighting.'))
|
||||||
->setConduitTypeDescription(pht('New highlighting language.'))
|
->setConduitTypeDescription(pht('New highlighting language.'))
|
||||||
->setValue($object->getLanguage()),
|
->setSingleValue($object->getLanguage()),
|
||||||
id(new PhabricatorTextAreaEditField())
|
id(new PhabricatorTextAreaEditField())
|
||||||
->setKey('text')
|
->setKey('text')
|
||||||
->setLabel(pht('Text'))
|
->setLabel(pht('Text'))
|
||||||
|
|
|
@ -42,7 +42,6 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
|
||||||
|
|
||||||
return id(new PhabricatorPaste())
|
return id(new PhabricatorPaste())
|
||||||
->setTitle('')
|
->setTitle('')
|
||||||
->setLanguage('')
|
|
||||||
->setStatus(self::STATUS_ACTIVE)
|
->setStatus(self::STATUS_ACTIVE)
|
||||||
->setAuthorPHID($actor->getPHID())
|
->setAuthorPHID($actor->getPHID())
|
||||||
->setViewPolicy($view_policy)
|
->setViewPolicy($view_policy)
|
||||||
|
@ -72,7 +71,7 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
|
||||||
self::CONFIG_COLUMN_SCHEMA => array(
|
self::CONFIG_COLUMN_SCHEMA => array(
|
||||||
'status' => 'text32',
|
'status' => 'text32',
|
||||||
'title' => 'text255',
|
'title' => 'text255',
|
||||||
'language' => 'text64',
|
'language' => 'text64?',
|
||||||
'mailKey' => 'bytes20',
|
'mailKey' => 'bytes20',
|
||||||
'parentPHID' => 'phid?',
|
'parentPHID' => 'phid?',
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PasteLanguageSelectDatasource
|
||||||
|
extends PhabricatorTypeaheadDatasource {
|
||||||
|
|
||||||
|
public function getBrowseTitle() {
|
||||||
|
return pht('Browse Languages');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlaceholderText() {
|
||||||
|
return pht('Type a language name or leave blank to auto-detect...');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDatasourceApplicationClass() {
|
||||||
|
return 'PhabricatorPasteApplication';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadResults() {
|
||||||
|
$results = $this->buildResults();
|
||||||
|
return $this->filterResultsAgainstTokens($results);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function renderSpecialTokens(array $values) {
|
||||||
|
return $this->renderTokensFromResults($this->buildResults(), $values);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildResults() {
|
||||||
|
$results = array();
|
||||||
|
$languages = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
|
||||||
|
|
||||||
|
foreach ($languages as $value => $name) {
|
||||||
|
$result = id(new PhabricatorTypeaheadResult())
|
||||||
|
->setPHID($value)
|
||||||
|
->setName($name);
|
||||||
|
|
||||||
|
$results[$value] = $result;
|
||||||
|
}
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue