Added option to download document from the context menu
This commit is contained in:
@@ -544,6 +544,7 @@ class documentBuffer(feedBuffer):
|
||||
added = False
|
||||
m = menus.documentMenu(added)
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.add_remove_document, menuitem=m.action)
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.download, menuitem=m.download)
|
||||
return m
|
||||
|
||||
def add_remove_document(self, *args, **kwargs):
|
||||
@@ -560,6 +561,16 @@ class documentBuffer(feedBuffer):
|
||||
result = self.session.vk.client.docs.add(owner_id=p["owner_id"], doc_id=p["id"])
|
||||
output.speak(_("The document has been successfully added."))
|
||||
|
||||
def download(self, *args, **kwargs):
|
||||
post = self.get_post()
|
||||
filename = post["title"]
|
||||
# If document does not end in .extension we must fix it so the file dialog will save it properly later.
|
||||
if filename.endswith(post["ext"]) == False:
|
||||
filename = filename+ "."+post["ext"]
|
||||
filepath = self.tab.get_download_path(filename)
|
||||
if filepath != None:
|
||||
pub.sendMessage("download-file", url=post["url"], filename=filepath)
|
||||
|
||||
class documentCommunityBuffer(documentBuffer):
|
||||
can_get_items = True
|
||||
|
||||
|
@@ -165,6 +165,11 @@ class documentCommunityTab(homeTab):
|
||||
self.list.set_size()
|
||||
self.list.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnKeyDown)
|
||||
|
||||
def get_download_path(self, filename):
|
||||
saveFileDialog = wx.FileDialog(self, _("Save document as"), "", filename, _("All files (*.*)|*.*"), wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
|
||||
if saveFileDialog.ShowModal() == widgetUtils.OK:
|
||||
return saveFileDialog.GetPath()
|
||||
|
||||
class documentTab(documentCommunityTab):
|
||||
def create_post_buttons(self):
|
||||
self.postBox = wx.StaticBoxSizer(parent=self, orient=wx.HORIZONTAL, label=_("Actions"))
|
||||
|
Reference in New Issue
Block a user