Allow navigating to comments from the prompt on the submission page

This commit is contained in:
Michael Lazar
2017-08-30 01:53:39 -04:00
parent d6735f7181
commit 97581a77a5
9 changed files with 4115 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import re
import time
import curses
@@ -38,7 +39,9 @@ class SubmissionPage(Page):
@SubmissionController.register(Command('SUBMISSION_TOGGLE_COMMENT'))
def toggle_comment(self):
"Toggle the selected comment tree between visible and hidden"
"""
Toggle the selected comment tree between visible and hidden
"""
current_index = self.nav.absolute_index
self.content.toggle(current_index)
@@ -58,17 +61,26 @@ class SubmissionPage(Page):
@SubmissionController.register(Command('SUBMISSION_EXIT'))
def exit_submission(self):
"Close the submission and return to the subreddit page"
"""
Close the submission and return to the subreddit page
"""
self.active = False
@SubmissionController.register(Command('REFRESH'))
def refresh_content(self, order=None, name=None):
"Re-download comments and reset the page index"
"""
Re-download comments and reset the page index
"""
order = order or self.content.order
url = name or self.content.name
# Hack to allow an order specified in the name by prompt_subreddit() to
# override the current default
if order == 'ignore':
order = None
with self.term.loader('Refreshing page'):
self.content = SubmissionContent.from_url(
self.reddit, url, self.term.loader, order=order,
@@ -78,20 +90,37 @@ class SubmissionPage(Page):
@SubmissionController.register(Command('PROMPT'))
def prompt_subreddit(self):
"Open a prompt to navigate to a different subreddit"
"""
Open a prompt to navigate to a different subreddit
"""
name = self.term.prompt_input('Enter page: /')
if name is not None:
with self.term.loader('Loading page'):
content = SubredditContent.from_name(
self.reddit, name, self.term.loader)
if not self.term.loader.exception:
self.selected_subreddit = content
self.active = False
# Check if opening a submission url or a subreddit url
# Example patterns for submissions:
# comments/571dw3
# /comments/571dw3
# /r/pics/comments/571dw3/
# https://www.reddit.com/r/pics/comments/571dw3/at_disneyland
submission_pattern = re.compile(r'(^|/)comments/(?P<id>.+?)($|/)')
match = submission_pattern.search(name)
if match:
url = 'https://www.reddit.com/comments/{0}'
self.refresh_content('ignore', url.format(match.group('id')))
else:
with self.term.loader('Loading page'):
content = SubredditContent.from_name(
self.reddit, name, self.term.loader)
if not self.term.loader.exception:
self.selected_subreddit = content
self.active = False
@SubmissionController.register(Command('SUBMISSION_OPEN_IN_BROWSER'))
def open_link(self):
"Open the selected item with the webbrowser"
"""
Open the selected item with the webbrowser
"""
data = self.get_selected_item()
if data['type'] == 'Submission':
@@ -104,7 +133,9 @@ class SubmissionPage(Page):
@SubmissionController.register(Command('SUBMISSION_OPEN_IN_PAGER'))
def open_pager(self):
"Open the selected item with the system's pager"
"""
Open the selected item with the system's pager
"""
data = self.get_selected_item()
if data['type'] == 'Submission':
@@ -165,7 +196,9 @@ class SubmissionPage(Page):
@SubmissionController.register(Command('DELETE'))
@logged_in
def delete_comment(self):
"Delete the selected comment"
"""
Delete the selected comment
"""
if self.get_selected_item()['type'] == 'Comment':
self.delete_item()

View File

@@ -37,7 +37,9 @@ class SubredditPage(Page):
@SubredditController.register(Command('REFRESH'))
def refresh_content(self, order=None, name=None):
"Re-download all submissions and reset the page index"
"""
Re-download all submissions and reset the page index
"""
order = order or self.content.order
@@ -62,7 +64,9 @@ class SubredditPage(Page):
@SubredditController.register(Command('SUBREDDIT_SEARCH'))
def search_subreddit(self, name=None):
"Open a prompt to search the given subreddit"
"""
Open a prompt to search the given subreddit
"""
name = name or self.content.name
@@ -78,7 +82,9 @@ class SubredditPage(Page):
@SubredditController.register(Command('PROMPT'))
def prompt_subreddit(self):
"Open a prompt to navigate to a different subreddit"
"""
Open a prompt to navigate to a different subreddit"
"""
name = self.term.prompt_input('Enter page: /')
if name is not None:
@@ -142,7 +148,9 @@ class SubredditPage(Page):
@SubredditController.register(Command('SUBREDDIT_OPEN_IN_BROWSER'))
def open_link(self):
"Open a link with the webbrowser"
"""
Open a link with the webbrowser
"""
data = self.get_selected_item()
if data['url_type'] == 'selfpost':
@@ -159,7 +167,9 @@ class SubredditPage(Page):
@SubredditController.register(Command('SUBREDDIT_POST'))
@logged_in
def post_submission(self):
"Post a new submission to the given subreddit"
"""
Post a new submission to the given subreddit
"""
# Check that the subreddit can be submitted to
name = self.content.name
@@ -205,7 +215,9 @@ class SubredditPage(Page):
@SubredditController.register(Command('SUBREDDIT_OPEN_SUBSCRIPTIONS'))
@logged_in
def open_subscriptions(self):
"Open user subscriptions page"
"""
Open user subscriptions page
"""
with self.term.loader('Loading subscriptions'):
page = SubscriptionPage(self.reddit, self.term, self.config,
@@ -224,7 +236,9 @@ class SubredditPage(Page):
@SubredditController.register(Command('SUBREDDIT_OPEN_MULTIREDDITS'))
@logged_in
def open_multireddit_subscriptions(self):
"Open user multireddit subscriptions page"
"""
Open user multireddit subscriptions page
"""
with self.term.loader('Loading multireddits'):
page = SubscriptionPage(self.reddit, self.term, self.config,

View File

@@ -29,7 +29,9 @@ class SubscriptionPage(Page):
@SubscriptionController.register(Command('REFRESH'))
def refresh_content(self, order=None, name=None):
"Re-download all subscriptions and reset the page index"
"""
Re-download all subscriptions and reset the page index
"""
# reddit.get_my_subreddits() does not support sorting by order
if order:
@@ -44,7 +46,9 @@ class SubscriptionPage(Page):
@SubscriptionController.register(Command('PROMPT'))
def prompt_subreddit(self):
"Open a prompt to navigate to a different subreddit"
"""
Open a prompt to navigate to a different subreddit
"""
name = self.term.prompt_input('Enter page: /')
if name is not None:
@@ -57,7 +61,9 @@ class SubscriptionPage(Page):
@SubscriptionController.register(Command('SUBSCRIPTION_SELECT'))
def select_subreddit(self):
"Store the selected subreddit and return to the subreddit page"
"""
Store the selected subreddit and return to the subreddit page
"""
name = self.get_selected_item()['name']
with self.term.loader('Loading page'):
@@ -69,7 +75,9 @@ class SubscriptionPage(Page):
@SubscriptionController.register(Command('SUBSCRIPTION_EXIT'))
def close_subscriptions(self):
"Close subscriptions and return to the subreddit page"
"""
Close subscriptions and return to the subreddit page
"""
self.active = False