Partial fix for bug 1896587. Added a fileNew()-function, and made it do some of what it's supposed to do. However, it only clears the part of the document that is within the max-row range. To fix properly, a separate function to clear a track should be added, and all tracks should be iterated through and truncated to 0. Another issue, is that there's no real purgeUnused()-method in SyncDocument yet, and it's a bit tricky to implement (needs to remap properly). But, at least some of this seems to work-ish now.

Also added a menu-hook for fileNew.
This commit is contained in:
Erik Faye-Lund 2008-02-19 09:10:05 +00:00
parent 24417212ce
commit eb180b4d15
8 changed files with 57 additions and 30 deletions

View File

@ -72,7 +72,7 @@ IDR_MENU MENU
BEGIN BEGIN
POPUP "&File" POPUP "&File"
BEGIN BEGIN
MENUITEM "New\tCtrl+N", ID_FILE_NEW40015 MENUITEM "New\tCtrl+N", ID_FILE_NEW
MENUITEM "&Open\tCtrl+O", ID_FILE_OPEN MENUITEM "&Open\tCtrl+O", ID_FILE_OPEN
MENUITEM "&Save\tCtrl+S", ID_FILE_SAVE MENUITEM "&Save\tCtrl+S", ID_FILE_SAVE
MENUITEM "Save &As", ID_FILE_SAVE_AS MENUITEM "Save &As", ID_FILE_SAVE_AS

View File

@ -17,6 +17,9 @@ size_t SyncDocument::getTrackIndexFromPos(size_t track) const
return trackIter->second; return trackIter->second;
} }
/* void SyncDocument::purgeUnused()
{
} */
#import <msxml4.dll> named_guids #import <msxml4.dll> named_guids

View File

@ -264,6 +264,8 @@ public:
size_t getTrackIndexFromPos(size_t track) const; size_t getTrackIndexFromPos(size_t track) const;
/* void purgeUnused(); */
bool load(const std::string &fileName); bool load(const std::string &fileName);
bool save(const std::string &fileName); bool save(const std::string &fileName);

View File

