Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14017408
D16463.id39615.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D16463.id39615.diff
View Options
diff --git a/resources/sql/autopatches/20160829.pastebin.language.sql b/resources/sql/autopatches/20160829.pastebin.language.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160829.pastebin.language.sql
@@ -0,0 +1,2 @@
+/* Allow this column to be nullable (null means we'll try to autodetect) */
+ALTER TABLE {$NAMESPACE}_pastebin.pastebin_paste MODIFY language VARCHAR(64);
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1731,6 +1731,7 @@
'PasteEditConduitAPIMethod' => 'applications/paste/conduit/PasteEditConduitAPIMethod.php',
'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php',
'PasteInfoConduitAPIMethod' => 'applications/paste/conduit/PasteInfoConduitAPIMethod.php',
+ 'PasteLanguageSelectDatasource' => 'applications/paste/typeahead/PasteLanguageSelectDatasource.php',
'PasteMailReceiver' => 'applications/paste/mail/PasteMailReceiver.php',
'PasteQueryConduitAPIMethod' => 'applications/paste/conduit/PasteQueryConduitAPIMethod.php',
'PasteReplyHandler' => 'applications/paste/mail/PasteReplyHandler.php',
@@ -6397,6 +6398,7 @@
'PasteEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'PasteEmbedView' => 'AphrontView',
'PasteInfoConduitAPIMethod' => 'PasteConduitAPIMethod',
+ 'PasteLanguageSelectDatasource' => 'PhabricatorTypeaheadDatasource',
'PasteMailReceiver' => 'PhabricatorObjectMailReceiver',
'PasteQueryConduitAPIMethod' => 'PasteConduitAPIMethod',
'PasteReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
diff --git a/src/applications/paste/editor/PhabricatorPasteEditEngine.php b/src/applications/paste/editor/PhabricatorPasteEditEngine.php
--- a/src/applications/paste/editor/PhabricatorPasteEditEngine.php
+++ b/src/applications/paste/editor/PhabricatorPasteEditEngine.php
@@ -63,35 +63,38 @@
}
protected function buildCustomEditFields($object) {
- $langs = array(
- '' => pht('(Detect From Filename in Title)'),
- ) + PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
-
- return array(
- id(new PhabricatorTextEditField())
- ->setKey('title')
- ->setLabel(pht('Title'))
- ->setTransactionType(PhabricatorPasteTitleTransaction::TRANSACTIONTYPE)
- ->setDescription(pht('The title of the paste.'))
- ->setConduitDescription(pht('Retitle the paste.'))
- ->setConduitTypeDescription(pht('New paste title.'))
- ->setValue($object->getTitle()),
- id(new PhabricatorSelectEditField())
+ $lang_selector = id(new PhabricatorDatasourceEditField())
->setKey('language')
->setLabel(pht('Language'))
->setTransactionType(
PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE)
->setAliases(array('lang'))
->setIsCopyable(true)
- ->setOptions($langs)
+ ->setDatasource(new PasteLanguageSelectDatasource())
->setDescription(
pht(
'Language used for syntax highlighting. By default, inferred '.
'from the title.'))
->setConduitDescription(
pht('Change language used for syntax highlighting.'))
- ->setConduitTypeDescription(pht('New highlighting language.'))
- ->setValue($object->getLanguage()),
+ ->setConduitTypeDescription(pht('New highlighting language.'));
+
+ if ($object->getLanguage() !== '') {
+ $lang_selector->setSingleValue($object->getLanguage());
+ } else {
+ $lang_selector->setSingleValue(null);
+ }
+
+ return array(
+ id(new PhabricatorTextEditField())
+ ->setKey('title')
+ ->setLabel(pht('Title'))
+ ->setTransactionType(PhabricatorPasteTitleTransaction::TRANSACTIONTYPE)
+ ->setDescription(pht('The title of the paste.'))
+ ->setConduitDescription(pht('Retitle the paste.'))
+ ->setConduitTypeDescription(pht('New paste title.'))
+ ->setValue($object->getTitle()),
+ $lang_selector,
id(new PhabricatorTextAreaEditField())
->setKey('text')
->setLabel(pht('Text'))
diff --git a/src/applications/paste/storage/PhabricatorPaste.php b/src/applications/paste/storage/PhabricatorPaste.php
--- a/src/applications/paste/storage/PhabricatorPaste.php
+++ b/src/applications/paste/storage/PhabricatorPaste.php
@@ -72,7 +72,7 @@
self::CONFIG_COLUMN_SCHEMA => array(
'status' => 'text32',
'title' => 'text255',
- 'language' => 'text64',
+ 'language' => 'text64?',
'mailKey' => 'bytes20',
'parentPHID' => 'phid?',
diff --git a/src/applications/paste/typeahead/PasteLanguageSelectDatasource.php b/src/applications/paste/typeahead/PasteLanguageSelectDatasource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/paste/typeahead/PasteLanguageSelectDatasource.php
@@ -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;
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 5, 5:10 PM (1 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6732000
Default Alt Text
D16463.id39615.diff (5 KB)
Attached To
Mode
D16463: Converted Paste language selection to a typeahead
Attached
Detach File
Event Timeline
Log In to Comment