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[in] h Height
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);
/// Get the value in a [Script Info] key as string.
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);
context->ass->AddCommitListener(&BaseGrid::OnSubtitlesCommit, 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));
OPT_SUB("Colour/Subtitle Grid/Active Border", Refresh);
@ -175,13 +176,25 @@ void BaseGrid::OnSubtitlesOpen() {
UpdateMaps();
if (GetRows()) {
SetActiveLine(GetDialogue(0));
SelectRow(0);
int row = context->ass->GetScriptInfoAsInt("Active Line");
if (row < 0 || row >= GetRows())
row = 0;
SetActiveLine(GetDialogue(row));
SelectRow(row);
}
ScrollTo(context->ass->GetScriptInfoAsInt("Scroll Position"));
EndBatch();
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) {
int item = event.GetId() - MENU_SHOW_COL;
showCol[item] = !showCol[item];

View file

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