MoveSelection: track selected area in undo/redo

Part of #99 work
This commit is contained in:
Daniel Collin 2014-09-24 20:46:22 +02:00
parent a327186b89
commit 29296761a8
3 changed files with 87 additions and 14 deletions

View File

@ -1,6 +1,7 @@
#include "Commands.h"
#include "RemoteConnection.h"
#include "TrackData.h"
#include "TrackView.h"
#include "../../sync/sync.h"
#include "../../sync/track.h"
#include <stdlib.h>
@ -282,6 +283,69 @@ void Commands_updateKey(int track, struct track_key* key)
execCommand(command);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct ChangeSelectionData
{
struct TrackViewInfo* viewInfo;
struct TrackViewInfo oldViewInfo;
int selectStartTrack;
int selectStopTrack;
int selectStartRow;
int selectStopRow;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void execChangeSelection(void* userData)
{
struct ChangeSelectionData* data = (struct ChangeSelectionData*)userData;
data->viewInfo->selectStartTrack = data->selectStartTrack;
data->viewInfo->selectStopTrack = data->selectStopTrack;
data->viewInfo->selectStartRow = data->selectStartRow;
data->viewInfo->selectStopRow = data->selectStopRow;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void execUndoSelection(void* userData)
{
struct ChangeSelectionData* data = (struct ChangeSelectionData*)userData;
data->viewInfo->selectStartTrack = data->oldViewInfo.selectStartTrack;
data->viewInfo->selectStopTrack = data->oldViewInfo.selectStopTrack;
data->viewInfo->selectStartRow = data->oldViewInfo.selectStartRow;
data->viewInfo->selectStopRow = data->oldViewInfo.selectStopRow;
data->viewInfo->rowPos = data->oldViewInfo.rowPos;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Commands_setSelection(struct TrackViewInfo* viewInfo, int startTrack, int endTrack, int startRow, int endRow)
{
struct ChangeSelectionData* data;
Command* command;
command = malloc(sizeof(Command));
memset(command, 0, sizeof(Command));
command->userData = data = malloc(sizeof(struct ChangeSelectionData));
command->exec = execChangeSelection;
command->undo = execUndoSelection;
data->viewInfo = viewInfo;
data->oldViewInfo = *viewInfo;
data->selectStartTrack = startTrack;
data->selectStopTrack = endTrack;
data->selectStartRow = startRow;
data->selectStopRow = endRow;
execCommand(command);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct InsertKeyData

View File

@ -5,6 +5,7 @@ struct sync_track;
struct track_key;
struct TrackData;
struct Track;
struct TrackViewInfo;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -28,6 +29,7 @@ void Commands_clearBookmarks(struct TrackData* trackData);
void Commands_toggleLoopmark(struct TrackData* trackData, int row);
void Commands_clearLoopmarks(struct TrackData* trackData);
void Commands_updateKey(int track, struct track_key* key);
void Commands_setSelection(struct TrackViewInfo* viewInfo, int startTrack, int endTrack, int startRow, int endRow);
void Commands_beginMulti(const char* name); // Used (for example) when changing many value at the same time
void Commands_endMulti();
int Commands_undoCount();

View File

@ -1168,6 +1168,7 @@ static void onMoveSelection(bool down)
int buffer_width, track, row;
TrackViewInfo* viewInfo = getTrackViewInfo();
struct sync_track** tracks = getTracks();
int startTrack, stopTrack, startRow, stopRow;
const int selectLeft = mini(viewInfo->selectStartTrack, viewInfo->selectStopTrack);
const int selectRight = maxi(viewInfo->selectStartTrack, viewInfo->selectStopTrack);
const int selectTop = mini(viewInfo->selectStartRow, viewInfo->selectStopRow);
@ -1190,7 +1191,6 @@ static void onMoveSelection(bool down)
if (idx < 0)
continue;
newKey = t->keys[idx];
newKey.row = down ? newKey.row + 1 : newKey.row - 1;
@ -1201,12 +1201,17 @@ static void onMoveSelection(bool down)
buffer_width = (selectRight - selectLeft) + 1;
startTrack = viewInfo->selectStartTrack;
stopTrack = viewInfo->selectStopTrack;
startRow = viewInfo->selectStartRow;
stopRow = viewInfo->selectStopRow;
// move the selection to the next position
if (down)
{
viewInfo->selectStartRow++;
viewInfo->selectStopRow++;
startRow++;
stopRow++;
}
else
{
@ -1219,24 +1224,26 @@ static void onMoveSelection(bool down)
return;
}
viewInfo->selectStartRow--;
viewInfo->selectStopRow--;
startRow--;
stopRow--;
viewInfo->selectStopRow = maxi(viewInfo->selectStopRow, 0);
viewInfo->selectStartRow = maxi(viewInfo->selectStartRow, 0);
stopRow = maxi(stopRow, 0);
startRow = maxi(startRow, 0);
}
if (viewInfo->selectStartRow < viewInfo->selectStopRow)
Commands_setSelection(viewInfo, startTrack, stopTrack, startRow, stopRow);
if (startRow < stopRow)
{
deleteArea(viewInfo->selectStartRow - 1, selectLeft, buffer_width, 1, true);
setRowPos(viewInfo->selectStartRow);
deleteArea(viewInfo->selectStopRow + 1, selectLeft, buffer_width, 1, true);
deleteArea(startRow - 1, selectLeft, buffer_width, 1, true);
setRowPos(startRow);
deleteArea(stopRow + 1, selectLeft, buffer_width, 1, true);
}
else
{
deleteArea(viewInfo->selectStopRow - 1, selectLeft, buffer_width, 1, true);
setRowPos(viewInfo->selectStopRow);
deleteArea(viewInfo->selectStartRow + 1, selectLeft, buffer_width, 1, true);
deleteArea(stopRow - 1, selectLeft, buffer_width, 1, true);
setRowPos(stopRow);
deleteArea(startRow + 1, selectLeft, buffer_width, 1, true);
}
Commands_endMulti();