Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/PhabricatorInlineCommentController.php
Show First 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | switch ($op) { | ||||
$inline->setIsDeleted(1); | $inline->setIsDeleted(1); | ||||
} else { | } else { | ||||
$inline->setIsDeleted(0); | $inline->setIsDeleted(0); | ||||
} | } | ||||
$this->saveComment($inline); | $this->saveComment($inline); | ||||
return $this->buildEmptyResponse(); | return $this->buildEmptyResponse(); | ||||
case 'edit': | |||||
case 'save': | case 'save': | ||||
$inline = $this->loadCommentByIDForEdit($this->getCommentID()); | $inline = $this->loadCommentByIDForEdit($this->getCommentID()); | ||||
if ($op === 'save') { | |||||
$this->updateCommentContentState($inline); | $this->updateCommentContentState($inline); | ||||
$inline | $inline | ||||
->setIsEditing(false) | ->setIsEditing(false) | ||||
->setIsDeleted(0); | ->setIsDeleted(0); | ||||
// Since we're saving the comment, update the committed state. | |||||
$active_state = $inline->getContentState(); | |||||
$inline->setCommittedContentState($active_state); | |||||
$this->saveComment($inline); | $this->saveComment($inline); | ||||
return $this->buildRenderedCommentResponse( | return $this->buildRenderedCommentResponse( | ||||
$inline, | $inline, | ||||
$this->getIsOnRight()); | $this->getIsOnRight()); | ||||
} else { | case 'edit': | ||||
$inline = $this->loadCommentByIDForEdit($this->getCommentID()); | |||||
// NOTE: At time of writing, the "editing" state of inlines is | // NOTE: At time of writing, the "editing" state of inlines is | ||||
// preserved by simulating a click on "Edit" when the inline loads. | // preserved by simulating a click on "Edit" when the inline loads. | ||||
// In this case, we don't want to "saveComment()", because it | // In this case, we don't want to "saveComment()", because it | ||||
// recalculates object drafts and purges versioned drafts. | // recalculates object drafts and purges versioned drafts. | ||||
// The recalculation is merely unnecessary (state doesn't change) | // The recalculation is merely unnecessary (state doesn't change) | ||||
// but purging drafts means that loading a page and then closing it | // but purging drafts means that loading a page and then closing it | ||||
// discards your drafts. | // discards your drafts. | ||||
// To avoid the purge, only invoke "saveComment()" if we actually | // To avoid the purge, only invoke "saveComment()" if we actually | ||||
// have changes to apply. | // have changes to apply. | ||||
$is_dirty = false; | $is_dirty = false; | ||||
if (!$inline->getIsEditing()) { | if (!$inline->getIsEditing()) { | ||||
$inline | $inline | ||||
->setIsDeleted(0) | ->setIsDeleted(0) | ||||
->setIsEditing(true); | ->setIsEditing(true); | ||||
$is_dirty = true; | $is_dirty = true; | ||||
} | } | ||||
if ($this->hasContentState()) { | if ($this->hasContentState()) { | ||||
$this->updateCommentContentState($inline); | $this->updateCommentContentState($inline); | ||||
$is_dirty = true; | $is_dirty = true; | ||||
} else { | } else { | ||||
PhabricatorInlineComment::loadAndAttachVersionedDrafts( | PhabricatorInlineComment::loadAndAttachVersionedDrafts( | ||||
$viewer, | $viewer, | ||||
array($inline)); | array($inline)); | ||||
} | } | ||||
if ($is_dirty) { | if ($is_dirty) { | ||||
$this->saveComment($inline); | $this->saveComment($inline); | ||||
} | } | ||||
} | |||||
$edit_dialog = $this->buildEditDialog($inline) | $edit_dialog = $this->buildEditDialog($inline) | ||||
->setTitle(pht('Edit Inline Comment')); | ->setTitle(pht('Edit Inline Comment')); | ||||
$view = $this->buildScaffoldForView($edit_dialog); | $view = $this->buildScaffoldForView($edit_dialog); | ||||
return $this->newInlineResponse($inline, $view, true); | return $this->newInlineResponse($inline, $view, true); | ||||
case 'cancel': | case 'cancel': | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | switch ($op) { | ||||
// Reload the inline to attach context. | // Reload the inline to attach context. | ||||
$inline = $this->loadCommentByIDForEdit($inline->getID()); | $inline = $this->loadCommentByIDForEdit($inline->getID()); | ||||
// Now, we can read the source file and set the initial state. | // Now, we can read the source file and set the initial state. | ||||
$state = $inline->getContentState(); | $state = $inline->getContentState(); | ||||
$default_suggestion = $inline->getDefaultSuggestionText(); | $default_suggestion = $inline->getDefaultSuggestionText(); | ||||
$state->setContentSuggestionText($default_suggestion); | $state->setContentSuggestionText($default_suggestion); | ||||
$inline->setInitialContentState($state); | |||||
$inline->setContentState($state); | $inline->setContentState($state); | ||||
$inline->setIsDeleted(0); | $inline->setIsDeleted(0); | ||||
$this->saveComment($inline); | $this->saveComment($inline); | ||||
$edit_dialog = $this->buildEditDialog($inline); | $edit_dialog = $this->buildEditDialog($inline); | ||||
if ($this->getOperation() == 'reply') { | if ($this->getOperation() == 'reply') { | ||||
$edit_dialog->setTitle(pht('Reply to Inline Comment')); | $edit_dialog->setTitle(pht('Reply to Inline Comment')); | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | private function buildScaffoldForView(PHUIDiffInlineCommentView $view) { | ||||
return id(new PHUIDiffInlineCommentTableScaffold()) | return id(new PHUIDiffInlineCommentTableScaffold()) | ||||
->addRowScaffold($view); | ->addRowScaffold($view); | ||||
} | } | ||||
private function newInlineResponse( | private function newInlineResponse( | ||||
PhabricatorInlineComment $inline, | PhabricatorInlineComment $inline, | ||||
$view, | $view, | ||||
$is_edit) { | $is_edit) { | ||||
$viewer = $this->getViewer(); | |||||
if ($inline->getReplyToCommentPHID()) { | if ($inline->getReplyToCommentPHID()) { | ||||
$can_suggest = false; | $can_suggest = false; | ||||
} else { | } else { | ||||
$can_suggest = (bool)$inline->getInlineContext(); | $can_suggest = (bool)$inline->getInlineContext(); | ||||
} | } | ||||
if ($is_edit) { | if ($is_edit) { | ||||
$viewer = $this->getViewer(); | $state = $inline->getContentStateMapForEdit($viewer); | ||||
$content_state = $inline->getContentStateForEdit($viewer); | |||||
} else { | } else { | ||||
$content_state = $inline->getContentState(); | $state = $inline->getContentStateMap(); | ||||
} | } | ||||
$state_map = $content_state->newStorageMap(); | |||||
$response = array( | $response = array( | ||||
'inline' => array( | 'inline' => array( | ||||
'id' => $inline->getID(), | 'id' => $inline->getID(), | ||||
'contentState' => $state_map, | 'state' => $state, | ||||
'canSuggestEdit' => $can_suggest, | 'canSuggestEdit' => $can_suggest, | ||||
), | ), | ||||
'view' => hsprintf('%s', $view), | 'view' => hsprintf('%s', $view), | ||||
); | ); | ||||
return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
->setContent($response); | ->setContent($response); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines |