mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Card data in images (minimum viable)
* remove wxEmptyString * improve style tab carousel * create web request window * add drop target and drop source
This commit is contained in:
@@ -90,7 +90,7 @@ void HoverButtonBase::onMouseEnter(wxMouseEvent&) {
|
||||
void HoverButtonBase::onMouseLeave(wxMouseEvent&) {
|
||||
hover = false;
|
||||
refreshIfNeeded();
|
||||
if (!help_text.empty()) set_status_text(this,wxEmptyString);
|
||||
if (!help_text.empty()) set_status_text(this,_(""));
|
||||
}
|
||||
void HoverButtonBase::onFocus(wxFocusEvent&) {
|
||||
focus = true;
|
||||
|
||||
@@ -27,7 +27,7 @@ AddCSVWindow::AddCSVWindow(Window* parent, const SetP& set, bool sizer)
|
||||
, set(set)
|
||||
{
|
||||
// init controls
|
||||
file_path = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
|
||||
file_path = new wxTextCtrl(this, wxID_ANY, _(""));
|
||||
file_browse = new wxButton(this, ID_CARD_ADD_CSV_BROWSE, _BUTTON_("browse"));
|
||||
separator_type = new wxChoice(this, ID_CARD_ADD_CSV_SEP, wxDefaultPosition, wxDefaultSize, 0, nullptr);
|
||||
separator_type->Clear();
|
||||
@@ -66,7 +66,7 @@ void AddCSVWindow::onSeparatorTypeChange(wxCommandEvent&) {
|
||||
}
|
||||
|
||||
void AddCSVWindow::onBrowseFiles(wxCommandEvent&) {
|
||||
wxFileDialog* dlg = new wxFileDialog(this, _TITLE_("add card csv file"), settings.default_set_dir, wxEmptyString, _("CSV files|*.csv;*.tsv|All files (*.*)|*"), wxFD_OPEN);
|
||||
wxFileDialog* dlg = new wxFileDialog(this, _TITLE_("add card csv file"), settings.default_set_dir, _(""), _("CSV files|*.csv;*.tsv|All files (*.*)|*"), wxFD_OPEN);
|
||||
if (dlg->ShowModal() == wxID_OK) {
|
||||
file_path->SetValue(dlg->GetPath());
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ AddJSONWindow::AddJSONWindow(Window* parent, const SetP& set, bool sizer)
|
||||
, set(set)
|
||||
{
|
||||
// init controls
|
||||
file_path = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
|
||||
file_path = new wxTextCtrl(this, wxID_ANY, _(""));
|
||||
file_browse = new wxButton(this, ID_CARD_ADD_JSON_BROWSE, _BUTTON_("browse"));
|
||||
json_type = new wxChoice(this, ID_CARD_ADD_JSON_ARRAY, wxDefaultPosition, wxDefaultSize, 0, nullptr);
|
||||
json_type->Clear();
|
||||
@@ -43,7 +43,7 @@ AddJSONWindow::AddJSONWindow(Window* parent, const SetP& set, bool sizer)
|
||||
}
|
||||
json_type->Append(_LABEL_("add card json custom"));
|
||||
json_type->SetSelection(0);
|
||||
card_array_path = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
|
||||
card_array_path = new wxTextCtrl(this, wxID_ANY, _(""));
|
||||
setJSONType();
|
||||
// init sizers
|
||||
if (sizer) {
|
||||
@@ -68,7 +68,7 @@ AddJSONWindow::AddJSONWindow(Window* parent, const SetP& set, bool sizer)
|
||||
void AddJSONWindow::setJSONType() {
|
||||
int sel = json_type->GetSelection();
|
||||
if (sel == json_type->GetCount() - 1) { // Custom type
|
||||
card_array_path->ChangeValue(wxEmptyString);
|
||||
card_array_path->ChangeValue(_(""));
|
||||
card_array_path->Enable();
|
||||
}
|
||||
else {
|
||||
@@ -89,7 +89,7 @@ void AddJSONWindow::onJSONTypeChange(wxCommandEvent&) {
|
||||
}
|
||||
|
||||
void AddJSONWindow::onBrowseFiles(wxCommandEvent&) {
|
||||
wxFileDialog* dlg = new wxFileDialog(this, _TITLE_("add card json file"), settings.default_set_dir, wxEmptyString, _("JSON files|*.json|All files (*.*)|*"), wxFD_OPEN);
|
||||
wxFileDialog* dlg = new wxFileDialog(this, _TITLE_("add card json file"), settings.default_set_dir, _(""), _("JSON files|*.json|All files (*.*)|*"), wxFD_OPEN);
|
||||
if (dlg->ShowModal() == wxID_OK) {
|
||||
file_path->SetValue(dlg->GetPath());
|
||||
}
|
||||
@@ -102,7 +102,7 @@ void AddJSONWindow::onBrowseFiles(wxCommandEvent&) {
|
||||
try {
|
||||
jv = boost::json::parse(input);
|
||||
} catch (...) {
|
||||
queue_message(MESSAGE_ERROR, _ERROR_("add card json failed to parse"));
|
||||
queue_message(MESSAGE_ERROR, _ERROR_("json cant parse"));
|
||||
return false;
|
||||
}
|
||||
// Split path into tokens
|
||||
|
||||
@@ -268,8 +268,8 @@ void AutoReplaceWindow::refreshItem() {
|
||||
enabled ->SetValue(ar->enabled);
|
||||
whole_word->SetValue(ar->whole_word);
|
||||
} else {
|
||||
match ->SetValue(wxEmptyString);
|
||||
replace ->SetValue(wxEmptyString);
|
||||
match ->SetValue(_(""));
|
||||
replace ->SetValue(_(""));
|
||||
enabled ->SetValue(false);
|
||||
whole_word->SetValue(false);
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ CardLinkWindow::CardLinkWindow(Window* parent, const SetP& set, const CardP& sel
|
||||
, set(set), selected_card(selected_card)
|
||||
{
|
||||
// init controls
|
||||
selected_relation = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
|
||||
linked_relation = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
|
||||
selected_relation = new wxTextCtrl(this, wxID_ANY, _(""));
|
||||
linked_relation = new wxTextCtrl(this, wxID_ANY, _(""));
|
||||
relation_type = new wxChoice(this, ID_CARD_LINK_TYPE, wxDefaultPosition, wxDefaultSize, 0, nullptr);
|
||||
relation_type->Clear();
|
||||
FOR_EACH(link, set->game->card_links) {
|
||||
|
||||
@@ -73,7 +73,7 @@ wxSizer* ExportWindowBase::Create() {
|
||||
s->AddSpacer(4);
|
||||
s->Add(new wxStaticLine(this), 0, wxALL | wxEXPAND, 4);
|
||||
s->AddSpacer(4);
|
||||
card_count = new wxStaticText(this, wxID_ANY, wxEmptyString);
|
||||
card_count = new wxStaticText(this, wxID_ANY, _(""));
|
||||
s->Add(card_count, 0, wxALL & ~wxTOP, 6);
|
||||
s->AddSpacer(4);
|
||||
// done
|
||||
|
||||
@@ -381,7 +381,7 @@ void DataEditor::onMouseLeave(wxMouseEvent& ev) {
|
||||
}
|
||||
// clear status text
|
||||
wxFrame* frame = dynamic_cast<wxFrame*>( wxGetTopLevelParent(this) );
|
||||
if (frame) frame->SetStatusText(wxEmptyString);
|
||||
if (frame) frame->SetStatusText(_(""));
|
||||
}
|
||||
|
||||
bool DataEditor::selectViewer(ValueViewer* v) {
|
||||
|
||||
+237
-46
@@ -11,6 +11,7 @@
|
||||
#include <gui/control/card_list_column_select.hpp>
|
||||
#include <gui/set/window.hpp> // for sorting all cardlists in a window
|
||||
#include <gui/card_link_window.hpp>
|
||||
#include <gui/web_request_window.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <gui/add_csv_window.hpp>
|
||||
#include <gui/add_json_window.hpp>
|
||||
@@ -22,11 +23,16 @@
|
||||
#include <data/settings.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/format/clipboard.hpp>
|
||||
#include <data/format/formats.hpp>
|
||||
#include <data/action/set.hpp>
|
||||
#include <data/action/value.hpp>
|
||||
#include <script/functions/json.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <wx/clipbrd.h>
|
||||
#include <wx/clipbrd.h>
|
||||
#include <wx/webrequest.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <unordered_set>
|
||||
#include <fstream>
|
||||
|
||||
DECLARE_POINTER_TYPE(ChoiceValue);
|
||||
|
||||
@@ -51,7 +57,9 @@ CardListBase* CardSelectEvent::getTheCardList() const {
|
||||
|
||||
CardListBase::CardListBase(Window* parent, int id, long additional_style)
|
||||
: ItemList(parent, id, additional_style, true)
|
||||
{}
|
||||
{
|
||||
drop_target = new CardListDropTarget(this);
|
||||
}
|
||||
|
||||
CardListBase::~CardListBase() {
|
||||
storeColumns();
|
||||
@@ -141,7 +149,7 @@ void CardListBase::getSelection(vector<CardP>& out) const {
|
||||
bool CardListBase::canCut() const { return canDelete(); }
|
||||
bool CardListBase::canCopy() const { return focusCount() > 0; }
|
||||
bool CardListBase::canPaste() const {
|
||||
return allowModify() && wxTheClipboard->IsSupported(CardsDataObject::format);
|
||||
return allowModify();
|
||||
}
|
||||
bool CardListBase::canDelete() const {
|
||||
return allowModify() && focusCount() > 0; // TODO: check for selection?
|
||||
@@ -158,7 +166,8 @@ bool CardListBase::doCopy() {
|
||||
bool ok = wxTheClipboard->SetData(new CardsOnClipboard(set, cards_to_copy)); // ignore result
|
||||
wxTheClipboard->Close();
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
bool CardListBase::doCopyCardAndLinkedCards() {
|
||||
if (!canCopy()) return false;
|
||||
vector<CardP> cards_selected;
|
||||
@@ -183,23 +192,17 @@ bool CardListBase::doCopyCardAndLinkedCards() {
|
||||
bool ok = wxTheClipboard->SetData(new CardsOnClipboard(set, cards_to_copy)); // ignore result
|
||||
wxTheClipboard->Close();
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
bool CardListBase::doPaste() {
|
||||
// get data
|
||||
if (!canPaste()) return false;
|
||||
if (!wxTheClipboard->Open()) return false;
|
||||
CardsDataObject data;
|
||||
bool ok = wxTheClipboard->GetData(data);
|
||||
wxTheClipboard->Close();
|
||||
if (!ok) return false;
|
||||
// get cards
|
||||
vector<CardP> new_cards;
|
||||
ok = data.getCards(set, new_cards);
|
||||
if (!ok) return false;
|
||||
// add card to set
|
||||
set->actions.addAction(make_unique<AddCardAction>(ADD, *set, new_cards));
|
||||
return true;
|
||||
}
|
||||
bool ok = wxTheClipboard->GetData(*drop_target->data_object);
|
||||
wxTheClipboard->Close();
|
||||
if (ok) return parseData();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CardListBase::doDelete() {
|
||||
// cards to delete
|
||||
vector<CardP> cards_to_delete;
|
||||
@@ -208,8 +211,182 @@ bool CardListBase::doDelete() {
|
||||
// delete cards
|
||||
set->actions.addAction(make_unique<AddCardAction>(REMOVE, *set, cards_to_delete));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CardListBase::doAddCSV() {
|
||||
AddCSVWindow wnd(this, set, true);
|
||||
if (wnd.ShowModal() == wxID_OK) {
|
||||
// The actual adding is done in this window's onOk function
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CardListBase::doAddJSON() {
|
||||
AddJSONWindow wnd(this, set, true);
|
||||
if (wnd.ShowModal() == wxID_OK) {
|
||||
// The actual adding is done in this window's onOk function
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CardListBase::parseUrl(String& url, vector<CardP>& out) {
|
||||
size_t j = out.size();
|
||||
size_t pos = url.find("URL=");
|
||||
if (pos != std::string::npos) {
|
||||
url = url.substr(pos+4);
|
||||
}
|
||||
if (!url.StartsWith(_("http"))) return false;
|
||||
|
||||
WebRequestWindow wnd(this, url);
|
||||
if (wnd.ShowModal() == wxID_OK) {
|
||||
const String& content_type = wnd.out.GetContentType();
|
||||
if (content_type.StartsWith(_("image"))) {
|
||||
Image img(*wnd.out.GetStream());
|
||||
if (img.IsOk()) {
|
||||
parseImage(img, out);
|
||||
}
|
||||
else {
|
||||
queue_message(MESSAGE_ERROR, _ERROR_("web request corrupted"));
|
||||
}
|
||||
}
|
||||
else if (content_type.StartsWith(_("text"))) {
|
||||
String text = wnd.out.AsString();
|
||||
parseText(text, out);
|
||||
}
|
||||
else {
|
||||
queue_message(MESSAGE_ERROR, _ERROR_("web request unsupported format"));
|
||||
}
|
||||
}
|
||||
return j < out.size();
|
||||
}
|
||||
|
||||
bool CardListBase::parseFiles(wxArrayString& filenames, vector<CardP>& out) {
|
||||
size_t j = out.size();
|
||||
for (size_t i = 0; i < filenames.size(); i++) {
|
||||
// if it's an image file, try to get meta_data
|
||||
Image image_file;
|
||||
image_file.SetLoadFlags(image_file.GetLoadFlags() & ~wxImage::Load_Verbose);
|
||||
if (image_file.LoadFile(filenames[i])) {
|
||||
parseImage(image_file, out);
|
||||
} else {
|
||||
// if it's an url, request the data
|
||||
std::ifstream ifs(filenames[i].ToStdString());
|
||||
if (ifs.bad() || ifs.fail() || !ifs.good() || !ifs.is_open()) continue;
|
||||
std::string content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
|
||||
wxString text(content);
|
||||
if (!parseUrl(text, out)) parseText(text, out);
|
||||
}
|
||||
}
|
||||
return j < out.size();
|
||||
}
|
||||
|
||||
bool CardListBase::parseImage(Image& image, vector<CardP>& out) {
|
||||
size_t j = out.size();
|
||||
if (image.HasOption(wxIMAGE_OPTION_PNG_DESCRIPTION)) {
|
||||
parseText(image.GetOption(wxIMAGE_OPTION_PNG_DESCRIPTION), out);
|
||||
// crop image rects to populate image fields
|
||||
for (; j < out.size(); j++) {
|
||||
CardP& card = out[j];
|
||||
for (IndexMap<FieldP, ValueP>::iterator it = card->data.begin(); it != card->data.end(); it++) {
|
||||
ImageValue* value = dynamic_cast<ImageValue*>(it->get());
|
||||
if (value && !value->filename.empty()) {
|
||||
wxRect rect = value->filename.getExternalRect();
|
||||
if (rect.width > 0 && rect.height > 0) {
|
||||
Image& img = image.GetSubImage(rect);
|
||||
LocalFileName filename = set->newFileName((*it)->fieldP->name, settings.internal_image_extension ? _(".png") : _("")); // a new unique name in the package
|
||||
img.SaveFile(set->nameOut(filename), wxBITMAP_TYPE_PNG);
|
||||
value->filename = filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return j < out.size();
|
||||
}
|
||||
|
||||
bool CardListBase::parseText(String& text, vector<CardP>& out) {
|
||||
size_t j = out.size();
|
||||
if (size_t pos = text.find("<mse-data-start>") != wxString::npos) {
|
||||
text = text.substr(pos + 15, text.find("<mse-data-end>") - pos - 15);
|
||||
}
|
||||
try {
|
||||
ScriptValueP& sv = json_to_mse(text, set.get());
|
||||
if (sv->type() == SCRIPT_COLLECTION) {
|
||||
if (ScriptCustomCollection* custom = dynamic_cast<ScriptCustomCollection*>(sv.get())) {
|
||||
for (size_t i = 0; i < custom->value.size(); i++) {
|
||||
if (ScriptObject<CardP>* c = dynamic_cast<ScriptObject<CardP>*>(custom->value[i].get())) {
|
||||
out.push_back(make_intrusive<Card>(*c->getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ScriptObject<CardP>* c = dynamic_cast<ScriptObject<CardP>*>(sv.get())) {
|
||||
out.push_back(make_intrusive<Card>(*c->getValue()));
|
||||
}
|
||||
} catch (...) {}
|
||||
return j < out.size();
|
||||
}
|
||||
|
||||
bool CardListBase::parseData() {
|
||||
wxBusyCursor wait;
|
||||
wxDataFormat format = drop_target->data_object->GetReceivedFormat();
|
||||
wxDataObject *data = drop_target->data_object->GetObject(format);
|
||||
vector<CardP> new_cards;
|
||||
|
||||
if (CardsDataObject* card_data = dynamic_cast<CardsDataObject*>(data)) {
|
||||
card_data->getCards(set, new_cards);
|
||||
}
|
||||
else switch (format.GetType())
|
||||
{
|
||||
case wxDF_FILENAME:
|
||||
{
|
||||
wxFileDataObject* file_data = static_cast<wxFileDataObject*>(data);
|
||||
wxArrayString filenames = file_data->GetFilenames();
|
||||
parseFiles(filenames, new_cards);
|
||||
}
|
||||
break;
|
||||
|
||||
case wxDF_PNG:
|
||||
{
|
||||
wxImageDataObject* image_data = static_cast<wxImageDataObject*>(data);
|
||||
Image image = image_data->GetImage();
|
||||
parseImage(image, new_cards);
|
||||
}
|
||||
break;
|
||||
|
||||
case wxDF_BITMAP:
|
||||
{
|
||||
wxBitmapDataObject* bitmap_data = static_cast<wxBitmapDataObject*>(data);
|
||||
wxBitmap bitmap = bitmap_data->GetBitmap();
|
||||
Image image = bitmap.ConvertToImage();
|
||||
parseImage(image, new_cards);
|
||||
}
|
||||
break;
|
||||
|
||||
case wxDF_UNICODETEXT:
|
||||
case wxDF_TEXT:
|
||||
case wxDF_HTML:
|
||||
{
|
||||
wxTextDataObject* text_data = static_cast<wxTextDataObject*>(data);
|
||||
String text = text_data->GetText();
|
||||
if (!parseUrl(text, new_cards)) parseText(text, new_cards);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
queue_message(MESSAGE_ERROR, _ERROR_("unknown data format"));
|
||||
}
|
||||
}
|
||||
|
||||
if (new_cards.size() > 0) {
|
||||
set->actions.addAction(make_unique<AddCardAction>(ADD, *set, new_cards));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// --------------------------------------------------- : CardListBase : Card linking
|
||||
|
||||
bool CardListBase::canLink() const {
|
||||
@@ -229,23 +406,6 @@ bool CardListBase::doUnlink(CardP unlinked_card) {
|
||||
set->actions.addAction(make_unique<UnlinkCardsAction>(*set, getCard(), unlinked_card));
|
||||
return true;
|
||||
}
|
||||
bool CardListBase::doAddCSV() {
|
||||
AddCSVWindow wnd(this, set, true);
|
||||
if (wnd.ShowModal() == wxID_OK) {
|
||||
// The actual adding is done in this window's onOk function
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CardListBase::doAddJSON() {
|
||||
AddJSONWindow wnd(this, set, true);
|
||||
if (wnd.ShowModal() == wxID_OK) {
|
||||
// The actual adding is done in this window's onOk function
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardListBase : Building the list
|
||||
|
||||
@@ -347,7 +507,7 @@ void CardListBase::storeColumns() {
|
||||
// store sorting
|
||||
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||
if (sort_by_column >= 0) gs.sort_cards_by = column_fields.at(sort_by_column)->name;
|
||||
else gs.sort_cards_by = wxEmptyString;
|
||||
else gs.sort_cards_by = _("");
|
||||
gs.sort_cards_ascending = sort_ascending;
|
||||
}
|
||||
|
||||
@@ -373,11 +533,11 @@ void CardListBase::selectColumns() {
|
||||
String CardListBase::OnGetItemText(long pos, long col) const {
|
||||
if (col < 0 || (size_t)col >= column_fields.size()) {
|
||||
// wx may give us non existing columns!
|
||||
return wxEmptyString;
|
||||
return _("");
|
||||
}
|
||||
ValueP val = getCard(pos)->data[column_fields[col]];
|
||||
if (val) return val->toString();
|
||||
else return wxEmptyString;
|
||||
else return _("");
|
||||
}
|
||||
|
||||
int CardListBase::OnGetItemImage(long pos) const {
|
||||
@@ -431,7 +591,16 @@ void CardListBase::onChar(wxKeyEvent& ev) {
|
||||
} else {
|
||||
ev.Skip();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CardListBase::onBeginDrag(wxListEvent&) {
|
||||
vector<CardP> cards;
|
||||
getSelection(cards);
|
||||
CardsOnClipboard* card_data = new CardsOnClipboard(set, cards);
|
||||
wxDropSource drag_source(this);
|
||||
drag_source.SetData(*card_data);
|
||||
drag_source.DoDragDrop(wxDrag_CopyOnly);
|
||||
}
|
||||
|
||||
void CardListBase::onDrag(wxMouseEvent& ev) {
|
||||
ev.Skip();
|
||||
@@ -473,14 +642,36 @@ void CardListBase::onItemActivate(wxListEvent& ev) {
|
||||
sendEvent(EVENT_CARD_ACTIVATE);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardListDropTarget
|
||||
|
||||
CardListDropTarget::CardListDropTarget(CardListBase* card_list)
|
||||
: card_list(card_list)
|
||||
{
|
||||
data_object = new wxDataObjectComposite();
|
||||
data_object->Add(new CardsDataObject(), true);
|
||||
data_object->Add(new wxFileDataObject());
|
||||
data_object->Add(new wxImageDataObject());
|
||||
data_object->Add(new wxTextDataObject());
|
||||
SetDataObject(data_object);
|
||||
}
|
||||
|
||||
CardListDropTarget::~CardListDropTarget() {}
|
||||
|
||||
wxDragResult CardListDropTarget::OnData(wxCoord x, wxCoord y, wxDragResult defaultDragResult) {
|
||||
if (!GetData()) return wxDragNone;
|
||||
if (!card_list->parseData()) return wxDragError;
|
||||
return wxDragCopy;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardListBase : Event table
|
||||
|
||||
BEGIN_EVENT_TABLE(CardListBase, ItemList)
|
||||
EVT_LIST_COL_RIGHT_CLICK (wxID_ANY, CardListBase::onColumnRightClick)
|
||||
EVT_LIST_COL_END_DRAG (wxID_ANY, CardListBase::onColumnResize)
|
||||
EVT_LIST_ITEM_ACTIVATED (wxID_ANY, CardListBase::onItemActivate)
|
||||
EVT_CHAR ( CardListBase::onChar)
|
||||
EVT_MOTION ( CardListBase::onDrag)
|
||||
EVT_MENU (ID_SELECT_COLUMNS, CardListBase::onSelectColumns)
|
||||
EVT_CONTEXT_MENU ( CardListBase::onContextMenu)
|
||||
EVT_LIST_COL_RIGHT_CLICK (wxID_ANY, CardListBase::onColumnRightClick)
|
||||
EVT_LIST_COL_END_DRAG (wxID_ANY, CardListBase::onColumnResize)
|
||||
EVT_LIST_ITEM_ACTIVATED (wxID_ANY, CardListBase::onItemActivate)
|
||||
EVT_LIST_BEGIN_DRAG (wxID_ANY, CardListBase::onBeginDrag)
|
||||
EVT_CHAR ( CardListBase::onChar)
|
||||
EVT_MOTION ( CardListBase::onDrag)
|
||||
EVT_MENU (ID_SELECT_COLUMNS, CardListBase::onSelectColumns)
|
||||
EVT_CONTEXT_MENU ( CardListBase::onContextMenu)
|
||||
END_EVENT_TABLE ()
|
||||
|
||||
@@ -12,10 +12,12 @@
|
||||
#include <gui/control/item_list.hpp>
|
||||
#include <data/card.hpp>
|
||||
#include <data/set.hpp>
|
||||
#include <wx/dnd.h>
|
||||
|
||||
DECLARE_POINTER_TYPE(ChoiceField);
|
||||
DECLARE_POINTER_TYPE(Field);
|
||||
class CardListBase;
|
||||
class CardListDropTarget;
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
@@ -67,8 +69,10 @@ public:
|
||||
inline CardP getCard() const { return static_pointer_cast<Card>(selected_item); }
|
||||
inline void setCard(const CardP& card, bool event = false) { selectItem(card, true, event); }
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
|
||||
// --------------------------------------------------- : Clipboard and Drag'n'Drop
|
||||
|
||||
CardListDropTarget* drop_target;
|
||||
|
||||
bool canCut() const override;
|
||||
bool canCopy() const override;
|
||||
bool canPaste() const override;
|
||||
@@ -80,6 +84,13 @@ public:
|
||||
bool doDelete() override;
|
||||
bool doAddCSV();
|
||||
bool doAddJSON();
|
||||
|
||||
// Look for cards inside some given data
|
||||
bool parseData();
|
||||
bool parseUrl (String& url, vector<CardP>& out);
|
||||
bool parseFiles(wxArrayString& filenames, vector<CardP>& out);
|
||||
bool parseText (String& text, vector<CardP>& out);
|
||||
bool parseImage(Image& image, vector<CardP>& out);
|
||||
|
||||
// --------------------------------------------------- : Card linking
|
||||
|
||||
@@ -135,7 +146,7 @@ private:
|
||||
vector<FieldP> column_fields; ///< The field to use for each column (by column index)
|
||||
FieldP alternate_sort_field; ///< Second field to sort by, if the column doesn't suffice
|
||||
|
||||
mutable wxListItemAttr item_attr; // for OnGetItemAttr
|
||||
mutable wxListItemAttr item_attr; ///< for OnGetItemAttr
|
||||
|
||||
public:
|
||||
/// Open a dialog for selecting columns to be shown
|
||||
@@ -152,7 +163,22 @@ private:
|
||||
void onItemActivate (wxListEvent&);
|
||||
void onSelectColumns (wxCommandEvent&);
|
||||
void onChar (wxKeyEvent&);
|
||||
void onBeginDrag (wxListEvent&);
|
||||
void onDrag (wxMouseEvent&);
|
||||
void onContextMenu (wxContextMenuEvent&);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : Drag'n'Drop
|
||||
|
||||
class CardListDropTarget : public wxDropTarget {
|
||||
public:
|
||||
CardListDropTarget(CardListBase* card_list);
|
||||
~CardListDropTarget();
|
||||
|
||||
wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult defaultDragResult) override;
|
||||
|
||||
wxDataObjectComposite* data_object; ///< the object that acquires the data from the Clipboard or a Drag'n'Drop
|
||||
private:
|
||||
CardListBase* card_list; ///< the card list we are the drop target of
|
||||
};
|
||||
|
||||
|
||||
@@ -1172,10 +1172,10 @@ bool GraphControl::hasSelection(size_t axis) const {
|
||||
return axis < current_item.size() && current_item[axis] >= 0;
|
||||
}
|
||||
String GraphControl::getSelection(size_t axis) const {
|
||||
if (!graph || axis >= current_item.size() || axis >= graph->getData()->axes.size()) return wxEmptyString;
|
||||
if (!graph || axis >= current_item.size() || axis >= graph->getData()->axes.size()) return _("");
|
||||
GraphAxis& a = *graph->getData()->axes[axis];
|
||||
int i = current_item[axis];
|
||||
if (i == -1 || (size_t)i >= a.groups.size()) return wxEmptyString;
|
||||
if (i == -1 || (size_t)i >= a.groups.size()) return _("");
|
||||
return a.groups[current_item[axis]].name;
|
||||
}
|
||||
vector<int> GraphControl::getSelectionIndices() const {
|
||||
|
||||
@@ -192,7 +192,7 @@ int KeywordList::usage(const Keyword& kw) const {
|
||||
// ----------------------------------------------------------------------------- : KeywordList : Item text
|
||||
|
||||
String KeywordList::OnGetItemText (long pos, long col) const {
|
||||
if (sorted_list.size() == 0) return wxEmptyString;
|
||||
if (sorted_list.size() == 0) return _("");
|
||||
|
||||
const Keyword& kw = *getKeyword(pos);
|
||||
switch(col) {
|
||||
@@ -218,7 +218,7 @@ String KeywordList::OnGetItemText (long pos, long col) const {
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
default: return wxEmptyString;
|
||||
default: return _("");
|
||||
}
|
||||
}
|
||||
int KeywordList::OnGetItemImage(long pos) const {
|
||||
|
||||
@@ -24,7 +24,7 @@ bool PackageData::contains(QuickFilterPart const& query) const {
|
||||
PackageList::PackageList(Window* parent, int id, int direction, bool always_focused)
|
||||
: GalleryList(parent, id, direction, always_focused)
|
||||
{
|
||||
item_size = subcolumns[0].size = wxSize(125, 150);
|
||||
item_size = subcolumns[0].size = wxSize(130, 150);
|
||||
SetThemeEnabled(true);
|
||||
}
|
||||
|
||||
@@ -42,16 +42,24 @@ void PackageList::drawItem(DC& dc, int x, int y, size_t item) {
|
||||
if (d->image.Ok()) {
|
||||
dc.DrawBitmap(d->image, x + int(align_delta_x(ALIGN_CENTER, item_size.x, d->image.GetWidth())), y + 3, true);
|
||||
}
|
||||
// draw short name
|
||||
dc.SetFont(wxFont(12,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_("Arial")));
|
||||
// draw short name
|
||||
wxFont font = wxFont(11,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_("Arial"));
|
||||
dc.SetFont(font);
|
||||
dc.GetTextExtent(capitalize(d->package->short_name), &w, &h);
|
||||
pos = align_in_rect(ALIGN_CENTER, RealSize(w,h), rect);
|
||||
dc.DrawText(capitalize(d->package->short_name), max(x+1,(int)pos.x), (int)pos.y + 110);
|
||||
// draw name
|
||||
dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
|
||||
dc.GetTextExtent(d->package->full_name, &w, &h);
|
||||
// draw full name
|
||||
font.SetPointSize(9);
|
||||
font.SetWeight(wxFONTWEIGHT_NORMAL);
|
||||
dc.SetFont(font);
|
||||
dc.GetTextExtent(d->package->full_name, &w, &h);
|
||||
if (w > item_size.x) {
|
||||
font.SetPointSize(max(7,9*item_size.x/w));
|
||||
dc.SetFont(font);
|
||||
dc.GetTextExtent(d->package->full_name, &w, &h);
|
||||
}
|
||||
RealPoint text_pos = align_in_rect(ALIGN_CENTER, RealSize(w,h), rect);
|
||||
dc.DrawText(d->package->full_name, max(x+1,(int)text_pos.x), (int)text_pos.y + 130);
|
||||
dc.DrawText(d->package->full_name, max(x+1,(int)text_pos.x), (int)(text_pos.y + 130 + 9-font.GetPointSize()));
|
||||
dc.DestroyClippingRegion();
|
||||
}
|
||||
|
||||
|
||||
+16
-17
@@ -40,10 +40,10 @@ CardsPanel::CardsPanel(Window* parent, int id)
|
||||
link_viewer_2 = new CardViewer(this, ID_CARD_LINK_VIEWER);
|
||||
link_viewer_3 = new CardViewer(this, ID_CARD_LINK_VIEWER);
|
||||
link_viewer_4 = new CardViewer(this, ID_CARD_LINK_VIEWER);
|
||||
link_relation_1 = new wxStaticText(this, ID_CARD_LINK_RELATION_1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
|
||||
link_relation_2 = new wxStaticText(this, ID_CARD_LINK_RELATION_2, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
|
||||
link_relation_3 = new wxStaticText(this, ID_CARD_LINK_RELATION_3, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
|
||||
link_relation_4 = new wxStaticText(this, ID_CARD_LINK_RELATION_4, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
|
||||
link_relation_1 = new wxStaticText(this, ID_CARD_LINK_RELATION_1, _(""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
|
||||
link_relation_2 = new wxStaticText(this, ID_CARD_LINK_RELATION_2, _(""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
|
||||
link_relation_3 = new wxStaticText(this, ID_CARD_LINK_RELATION_3, _(""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
|
||||
link_relation_4 = new wxStaticText(this, ID_CARD_LINK_RELATION_4, _(""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
|
||||
link_select = new wxButton(this, ID_CARD_LINK_SELECT, _BUTTON_("link select"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
||||
link_unlink_1 = new wxButton(this, ID_CARD_LINK_UNLINK_1, _BUTTON_("unlink"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
||||
link_unlink_2 = new wxButton(this, ID_CARD_LINK_UNLINK_2, _BUTTON_("unlink"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
||||
@@ -56,7 +56,8 @@ CardsPanel::CardsPanel(Window* parent, int id)
|
||||
collapse_notes = new HoverButton(nodes_panel, ID_COLLAPSE_NOTES, _("btn_collapse"), Color(), false);
|
||||
collapse_notes->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES);
|
||||
filter = nullptr;
|
||||
editor->next_in_tab_order = card_list;
|
||||
editor->next_in_tab_order = card_list;
|
||||
SetDropTarget(card_list->drop_target);
|
||||
wxFont font = link_relation_1->GetFont();
|
||||
font.SetWeight(wxFONTWEIGHT_BOLD);
|
||||
link_relation_1->SetFont(font);
|
||||
@@ -537,14 +538,12 @@ bool CardsPanel::canPaste() const {
|
||||
else return false;
|
||||
}
|
||||
void CardsPanel::doPaste() {
|
||||
if (card_list->canPaste()) {
|
||||
card_list->doPaste();
|
||||
} else {
|
||||
int id = focused_control(this);
|
||||
if (id == ID_EDITOR) editor->doPaste();
|
||||
else if (id == ID_CARD_LINK_EDITOR) link_editor->doPaste();
|
||||
else if (id == ID_NOTES) notes->doPaste();
|
||||
}
|
||||
if (card_list->doPaste()) return;
|
||||
|
||||
int id = focused_control(this);
|
||||
if (id == ID_EDITOR) editor->doPaste();
|
||||
else if (id == ID_CARD_LINK_EDITOR) link_editor->doPaste();
|
||||
else if (id == ID_NOTES) notes->doPaste();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Text selection
|
||||
@@ -657,7 +656,7 @@ void CardsPanel::selectCard(const CardP& card) {
|
||||
link_box_1->Show(false);
|
||||
link_editor->setCard(card);
|
||||
link_viewer_1->setCard(card);
|
||||
//link_relation_1->SetLabel(wxEmptyString);
|
||||
//link_relation_1->SetLabel(_(""));
|
||||
}
|
||||
if (count >= 2) {
|
||||
link_box_2->Show(true);
|
||||
@@ -668,7 +667,7 @@ void CardsPanel::selectCard(const CardP& card) {
|
||||
} else {
|
||||
link_box_2->Show(false);
|
||||
link_viewer_2->setCard(card);
|
||||
//link_relation_2->SetLabel(wxEmptyString);
|
||||
//link_relation_2->SetLabel(_(""));
|
||||
}
|
||||
if (count >= 3) {
|
||||
link_box_3->Show(true);
|
||||
@@ -679,7 +678,7 @@ void CardsPanel::selectCard(const CardP& card) {
|
||||
} else {
|
||||
link_box_3->Show(false);
|
||||
link_viewer_3->setCard(card);
|
||||
//link_relation_3->SetLabel(wxEmptyString);
|
||||
//link_relation_3->SetLabel(_(""));
|
||||
}
|
||||
if (count >= 4) {
|
||||
link_box_4->Show(true);
|
||||
@@ -690,7 +689,7 @@ void CardsPanel::selectCard(const CardP& card) {
|
||||
} else {
|
||||
link_box_4->Show(false);
|
||||
link_viewer_4->setCard(card);
|
||||
//link_relation_4->SetLabel(wxEmptyString);
|
||||
//link_relation_4->SetLabel(_(""));
|
||||
}
|
||||
if (count >= 5) {
|
||||
queue_message(MESSAGE_WARNING, "DEBUG More than 4 linked cards found for card: " + card->identification());
|
||||
|
||||
@@ -257,7 +257,7 @@ String KeywordsPanel::runRefScript(int find_i) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return wxEmptyString;
|
||||
return _("");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Clipboard
|
||||
|
||||
@@ -79,8 +79,8 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
|
||||
menuBar->Append(menuFile, _MENU_("file"));
|
||||
|
||||
auto menuEdit = new wxMenu();
|
||||
add_menu_item(menuEdit, ID_EDIT_UNDO, settings.darkModePrefix() + "undo", _MENU_1_("undo",wxEmptyString), _HELP_("undo"));
|
||||
add_menu_item(menuEdit, ID_EDIT_REDO, settings.darkModePrefix() + "redo", _MENU_1_("redo",wxEmptyString), _HELP_("redo"));
|
||||
add_menu_item(menuEdit, ID_EDIT_UNDO, settings.darkModePrefix() + "undo", _MENU_1_("undo",_("")), _HELP_("undo"));
|
||||
add_menu_item(menuEdit, ID_EDIT_REDO, settings.darkModePrefix() + "redo", _MENU_1_("redo",_("")), _HELP_("redo"));
|
||||
menuEdit->AppendSeparator();
|
||||
add_menu_item_tr(menuEdit, ID_EDIT_CUT, settings.darkModePrefix() + "cut", "cut");
|
||||
add_menu_item_tr(menuEdit, ID_EDIT_COPY, "copy", "copy");
|
||||
@@ -554,7 +554,7 @@ void SetWindow::updateRecentSets() {
|
||||
// add new item
|
||||
wxMenu* file_menu = mb->GetMenu(0);
|
||||
size_t pos = file_menu->GetMenuItemCount() - 2; // last two items are separator and exit
|
||||
file_menu->Insert(pos, ID_FILE_RECENT + i, String(_("&")) << (i+1) << _(" ") << file, wxEmptyString);
|
||||
file_menu->Insert(pos, ID_FILE_RECENT + i, String(_("&")) << (i+1) << _(" ") << file, _(""));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ void SymbolWindow::init(Window* parent, SymbolP symbol) {
|
||||
menuBar->Append(menuFile, _MENU_("file"));
|
||||
|
||||
auto menuEdit = new wxMenu();
|
||||
add_menu_item(menuEdit, ID_EDIT_UNDO, settings.darkModePrefix() + "undo", _MENU_1_("undo",wxEmptyString), _HELP_("undo"));
|
||||
add_menu_item(menuEdit, ID_EDIT_REDO, settings.darkModePrefix() + "redo", _MENU_1_("redo",wxEmptyString), _HELP_("redo"));
|
||||
add_menu_item(menuEdit, ID_EDIT_UNDO, settings.darkModePrefix() + "undo", _MENU_1_("undo",_("")), _HELP_("undo"));
|
||||
add_menu_item(menuEdit, ID_EDIT_REDO, settings.darkModePrefix() + "redo", _MENU_1_("redo",_("")), _HELP_("redo"));
|
||||
menuEdit->AppendSeparator();
|
||||
add_menu_item_tr(menuEdit, ID_EDIT_GROUP, "group", "group");
|
||||
add_menu_item_tr(menuEdit, ID_EDIT_UNGROUP, "ungroup", "ungroup");
|
||||
@@ -111,8 +111,8 @@ void SymbolWindow::init(Window* parent, SymbolP symbol) {
|
||||
wxToolBar* tb = CreateToolBar(wxTB_FLAT | wxNO_BORDER | wxTB_HORIZONTAL | wxTB_TEXT);
|
||||
add_tool_tr(tb, ID_FILE_STORE, "apply", "store_symbol", true);
|
||||
tb->AddSeparator();
|
||||
add_tool(tb, ID_EDIT_UNDO, settings.darkModePrefix() + "undo", _TOOL_("undo"), _TOOLTIP_1_("undo",wxEmptyString), _HELP_("undo"));
|
||||
add_tool(tb, ID_EDIT_REDO, settings.darkModePrefix() + "redo", _TOOL_("redo"), _TOOLTIP_1_("redo",wxEmptyString), _HELP_("redo"));
|
||||
add_tool(tb, ID_EDIT_UNDO, settings.darkModePrefix() + "undo", _TOOL_("undo"), _TOOLTIP_1_("undo",_("")), _HELP_("undo"));
|
||||
add_tool(tb, ID_EDIT_REDO, settings.darkModePrefix() + "redo", _TOOL_("redo"), _TOOLTIP_1_("redo",_("")), _HELP_("redo"));
|
||||
tb->AddSeparator();
|
||||
add_tool_tr(tb, ID_VIEW_GRID, "grid", "grid", true, wxITEM_CHECK);
|
||||
add_tool_tr(tb, ID_VIEW_GRID_SNAP, "grid_snap", "snap", true, wxITEM_CHECK);
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ struct FakeEvtHandlerClass : public wxEvtHandler {
|
||||
ev.Skip();
|
||||
}
|
||||
void onControlLeave(wxMouseEvent& ev) {
|
||||
set_status_text((wxWindow*)ev.GetEventObject(), wxEmptyString);
|
||||
set_status_text((wxWindow*)ev.GetEventObject(), _(""));
|
||||
ev.Skip();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,10 +58,7 @@ void ImageValueEditor::sliceImage(const Image& image, const String& filename, co
|
||||
// clicked ok?
|
||||
if (s.ShowModal() == wxID_OK) {
|
||||
// store the image into the set
|
||||
StyleP style = field().styleP;
|
||||
String rect = style ? style->getRect() : _("");
|
||||
String extension = settings.internal_image_extension ? _(".png") : _("");
|
||||
LocalFileName new_image_file = getLocalPackage().newFileName(field().name, rect + extension); // a new unique name in the package
|
||||
LocalFileName new_image_file = getLocalPackage().newFileName(field().name, settings.internal_image_extension ? _(".png") : _("")); // a new unique name in the package
|
||||
|
||||
// Specify a desired size based on the stylesheet and a scale multiplier defined within the user's settings.
|
||||
// Storing at a greater than 100% resolution allows for better exports >100%, but may change how images look when filters (sharpen) are applied.
|
||||
|
||||
@@ -459,7 +459,7 @@ bool TextValueEditor::onChar(wxKeyEvent& ev) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
replaceSelection(wxEmptyString, _ACTION_("backspace"));
|
||||
replaceSelection(_(""), _ACTION_("backspace"));
|
||||
return true;
|
||||
case WXK_DELETE:
|
||||
if (selection_start == selection_end) {
|
||||
@@ -470,7 +470,7 @@ bool TextValueEditor::onChar(wxKeyEvent& ev) {
|
||||
moveSelection(TYPE_CURSOR, nextCharBoundary(selection_end), true, MOVE_RIGHT);
|
||||
}
|
||||
}
|
||||
replaceSelection(wxEmptyString, _ACTION_("delete"));
|
||||
replaceSelection(_(""), _ACTION_("delete"));
|
||||
return true;
|
||||
case WXK_RETURN:
|
||||
if (field().multi_line) {
|
||||
@@ -581,7 +581,7 @@ bool TextValueEditor::onContextMenu(wxMenu& m, wxContextMenuEvent& ev) {
|
||||
} else {
|
||||
int i = 0;
|
||||
FOR_EACH(s,suggestions) {
|
||||
m.Insert(i, ID_SPELLING_SUGGEST + i, s, wxEmptyString);
|
||||
m.Insert(i, ID_SPELLING_SUGGEST + i, s, _(""));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -797,7 +797,7 @@ bool TextValueEditor::doCopy() {
|
||||
}
|
||||
|
||||
bool TextValueEditor::doDelete() {
|
||||
replaceSelection(wxEmptyString, _ACTION_("cut"));
|
||||
replaceSelection(_(""), _ACTION_("cut"));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) Twan van Laarhoven and the other MSE developers |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <gui/web_request_window.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : WebRequestWindow
|
||||
|
||||
WebRequestWindow::WebRequestWindow(Window* parent, const String& url, bool sizer)
|
||||
: wxDialog(parent, wxID_ANY, _TITLE_("web request"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||
{
|
||||
// init controls
|
||||
info = new wxStaticText(this, -1, _LABEL_("web request address"));
|
||||
address = new wxStaticText(this, -1, url);
|
||||
gauge = new wxGauge(this, wxID_ANY, 0);
|
||||
// init sizers
|
||||
if (sizer) {
|
||||
wxSizer* s = new wxBoxSizer(wxVERTICAL);
|
||||
s->Add(info, 0, wxALL, 8);
|
||||
s->Add(address, 0, (wxALL & ~wxTOP), 4);
|
||||
s->Add(gauge, 0, wxEXPAND | wxALL, 8);
|
||||
s->Add(CreateButtonSizer(wxCANCEL), 1, wxEXPAND, 8);
|
||||
s->SetSizeHints(this);
|
||||
SetSizer(s);
|
||||
}
|
||||
|
||||
// create web request
|
||||
request = wxWebSession::GetDefault().CreateRequest(this, url);
|
||||
if (!request.IsOk() ) {
|
||||
onFail(_ERROR_("web request cant create"));
|
||||
return;
|
||||
}
|
||||
|
||||
// bind request events
|
||||
Bind(wxEVT_WEBREQUEST_STATE, [this](wxWebRequestEvent& evt) {
|
||||
switch (evt.GetState())
|
||||
{
|
||||
// request completed
|
||||
case wxWebRequest::State_Completed:
|
||||
{
|
||||
onComplete(evt);
|
||||
break;
|
||||
}
|
||||
// request failed
|
||||
case wxWebRequest::State_Failed:
|
||||
onFail(evt.GetErrorDescription());
|
||||
break;
|
||||
}
|
||||
});
|
||||
Bind(wxEVT_WEBREQUEST_DATA, [this](wxWebRequestEvent& evt) {
|
||||
// request updated
|
||||
onUpdate(evt);
|
||||
});
|
||||
|
||||
// start request
|
||||
request.Start();
|
||||
}
|
||||
|
||||
void WebRequestWindow::onUpdate(wxWebRequestEvent& evt) {
|
||||
off_t expected_bytes = request.GetBytesExpectedToReceive();
|
||||
off_t bytes = request.GetBytesReceived();
|
||||
if (expected_bytes > 0) {
|
||||
gauge->SetRange(expected_bytes);
|
||||
gauge->SetValue(bytes);
|
||||
}
|
||||
else {
|
||||
gauge->Pulse();
|
||||
}
|
||||
}
|
||||
|
||||
void WebRequestWindow::onComplete(wxWebRequestEvent& evt) {
|
||||
out = evt.GetResponse();
|
||||
if (out.IsOk()) {
|
||||
EndModal(wxID_OK);
|
||||
}
|
||||
else {
|
||||
onFail(_ERROR_("web request corrupted"));
|
||||
}
|
||||
}
|
||||
|
||||
void WebRequestWindow::onFail(const String& message) {
|
||||
info->SetLabel(_ERROR_("web request failed"));
|
||||
address->SetLabel(message);
|
||||
}
|
||||
|
||||
void WebRequestWindow::onCancel(wxCommandEvent&) {
|
||||
EndModal(wxID_CANCEL);
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(WebRequestWindow, wxDialog)
|
||||
EVT_BUTTON (wxID_CANCEL, WebRequestWindow::onCancel)
|
||||
END_EVENT_TABLE ()
|
||||
@@ -0,0 +1,39 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) Twan van Laarhoven and the other MSE developers |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
#pragma once
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <wx/gauge.h>
|
||||
#include <wx/webrequest.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : WebRequestWindow
|
||||
|
||||
/// A window for displaying the progression of a WebRequest and returning the WebResponse
|
||||
class WebRequestWindow : public wxDialog {
|
||||
public:
|
||||
WebRequestWindow(Window* parent, const String& url, bool sizer=true);
|
||||
|
||||
wxWebResponse out;
|
||||
|
||||
protected:
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
wxStaticText* info, *address;
|
||||
wxGauge* gauge;
|
||||
wxWebRequest request;
|
||||
|
||||
void onUpdate(wxWebRequestEvent& evt);
|
||||
|
||||
void onComplete(wxWebRequestEvent& evt);
|
||||
|
||||
void onFail(const String& message);
|
||||
|
||||
void onCancel(wxCommandEvent&);
|
||||
|
||||
};
|
||||
@@ -126,7 +126,7 @@ void WelcomeWindow::onSelectLanguage(wxCommandEvent&) {
|
||||
}
|
||||
|
||||
void WelcomeWindow::onOpenSet(wxCommandEvent&) {
|
||||
wxFileDialog* dlg = new wxFileDialog(this, _TITLE_("open set"), settings.default_set_dir, wxEmptyString, import_formats(), wxFD_OPEN);
|
||||
wxFileDialog* dlg = new wxFileDialog(this, _TITLE_("open set"), settings.default_set_dir, _(""), import_formats(), wxFD_OPEN);
|
||||
if (dlg->ShowModal() == wxID_OK) {
|
||||
settings.default_set_dir = dlg->GetDirectory();
|
||||
wxBusyCursor wait;
|
||||
|
||||
Reference in New Issue
Block a user