2006-07-01 04:27:37 +02:00
|
|
|
// Copyright (c) 2006, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file dialog_attachments.cpp
|
|
|
|
/// @brief Manage files attached to the subtitle file
|
|
|
|
/// @ingroup tools_ui
|
|
|
|
///
|
2006-07-01 04:27:37 +02:00
|
|
|
|
2011-12-22 22:15:47 +01:00
|
|
|
#include "dialog_attachments.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/button.h>
|
2006-07-01 05:06:21 +02:00
|
|
|
#include <wx/filedlg.h>
|
2013-01-22 05:27:56 +01:00
|
|
|
#include <wx/dirdlg.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/listctrl.h>
|
2007-09-12 01:22:26 +02:00
|
|
|
#include <wx/sizer.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
|
2006-07-01 04:27:37 +02:00
|
|
|
#include "ass_attachment.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_file.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "compat.h"
|
2008-01-14 00:34:38 +01:00
|
|
|
#include "help_button.h"
|
2009-07-24 02:08:25 +02:00
|
|
|
#include "libresrc/libresrc.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "utils.h"
|
2006-07-01 04:27:37 +02:00
|
|
|
|
2010-07-09 09:31:48 +02:00
|
|
|
DialogAttachments::DialogAttachments(wxWindow *parent, AssFile *ass)
|
2013-01-04 16:01:50 +01:00
|
|
|
: wxDialog(parent, -1, _("Attachment List"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
|
2010-07-09 09:31:48 +02:00
|
|
|
, ass(ass)
|
2006-07-01 04:27:37 +02:00
|
|
|
{
|
2012-04-03 22:40:24 +02:00
|
|
|
SetIcon(GETICON(attach_button_16));
|
2007-07-05 01:09:40 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
listView = new wxListView(this, -1, wxDefaultPosition, wxSize(500, 200));
|
2006-07-01 04:46:41 +02:00
|
|
|
UpdateList();
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
auto attachFont = new wxButton(this, -1, _("Attach &Font"));
|
|
|
|
auto attachGraphics = new wxButton(this, -1, _("Attach &Graphics"));
|
|
|
|
extractButton = new wxButton(this, -1, _("E&xtract"));
|
|
|
|
deleteButton = new wxButton(this, -1, _("&Delete"));
|
2006-07-09 01:18:07 +02:00
|
|
|
extractButton->Enable(false);
|
|
|
|
deleteButton->Enable(false);
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
auto buttonSizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
buttonSizer->Add(attachFont, 1);
|
|
|
|
buttonSizer->Add(attachGraphics, 1);
|
|
|
|
buttonSizer->Add(extractButton, 1);
|
|
|
|
buttonSizer->Add(deleteButton, 1);
|
|
|
|
buttonSizer->Add(new HelpButton(this, "Attachment Manager"), 1, wxLEFT, 5);
|
|
|
|
buttonSizer->Add(new wxButton(this, wxID_CANCEL, _("&Close")), 1);
|
|
|
|
|
|
|
|
auto mainSizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
mainSizer->Add(listView, 1, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, 5);
|
|
|
|
mainSizer->Add(buttonSizer, 0, wxALL | wxEXPAND, 5);
|
2011-12-22 22:16:14 +01:00
|
|
|
SetSizerAndFit(mainSizer);
|
2007-06-20 07:18:47 +02:00
|
|
|
CenterOnParent();
|
2013-01-04 16:01:50 +01:00
|
|
|
|
2013-12-12 03:25:13 +01:00
|
|
|
attachFont->Bind(wxEVT_BUTTON, &DialogAttachments::OnAttachFont, this);
|
|
|
|
attachGraphics->Bind(wxEVT_BUTTON, &DialogAttachments::OnAttachGraphics, this);
|
|
|
|
extractButton->Bind(wxEVT_BUTTON, &DialogAttachments::OnExtract, this);
|
|
|
|
deleteButton->Bind(wxEVT_BUTTON, &DialogAttachments::OnDelete, this);
|
2013-01-04 16:01:50 +01:00
|
|
|
|
2013-12-12 03:25:13 +01:00
|
|
|
listView->Bind(wxEVT_LIST_ITEM_SELECTED, &DialogAttachments::OnListClick, this);
|
|
|
|
listView->Bind(wxEVT_LIST_ITEM_DESELECTED, &DialogAttachments::OnListClick, this);
|
|
|
|
listView->Bind(wxEVT_LIST_ITEM_FOCUSED, &DialogAttachments::OnListClick, this);
|
2006-07-01 04:46:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogAttachments::UpdateList() {
|
|
|
|
listView->ClearAll();
|
|
|
|
|
2006-07-01 09:25:37 +02:00
|
|
|
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);
|
2006-07-01 04:27:37 +02:00
|
|
|
|
2014-03-07 19:58:51 +01:00
|
|
|
for (auto& attach : ass->Attachments) {
|
2012-11-05 17:20:58 +01:00
|
|
|
int row = listView->GetItemCount();
|
2014-03-07 19:58:51 +01:00
|
|
|
listView->InsertItem(row, to_wx(attach.GetFileName(true)));
|
|
|
|
listView->SetItem(row, 1, PrettySize(attach.GetSize()));
|
|
|
|
listView->SetItem(row, 2, to_wx(attach.GroupHeader()));
|
2006-07-01 04:27:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void DialogAttachments::AttachFile(wxFileDialog &diag, wxString const& commit_msg) {
|
2011-12-22 22:15:47 +01:00
|
|
|
if (diag.ShowModal() == wxID_CANCEL) return;
|
2006-07-01 04:27:37 +02:00
|
|
|
|
2006-07-01 06:08:01 +02:00
|
|
|
wxArrayString paths;
|
2011-12-22 22:15:47 +01:00
|
|
|
diag.GetPaths(paths);
|
2006-07-01 06:08:01 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
for (auto const& fn : paths)
|
|
|
|
ass->InsertAttachment(agi::fs::path(fn));
|
2006-07-01 06:08:01 +02:00
|
|
|
|
2011-12-22 22:15:47 +01:00
|
|
|
ass->Commit(commit_msg, AssFile::COMMIT_ATTACHMENT);
|
2010-06-24 08:13:51 +02:00
|
|
|
|
2006-07-01 06:08:01 +02:00
|
|
|
UpdateList();
|
2006-07-01 04:27:37 +02:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:15:47 +01:00
|
|
|
void DialogAttachments::OnAttachFont(wxCommandEvent &) {
|
|
|
|
wxFileDialog diag(this,
|
|
|
|
_("Choose file to be attached"),
|
2012-12-23 00:18:38 +01:00
|
|
|
to_wx(OPT_GET("Path/Fonts Collector Destination")->GetString()), "", "Font Files (*.ttf)|*.ttf",
|
2011-12-22 22:15:47 +01:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE);
|
2006-07-01 04:27:37 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
AttachFile(diag, _("attach font file"));
|
2011-12-22 22:15:47 +01:00
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-12-22 22:09:31 +01:00
|
|
|
void DialogAttachments::OnAttachGraphics(wxCommandEvent &) {
|
2011-12-22 22:15:47 +01:00
|
|
|
wxFileDialog diag(this,
|
|
|
|
_("Choose file to be attached"),
|
|
|
|
"", "",
|
2013-01-04 16:01:50 +01:00
|
|
|
"Graphic Files (*.bmp, *.gif, *.jpg, *.ico, *.wmf)|*.bmp;*.gif;*.jpg;*.ico;*.wmf",
|
2011-12-22 22:15:47 +01:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE);
|
2010-06-24 08:13:51 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
AttachFile(diag, _("attach graphics file"));
|
2006-07-01 07:00:03 +02:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:09:31 +01:00
|
|
|
void DialogAttachments::OnExtract(wxCommandEvent &) {
|
2006-07-01 05:06:21 +02:00
|
|
|
int i = listView->GetFirstSelected();
|
2011-12-22 22:15:56 +01:00
|
|
|
if (i == -1) return;
|
|
|
|
|
2013-01-22 05:27:56 +01:00
|
|
|
agi::fs::path path;
|
2011-12-22 22:15:56 +01:00
|
|
|
bool fullPath = false;
|
|
|
|
|
|
|
|
// Multiple or single?
|
|
|
|
if (listView->GetNextSelected(i) != -1)
|
2014-01-05 17:10:08 +01:00
|
|
|
path = wxDirSelector(_("Select the path to save the files to:"), to_wx(OPT_GET("Path/Fonts Collector Destination")->GetString())).c_str();
|
2011-12-22 22:15:56 +01:00
|
|
|
else {
|
2013-01-22 05:27:56 +01:00
|
|
|
path = SaveFileSelector(
|
2012-04-17 01:55:04 +02:00
|
|
|
_("Select the path to save the file to:"),
|
2013-01-22 05:27:56 +01:00
|
|
|
"Path/Fonts Collector Destination",
|
2014-03-08 02:13:23 +01:00
|
|
|
ass->Attachments[i].GetFileName(),
|
2013-01-22 05:27:56 +01:00
|
|
|
".ttf", "Font Files (*.ttf)|*.ttf",
|
|
|
|
this);
|
2011-12-22 22:15:56 +01:00
|
|
|
fullPath = true;
|
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
if (path.empty()) return;
|
2006-07-01 05:06:21 +02:00
|
|
|
|
2011-12-22 22:15:56 +01:00
|
|
|
// Loop through items in list
|
|
|
|
while (i != -1) {
|
2014-03-08 02:13:23 +01:00
|
|
|
auto& attach = ass->Attachments[i];
|
|
|
|
attach.Extract(fullPath ? path : path/attach.GetFileName());
|
2011-12-22 22:15:56 +01:00
|
|
|
i = listView->GetNextSelected(i);
|
2006-07-01 05:06:21 +02:00
|
|
|
}
|
2006-07-01 04:27:37 +02:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:09:31 +01:00
|
|
|
void DialogAttachments::OnDelete(wxCommandEvent &) {
|
2014-03-08 02:13:23 +01:00
|
|
|
size_t removed = 0;
|
|
|
|
for (auto i = listView->GetFirstSelected(); i != -1; i = listView->GetNextSelected(i))
|
|
|
|
ass->Attachments.erase(ass->Attachments.begin() + i - removed++);
|
2006-07-01 04:46:41 +02:00
|
|
|
|
2011-09-15 07:16:32 +02:00
|
|
|
ass->Commit(_("remove attachment"), AssFile::COMMIT_ATTACHMENT);
|
2010-06-24 08:13:51 +02:00
|
|
|
|
2006-07-01 04:46:41 +02:00
|
|
|
UpdateList();
|
2011-12-22 22:15:56 +01:00
|
|
|
extractButton->Enable(false);
|
|
|
|
deleteButton->Enable(false);
|
2006-07-01 04:27:37 +02:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:09:31 +01:00
|
|
|
void DialogAttachments::OnListClick(wxListEvent &) {
|
2006-07-09 01:18:07 +02:00
|
|
|
bool hasSel = listView->GetFirstSelected() != -1;
|
|
|
|
extractButton->Enable(hasSel);
|
|
|
|
deleteButton->Enable(hasSel);
|
|
|
|
}
|