Times can now be copy and pasted with ctrl+c and ctrl+v, as well as from context menu, in the time edit boxes.

Originally committed to SVN as r562.
This commit is contained in:
Rodrigo Braz Monteiro 2006-12-17 17:19:45 +00:00
parent ae26a23d96
commit 1fe045ba92
4 changed files with 137 additions and 8 deletions

View file

@ -24,6 +24,7 @@ Please visit http://aegisub.net to download latest version
o Previously those storages seemed to be created correctly, but were never written to disk and thus lost o Previously those storages seemed to be created correctly, but were never written to disk and thus lost
- Added a "Auto Save on Every Change" option to config.dat (default false), that automatically saves the files whenever you change anything. (AMZ) - Added a "Auto Save on Every Change" option to config.dat (default false), that automatically saves the files whenever you change anything. (AMZ)
- Added support for reading ASS, SSA and SRT softsubs directly from Matroska files. (AMZ) - Added support for reading ASS, SSA and SRT softsubs directly from Matroska files. (AMZ)
- Fixed line selection after pasting. (AMZ)
= 1.10 beta - 2006.08.07 =========================== = 1.10 beta - 2006.08.07 ===========================

View file

@ -891,7 +891,7 @@ void SubtitlesGrid::PasteLines(int n) {
for (int i=n+1;i<n+inserted;i++) { for (int i=n+1;i<n+inserted;i++) {
SelectRow(i,true); SelectRow(i,true);
} }
editBox->SetToLine(n+1); editBox->SetToLine(n);
} }
} }

View file

@ -36,6 +36,7 @@
//////////// ////////////
// Includes // Includes
#include <wx/clipbrd.h>
#include "timeedit_ctrl.h" #include "timeedit_ctrl.h"
#include "ass_time.h" #include "ass_time.h"
#include "vfr.h" #include "vfr.h"
@ -63,12 +64,23 @@ wxTextCtrl(parent,id,value,pos,size,wxTE_CENTRE | style,validator,name)
BEGIN_EVENT_TABLE(TimeEdit, wxTextCtrl) BEGIN_EVENT_TABLE(TimeEdit, wxTextCtrl)
EVT_MOUSE_EVENTS(TimeEdit::OnMouseEvent) EVT_MOUSE_EVENTS(TimeEdit::OnMouseEvent)
EVT_KEY_DOWN(TimeEdit::OnKeyDown) EVT_KEY_DOWN(TimeEdit::OnKeyDown)
EVT_MENU(Time_Edit_Copy,TimeEdit::OnCopy)
EVT_MENU(Time_Edit_Paste,TimeEdit::OnPaste)
END_EVENT_TABLE() END_EVENT_TABLE()
////////////////// //////////////////
// Modified event // Modified event
void TimeEdit::OnModified(wxCommandEvent &event) { void TimeEdit::OnModified(wxCommandEvent &event) {
if (!ready) return;
Modified();
event.Skip();
}
/////////////////////
// Modified function
void TimeEdit::Modified() {
// Lock // Lock
if (!ready) return; if (!ready) return;
ready = false; ready = false;
@ -85,7 +97,6 @@ void TimeEdit::OnModified(wxCommandEvent &event) {
// Done // Done
ready = true; ready = true;
event.Skip();
} }
@ -134,15 +145,39 @@ void TimeEdit::UpdateText() {
/////////////// ///////////////
// Mouse event // Mouse event
void TimeEdit::OnMouseEvent(wxMouseEvent &event) { void TimeEdit::OnMouseEvent(wxMouseEvent &event) {
if (!byFrame) { // Right click context menu
long from=0,to=0; if (event.RightUp()) {
GetSelection(&from,&to); wxMenu menu;
if (to != from) SetSelection(to,to); menu.Append(Time_Edit_Copy,_T("&Copy"));
menu.Append(Time_Edit_Paste,_T("&Paste"));
PopupMenu(&menu);
return;
} }
// Allow other events through
event.Skip(); event.Skip();
} }
/////////////
// Menu Copy
void TimeEdit::OnCopy(wxCommandEvent &event) {
SetFocus();
SetSelection(0,GetValue().Length());
CopyTime();
Refresh();
}
//////////////
// Menu Paste
void TimeEdit::OnPaste(wxCommandEvent &event) {
SetFocus();
PasteTime();
Refresh();
}
////////// //////////
// Update // Update
void TimeEdit::Update() { void TimeEdit::Update() {
@ -165,6 +200,85 @@ void TimeEdit::Update() {
/////////////// ///////////////
// Key pressed // Key pressed
void TimeEdit::OnKeyDown(wxKeyEvent &event) { void TimeEdit::OnKeyDown(wxKeyEvent &event) {
// Get key ID
int key = event.GetKeyCode(); int key = event.GetKeyCode();
if (byFrame || (key != WXK_BACK && key != WXK_DELETE)) event.Skip();
// Check if it's an acceptable key
if (!event.ControlDown()) {
if (byFrame || (key != WXK_BACK && key != WXK_DELETE)) {
// Reset selection first, if necessary
if (!byFrame) {
long from=0,to=0;
GetSelection(&from,&to);
if (to != from) SetSelection(from,from);
}
// Allow it through
event.Skip();
}
}
else {
// Copy
if (key == 'C' || key == 'X') {
CopyTime();
}
// Paste
if (key == 'V') {
PasteTime();
}
}
}
/////////////////////
// Copy to clipboard
void TimeEdit::CopyTime() {
// Frame
if (byFrame) {
Copy();
return;
}
// Time
if (wxTheClipboard->Open()) {
wxTheClipboard->SetData(new wxTextDataObject(GetStringSelection()));
wxTheClipboard->Close();
}
}
////////////////////////
// Paste from clipboard
void TimeEdit::PasteTime() {
// Frame
if (byFrame) {
Paste();
return;
}
// Time
if (wxTheClipboard->Open()) {
// Read text
wxString text;
if (wxTheClipboard->IsSupported(wxDF_TEXT)) {
wxTextDataObject data;
wxTheClipboard->GetData(data);
text = data.GetText();
text.Trim(false).Trim(true);
}
wxTheClipboard->Close();
// Paste time
AssTime tempTime;
tempTime.ParseASS(text);
if (tempTime.GetASSFormated() == text) {
ready = false;
SetValue(text);
SetSelection(0,GetValue().Length());
ready = true;
Modified();
}
}
} }

View file

@ -51,10 +51,16 @@ private:
bool ready; bool ready;
bool modified; bool modified;
void Modified();
void UpdateText();
void CopyTime();
void PasteTime();
void OnModified(wxCommandEvent &event); void OnModified(wxCommandEvent &event);
void OnMouseEvent(wxMouseEvent &event); void OnMouseEvent(wxMouseEvent &event);
void OnKeyDown(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event);
void UpdateText(); void OnCopy(wxCommandEvent &event);
void OnPaste(wxCommandEvent &event);
public: public:
AssTime time; AssTime time;
@ -69,3 +75,11 @@ public:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
///////
// IDs
enum {
Time_Edit_Copy = 1320,
Time_Edit_Paste
};