Fixed browser links to selfposts. Added links to the submission page. #21

This commit is contained in:
Michael Lazar
2015-03-04 22:58:36 -08:00
parent 46be3d6833
commit 4e5f564db5
3 changed files with 19 additions and 14 deletions

View File

@@ -180,7 +180,8 @@ class BaseContent(object):
else '[deleted]')
data['permalink'] = clean(sub.permalink)
data['subreddit'] = strip_subreddit_url(sub.permalink)
data['url'] = ('(selfpost)' if is_selfpost(sub.url) else clean(sub.url))
data['url_full'] = clean(sub.url)
data['url'] = ('selfpost' if is_selfpost(sub.url) else clean(sub.url))
return data

View File

@@ -1,5 +1,6 @@
import curses
import sys
import webbrowser
import six
@@ -36,24 +37,23 @@ class SubmissionPage(BasePage):
self.move_cursor_down()
self.clear_input_queue()
# Refresh page
elif cmd in (curses.KEY_F5, ord('r')):
self.refresh_content()
self.draw()
# Show / hide a comment tree
elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER, ord('l')):
self.toggle_comment()
self.draw()
elif cmd == ord('o'):
self.open_link()
elif cmd == curses.KEY_RESIZE:
self.draw()
# Go back
elif cmd in (ESCAPE, curses.KEY_LEFT, ord('h')):
break
# Quit
elif cmd == ord('q'):
sys.exit()
@@ -70,6 +70,13 @@ class SubmissionPage(BasePage):
self.nav.page_index, self.nav.cursor_index = -1, 0
self.nav.inverted = False
def open_link(self):
# Always open the page for the submission
# May want to expand at some point to open comment permalinks
url = self.content.get(-1)['permalink']
webbrowser.open_new_tab(url)
def draw_item(self, win, data, inverted=False):
if data['type'] == 'MoreComments':

View File

@@ -34,7 +34,6 @@ class SubredditPage(BasePage):
self.move_cursor_down()
self.clear_input_queue()
# View submission
elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER, ord('l')):
self.open_submission()
self.draw()
@@ -42,12 +41,10 @@ class SubredditPage(BasePage):
elif cmd == ord('o'):
self.open_link()
# Enter edit mode to change subreddit
elif cmd == ord('/'):
self.prompt_subreddit()
self.draw()
# Refresh page
elif cmd in (curses.KEY_F5, ord('r')):
self.refresh_content()
self.draw()
@@ -55,7 +52,6 @@ class SubredditPage(BasePage):
elif cmd == curses.KEY_RESIZE:
self.draw()
# Quit
elif cmd == ord('q'):
sys.exit()
@@ -99,6 +95,11 @@ class SubredditPage(BasePage):
page = SubmissionPage(self.stdscr, self.reddit, submission=submission)
page.loop()
def open_link(self):
url = self.content.get(self.nav.absolute_index)['url_full']
webbrowser.open_new_tab(url)
@staticmethod
def draw_item(win, data, inverted=False):
@@ -132,7 +133,3 @@ class SubredditPage(BasePage):
win.addnstr(row, 1, text, n_cols-1, curses.A_BOLD)
text = ' {subreddit}'.format(**data)
win.addnstr(text, n_cols - win.getyx()[1], Color.YELLOW)
def open_link(self):
url = self.content.get(self.nav.absolute_index)['url']
webbrowser.open_new_tab(url)