Skip to content
Snippets Groups Projects
Commit 09412b4b authored by rswindell's avatar rswindell
Browse files

Allow services to added and removed using the new GUI controls.

Allow global services.ini keys to edited on the "General" tab.
Moved "Sound" tab to the far right.
Still need a method for deleting keys.
parent cdd5d7ab
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@
#include "MainFormUnit.h"
#include "TextFileEditUnit.h"
#include "ServicesCfgDlgUnit.h"
#include "CodeInputFormUnit.h"
#include <stdio.h> // sprintf()
#include <mmsystem.h> // sndPlaySound()
//---------------------------------------------------------------------------
......@@ -52,7 +53,6 @@ void __fastcall TServicesCfgDlg::FormShow(TObject *Sender)
str_list_t services = iniGetSectionList(ini, NULL);
CheckListBox->Items->BeginUpdate();
for(unsigned u=0; services!=NULL && services[u]!=NULL; u++) {
OutputDebugString(services[u]);
CheckListBox->Items->Append(services[u]);
}
CheckListBox->Items->EndUpdate();
......@@ -63,8 +63,19 @@ void __fastcall TServicesCfgDlg::FormShow(TObject *Sender)
iniFreeStringList(section);
}
iniFreeStringList(services);
if(CheckListBox->Items->Count)
if(CheckListBox->Items->Count) {
CheckListBox->ItemIndex=0;
CheckListBoxClick(Sender);
}
str_list_t keys = iniGetKeyList(ini, ROOT_SECTION);
for(unsigned u=0; keys!=NULL && keys[u]!=NULL; u++) {
if(keys[u][0])
GlobalValueListEditor->InsertRow(AnsiString(keys[u])
,AnsiString(iniGetString(ini,ROOT_SECTION,keys[u],"error",NULL))
,/* append: */true);
}
iniFreeStringList(keys);
PageControl->ActivePage=GeneralTabSheet;
}
......@@ -184,3 +195,50 @@ void __fastcall TServicesCfgDlg::ValueListEditorValidate(TObject *Sender,
}
//---------------------------------------------------------------------------
void __fastcall TServicesCfgDlg::ServiceAddClick(TObject *Sender)
{
Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
CodeInputForm->Label->Caption="New Service Name";
CodeInputForm->Edit->Visible=true;
if(CodeInputForm->ShowModal()==mrOk
&& CodeInputForm->Edit->Text.Length()
&& !iniSectionExists(ini,CodeInputForm->Edit->Text.c_str())
&& iniAppendSection(&ini,CodeInputForm->Edit->Text.c_str(),/* style: */NULL)) {
CheckListBox->Items->Append(CodeInputForm->Edit->Text);
CheckListBox->ItemIndex = CheckListBox->Items->Count-1;
CheckListBoxClick(Sender);
}
delete CodeInputForm;
}
//---------------------------------------------------------------------------
void __fastcall TServicesCfgDlg::ServiceRemoveClick(TObject *Sender)
{
if(CheckListBox->ItemIndex >= 0
&& iniRemoveSection(&ini,CheckListBox->Items->Strings[CheckListBox->ItemIndex].c_str())) {
CheckListBox->DeleteSelected();
CheckListBoxClick(Sender);
}
}
//---------------------------------------------------------------------------
void __fastcall TServicesCfgDlg::CheckListBoxKeyDown(TObject *Sender,
WORD &Key, TShiftState Shift)
{
if(Key==VK_INSERT)
ServiceAddClick(Sender);
else if(Key==VK_DELETE)
ServiceRemoveClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TServicesCfgDlg::GlobalValueListEditorValidate(
TObject *Sender, int ACol, int ARow, const AnsiString KeyName,
const AnsiString KeyValue)
{
iniSetString(&ini
,ROOT_SECTION
,KeyName.c_str(), KeyValue.c_str(), /* style: */NULL);
}
//---------------------------------------------------------------------------
......@@ -95,6 +95,22 @@ object ServicesCfgDlg: TServicesCfgDlg
ShowHint = True
TabOrder = 1
end
object GlobalValueListEditor: TValueListEditor
Left = 8
Top = 88
Width = 250
Height = 75
Hint = 'Global settings for services'
KeyOptions = [keyEdit, keyAdd, keyDelete, keyUnique]
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing, goEditing, goThumbTracking]
ParentShowHint = False
ShowHint = True
TabOrder = 3
OnValidate = GlobalValueListEditorValidate
ColWidths = (
99
145)
end
end
object SoundTabSheet: TTabSheet
Caption = 'Sound'
......@@ -165,9 +181,11 @@ object ServicesCfgDlg: TServicesCfgDlg
Hint = 'Services and their enabled/disabled state'
ItemHeight = 13
ParentShowHint = False
PopupMenu = ServicesCfgPopupMenu
ShowHint = True
TabOrder = 0
OnClick = CheckListBoxClick
OnKeyDown = CheckListBoxKeyDown
end
object ValueListEditor: TValueListEditor
Left = 8
......@@ -260,4 +278,18 @@ object ServicesCfgDlg: TServicesCfgDlg
Left = 104
Top = 64
end
object ServicesCfgPopupMenu: TPopupMenu
Left = 176
Top = 48
object ServiceAdd: TMenuItem
Caption = 'Add'
Hint = 'Add a new service'
OnClick = ServiceAddClick
end
object ServiceRemove: TMenuItem
Caption = 'Remove'
Hint = 'Remove the selected service'
OnClick = ServiceRemoveClick
end
end
end
......@@ -41,6 +41,10 @@ __published: // IDE-managed Components
TTabSheet *EnableTabSheet;
TCheckListBox *CheckListBox;
TValueListEditor *ValueListEditor;
TPopupMenu *ServicesCfgPopupMenu;
TMenuItem *ServiceAdd;
TMenuItem *ServiceRemove;
TValueListEditor *GlobalValueListEditor;
void __fastcall FormShow(TObject *Sender);
void __fastcall OKButtonClick(TObject *Sender);
void __fastcall AnswerSoundButtonClick(TObject *Sender);
......@@ -49,6 +53,13 @@ __published: // IDE-managed Components
void __fastcall CheckListBoxClick(TObject *Sender);
void __fastcall ValueListEditorValidate(TObject *Sender, int ACol,
int ARow, const AnsiString KeyName, const AnsiString KeyValue);
void __fastcall ServiceAddClick(TObject *Sender);
void __fastcall ServiceRemoveClick(TObject *Sender);
void __fastcall CheckListBoxKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall GlobalValueListEditorValidate(TObject *Sender,
int ACol, int ARow, const AnsiString KeyName,
const AnsiString KeyValue);
private: // User declarations
char iniFilename[MAX_PATH+1];
str_list_t ini;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment