-
Notifications
You must be signed in to change notification settings - Fork 0
/
DirectEdit.cpp
162 lines (141 loc) · 4.91 KB
/
DirectEdit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
Open source not for commercial deployment
*/
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "DirectEdit.h"
#include "OutputScreenUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TDirectEditForm *DirectEditForm;
//---------------------------------------------------------------------------
__fastcall TDirectEditForm::TDirectEditForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TDirectEditForm::FormActivate(TObject *Sender)
{
MainForm->BlockFocus = true;
TitleLabel->Caption = GetLanguageString("Title",TitleLabel->Caption);
LineCountLabel->Caption = GetLanguageString("NumberOfLinesOnBeamer",TitleLabel->Caption);
DirectEditForm->Caption = GetLanguageString("DirectEditTitle",TitleLabel->Caption);
}
//---------------------------------------------------------------------------
void __fastcall TDirectEditForm::FormShow(TObject *Sender)
{
Left = MainForm->Left + 10;
Top = MainForm->Top + 10;
Height = MainForm->Height -20;
}
//---------------------------------------------------------------------------
void __fastcall TDirectEditForm::TextMemoKeyDown(TObject *Sender,
WORD &Key, TShiftState Shift)
{
shiftDown = Shift.Contains(ssShift);
controlDown = Shift.Contains(ssCtrl);
altDown = Shift.Contains(ssAlt);
if (!shiftDown && !controlDown && !altDown)
if ((Key == 13) || (Key == ' '))
ShowOnScreen();
if (shiftDown && !controlDown && !altDown)
if (Key==186)
ShowOnScreen();
if (!shiftDown && controlDown && !altDown)
if (Key==49) //ctrl 1
Hide();
}
//---------------------------------------------------------------------------
void __fastcall TDirectEditForm::TextMemoKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
shiftDown = Shift.Contains(ssShift);
controlDown = Shift.Contains(ssCtrl);
altDown = Shift.Contains(ssAlt);
}
//---------------------------------------------------------------------------
void TDirectEditForm::ShowOnScreen()
{
SongData *sd;
sd = &(OutputScreen->curScreenSettings.CurSongData);
sd->TitleText = TitleEdit->Text;
String tempText = TextMemo->Lines->Text;
int i=0;
while (tempText.Length()>0)
{
sd->text[i]= getUntil(tempText,"\r\n");
tempText = getAfter(tempText,"\r\n");
i++;
}
int startline = i-LineCountComboBox->ItemIndex-1;
if (startline < 0) startline = 0;
OutputScreen->curScreenSettings.startLine=startline;
OutputScreen->curScreenSettings.CurLine = startline;
sd->shortFileNameAndVers = "";
sd->setSongLength(i);
OutputScreen->LateRefesch=true;
}
void TDirectEditForm::Process_Command(String s)
{
if (LoadedFile.Length()==0)
LoadedFile = MainForm->ProgramDir + "DirectEdit\\*";
if (s=="Open")
{
MainForm->FileOpenDialog->Filter="Text(*.txt)|*.txt";
MainForm->FileOpenDialog->FileName = LoadedFile;
MainForm->FileOpenDialog->DefaultExt=".txt";
if (MainForm->FileOpenDialog->Execute())
{
Open(MainForm->FileOpenDialog->FileName);
}
}
else if (s=="SaveAs")
{
MainForm->FileSaveDialog->Filter="Text(*.txt)|*.txt";
MainForm->FileSaveDialog->FileName = LoadedFile;
MainForm->FileSaveDialog->DefaultExt=".txt";
if (MainForm->FileSaveDialog->Execute())
{
SaveAs(MainForm->FileSaveDialog->FileName);
}
}
}
void TDirectEditForm::SaveAs(String s)
{
//check if already exist
ifstream testFile (s.c_str());
if (testFile.is_open())
{
testFile.close(); // the file already exists.
int answer = MessageDlgPos("Overwrite existing file?", mtInformation, TMsgDlgButtons() << mbOK << mbCancel, 0, DirectEditForm->Left, DirectEditForm->Top);
if (answer == 2) return; // cancel pressed.
}
//save to the file.
ofstream editFile (s.c_str());
editFile.write(TitleEdit->Text.c_str(),TitleEdit->Text.Length());
editFile.write("\r\n",2);
editFile.write(TextMemo->Text.c_str(), TextMemo->Text.Length());
editFile.close();
LoadedFile = s;
}
void TDirectEditForm::Open(String s)
{
char buffer[4096];
ifstream editFile (s.c_str());
if (editFile.is_open())
{
int data_len = editFile.readsome(buffer, 4096);
buffer[data_len] = 0; // put a null terminator after the text read.
TitleEdit->Text = getUntil(buffer,"\r\n");
TextMemo->Text = getAfter(buffer,"\r\n");
editFile.close();
LoadedFile = s;
}
}
void __fastcall TDirectEditForm::FormDeactivate(TObject *Sender)
{
MainForm->BlockFocus = false;
}
//---------------------------------------------------------------------------