@ -126,8 +126,14 @@ bool fileNameValid = false;
void fileNew() void fileNew()
{ {
/* document.purgeUnused(); */
trackView->selectAll();
trackView->editDelete();
trackView->selectNone();
fileNameValid = false;
// fileNameValid = false; document.clearUndoStack();
document.clearRedoStack();
} }
void fileOpen() void fileOpen()
@ -144,10 +150,13 @@ void fileOpen()
ofn.Flags = OFN_SHOWHELP; ofn.Flags = OFN_SHOWHELP;
if (GetOpenFileName(&ofn)) if (GetOpenFileName(&ofn))
{ {
fileNew();
if (document.load(fileName)) if (document.load(fileName))
{ {
document.clearUndoStack();
document.clearRedoStack();
fileNameValid = true; fileNameValid = true;
InvalidateRect(trackViewWin, NULL, FALSE);
} }
else MessageBox(trackViewWin, _T("failed to open file"), NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); else MessageBox(trackViewWin, _T("failed to open file"), NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
} }
@ -239,8 +248,14 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
case WM_COMMAND: case WM_COMMAND:
switch (LOWORD(wParam)) switch (LOWORD(wParam))
{ {
case ID_FILE_NEW:
fileNew();
InvalidateRect(hwnd, NULL, FALSE);
break;
case ID_FILE_OPEN: case ID_FILE_OPEN:
fileOpen(); fileOpen();
InvalidateRect(hwnd, NULL, FALSE);
break; break;
case ID_FILE_SAVE_AS: case ID_FILE_SAVE_AS:

View File

@ -747,12 +747,9 @@ void TrackView::editDelete()
int selectRight = max(selectStartTrack, selectStopTrack); int selectRight = max(selectStartTrack, selectStopTrack);
int selectTop = min(selectStartRow, selectStopRow); int selectTop = min(selectStartRow, selectStopRow);
int selectBottom = max(selectStartRow, selectStopRow); int selectBottom = max(selectStartRow, selectStopRow);
if (selectRight >= int(document->getTrackCount())) if (0 == document->getTrackCount()) return;
{ assert(selectRight < int(document->getTrackCount()));
MessageBeep(0);
return;
}
SyncDocument::MultiCommand *multiCmd = new SyncDocument::MultiCommand(); SyncDocument::MultiCommand *multiCmd = new SyncDocument::MultiCommand();
for (int track = selectLeft; track <= selectRight; ++track) for (int track = selectLeft; track <= selectRight; ++track)

View File

@ -27,11 +27,38 @@ public:
void setRows(int rows); void setRows(int rows);
int getRows() const { return rows; } int getRows() const { return rows; }
void editEnterValue();
void editDelete();
void editCopy();
void editCut();
void editPaste();
void editBiasValue(float amount); void editBiasValue(float amount);
void editToggleInterpolationType();
void setEditRow(int newEditRow); void setEditRow(int newEditRow);
int getEditRow() { return editRow; } int getEditRow() { return editRow; }
void selectAll()
{
selectStartTrack = 0;
selectStopTrack = this->getTrackCount() - 1;
selectStartRow = 0;
selectStopRow = this->getRows() - 1;
editTrack = 0;
editRow = 0;
InvalidateRect(hwnd, NULL, FALSE);
}
void selectNone()
{
selectStartTrack = selectStopTrack = editTrack;
selectStartRow = selectStopRow = editRow;
InvalidateRect(hwnd, NULL, FALSE);
}
private: private:
// some nasty hackery to forward the window messages // some nasty hackery to forward the window messages
friend static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); friend static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
@ -46,13 +73,6 @@ private:
LRESULT onKeyDown(UINT keyCode, UINT flags); LRESULT onKeyDown(UINT keyCode, UINT flags);
LRESULT onChar(UINT keyCode, UINT flags); LRESULT onChar(UINT keyCode, UINT flags);
void editEnterValue();
void editDelete();
void editCopy();
void editCut();
void editPaste();
void editToggleInterpolationType();
void paintTracks(HDC hdc, RECT rcTracks); void paintTracks(HDC hdc, RECT rcTracks);
void paintTopMargin(HDC hdc, RECT rcTracks); void paintTopMargin(HDC hdc, RECT rcTracks);

View File

@ -35,7 +35,7 @@ namespace sync
typedef std::map<const std::basic_string<TCHAR>, size_t> TrackContainer; typedef std::map<const std::basic_string<TCHAR>, size_t> TrackContainer;
TrackContainer tracks; TrackContainer tracks;
// protected: protected:
std::vector<Track*> actualTracks; std::vector<Track*> actualTracks;
}; };
} }

View File

@ -40,31 +40,21 @@ ClientDevice::~ClientDevice()
Track &ClientDevice::getTrack(const std::string &trackName) Track &ClientDevice::getTrack(const std::string &trackName)
{ {
/* const size_t oldCount = syncData.getTrackCount();
Track &track = syncData.getTrack(trackName);
if (oldCount == syncData.getTrackCount()) return track; */
sync::Data::TrackContainer::iterator iter = syncData.tracks.find(trackName); sync::Data::TrackContainer::iterator iter = syncData.tracks.find(trackName);
if (iter != syncData.tracks.end()) return syncData.getTrack(iter->second); if (iter != syncData.tracks.end()) return syncData.getTrack(iter->second);
// send request data
unsigned char cmd = GET_TRACK; unsigned char cmd = GET_TRACK;
send(serverSocket, (char*)&cmd, 1, 0); send(serverSocket, (char*)&cmd, 1, 0);
size_t clientIndex = syncData.getTrackCount(); size_t clientIndex = syncData.getTrackCount();
send(serverSocket, (char*)&clientIndex, sizeof(size_t), 0); send(serverSocket, (char*)&clientIndex, sizeof(size_t), 0);
// send request data
size_t name_len = trackName.size(); size_t name_len = trackName.size();
send(serverSocket, (char*)&name_len, sizeof(size_t), 0); send(serverSocket, (char*)&name_len, sizeof(size_t), 0);
const char *name_str = trackName.c_str(); const char *name_str = trackName.c_str();
send(serverSocket, name_str, int(name_len), 0); send(serverSocket, name_str, int(name_len), 0);
sync::Track *track = new sync::Track(); // insert new track
syncData.actualTracks.push_back(track); return syncData.getTrack(trackName);
syncData.tracks[trackName] = clientIndex;
return *track;
// return track;
} }
bool ClientDevice::update(float row) bool ClientDevice::update(float row)