Save the current row and scroll position in the file and restore it when the file is reopened. Closes #1417.

Originally committed to SVN as r6362.
This commit is contained in:
Thomas Goyne 2012-01-25 19:07:36 +00:00
parent 71a4e38c7d
commit 2094814077
3 changed files with 17 additions and 3 deletions

View File

@ -152,7 +152,7 @@ public:
/// @param[out] w Width /// @param[out] w Width
/// @param[in] h Height /// @param[in] h Height
void GetResolution(int &w,int &h); void GetResolution(int &w,int &h);
/// Get the value in a [Script Info] key as int. /// Get the value in a [Script Info] key as int, or 0 if it is not present
int GetScriptInfoAsInt(const wxString key); int GetScriptInfoAsInt(const wxString key);
/// Get the value in a [Script Info] key as string. /// Get the value in a [Script Info] key as string.
wxString GetScriptInfo(wxString key); wxString GetScriptInfo(wxString key);

View File

@ -118,6 +118,7 @@ BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context, const wxSize& size,
OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", &BaseGrid::OnHighlightVisibleChange, this); OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", &BaseGrid::OnHighlightVisibleChange, this);
context->ass->AddCommitListener(&BaseGrid::OnSubtitlesCommit, this); context->ass->AddCommitListener(&BaseGrid::OnSubtitlesCommit, this);
context->ass->AddFileOpenListener(&BaseGrid::OnSubtitlesOpen, this); context->ass->AddFileOpenListener(&BaseGrid::OnSubtitlesOpen, this);
context->ass->AddFileSaveListener(&BaseGrid::OnSubtitlesSave, this);
std::tr1::function<void (agi::OptionValue const&)> Refresh(std::tr1::bind(&BaseGrid::Refresh, this, false, (wxRect*)NULL)); std::tr1::function<void (agi::OptionValue const&)> Refresh(std::tr1::bind(&BaseGrid::Refresh, this, false, (wxRect*)NULL));
OPT_SUB("Colour/Subtitle Grid/Active Border", Refresh); OPT_SUB("Colour/Subtitle Grid/Active Border", Refresh);
@ -175,13 +176,25 @@ void BaseGrid::OnSubtitlesOpen() {
UpdateMaps(); UpdateMaps();
if (GetRows()) { if (GetRows()) {
SetActiveLine(GetDialogue(0)); int row = context->ass->GetScriptInfoAsInt("Active Line");
SelectRow(0); if (row < 0 || row >= GetRows())
row = 0;
SetActiveLine(GetDialogue(row));
SelectRow(row);
} }
ScrollTo(context->ass->GetScriptInfoAsInt("Scroll Position"));
EndBatch(); EndBatch();
SetColumnWidths(); SetColumnWidths();
} }
void BaseGrid::OnSubtitlesSave() {
context->ass->SetScriptInfo("Scroll Position", wxString::Format("%d", yPos));
context->ass->SetScriptInfo("Active Line", wxString::Format("%d", GetDialogueIndex(active_line)));
}
void BaseGrid::OnShowColMenu(wxCommandEvent &event) { void BaseGrid::OnShowColMenu(wxCommandEvent &event) {
int item = event.GetId() - MENU_SHOW_COL; int item = event.GetId() - MENU_SHOW_COL;
showCol[item] = !showCol[item]; showCol[item] = !showCol[item];

View File

@ -110,6 +110,7 @@ class BaseGrid : public wxWindow, public BaseSelectionController<AssDialogue> {
void OnSize(wxSizeEvent &event); void OnSize(wxSizeEvent &event);
void OnSubtitlesCommit(int type); void OnSubtitlesCommit(int type);
void OnSubtitlesOpen(); void OnSubtitlesOpen();
void OnSubtitlesSave();
void DrawImage(wxDC &dc, bool paint_columns[]); void DrawImage(wxDC &dc, bool paint_columns[]);
void GetRowStrings(int row, AssDialogue *line, bool *paint_columns, wxString *strings) const; void GetRowStrings(int row, AssDialogue *line, bool *paint_columns, wxString *strings) const;