Clean up pointer use:

* Use unique_ptr for Actions instead of manual memory management
 * Use unique_ptr in KeywordDatabase
 * Use unique_ptr instead of shared_ptr for file formats
 * Don't pass shared_ptr to Reader/Writer, use references instead
Also
 * Switch to C++17 so we can use map::try_emplace
This commit is contained in:
Twan van Laarhoven
2020-04-25 21:30:05 +02:00
parent 708b4389a0
commit 64ea1d7322
57 changed files with 363 additions and 385 deletions
+2 -2
View File
@@ -58,8 +58,8 @@ bool DataEditor::viewerIsCurrent(const ValueViewer* viewer) const {
}
void DataEditor::addAction(Action* action) {
set->actions.addAction(action);
void DataEditor::addAction(unique_ptr<Action> action) {
set->actions.addAction(move(action));
}
// ----------------------------------------------------------------------------- : Selection
+1 -1
View File
@@ -27,7 +27,7 @@ class DataEditor : public CardViewer {
virtual DrawWhat drawWhat(const ValueViewer*) const;
virtual bool viewerIsCurrent(const ValueViewer*) const;
virtual void addAction(Action* action);
virtual void addAction(unique_ptr<Action> action);
inline SetP getSetForActions() { return set; }
// --------------------------------------------------- : Selection
+3 -3
View File
@@ -179,7 +179,7 @@ bool CardListBase::doPaste() {
ok = data.getCards(set, new_cards);
if (!ok) return false;
// add card to set
set->actions.addAction(new AddCardAction(ADD, *set, new_cards));
set->actions.addAction(make_unique<AddCardAction>(ADD, *set, new_cards));
return true;
}
bool CardListBase::doDelete() {
@@ -188,7 +188,7 @@ bool CardListBase::doDelete() {
getSelection(cards_to_delete);
if (cards_to_delete.empty()) return false;
// delete cards
set->actions.addAction(new AddCardAction(REMOVE, *set, cards_to_delete));
set->actions.addAction(make_unique<AddCardAction>(REMOVE, *set, cards_to_delete));
return true;
}
@@ -378,7 +378,7 @@ void CardListBase::onDrag(wxMouseEvent& ev) {
findSelectedItemPos();
if (item != selected_item_pos) {
// move card in the set
set->actions.addAction(new ReorderCardsAction(*set, item, selected_item_pos));
set->actions.addAction(make_unique<ReorderCardsAction>(*set, item, selected_item_pos));
}
ev.Skip(false);
}
+2 -2
View File
@@ -132,14 +132,14 @@ bool KeywordList::doPaste() {
// add keyword to set
KeywordP keyword = data.getKeyword(set);
if (keyword) {
set->actions.addAction(new AddKeywordAction(ADD, *set, keyword));
set->actions.addAction(make_unique<AddKeywordAction>(ADD, *set, keyword));
return true;
} else {
return false;
}
}
bool KeywordList::doDelete() {
set->actions.addAction(new AddKeywordAction(REMOVE, *set, getKeyword()));
set->actions.addAction(make_unique<AddKeywordAction>(REMOVE, *set, getKeyword()));
return true;
}
+1 -1
View File
@@ -73,7 +73,7 @@ void PackageList::showData(const String& pattern) {
FOR_EACH(p, matching) {
// open image
PROFILER(_("load package image"));
InputStreamP stream = p->openIconFile();
auto stream = p->openIconFile();
Image img;
Bitmap bmp;
if (stream && image_load_file(img, *stream)) {
+4 -5
View File
@@ -82,15 +82,14 @@ bool DownloadableInstallerList::download() {
wxThread::ExitCode DownloadableInstallerList::Thread::Entry() {
// open url
wxURL url(settings.installer_list_url);
wxInputStream* isP = url.GetInputStream();
if (!isP) {
unique_ptr<wxInputStream> stream(url.GetInputStream());
if (!stream) {
wxMutexLocker l(downloadable_installers.lock);
downloadable_installers.status = DONE;
return 0;
}
InputStreamP is(isP);
// Read installer list
Reader reader(is, nullptr, _("installers"), true);
Reader reader(*stream, nullptr, _("installers"), true);
vector<DownloadableInstallerP> installers;
reader.handle(_("installers"),installers);
// done
@@ -344,7 +343,7 @@ void PackagesWindow::onOk(wxCommandEvent& ev) {
}
// download installer
wxURL url(ip->installer->installer_url);
wxInputStream* is = url.GetInputStream();
unique_ptr<wxInputStream> is(url.GetInputStream());
if (!is) {
throw Error(_ERROR_2_("can't download installer", ip->description->name, ip->installer->installer_url));
}
+1 -1
View File
@@ -325,7 +325,7 @@ void CardsPanel::onCommand(int id) {
if (card_list->canSelectNext()) card_list->selectNext();
break;
case ID_CARD_ADD:
set->actions.addAction(new AddCardAction(*set));
set->actions.addAction(make_unique<AddCardAction>(*set));
break;
case ID_CARD_REMOVE:
card_list->doDelete();
+2 -2
View File
@@ -180,7 +180,7 @@ void KeywordsPanel::onCommand(int id) {
list->selectNext();
break;
case ID_KEYWORD_ADD:
set->actions.addAction(new AddKeywordAction(*set));
set->actions.addAction(make_unique<AddKeywordAction>(*set));
break;
case ID_KEYWORD_REMOVE:
if (list->canDelete()) {
@@ -370,7 +370,7 @@ void KeywordsPanel::onModeChange(wxCommandEvent& ev) {
if (!list->getKeyword()) return;
int sel = mode->GetSelection();
if (sel >= 0 && (size_t)sel < set->game->keyword_modes.size()) {
set->actions.addAction(new ChangeKeywordModeAction(*list->getKeyword(), set->game->keyword_modes[sel]->name));
set->actions.addAction(make_unique<ChangeKeywordModeAction>(*list->getKeyword(), set->game->keyword_modes[sel]->name));
}
}
+3 -3
View File
@@ -528,7 +528,7 @@ void RandomPackPanel::onCommand(int id) {
case ID_CUSTOM_PACK: {
CustomPackDialog dlg(this, set, PackTypeP(), false);
if (dlg.ShowModal() == wxID_OK) {
set->actions.addAction( new AddPackAction(ADD,*set,dlg.get()) );
set->actions.addAction(make_unique<AddPackAction>(ADD,*set,dlg.get()));
}
break;
}
@@ -544,12 +544,12 @@ void RandomPackPanel::onPackTypeClick(wxCommandEvent& ev) {
// update pack
for (size_t i = 0 ; i < set->pack_types.size() ; ++i) {
if (set->pack_types[i] == pick.pack) {
set->actions.addAction( new ChangePackAction(*set,i,dlg.get()) );
set->actions.addAction(make_unique<ChangePackAction>(*set,i,dlg.get()));
}
}
} else {
// delete pack
set->actions.addAction( new AddPackAction(REMOVE,*set,pick.pack) );
set->actions.addAction(make_unique<AddPackAction>(REMOVE,*set,pick.pack));
}
}
break;
+1 -1
View File
@@ -238,7 +238,7 @@ void StatDimensionList::drawItem(DC& dc, int x, int y, size_t item) {
StatsDimension& dim = *dimensions.at(item - show_empty);
// draw icon
if (!dim.icon_filename.empty() && !dim.icon.Ok()) {
InputStreamP file = game->openIn(dim.icon_filename);
auto file = game->openIn(dim.icon_filename);
Image img(*file);
if (img.HasMask()) img.InitAlpha(); // we can't handle masks
Image resampled(21, 21);
+3 -3
View File
@@ -171,18 +171,18 @@ void StylePanel::onStyleSelect(wxCommandEvent&) {
// select no special style when selecting the same style as the set default
stylesheet = StyleSheetP();
}
set->actions.addAction(new ChangeCardStyleAction(card, stylesheet));
set->actions.addAction(make_unique<ChangeCardStyleAction>(card, stylesheet));
Layout();
}
}
void StylePanel::onUseForAll(wxCommandEvent&) {
set->actions.addAction(new ChangeSetStyleAction(*set, card));
set->actions.addAction(make_unique<ChangeSetStyleAction>(*set, card));
Layout();
}
void StylePanel::onUseCustom(wxCommandEvent&) {
set->actions.addAction(new ChangeCardHasStylingAction(*set, card));
set->actions.addAction(make_unique<ChangeCardHasStylingAction>(*set, card));
}
BEGIN_EVENT_TABLE(StylePanel, wxPanel)
+1 -1
View File
@@ -100,7 +100,7 @@ void SymbolBasicShapeEditor::onLeftDown (const Vector2D& pos, wxMouseEvent& ev
void SymbolBasicShapeEditor::onLeftUp (const Vector2D& pos, wxMouseEvent& ev) {
if (drawing && shape) {
// Finalize the shape
addAction(new AddSymbolPartAction(*getSymbol(), shape));
addAction(make_unique<AddSymbolPartAction>(*getSymbol(), shape));
// Select the part
control.selectPart(shape);
// no need to clean up, this editor is replaced
+2 -2
View File
@@ -16,6 +16,6 @@ void SymbolEditorBase::SetStatusText(const String& text) {
control.parent->SetStatusText(text);
}
void SymbolEditorBase::addAction(Action* action, bool allow_merge) {
getSymbol()->actions.addAction(action, allow_merge);
void SymbolEditorBase::addAction(unique_ptr<Action> action, bool allow_merge) {
getSymbol()->actions.addAction(move(action), allow_merge);
}
+1 -1
View File
@@ -30,7 +30,7 @@ class SymbolEditorBase : public IntrusivePtrVirtualBase {
inline SymbolP getSymbol() { return control.getSymbol(); }
/// Perform an action
void addAction(Action* action, bool allow_merge = true);
void addAction(unique_ptr<Action> action, bool allow_merge = true);
void SetStatusText(const String& text);
+5 -5
View File
@@ -166,9 +166,9 @@ void SymbolPartList::onLeftUp(wxMouseEvent& ev) {
if (par != drop_parent && par->parts.size() == 1 && !par->isSymbolSymmetry()) {
// this leaves a group without elements, remove it
findParent(*par, par, drag_position); // parent of the group
symbol->actions.addAction(new UngroupReorderSymbolPartsAction(*par, drag_position, *drop_parent, drop_position));
symbol->actions.addAction(make_unique<UngroupReorderSymbolPartsAction>(*par, drag_position, *drop_parent, drop_position));
} else {
symbol->actions.addAction(new ReorderSymbolPartsAction(*par, drag_position, *drop_parent, drop_position));
symbol->actions.addAction(make_unique<ReorderSymbolPartsAction>(*par, drag_position, *drop_parent, drop_position));
}
} else {
Refresh(false);
@@ -257,14 +257,14 @@ void SymbolPartList::onChar(wxKeyEvent& ev) {
if (cursor > 0 && cursor <= typing_in->name.size()) {
String new_name = typing_in->name;
new_name.erase(cursor - 1, 1);
symbol->actions.addAction(new SymbolPartNameAction(typing_in, new_name, cursor, cursor - 1));
symbol->actions.addAction(make_unique<SymbolPartNameAction>(typing_in, new_name, cursor, cursor - 1));
}
break;
case WXK_DELETE:
if (cursor < typing_in->name.size()) {
String new_name = typing_in->name;
new_name.erase(cursor, 1);
symbol->actions.addAction(new SymbolPartNameAction(typing_in, new_name, cursor, cursor));
symbol->actions.addAction(make_unique<SymbolPartNameAction>(typing_in, new_name, cursor, cursor));
}
break;
default:
@@ -281,7 +281,7 @@ void SymbolPartList::onChar(wxKeyEvent& ev) {
#endif
String new_name = typing_in->name;
new_name.insert(cursor, 1, key);
symbol->actions.addAction(new SymbolPartNameAction(typing_in, new_name, cursor, cursor + 1));
symbol->actions.addAction(make_unique<SymbolPartNameAction>(typing_in, new_name, cursor, cursor + 1));
}
}
}
+22 -18
View File
@@ -253,10 +253,11 @@ void SymbolPointEditor::onLeftDClick(const Vector2D& pos, wxMouseEvent& ev) {
findHoveredItem(pos, false);
if (hovering == SELECTED_NEW_POINT) {
// Add point
ControlPointAddAction* act = new ControlPointAddAction(part, hover_line_1_idx, hover_line_t);
addAction(act);
auto act = make_unique<ControlPointAddAction>(part, hover_line_1_idx, hover_line_t);
ControlPointP new_point = act->getNewPoint();
addAction(move(act));
// select the new point
selectPoint(act->getNewPoint(), false);
selectPoint(new_point, false);
selection = SELECTED_POINTS;
} else if (hovering == SELECTED_HANDLE && hover_handle.handle == HANDLE_MAIN) {
// Delete point
@@ -287,8 +288,9 @@ void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wx
// Drag the curve
if (controlPointMoveAction) controlPointMoveAction = 0;
if (!curveDragAction) {
curveDragAction = new CurveDragAction(selected_line1, selected_line2);
addAction(curveDragAction);
auto action = make_unique<CurveDragAction>(selected_line1, selected_line2);
curveDragAction = action.get();
addAction(std::move(action));
}
curveDragAction->move(delta, selected_line_t);
control.Refresh(false);
@@ -297,8 +299,9 @@ void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wx
if (curveDragAction) curveDragAction = 0;
if (!controlPointMoveAction) {
// create action we can add this movement to
controlPointMoveAction = new ControlPointMoveAction(selected_points);
addAction(controlPointMoveAction);
auto action = make_unique<ControlPointMoveAction>(selected_points);
controlPointMoveAction = action.get();
addAction(std::move(action));
}
controlPointMoveAction->constrain = ev.ControlDown(); // ctrl constrains
controlPointMoveAction->snap = snap(ev);
@@ -308,8 +311,9 @@ void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wx
} else if (selection == SELECTED_HANDLE) {
// Move the selected handle
if (!handleMoveAction) {
handleMoveAction = new HandleMoveAction(selected_handle);
addAction(handleMoveAction);
auto action = make_unique<HandleMoveAction>(selected_handle);
handleMoveAction = action.get();
addAction(std::move(action));
}
handleMoveAction->constrain = ev.ControlDown(); // ctrl constrains
handleMoveAction->snap = snap(ev);
@@ -353,6 +357,7 @@ void SymbolPointEditor::onChar(wxKeyEvent& ev) {
if (ev.GetKeyCode() == WXK_DELETE) {
deleteSelection();
} else {
resetActions();
// move selection using arrow keys
double step = 1.0 / settings.symbol_grid_size;
Vector2D delta;
@@ -367,19 +372,18 @@ void SymbolPointEditor::onChar(wxKeyEvent& ev) {
// what to move
if (selection == SELECTED_POINTS || selection == SELECTED_LINE) {
// Move all selected points
controlPointMoveAction = new ControlPointMoveAction(selected_points);
addAction(controlPointMoveAction);
controlPointMoveAction->move(delta);
auto action = make_unique<ControlPointMoveAction>(selected_points);
action->move(delta);
addAction(std::move(action));
new_point += delta;
control.Refresh(false);
} else if (selection == SELECTED_HANDLE) {
// Move the selected handle
handleMoveAction = new HandleMoveAction(selected_handle);
addAction(handleMoveAction);
handleMoveAction->move(delta);
auto action = make_unique<HandleMoveAction>(selected_handle);
action->move(delta);
addAction(std::move(action));
control.Refresh(false);
}
resetActions();
}
}
@@ -477,12 +481,12 @@ void SymbolPointEditor::onChangeSegment(SegmentMode mode) {
assert(selected_line1);
assert(selected_line2);
if (selected_line1->segment_after == mode) return;
addAction(new SegmentModeAction(selected_line1, selected_line2, mode));
addAction(make_unique<SegmentModeAction>(selected_line1, selected_line2, mode));
control.Refresh(false);
}
void SymbolPointEditor::onChangeLock(LockMode mode) {
addAction(new LockModeAction(*selected_points.begin(), mode));
addAction(make_unique<LockModeAction>(*selected_points.begin(), mode));
control.Refresh(false);
}
+18 -14
View File
@@ -173,22 +173,22 @@ void SymbolSelectEditor::onUpdateUI(wxUpdateUIEvent& ev) {
void SymbolSelectEditor::onCommand(int id) {
if (id >= ID_SYMBOL_COMBINE && id < ID_SYMBOL_COMBINE_MAX) {
// change combine mode
addAction(new CombiningModeAction(
addAction(make_unique<CombiningModeAction>(
control.selected_parts.get(),
static_cast<SymbolShapeCombine>(id - ID_SYMBOL_COMBINE)
));
control.Refresh(false);
} else if (id == ID_EDIT_DUPLICATE && !isEditing()) {
// duplicate selection, not when dragging
addAction(new DuplicateSymbolPartsAction(*getSymbol(), control.selected_parts.get()));
addAction(make_unique<DuplicateSymbolPartsAction>(*getSymbol(), control.selected_parts.get()));
control.Refresh(false);
} else if (id == ID_EDIT_GROUP && !isEditing()) {
// group selection, not when dragging
addAction(new GroupSymbolPartsAction(*getSymbol(), control.selected_parts.get(), make_intrusive<SymbolGroup>()));
addAction(make_unique<GroupSymbolPartsAction>(*getSymbol(), control.selected_parts.get(), make_intrusive<SymbolGroup>()));
control.Refresh(false);
} else if (id == ID_EDIT_UNGROUP && !isEditing()) {
// ungroup selection, not when dragging
addAction(new UngroupSymbolPartsAction(*getSymbol(), control.selected_parts.get()));
addAction(make_unique<UngroupSymbolPartsAction>(*getSymbol(), control.selected_parts.get()));
control.Refresh(false);
}
}
@@ -312,24 +312,28 @@ void SymbolSelectEditor::onMouseDrag (const Vector2D& from, const Vector2D& to,
if (rotate) {
if (scaleX == 0 || scaleY == 0) {
// shear, center/fixed point on the opposite side
shearAction = new SymbolPartShearAction(control.selected_parts.get(), bounds.corner(-scaleX, -scaleY));
addAction(shearAction);
auto action = make_unique<SymbolPartShearAction>(control.selected_parts.get(), bounds.corner(-scaleX, -scaleY));
shearAction = action.get();
addAction(std::move(action));
} else {
// rotate
rotateAction = new SymbolPartRotateAction(control.selected_parts.get(), center);
addAction(rotateAction);
auto action = make_unique<SymbolPartRotateAction>(control.selected_parts.get(), center);
rotateAction = action.get();
addAction(std::move(action));
startAngle = angleTo(to);
}
} else {
// we are on a handle; start scaling
scaleAction = new SymbolPartScaleAction(control.selected_parts.get(), scaleX, scaleY);
addAction(scaleAction);
auto action = make_unique<SymbolPartScaleAction>(control.selected_parts.get(), scaleX, scaleY);
scaleAction = action.get();
addAction(std::move(action));
}
} else {
// move
click_mode = CLICK_MOVE;
moveAction = new SymbolPartMoveAction(control.selected_parts.get());
addAction(moveAction);
auto action = make_unique<SymbolPartMoveAction>(control.selected_parts.get());
moveAction = action.get();
addAction(std::move(action));
}
}
@@ -399,7 +403,7 @@ void SymbolSelectEditor::onKeyChange (wxKeyEvent& ev) {
void SymbolSelectEditor::onChar(wxKeyEvent& ev) {
if (ev.GetKeyCode() == WXK_DELETE) {
// delete selected parts
addAction(new RemoveSymbolPartsAction(*getSymbol(), control.selected_parts.get()));
addAction(make_unique<RemoveSymbolPartsAction>(*getSymbol(), control.selected_parts.get()));
if (control.selected_parts.selected(highlightPart)) highlightPart = SymbolPartP(); // deleted it
control.selected_parts.clear();
resetActions();
@@ -416,7 +420,7 @@ void SymbolSelectEditor::onChar(wxKeyEvent& ev) {
ev.Skip();
return;
}
addAction(new SymbolPartMoveAction(control.selected_parts.get(), delta));
addAction(make_unique<SymbolPartMoveAction>(control.selected_parts.get(), delta));
}
}
+7 -6
View File
@@ -107,13 +107,13 @@ void SymbolSymmetryEditor::onCommand(int id) {
if (id >= ID_SYMMETRY && id < ID_SYMMETRY_MAX) {
SymbolSymmetryType kind = id == ID_SYMMETRY_ROTATION ? SYMMETRY_ROTATION : SYMMETRY_REFLECTION;
if (symmetry && symmetry->kind != kind) {
addAction(new SymmetryTypeAction(*symmetry, kind));
addAction(make_unique<SymmetryTypeAction>(*symmetry, kind));
control.Refresh(false);
}
resetActions();
} else if (id == ID_COPIES) {
if (symmetry && symmetry->copies != copies->GetValue()) {
addAction(new SymmetryCopiesAction(*symmetry, copies->GetValue()));
addAction(make_unique<SymmetryCopiesAction>(*symmetry, copies->GetValue()));
control.Refresh(false);
}
resetActions();
@@ -124,11 +124,11 @@ void SymbolSymmetryEditor::onCommand(int id) {
symmetry->center = Vector2D(0.5,0.5);
symmetry->handle = Vector2D(0.2,0);
symmetry->name = symmetry->expectedName();
addAction(new GroupSymbolPartsAction(*getSymbol(), control.selected_parts.get(), symmetry));
addAction(make_unique<GroupSymbolPartsAction>(*getSymbol(), control.selected_parts.get(), symmetry));
control.selected_parts.select(symmetry);
control.Refresh(false);
} else if (id == ID_REMOVE_SYMMETRY) {
addAction(new UngroupSymbolPartsAction(*getSymbol(), control.selected_parts.get()));
addAction(make_unique<UngroupSymbolPartsAction>(*getSymbol(), control.selected_parts.get()));
symmetry = SymbolSymmetryP();
control.Refresh(false);
}
@@ -155,10 +155,11 @@ void SymbolSymmetryEditor::onMouseDrag (const Vector2D& from, const Vector2D& t
// Resize the object
if (selection == SELECTION_NONE) return;
if (!symmetryMoveAction) {
symmetryMoveAction = new SymmetryMoveAction(*symmetry, selection == SELECTION_HANDLE);
auto action = make_unique<SymmetryMoveAction>(*symmetry, selection == SELECTION_HANDLE);
symmetryMoveAction = action.get();
symmetryMoveAction->constrain = ev.ControlDown();
symmetryMoveAction->snap = ev.ShiftDown() != settings.symbol_grid_snap ? settings.symbol_grid_size : 0;
addAction(symmetryMoveAction);
addAction(std::move(action));
}
symmetryMoveAction->move(to - from);
control.Refresh(false);
+8 -4
View File
@@ -36,7 +36,8 @@ SymbolWindow::SymbolWindow(Window* parent, const String& filename)
: performer(nullptr)
{
// open file
Reader reader(make_shared<wxFileInputStream>(filename), nullptr, filename);
wxFileInputStream stream(filename);
Reader reader(stream, nullptr, filename);
SymbolP symbol;
reader.handle_greedy(symbol);
init(parent, symbol);
@@ -217,7 +218,8 @@ void SymbolWindow::onFileOpen(wxCommandEvent& ev) {
String ext = n.GetExt();
SymbolP symbol;
if (ext.Lower() == _("mse-symbol")) {
Reader reader(make_shared<wxFileInputStream>(name), nullptr, name);
wxFileInputStream stream(name);
Reader reader(stream, nullptr, name);
reader.handle_greedy(symbol);
} else {
wxBusyCursor busy;
@@ -240,7 +242,8 @@ void SymbolWindow::onFileSaveAs(wxCommandEvent& ev) {
String name = wxFileSelector(_("Save symbol"),settings.default_set_dir,_(""),_(""),_("Symbol files (*.mse-symbol)|*.mse-symbol"),wxFD_SAVE, this);
if (!name.empty()) {
settings.default_set_dir = wxPathOnly(name);
Writer writer(make_shared<wxFileOutputStream>(name), file_version_symbol);
wxFileOutputStream stream(name);
Writer writer(stream, file_version_symbol);
writer.handle(control->getSymbol());
}
}
@@ -250,7 +253,8 @@ void SymbolWindow::onFileStore(wxCommandEvent& ev) {
SymbolValueP value = static_pointer_cast<SymbolValue>(performer->value);
Package& package = performer->getLocalPackage();
FileName new_filename = package.newFileName(value->field().name,_(".mse-symbol")); // a new unique name in the package
Writer writer(package.openOut(new_filename), file_version_symbol);
auto stream = package.openOut(new_filename);
Writer writer(*stream, file_version_symbol);
writer.handle(control->getSymbol());
performer->addAction(value_action(value, new_filename));
}
+2 -3
View File
@@ -107,13 +107,12 @@ class CheckUpdateThread : public wxThread {
String& the_url = settings.updates_url;
#endif
wxURL url(the_url);
wxInputStream* isP = url.GetInputStream();
unique_ptr<wxInputStream> isP(url.GetInputStream());
if (!isP) return; // failed to get data
InputStreamP is(isP);
// Read version data
// ignore errors for forwards compatability
VersionDataP version_data;
Reader reader(is, nullptr, _("updates"), true);
Reader reader(*isP, nullptr, _("updates"), true);
reader.handle(version_data);
// has the updates url changed?
if (!version_data->new_updates_url.empty()) {
+2 -2
View File
@@ -12,9 +12,9 @@
// ----------------------------------------------------------------------------- : ValueEditor
void ValueEditor::addAction(ValueAction* a) {
void ValueEditor::addAction(unique_ptr<ValueAction> a) {
if (a) {
a->isOnCard(editor().getCard().get());
editor().addAction(a);
editor().addAction(move(a));
}
}
+1 -1
View File
@@ -130,7 +130,7 @@ class ValueEditor {
virtual DataEditor& editor() const = 0;
/// Perform an action
void addAction(ValueAction* a);
void addAction(unique_ptr<ValueAction> a);
};
// ----------------------------------------------------------------------------- : Utility
+1 -1
View File
@@ -65,7 +65,7 @@ bool ImageValueEditor::canPaste() const {
bool ImageValueEditor::doCopy() {
// load image
InputStreamP image_file = getLocalPackage().openIn(value().filename);
auto image_file = getLocalPackage().openIn(value().filename);
Image image;
if (!image_load_file(image, *image_file)) return false;
// set data
+3 -3
View File
@@ -856,7 +856,7 @@ void TextValueEditor::doFormat(int type) {
break;
}
case ID_FORMAT_REMINDER: {
addAction(new TextToggleReminderAction(valueP(), selection_start_i));
addAction(make_unique<TextToggleReminderAction>(valueP(), selection_start_i));
break;
}
}
@@ -983,7 +983,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
fixSelection();
// execute the action before adding it to the stack,
// because we want to run scripts before action listeners see the action
TextValueAction* action = typing_action(valueP(), selection_start_i, selection_end_i, select_on_undo ? selection_start : selection_end, selection_end, replacement, name);
auto action = typing_action(valueP(), selection_start_i, selection_end_i, select_on_undo ? selection_start : selection_end, selection_end, replacement, name);
if (!action) {
// nothing changes, but move the selection anyway
moveSelection(TYPE_CURSOR, selection_end);
@@ -994,7 +994,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
size_t expected_cursor = min(selection_start, selection_end) + untag_for_cursor(replacement).size();
// perform the action
// NOTE: this calls our onAction, invalidating the text viewer and moving the selection around the new text
addAction(action);
addAction(std::move(action));
// move cursor
{
String real_value = untag_for_cursor(value().value());