/////////// // Extract void DialogAttachments::OnExtract(wxCommandEvent &event) { // Check if there's a selection int i = listView->GetFirstSelected(); // Get path if (i != -1) { wxString path; bool fullPath = false; // Multiple or single? if (listView->GetNextSelected(i) != -1) path = wxDirSelector(_("Select the path to save the files to:"),Options.AsText(_T("Fonts Collector Destination"))) + _T("/"); else { // Default path wxString defPath = ((AssAttachment*) listView->GetItemData(i))->GetFileName(); path = wxFileSelector(_("Select the path to save the file to:"),Options.AsText(_T("Fonts Collector Destination")),defPath); fullPath = true; } if (path.IsEmpty()) return; // Loop through items in list while (i != -1) { AssAttachment *attach = (AssAttachment*) listView->GetItemData(i); wxString filename = path; if (!fullPath) filename += attach->GetFileName(); attach->Extract(filename); i = listView->GetNextSelected(i); } } }
/////////////////// // Attach graphics void DialogAttachments::OnAttachGraphics(wxCommandEvent &event) { // Pick files wxArrayString filenames; wxArrayString paths; { wxFileDialog diag (this,_("Choose file to be attached"), _T(""), _T(""), _T("Graphic Files (*.bmp,*.gif,*.jpg,*.ico,*.wmf)|*.bmp;*.gif;*.jpg;*.ico;*.wmf"), wxOPEN | wxFILE_MUST_EXIST | wxMULTIPLE); if (diag.ShowModal() == wxID_CANCEL) return; diag.GetFilenames(filenames); diag.GetPaths(paths); } // Create attachments for (size_t i=0;i<filenames.Count();i++) { //wxFileName file(filenames[i]); AssAttachment *newAttach = new AssAttachment(filenames[i]); try { newAttach->Import(paths[i]); } catch (...) { delete newAttach; return; } newAttach->group = _T("[Graphics]"); AssFile::top->InsertAttachment(newAttach); } // Update UpdateList(); }
/////////////// // Attach font void DialogAttachments::OnAttachFont(wxCommandEvent &event) { // Pick files wxArrayString filenames; wxArrayString paths; { wxFileDialog diag (this,_("Choose file to be attached"), Options.AsText(_T("Fonts Collector Destination")), _T(""), _T("Font Files (*.ttf)|*.ttf"), wxOPEN | wxFILE_MUST_EXIST | wxMULTIPLE); if (diag.ShowModal() == wxID_CANCEL) return; diag.GetFilenames(filenames); diag.GetPaths(paths); } // Create attachments for (size_t i=0;i<filenames.Count();i++) { //wxFileName file(filenames[i]); AssAttachment *newAttach = new AssAttachment(filenames[i]); try { newAttach->Import(paths[i]); } catch (...) { delete newAttach; return; } newAttach->group = _T("[Fonts]"); AssFile::top->InsertAttachment(newAttach); } // Update UpdateList(); }
void DialogAttachments::OnExtract(wxCommandEvent &) { int i = listView->GetFirstSelected(); if (i == -1) return; wxString path; bool fullPath = false; // Multiple or single? if (listView->GetNextSelected(i) != -1) path = wxDirSelector(_("Select the path to save the files to:"),lagi_wxString(OPT_GET("Path/Fonts Collector Destination")->GetString())) + "/"; else { // Default path wxString defPath = ((AssAttachment*)wxUIntToPtr(listView->GetItemData(i)))->GetFileName(); path = wxFileSelector( _("Select the path to save the file to:"), lagi_wxString(OPT_GET("Path/Fonts Collector Destination")->GetString()), defPath, ".ttf", "Font Files (*.ttf)|*.ttf", wxFD_SAVE | wxFD_OVERWRITE_PROMPT, this); fullPath = true; } if (!path) return; // Loop through items in list while (i != -1) { AssAttachment *attach = (AssAttachment*)wxUIntToPtr(listView->GetItemData(i)); attach->Extract(fullPath ? path : path + attach->GetFileName()); i = listView->GetNextSelected(i); } }
void DialogAttachments::AttachFile(wxFileDialog &diag, AssEntryGroup group, wxString const& commit_msg) { if (diag.ShowModal() == wxID_CANCEL) return; wxArrayString filenames; diag.GetFilenames(filenames); wxArrayString paths; diag.GetPaths(paths); // Create attachments for (size_t i = 0; i < filenames.size(); ++i) { AssAttachment *newAttach = new AssAttachment(filenames[i], group); try { newAttach->Import(paths[i]); } catch (...) { delete newAttach; return; } ass->InsertLine(newAttach); } ass->Commit(commit_msg, AssFile::COMMIT_ATTACHMENT); UpdateList(); }
/////////////// // Update list void DialogAttachments::UpdateList() { // Clear list listView->ClearAll(); // Insert list columns listView->InsertColumn(0, _("Attachment name"), wxLIST_FORMAT_LEFT, 280); listView->InsertColumn(1, _("Size"), wxLIST_FORMAT_LEFT, 100); listView->InsertColumn(2, _("Group"), wxLIST_FORMAT_LEFT, 100); // Fill list AssAttachment *attach; for (std::list<AssEntry*>::iterator cur = AssFile::top->Line.begin();cur != AssFile::top->Line.end();cur++) { attach = AssEntry::GetAsAttachment(*cur); if (attach) { // Add item int row = listView->GetItemCount(); listView->InsertItem(row,attach->GetFileName(true)); listView->SetItem(row,1,PrettySize(attach->GetData().size())); listView->SetItem(row,2,attach->group); listView->SetItemData(row,(long)attach); } } }