Move everything but the subtitle modification utility functions from SubtitlesGrid to BaseGrid. There never has been a clean division of responsibilities between them and the split mostly just made things awkward.

Originally committed to SVN as r5828.
This commit is contained in:
Thomas Goyne 2011-11-08 00:24:41 +00:00
parent 14d734298e
commit 8e81fd07ed
4 changed files with 128 additions and 169 deletions

View file

@ -45,6 +45,7 @@
#include <wx/dcclient.h>
#include <wx/dcmemory.h>
#include <wx/kbdstate.h>
#include <wx/menu.h>
#include <wx/sizer.h>
#endif
@ -52,6 +53,7 @@
#include "include/aegisub/context.h"
#include "include/aegisub/hotkey.h"
#include "include/aegisub/menu.h"
#include "ass_dialogue.h"
#include "ass_file.h"
@ -64,7 +66,8 @@
#include "video_slider.h"
enum {
GRID_SCROLLBAR = 1730
GRID_SCROLLBAR = 1730,
MENU_SHOW_COL = 1250 // Needs 15 IDs after this
};
template<class S1, class S2, class D>
@ -86,6 +89,8 @@ BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context, const wxSize& size,
, active_line(0)
, batch_level(0)
, batch_active_line_changed(false)
, seek_listener(context->videoController->AddSeekListener(std::tr1::bind(&BaseGrid::Refresh, this, false, (wxRect*)NULL)))
, context_menu(0)
, context(context)
, yPos(0)
{
@ -98,9 +103,13 @@ BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context, const wxSize& size,
SetSizerAndFit(scrollbarpositioner);
UpdateStyle();
OnHighlightVisibleChange(*OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame"));
OPT_SUB("Subtitle/Grid/Font Face", &BaseGrid::UpdateStyle, this);
OPT_SUB("Subtitle/Grid/Font Size", &BaseGrid::UpdateStyle, this);
OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", &BaseGrid::OnHighlightVisibleChange, this);
context->ass->AddCommitListener(&BaseGrid::OnSubtitlesCommit, this);
context->ass->AddFileOpenListener(&BaseGrid::OnSubtitlesOpen, 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);
@ -115,7 +124,7 @@ BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context, const wxSize& size,
OPT_SUB("Colour/Subtitle Grid/Lines", Refresh);
OPT_SUB("Colour/Subtitle Grid/Selection", Refresh);
OPT_SUB("Colour/Subtitle Grid/Standard", Refresh);
OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", Refresh);
OPT_SUB("Subtitle/Grid/Hide Overrides", Refresh);
Bind(wxEVT_CONTEXT_MENU, &BaseGrid::OnContextMenu, this);
}
@ -123,6 +132,66 @@ BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context, const wxSize& size,
BaseGrid::~BaseGrid() {
ClearMaps();
delete bmp;
delete context_menu;
}
BEGIN_EVENT_TABLE(BaseGrid,wxWindow)
EVT_PAINT(BaseGrid::OnPaint)
EVT_SIZE(BaseGrid::OnSize)
EVT_COMMAND_SCROLL(GRID_SCROLLBAR,BaseGrid::OnScroll)
EVT_MOUSE_EVENTS(BaseGrid::OnMouseEvent)
EVT_KEY_DOWN(BaseGrid::OnKeyDown)
EVT_MENU_RANGE(MENU_SHOW_COL,MENU_SHOW_COL+15,BaseGrid::OnShowColMenu)
END_EVENT_TABLE();
void BaseGrid::OnSubtitlesCommit(int type) {
if (type == AssFile::COMMIT_NEW)
UpdateMaps(true);
else if (type & AssFile::COMMIT_ORDER || type & AssFile::COMMIT_DIAG_ADDREM)
UpdateMaps(false);
if (type & AssFile::COMMIT_DIAG_META) {
SetColumnWidths();
Refresh(false);
return;
}
if (type & AssFile::COMMIT_DIAG_TIME)
RefreshRect(wxRect(time_cols_x, 0, time_cols_w, GetClientSize().GetHeight()), false);
if (type & AssFile::COMMIT_DIAG_TEXT)
RefreshRect(wxRect(text_col_x, 0, text_col_w, GetClientSize().GetHeight()), false);
}
void BaseGrid::OnSubtitlesOpen() {
BeginBatch();
ClearMaps();
UpdateMaps();
if (GetRows()) {
SetActiveLine(GetDialogue(0));
SelectRow(0);
}
EndBatch();
SetColumnWidths();
}
void BaseGrid::OnShowColMenu(wxCommandEvent &event) {
int item = event.GetId() - MENU_SHOW_COL;
showCol[item] = !showCol[item];
std::vector<bool> map(showCol, showCol + columns);
OPT_SET("Subtitle/Grid/Column")->SetListBool(map);
SetColumnWidths();
Refresh(false);
}
void BaseGrid::OnHighlightVisibleChange(agi::OptionValue const& opt) {
if (opt.GetBool()) {
seek_listener.Unblock();
}
else {
seek_listener.Block();
}
}
void BaseGrid::UpdateStyle() {
@ -350,13 +419,6 @@ wxArrayInt BaseGrid::GetSelection() const {
return res;
}
BEGIN_EVENT_TABLE(BaseGrid,wxWindow)
EVT_PAINT(BaseGrid::OnPaint)
EVT_SIZE(BaseGrid::OnSize)
EVT_COMMAND_SCROLL(GRID_SCROLLBAR,BaseGrid::OnScroll)
EVT_MOUSE_EVENTS(BaseGrid::OnMouseEvent)
EVT_KEY_DOWN(BaseGrid::OnKeyDown)
END_EVENT_TABLE()
void BaseGrid::OnPaint(wxPaintEvent &event) {
// Get size and pos
@ -723,10 +785,29 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
void BaseGrid::OnContextMenu(wxContextMenuEvent &evt) {
wxPoint pos = evt.GetPosition();
if (pos == wxDefaultPosition || ScreenToClient(pos).y > lineHeight)
OpenBodyContextMenu();
else
OpenHeaderContextMenu();
if (pos == wxDefaultPosition || ScreenToClient(pos).y > lineHeight) {
if (!context_menu) context_menu = menu::GetMenu("grid_context", context);
menu::OpenPopupMenu(context_menu, this);
}
else {
const wxString strings[] = {
_("Line Number"),
_("Layer"),
_("Start"),
_("End"),
_("Style"),
_("Actor"),
_("Effect"),
_("Left"),
_("Right"),
_("Vert"),
};
wxMenu menu;
for (size_t i = 0; i < columns; ++i)
menu.Append(MENU_SHOW_COL + i, strings[i], "", wxITEM_CHECK)->Check(showCol[i]);
PopupMenu(&menu);
}
}
void BaseGrid::ScrollTo(int y) {
@ -872,17 +953,11 @@ void BaseGrid::SetColumnWidths() {
text_col_w = colWidth[10];
}
/// @brief Get dialogue by index
/// @param n Index to look up
/// @return Subtitle dialogue line for index, or 0 if invalid index
AssDialogue *BaseGrid::GetDialogue(int n) const {
if (static_cast<size_t>(n) >= index_line_map.size()) return 0;
return index_line_map[n];
}
/// @brief Get index by dialogue line
/// @param diag Dialogue line to look up
/// @return Subtitle index for object, or -1 if unknown subtitle
int BaseGrid::GetDialogueIndex(AssDialogue *diag) const {
std::map<AssDialogue*,int>::const_iterator it = line_index_map.find(diag);
if (it != line_index_map.end()) return it->second;

View file

@ -38,7 +38,6 @@
#pragma once
#ifndef AGI_PRE
#include <list>
#include <map>
#include <vector>
@ -46,12 +45,15 @@
#include <wx/scrolbar.h>
#endif
#include <libaegisub/signal.h>
#include "selection_controller.h"
namespace agi { struct Context; }
class AssEntry;
namespace agi {
struct Context;
class OptionValue;
}
class AssDialogue;
class SubsEditBox;
typedef SelectionController<AssDialogue> SubtitleSelectionController;
typedef SelectionListener<AssDialogue> SubtitleSelectionListener;
@ -91,22 +93,28 @@ class BaseGrid : public wxWindow, public BaseSelectionController<AssDialogue> {
/// is completed; should be a subset of selection
Selection batch_selection_removed;
/// Connection for video seek event. Stored explicitly so that it can be
/// blocked if the relevant option is disabled
agi::signal::Connection seek_listener;
/// Cached grid body context menu
wxMenu *context_menu;
void OnContextMenu(wxContextMenuEvent &evt);
void OnPaint(wxPaintEvent &event);
void OnSize(wxSizeEvent &event);
void OnScroll(wxScrollEvent &event);
void OnMouseEvent(wxMouseEvent &event);
void OnHighlightVisibleChange(agi::OptionValue const& opt);
void OnKeyDown(wxKeyEvent &event);
void OnMouseEvent(wxMouseEvent &event);
void OnPaint(wxPaintEvent &event);
void OnScroll(wxScrollEvent &event);
void OnShowColMenu(wxCommandEvent &event);
void OnSize(wxSizeEvent &event);
void OnSubtitlesCommit(int type);
void OnSubtitlesOpen();
void DrawImage(wxDC &dc, bool paint_columns[]);
void ScrollTo(int y);
virtual void OpenHeaderContextMenu() { }
virtual void OpenBodyContextMenu() { }
protected:
int colWidth[16]; ///< Width in pixels of each column
agi::Context *context; ///< Current project context
int time_cols_x; ///< Left edge of the times columns
int time_cols_w; ///< Width of the two times columns
@ -127,6 +135,9 @@ protected:
void AnnounceActiveLineChanged(AssDialogue *new_line);
void AnnounceSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed);
protected:
agi::Context *context; ///< Current project context
public:
// SelectionController implementation
void SetActiveLine(AssDialogue *new_line);
@ -155,7 +166,14 @@ public:
int GetRows() const { return index_line_map.size(); }
void MakeCellVisible(int row, int col,bool center=true);
/// @brief Get dialogue by index
/// @param n Index to look up
/// @return Subtitle dialogue line for index, or 0 if invalid index
AssDialogue *GetDialogue(int n) const;
/// @brief Get index by dialogue line
/// @param diag Dialogue line to look up
/// @return Subtitle index for object, or -1 if unknown subtitle
int GetDialogueIndex(AssDialogue *diag) const;
BaseGrid(wxWindow* parent, agi::Context *context, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr);

View file

@ -46,114 +46,19 @@
#include <wx/tokenzr.h>
#endif
#include "command/command.h"
#include "subs_grid.h"
#include "include/aegisub/context.h"
#include "include/aegisub/audio_provider.h"
#include "include/aegisub/menu.h"
#include "ass_dialogue.h"
#include "ass_file.h"
#include "ass_override.h"
#include "ass_style.h"
#include "audio_controller.h"
#include "charset_conv.h"
#include "dialog_paste_over.h"
#include "frame_main.h"
#include "main.h"
#include "subs_grid.h"
#include "utils.h"
#include "video_context.h"
BEGIN_EVENT_TABLE(SubtitlesGrid, BaseGrid)
EVT_MENU_RANGE(MENU_SHOW_COL,MENU_SHOW_COL+15,SubtitlesGrid::OnShowColMenu)
END_EVENT_TABLE()
SubtitlesGrid::SubtitlesGrid(wxWindow *parent, agi::Context *context, const wxSize& size, long style, const wxString& name)
: BaseGrid(parent,context,size,style,name)
, seekListener(context->videoController->AddSeekListener(&SubtitlesGrid::Refresh, this, false, (const wxRect *)NULL))
, context_menu(0)
{
OnHighlightVisibleChange(*OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame"));
OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", &SubtitlesGrid::OnHighlightVisibleChange, this);
OPT_SUB("Subtitle/Grid/Hide Overrides", std::tr1::bind(&SubtitlesGrid::Refresh, this, false, (const wxRect*)0));
context->ass->AddCommitListener(&SubtitlesGrid::OnSubtitlesCommit, this);
context->ass->AddFileOpenListener(&SubtitlesGrid::OnSubtitlesOpen, this);
}
/// @brief Destructor
SubtitlesGrid::~SubtitlesGrid() {
delete context_menu;
}
void SubtitlesGrid::OnSubtitlesCommit(int type) {
if (type == AssFile::COMMIT_NEW)
UpdateMaps(true);
else if (type & AssFile::COMMIT_ORDER || type & AssFile::COMMIT_DIAG_ADDREM)
UpdateMaps(false);
if (type & AssFile::COMMIT_DIAG_META) {
SetColumnWidths();
Refresh(false);
return;
}
if (type & AssFile::COMMIT_DIAG_TIME)
RefreshRect(wxRect(time_cols_x, 0, time_cols_w, GetClientSize().GetHeight()), false);
if (type & AssFile::COMMIT_DIAG_TEXT)
RefreshRect(wxRect(text_col_x, 0, text_col_w, GetClientSize().GetHeight()), false);
}
void SubtitlesGrid::OnSubtitlesOpen() {
BeginBatch();
ClearMaps();
UpdateMaps();
if (GetRows()) {
SetActiveLine(GetDialogue(0));
SelectRow(0);
}
EndBatch();
SetColumnWidths();
}
void SubtitlesGrid::OpenHeaderContextMenu() {
const wxString strings[] = {
_("Line Number"),
_("Layer"),
_("Start"),
_("End"),
_("Style"),
_("Actor"),
_("Effect"),
_("Left"),
_("Right"),
_("Vert"),
};
// Create Menu
wxMenu menu;
for (size_t i=0;i<columns;i++) {
menu.Append(MENU_SHOW_COL + i,strings[i],"",wxITEM_CHECK)->Check(showCol[i]);
}
PopupMenu(&menu);
}
void SubtitlesGrid::OpenBodyContextMenu() {
if (!context_menu) context_menu = menu::GetMenu("grid_context", context);
menu::OpenPopupMenu(context_menu, this);
}
/// @brief Process a show/hide column event
/// @param event
void SubtitlesGrid::OnShowColMenu(wxCommandEvent &event) {
int item = event.GetId()-MENU_SHOW_COL;
showCol[item] = !showCol[item];
std::vector<bool> map(showCol, showCol + columns);
OPT_SET("Subtitle/Grid/Column")->SetListBool(map);
// Update
SetColumnWidths();
Refresh(false);
}
static void trim_text(AssDialogue *diag) {
@ -162,6 +67,7 @@ static void trim_text(AssDialogue *diag) {
start.ReplaceFirst(&diag->Text, "");
end.ReplaceFirst(&diag->Text, "");
}
static void expand_times(AssDialogue *src, AssDialogue *dst) {
dst->Start.SetMS(std::min(dst->Start.GetMS(), src->Start.GetMS()));
dst->End.SetMS(std::max(dst->End.GetMS(), src->End.GetMS()));
@ -552,12 +458,3 @@ void SubtitlesGrid::SetSelectionFromAbsolute(std::vector<int> &selection) {
SetSelectedSet(newsel);
}
void SubtitlesGrid::OnHighlightVisibleChange(agi::OptionValue const& opt) {
if (opt.GetBool()) {
seekListener.Unblock();
}
else {
seekListener.Block();
}
}

View file

@ -35,9 +35,6 @@
///
#ifndef AGI_PRE
#include <fstream>
#include <iostream>
#include <list>
#include <vector>
#include <wx/grid.h>
@ -46,35 +43,14 @@
#include "base_grid.h"
#include <libaegisub/signal.h>
namespace agi { class OptionValue; }
class AssEntry;
class wxMenu;
/// DOCME
/// @class SubtitlesGrid
/// @brief DOCME
///
/// DOCME
class SubtitlesGrid: public BaseGrid {
agi::signal::Connection seekListener;
wxMenu *context_menu;
void OpenHeaderContextMenu();
void OpenBodyContextMenu();
void OnShowColMenu(wxCommandEvent &event);
void OnHighlightVisibleChange(agi::OptionValue const& opt);
void OnSubtitlesCommit(int type);
void OnSubtitlesOpen();
public:
SubtitlesGrid(wxWindow *parent, agi::Context *context, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr);
~SubtitlesGrid();
/// @brief Adjoins selected lines, setting each line's start time to the previous line's end time
/// @param n1 First line to adjoin
@ -113,11 +89,4 @@ public:
/// @brief Update list of selected lines from absolute selection
/// @param selection Sorted list of selections
void SetSelectionFromAbsolute(std::vector<int> &selection);
DECLARE_EVENT_TABLE()
};
/// Menu event IDs
enum {
MENU_SHOW_COL = 1250 // Don't put anything after this
};