-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Refactored edition actions into a separate namespace for reusability
- Direct consequence of the previous : smooth addition of the Edit Menu
- Loading branch information
Showing
6 changed files
with
201 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// Created by Syméon on 28/03/2019. | ||
// | ||
|
||
#include "EditActions.h" | ||
|
||
void EditActions::undo(std::optional<EditorState>& ed, NotificationsQueue& nq) { | ||
if (ed and ed->chart) { | ||
auto previous = ed->chart->history.get_previous(); | ||
if (previous) { | ||
nq.push(std::make_shared<UndoNotification>(**previous)); | ||
(*previous)->undoAction(*ed); | ||
ed->densityGraph.should_recompute = true; | ||
} | ||
} | ||
} | ||
|
||
void EditActions::redo(std::optional<EditorState>& ed, NotificationsQueue& nq) { | ||
if (ed and ed->chart) { | ||
auto next = ed->chart->history.get_next(); | ||
if (next) { | ||
nq.push(std::make_shared<RedoNotification>(**next)); | ||
(*next)->doAction(*ed); | ||
ed->densityGraph.should_recompute = true; | ||
} | ||
} | ||
} | ||
|
||
|
||
void EditActions::cut(std::optional<EditorState>& ed, NotificationsQueue& nq) { | ||
if (ed and ed->chart and (not ed->chart->selectedNotes.empty())) { | ||
|
||
std::stringstream ss; | ||
ss << "Cut " << ed->chart->selectedNotes.size() << " note"; | ||
if (ed->chart->selectedNotes.size() > 1) { | ||
ss << "s"; | ||
} | ||
nq.push(std::make_shared<TextNotification>(ss.str())); | ||
|
||
ed->chart->notesClipboard.copy(ed->chart->selectedNotes); | ||
for (auto note : ed->chart->selectedNotes) { | ||
ed->chart->ref.Notes.erase(note); | ||
} | ||
ed->chart->history.push(std::make_shared<ToggledNotes>(ed->chart->selectedNotes,false)); | ||
ed->chart->selectedNotes.clear(); | ||
} | ||
} | ||
|
||
void EditActions::copy(std::optional<EditorState>& ed, NotificationsQueue& nq) { | ||
if (ed and ed->chart and (not ed->chart->selectedNotes.empty())) { | ||
|
||
std::stringstream ss; | ||
ss << "Copied " << ed->chart->selectedNotes.size() << " note"; | ||
if (ed->chart->selectedNotes.size() > 1) { | ||
ss << "s"; | ||
} | ||
nq.push(std::make_shared<TextNotification>(ss.str())); | ||
|
||
ed->chart->notesClipboard.copy(ed->chart->selectedNotes); | ||
} | ||
} | ||
|
||
void EditActions::paste(std::optional<EditorState>& ed, NotificationsQueue& nq) { | ||
if (ed and ed->chart and (not ed->chart->notesClipboard.empty())) { | ||
|
||
int tick_offset = static_cast<int>(ed->getCurrentTick()); | ||
std::set<Note> pasted_notes = ed->chart->notesClipboard.paste(tick_offset); | ||
|
||
std::stringstream ss; | ||
ss << "Pasted " << pasted_notes.size() << " note"; | ||
if (pasted_notes.size() > 1) { | ||
ss << "s"; | ||
} | ||
nq.push(std::make_shared<TextNotification>(ss.str())); | ||
|
||
for (auto note : pasted_notes) { | ||
ed->chart->ref.Notes.insert(note); | ||
} | ||
ed->chart->selectedNotes = pasted_notes; | ||
ed->chart->history.push(std::make_shared<ToggledNotes>(ed->chart->selectedNotes,true)); | ||
} | ||
|
||
} | ||
|
||
void EditActions::delete_(std::optional<EditorState>& ed, NotificationsQueue& nq) { | ||
if (ed and ed->chart) { | ||
if (not ed->chart->selectedNotes.empty()) { | ||
ed->chart->history.push(std::make_shared<ToggledNotes>(ed->chart->selectedNotes,false)); | ||
nq.push(std::make_shared<TextNotification>("Deleted selected notes")); | ||
for (auto note : ed->chart->selectedNotes) { | ||
ed->chart->ref.Notes.erase(note); | ||
} | ||
ed->chart->selectedNotes.clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Created by Syméon on 28/03/2019. | ||
// | ||
|
||
#ifndef FEIS_EDITACTIONS_H | ||
#define FEIS_EDITACTIONS_H | ||
|
||
#include "NotificationsQueue.h" | ||
#include "EditorState.h" | ||
|
||
namespace EditActions { | ||
|
||
void undo(std::optional<EditorState>& ed, NotificationsQueue& nq); | ||
void redo(std::optional<EditorState>& ed, NotificationsQueue& nq); | ||
|
||
void cut(std::optional<EditorState>& ed, NotificationsQueue& nq); | ||
void copy(std::optional<EditorState>& ed, NotificationsQueue& nq); | ||
void paste(std::optional<EditorState>& ed, NotificationsQueue& nq); | ||
void delete_(std::optional<EditorState>& ed, NotificationsQueue& nq); | ||
|
||
}; | ||
|
||
|
||
#endif //FEIS_EDITACTIONS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.