File: frmOptions.cpp

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (1050 lines) | stat: -rw-r--r-- 39,519 bytes parent folder | download
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// frmOptions.cpp - The main options dialogue
//
//////////////////////////////////////////////////////////////////////////

#include "pgAdmin3.h"

// wxWindows headers
#include <wx/wx.h>
#include <wx/xrc/xmlres.h>
#include <wx/fontdlg.h>
#include <wx/fontutil.h>
#include <wx/file.h>
#include <wx/clrpicker.h>
#include <wx/filepicker.h>
#include <wx/fontpicker.h>
#include <wx/treectrl.h>

// App headers
#include "frm/frmOptions.h"
#include "frm/frmMain.h"
#include "frm/frmHint.h"
#include "utils/sysSettings.h"
#include "utils/sysLogger.h"
#include "utils/misc.h"
#include "frm/menu.h"
#include "ctl/ctlColourPicker.h"

// Must be after pgAdmin3.h or MSVC++ complains
#include <wx/colordlg.h>

#include "images/properties.pngc"

#define BROWSER_ITEM _("Browser")
#define BROWSER_DISPLAY_ITEM _("Display")
#define BROWSER_PROPERTIES_ITEM _("Properties")
#define BROWSER_BINPATH_ITEM _("Binary paths")
#define BROWSER_MISC_ITEM _("UI Miscellaneous")
#define QUERYTOOL_ITEM _("Query tool")
#define QUERYTOOL_EDITOR_ITEM _("Query editor")
#define QUERYTOOL_COLOURS_ITEM _("Colours")
#define QUERYTOOL_RESULTS_ITEM _("Results grid")
#define QUERYTOOL_FILES_ITEM _("Query file")
#define QUERYTOOL_FAVOURITES_ITEM _("Favourites")
#define QUERYTOOL_MACROS_ITEM _("Macros")
#define QUERYTOOL_HISTORYFILE_ITEM _("History file")
#define DATABASEDESIGNER_ITEM _("Database Designer")
#define SERVERSTATUS_ITEM _("Server status")
#define MISC_ITEM _("Miscellaneous")
#define MISC_UI_ITEM _("User Interface")
#define MISC_HELPPATH_ITEM _("Help paths")
#define MISC_GURUHINTS_ITEM _("Guru hints")
#define MISC_LOGGING_ITEM _("Logging")

#define txtPgHelpPath               CTRL_TEXT("txtPgHelpPath")
#define txtEdbHelpPath              CTRL_TEXT("txtEdbHelpPath")
#define txtGpHelpPath               CTRL_TEXT("txtGpHelpPath")
#define txtSlonyHelpPath            CTRL_TEXT("txtSlonyHelpPath")
#define pickerSlonyPath             CTRL_DIRPICKER("pickerSlonyPath")
#define pickerPostgresqlPath        CTRL_DIRPICKER("pickerPostgresqlPath")
#define pickerEnterprisedbPath      CTRL_DIRPICKER("pickerEnterprisedbPath")
#define pickerGPDBPath              CTRL_DIRPICKER("pickerGPDBPath")
#define txtSystemSchemas            CTRL_TEXT("txtSystemSchemas")
#define pickerLogfile               CTRL_FILEPICKER("pickerLogfile")
#define radLoglevel                 CTRL_RADIOBOX("radLoglevel")
#define txtMaxRows                  CTRL_TEXT("txtMaxRows")
#define txtMaxColSize               CTRL_TEXT("txtMaxColSize")
#define pickerFont                  CTRL_FONTPICKER("pickerFont")
#define chkUnicodeFile              CTRL_CHECKBOX("chkUnicodeFile")
#define chkWriteBOM                 CTRL_CHECKBOX("chkWriteBOM")
#define chkAskSaveConfirm           CTRL_CHECKBOX("chkAskSaveConfirm")
#define chkAskDelete                CTRL_CHECKBOX("chkAskDelete")
#define chkShowUsersForPrivileges   CTRL_CHECKBOX("chkShowUsersForPrivileges")
#define txtAutoRowCount             CTRL_TEXT("txtAutoRowCount")
#define txtIndent                   CTRL_TEXT("txtIndent")
#define chkSpacesForTabs			CTRL_CHECKBOX("chkSpacesForTabs")
#define cbCopyQuote					CTRL_COMBOBOX("cbCopyQuote")
#define cbCopyQuoteChar				CTRL_COMBOBOX("cbCopyQuoteChar")
#define cbCopySeparator				CTRL_COMBOBOX("cbCopySeparator")
#define chkStickySql                CTRL_CHECKBOX("chkStickySql")
#define chkIndicateNull             CTRL_CHECKBOX("chkIndicateNull")
#define txtDecimalMark	            CTRL_TEXT("txtDecimalMark")
#define chkColumnNames				CTRL_CHECKBOX("chkColumnNames")
#define txtThousandsSeparator       CTRL_TEXT("txtThousandsSeparator")
#define chkAutoRollback             CTRL_CHECKBOX("chkAutoRollback")
#define chkDoubleClickProperties    CTRL_CHECKBOX("chkDoubleClickProperties")
#define chkShowNotices			    CTRL_CHECKBOX("chkShowNotices")
#define cbLanguage                  CTRL_COMBOBOX("cbLanguage")
#define pickerSqlFont               CTRL_FONTPICKER("pickerSqlFont")
#define chkSuppressHints            CTRL_CHECKBOX("chkSuppressHints")
#define chkResetHints               CTRL_CHECKBOX("chkResetHints")
#define lstDisplay					CTRL_CHECKLISTBOX("lstDisplay")
#define chkSystemObjects            CTRL_CHECKBOX("chkSystemObjects")
#define chkIgnoreVersion            CTRL_CHECKBOX("chkIgnoreVersion")
#define pickerIdleProcessColour     CTRL_COLOURPICKER("pickerIdleProcessColour")
#define pickerActiveProcessColour   CTRL_COLOURPICKER("pickerActiveProcessColour")
#define pickerSlowProcessColour     CTRL_COLOURPICKER("pickerSlowProcessColour")
#define pickerBlockedProcessColour  CTRL_COLOURPICKER("pickerBlockedProcessColour")
#define pickerFavouritesFile        CTRL_FILEPICKER("pickerFavouritesFile")
#define pickerMacrosFile               CTRL_FILEPICKER("pickerMacrosFile")
#define pickerHistoryFile              CTRL_FILEPICKER("pickerHistoryFile")
#define txtHistoryMaxQueries        CTRL_TEXT("txtHistoryMaxQueries")
#define txtHistoryMaxQuerySize      CTRL_TEXT("txtHistoryMaxQuerySize")
#define chkSQLUseSystemBackgroundColour  CTRL_CHECKBOX("chkSQLUseSystemBackgroundColour")
#define chkSQLUseSystemForegroundColour  CTRL_CHECKBOX("chkSQLUseSystemForegroundColour")
#define pickerSQLBackgroundColour        CTRL_COLOURPICKER("pickerSQLBackgroundColour")
#define pickerSQLForegroundColour        CTRL_COLOURPICKER("pickerSQLForegroundColour")
#define stSQLCustomBackgroundColour      CTRL_STATIC("stSQLCustomBackgroundColour")
#define stSQLCustomForegroundColour      CTRL_STATIC("stSQLCustomForegroundColour")
#define pickerSQLMarginBackgroundColour  CTRL_COLOURPICKER("pickerSQLMarginBackgroundColour")
#define pickerSQLColour1            CTRL_COLOURPICKER("pickerSQLColour1")
#define pickerSQLColour2            CTRL_COLOURPICKER("pickerSQLColour2")
#define pickerSQLColour3            CTRL_COLOURPICKER("pickerSQLColour3")
#define pickerSQLColour4            CTRL_COLOURPICKER("pickerSQLColour4")
#define pickerSQLColour5            CTRL_COLOURPICKER("pickerSQLColour5")
#define pickerSQLColour6            CTRL_COLOURPICKER("pickerSQLColour6")
#define pickerSQLColour7            CTRL_COLOURPICKER("pickerSQLColour7")
#define pickerSQLColour10           CTRL_COLOURPICKER("pickerSQLColour10")
#define pickerSQLColour11           CTRL_COLOURPICKER("pickerSQLColour11")
#define pickerSQLCaretColour        CTRL_COLOURPICKER("pickerSQLCaretColour")
#define chkKeywordsInUppercase      CTRL_CHECKBOX("chkKeywordsInUppercase")
#define menus                		CTRL_TREE("menus")
#define pnlBrowserDisplay           CTRL_PANEL("pnlBrowserDisplay")
#define pnlBrowserProperties        CTRL_PANEL("pnlBrowserProperties")
#define pnlBrowserBinPath         	CTRL_PANEL("pnlBrowserBinPath")
#define pnlBrowserMisc          	CTRL_PANEL("pnlBrowserMisc")
#define pnlQueryToolEditor          CTRL_PANEL("pnlQueryToolEditor")
#define pnlQueryToolColours         CTRL_PANEL("pnlQueryToolColours")
#define pnlQueryToolResults         CTRL_PANEL("pnlQueryToolResults")
#define pnlQueryToolFiles          	CTRL_PANEL("pnlQueryToolFiles")
#define pnlQueryToolFavourites      CTRL_PANEL("pnlQueryToolFavourites")
#define pnlQueryToolMacros          CTRL_PANEL("pnlQueryToolMacros")
#define pnlQueryToolHistoryFile     CTRL_PANEL("pnlQueryToolHistoryFile")
#define pnlDatabaseDesigner         CTRL_PANEL("pnlDatabaseDesigner")
#define pnlServerStatus          	CTRL_PANEL("pnlServerStatus")
#define pnlMiscUI                	CTRL_PANEL("pnlMiscUI")
#define pnlMiscHelpPath             CTRL_PANEL("pnlMiscHelpPath")
#define pnlMiscGuruHints          	CTRL_PANEL("pnlMiscGuruHints")
#define pnlMiscLogging          	CTRL_PANEL("pnlMiscLogging")
#define cbRefreshOnClick			CTRL_COMBOBOX("cbRefreshOnClick")
#define pickerFontDD                CTRL_FONTPICKER("pickerFontDD")


BEGIN_EVENT_TABLE(frmOptions, pgDialog)
	EVT_MENU(MNU_HELP,                                            frmOptions::OnHelp)
	EVT_BUTTON (XRCID("btnDefault"),                              frmOptions::OnDefault)
	EVT_CHECKBOX(XRCID("chkSuppressHints"),                       frmOptions::OnSuppressHints)
	EVT_CHECKBOX(XRCID("chkResetHints"),                          frmOptions::OnResetHints)
	EVT_CHECKBOX(XRCID("chkSQLUseSystemBackgroundColour"),        frmOptions::OnChangeSQLUseCustomColour)
	EVT_CHECKBOX(XRCID("chkSQLUseSystemForegroundColour"),        frmOptions::OnChangeSQLUseCustomColour)
	EVT_BUTTON (wxID_OK,                                          frmOptions::OnOK)
	EVT_BUTTON (wxID_HELP,                                        frmOptions::OnHelp)
	EVT_BUTTON (wxID_CANCEL,                                      frmOptions::OnCancel)
	EVT_COMBOBOX(XRCID("cbCopyQuote"),		                      frmOptions::OnChangeCopyQuote)
	EVT_TREE_SEL_CHANGED(XRCID("menus"),                          frmOptions::OnTreeSelChanged)
END_EVENT_TABLE()


//----------------------------------------------------------------------------
// wxRichTextFontDialog: a substitute for wxFontDialog, which is broken on
// Mac OS X Snow Leopard
//----------------------------------------------------------------------------

#ifdef __WXMAC__
#if !wxCHECK_VERSION(2, 9, 0)

#include <wx/fontdlg.h>
#include <wx/richtext/richtextbuffer.h>
#include <wx/richtext/richtextformatdlg.h>

class wxRichTextFontDialog: public wxFontDialogBase
{
public:
	wxRichTextFontDialog() : wxFontDialogBase()
	{
		Init(); /* must be
														   Create()d later */
	}
	wxRichTextFontDialog(wxWindow *parent)
		: wxFontDialogBase(parent)
	{
		Init();
		Create(parent);
	}
	wxRichTextFontDialog(wxWindow *parent, const wxFontData &data)
		: wxFontDialogBase(parent, data)
	{
		Init();
		Create(parent, data);
	}

	void Init()
	{
		m_title = _("Font");
	}

	virtual int ShowModal();

	virtual void SetTitle( const wxString &title)
	{
		m_title = title;
	}
	virtual wxString GetTitle() const
	{
		return m_title;
	}

protected:
	wxString    m_title;

	DECLARE_DYNAMIC_CLASS_NO_COPY(wxRichTextFontDialog)

};

IMPLEMENT_DYNAMIC_CLASS(wxRichTextFontDialog, wxDialog)

int wxRichTextFontDialog::ShowModal()
{
	wxTextAttrEx attr;
	if (m_fontData.GetInitialFont().Ok())
		attr.SetFont(m_fontData.GetInitialFont());

	if (m_fontData.GetColour().Ok())
		attr.SetTextColour(m_fontData.GetColour());

	wxRichTextFormattingDialog formatDlg(wxRICHTEXT_FORMAT_FONT,
	                                     GetParent(), GetTitle());
	formatDlg.SetAttributes(attr);

	if (formatDlg.ShowModal() == wxID_OK)
	{
		wxTextAttrEx attr(formatDlg.GetAttributes());

		m_fontData.SetChosenFont(attr.GetFont());
		m_fontData.SetColour(attr.GetTextColour());

		return wxID_OK;
	}
	else
		return wxID_CANCEL;

}

#endif
#endif

//----------------------------------------------------------------------------

frmOptions::frmOptions(frmMain *parent)
{
	wxTreeItemId root, node;
	wxTreeItemIdValue cookie;

	mainForm = parent;
	SetFont(settings->GetSystemFont());
	LoadResource(parent, wxT("frmOptions"));

	// Icon
	SetIcon(*properties_png_ico);
	RestorePosition();

	wxAcceleratorEntry entries[1];

	entries[0].Set(wxACCEL_NORMAL,              WXK_F1,        MNU_HELP);

	wxAcceleratorTable accel(1, entries);
	SetAcceleratorTable(accel);

	wxTextValidator numval(wxFILTER_NUMERIC);
	txtMaxRows->SetValidator(numval);
	txtMaxColSize->SetValidator(numval);
	txtAutoRowCount->SetValidator(numval);
	txtIndent->SetValidator(numval);
	txtHistoryMaxQueries->SetValidator(numval);
	txtHistoryMaxQuerySize->SetValidator(numval);

	pickerLogfile->SetPath(settings->GetLogFile());
	radLoglevel->SetSelection(settings->GetLogLevel());
	txtMaxRows->SetValue(NumToStr(settings->GetMaxRows()));
	txtMaxColSize->SetValue(NumToStr(settings->GetMaxColSize()));
	chkAskSaveConfirm->SetValue(!settings->GetAskSaveConfirmation());
	chkAskDelete->SetValue(settings->GetConfirmDelete());
	chkShowUsersForPrivileges->SetValue(settings->GetShowUsersForPrivileges());
	txtAutoRowCount->SetValue(NumToStr(settings->GetAutoRowCountThreshold()));
	txtIndent->SetValue(NumToStr(settings->GetIndentSpaces()));
	chkSpacesForTabs->SetValue(settings->GetSpacesForTabs());
	cbCopyQuote->SetSelection(settings->GetCopyQuoting());
	cbCopyQuoteChar->SetValue(settings->GetCopyQuoteChar());
	cbRefreshOnClick->SetSelection(settings->GetRefreshOnClick());

	wxString copySeparator = settings->GetCopyColSeparator();
	if (copySeparator == wxT("\t"))
		copySeparator = _("Tab");
	cbCopySeparator->SetValue(copySeparator);

	chkStickySql->SetValue(settings->GetStickySql());
	chkIndicateNull->SetValue(settings->GetIndicateNull());
	txtThousandsSeparator->SetValue(settings->GetThousandsSeparator());
	chkAutoRollback->SetValue(settings->GetAutoRollback());
	chkDoubleClickProperties->SetValue(settings->GetDoubleClickProperties());
	txtDecimalMark->SetValue(settings->GetDecimalMark());
	chkColumnNames->SetValue(settings->GetColumnNames());
	chkShowNotices->SetValue(settings->GetShowNotices());

	txtPgHelpPath->SetValue(settings->GetPgHelpPath());
	txtEdbHelpPath->SetValue(settings->GetEdbHelpPath());
	txtGpHelpPath->SetValue(settings->GetGpHelpPath());
	txtSlonyHelpPath->SetValue(settings->GetSlonyHelpPath());

	txtSystemSchemas->SetValue(settings->GetSystemSchemas());
	chkUnicodeFile->SetValue(settings->GetUnicodeFile());
	chkWriteBOM->SetValue(settings->GetWriteBOM());
	chkSuppressHints->SetValue(settings->GetSuppressGuruHints());
	pickerSlonyPath->SetPath(settings->GetSlonyPath());
	pickerPostgresqlPath->SetPath(settings->GetPostgresqlPath());
	pickerEnterprisedbPath->SetPath(settings->GetEnterprisedbPath());
	pickerGPDBPath->SetPath(settings->GetGPDBPath());
	chkIgnoreVersion->SetValue(settings->GetIgnoreVersion());

	// Get back the colours
	pickerIdleProcessColour->SetColour(settings->GetIdleProcessColour());
	pickerActiveProcessColour->SetColour(settings->GetActiveProcessColour());
	pickerSlowProcessColour->SetColour(settings->GetSlowProcessColour());
	pickerBlockedProcessColour->SetColour(settings->GetBlockedProcessColour());

	pickerFavouritesFile->SetPath(settings->GetFavouritesFile());
	pickerMacrosFile->SetPath(settings->GetMacrosFile());
	pickerHistoryFile->SetPath(settings->GetHistoryFile());

	txtHistoryMaxQueries->SetValue(NumToStr(settings->GetHistoryMaxQueries()));
	txtHistoryMaxQuerySize->SetValue(NumToStr(settings->GetHistoryMaxQuerySize()));

	chkSQLUseSystemBackgroundColour->SetValue(settings->GetSQLBoxUseSystemBackground());
	chkSQLUseSystemForegroundColour->SetValue(settings->GetSQLBoxUseSystemForeground());
	UpdateColourControls();

	pickerSQLColour1->SetColour(settings->GetSQLBoxColour(1));
	pickerSQLColour2->SetColour(settings->GetSQLBoxColour(2));
	pickerSQLColour3->SetColour(settings->GetSQLBoxColour(3));
	pickerSQLColour4->SetColour(settings->GetSQLBoxColour(4));
	pickerSQLColour5->SetColour(settings->GetSQLBoxColour(5));
	pickerSQLColour6->SetColour(settings->GetSQLBoxColour(6));
	pickerSQLColour7->SetColour(settings->GetSQLBoxColour(7));
	pickerSQLColour10->SetColour(settings->GetSQLBoxColour(10));
	pickerSQLColour11->SetColour(settings->GetSQLBoxColour(11));

	chkKeywordsInUppercase->SetValue(settings->GetSQLKeywordsInUppercase());

	cbLanguage->Append(_("Default"));
	int sel = 0;
	wxLanguage langId = settings->GetCanonicalLanguage();

	int langCount = existingLangs.GetCount();
	if (langCount)
	{
		int langNo;
		const wxLanguageInfo *langInfo;
		for (langNo = 0; langNo < langCount ; langNo++)
		{
			langInfo = wxLocale::GetLanguageInfo(existingLangs.Item(langNo));
			cbLanguage->Append(wxT("(") + langInfo->CanonicalName + wxT(") ")
			                   + existingLangNames.Item(langNo));
			if (langId == langInfo->Language)
				sel = langNo + 1;
		}
	}
	cbLanguage->SetSelection(sel);

	pickerFont->SetSelectedFont(settings->GetSystemFont());
	pickerSqlFont->SetSelectedFont(settings->GetSQLFont());
	pickerFontDD->SetSelectedFont(settings->GetDDFont());

	// Load the display options
	lstDisplay->Append(_("Databases"));
	lstDisplay->Append(_("Tablespaces"));
	lstDisplay->Append(_("pgAgent Jobs"));
	lstDisplay->Append(_("Groups/group Roles"));
	lstDisplay->Append(_("Users/login Roles"));
	lstDisplay->Append(_("Resource Queues"));
	lstDisplay->Append(_("Resource Groups"));
	lstDisplay->Append(_("Catalogs"));
	lstDisplay->Append(_("Casts"));
	lstDisplay->Append(_("Event Triggers"));
	lstDisplay->Append(_("Extensions"));
	lstDisplay->Append(_("Foreign Data Wrappers"));
	lstDisplay->Append(_("Foreign Servers"));
	lstDisplay->Append(_("User Mappings"));
	lstDisplay->Append(_("Languages"));
	lstDisplay->Append(_("Schemas"));
	lstDisplay->Append(_("Synonyms"));
	lstDisplay->Append(_("Slony-I Clusters"));
	lstDisplay->Append(_("Aggregates"));
	lstDisplay->Append(_("Collations"));
	lstDisplay->Append(_("Conversions"));
	lstDisplay->Append(_("Domains"));
	lstDisplay->Append(_("External Tables"));
	lstDisplay->Append(_("Foreign Tables"));
	lstDisplay->Append(_("FTS Configurations"));
	lstDisplay->Append(_("FTS Dictionaries"));
	lstDisplay->Append(_("FTS Parsers"));
	lstDisplay->Append(_("FTS Templates"));
	lstDisplay->Append(_("Functions"));
	lstDisplay->Append(_("Operators"));
	lstDisplay->Append(_("Operator Classes"));
	lstDisplay->Append(_("Operator Families"));
	lstDisplay->Append(_("Packages"));
	lstDisplay->Append(_("Procedures"));
	lstDisplay->Append(_("Sequences"));
	lstDisplay->Append(_("Tables"));
	lstDisplay->Append(_("Trigger Functions"));
	lstDisplay->Append(_("Types"));
	lstDisplay->Append(_("Views"));

	for (unsigned int x = 0; x < lstDisplay->GetCount(); x++)
		lstDisplay->Check(x, settings->GetDisplayOption(lstDisplay->GetString(x)));

	chkSystemObjects->SetValue(settings->GetShowSystemObjects());

	wxCommandEvent e;
	OnChangeCopyQuote(e);

	// Fill the treeview
	root = menus->AddRoot(_("Options"));

	node = menus->AppendItem(root, BROWSER_ITEM);
	menus->AppendItem(node, BROWSER_DISPLAY_ITEM);
	menus->AppendItem(node, BROWSER_PROPERTIES_ITEM);
	menus->AppendItem(node, BROWSER_BINPATH_ITEM);
	menus->AppendItem(node, BROWSER_MISC_ITEM);

	node = menus->AppendItem(root, QUERYTOOL_ITEM);
	menus->AppendItem(node, QUERYTOOL_EDITOR_ITEM);
	menus->AppendItem(node, QUERYTOOL_COLOURS_ITEM);
	menus->AppendItem(node, QUERYTOOL_RESULTS_ITEM);
	menus->AppendItem(node, QUERYTOOL_FILES_ITEM);
	menus->AppendItem(node, QUERYTOOL_FAVOURITES_ITEM);
	menus->AppendItem(node, QUERYTOOL_MACROS_ITEM);
	menus->AppendItem(node, QUERYTOOL_HISTORYFILE_ITEM);

	node = menus->AppendItem(root, DATABASEDESIGNER_ITEM);

	node = menus->AppendItem(root, SERVERSTATUS_ITEM);

	node = menus->AppendItem(root, MISC_ITEM);
	menus->AppendItem(node, MISC_UI_ITEM);
	menus->AppendItem(node, MISC_HELPPATH_ITEM);
	menus->AppendItem(node, MISC_GURUHINTS_ITEM);
	menus->AppendItem(node, MISC_LOGGING_ITEM);

	menus->ExpandAllChildren(root);

	menuSelection = settings->GetOptionsLastTreeItem();
	wxTreeItemId menuItem = GetTreeItemByLabel(root, menuSelection);
	if (!menuItem.IsOk())
		menuItem = menus->GetFirstChild(root, cookie);

	menus->SelectItem(menuItem);
	ShowPanel(menuItem);
}


frmOptions::~frmOptions()
{
	SavePosition();
}

void frmOptions::OnHelp(wxCommandEvent &ev)
{
	DisplayHelp(wxT("options"), HELP_PGADMIN);
}

void frmOptions::OnDefault(wxCommandEvent &ev)
{
	// Reset the display options to the defaults.
	// Clear them all first
	for (unsigned int x = 0; x < lstDisplay->GetCount(); x++)
		lstDisplay->Check(x, settings->GetDisplayOption(lstDisplay->GetString(x), true));
}

void frmOptions::OnSuppressHints(wxCommandEvent &ev)
{
	if (chkSuppressHints->GetValue())
		chkResetHints->SetValue(false);
}


void frmOptions::OnResetHints(wxCommandEvent &ev)
{
	if (chkResetHints->GetValue())
		chkSuppressHints->SetValue(false);
}

void frmOptions::UpdateColourControls()
{
	if (chkSQLUseSystemBackgroundColour->GetValue())
	{
		pickerSQLBackgroundColour->Enable(false);
		pickerSQLBackgroundColour->SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
		stSQLCustomBackgroundColour->Enable(false);
	}
	else
	{
		pickerSQLBackgroundColour->Enable(true);
		pickerSQLBackgroundColour->SetColour(settings->GetSQLBoxColourBackground());
		stSQLCustomBackgroundColour->Enable(true);
	}

	if (chkSQLUseSystemForegroundColour->GetValue())
	{
		pickerSQLForegroundColour->Enable(false);
		pickerSQLForegroundColour->SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
		stSQLCustomForegroundColour->Enable(false);
	}
	else
	{
		pickerSQLForegroundColour->Enable(true);
		pickerSQLForegroundColour->SetColour(settings->GetSQLBoxColourForeground());
		stSQLCustomForegroundColour->Enable(true);
	}

	pickerSQLCaretColour->SetColour(settings->GetSQLColourCaret());

	pickerSQLMarginBackgroundColour->SetColour(settings->GetSQLMarginBackgroundColour());
}

void frmOptions::OnChangeSQLUseCustomColour(wxCommandEvent &ev)
{
	UpdateColourControls();
}

void frmOptions::OnOK(wxCommandEvent &ev)
{
	// Check the PostgreSQL and EnterpriseDB paths
#ifdef __WXMSW__
	if (!pickerPostgresqlPath->GetPath().IsEmpty() && !isPgApp(pickerPostgresqlPath->GetPath() + wxT("\\pg_dump.exe")))
#else
	if (!pickerPostgresqlPath->GetPath().IsEmpty() && !isPgApp(pickerPostgresqlPath->GetPath() + wxT("/pg_dump")))
#endif
	{
		wxMessageBox(_("The PostgreSQL bin path specified is not valid or does not contain a PostgreSQL pg_dump executable.\n\nPlease select another directory, or leave the path blank."), _("Error"), wxICON_ERROR | wxOK);
		return;
	}

#ifdef __WXMSW__
	if (!pickerEnterprisedbPath->GetPath().IsEmpty() && !isEdbApp(pickerEnterprisedbPath->GetPath() + wxT("\\pg_dump.exe")))
#else
	if (!pickerEnterprisedbPath->GetPath().IsEmpty() && !isEdbApp(pickerEnterprisedbPath->GetPath() + wxT("/pg_dump")))
#endif
	{
		wxMessageBox(_("The EnterpriseDB bin path specified is not valid or does not contain an EnterpriseDB pg_dump executable.\n\nPlease select another directory, or leave the path blank."), _("Error"), wxICON_ERROR | wxOK);
		return;
	}

#ifdef __WXMSW__
	if (!pickerGPDBPath->GetPath().IsEmpty() && !isGpApp(pickerGPDBPath->GetPath() + wxT("\\pg_dump.exe")))
#else
	if (!pickerGPDBPath->GetPath().IsEmpty() && !isGpApp(pickerGPDBPath->GetPath() + wxT("/pg_dump")))
#endif
	{
		wxMessageBox(_("The Greenplum bin path specified is not valid or does not contain a Greenplum pg_dump executable.\n\nPlease select another directory, or leave the path blank."), _("Error"), wxICON_ERROR | wxOK);
		return;
	}


	if (txtDecimalMark->GetValue() != wxEmptyString)
	{
		// Check decimal mark <> thousands separator
		if (txtDecimalMark->GetValue() == txtThousandsSeparator->GetValue())
		{
			wxMessageBox(_("The decimal mark and thousands separator must not be equal."), _("Error"), wxICON_ERROR | wxOK);
			return;
		}
	}

	// Clean and check the help paths
	txtPgHelpPath->SetValue(CleanHelpPath(txtPgHelpPath->GetValue()));
	if (!HelpPathValid(txtPgHelpPath->GetValue()))
	{
		wxMessageBox(_("An invalid PostgreSQL help path was specified.\n\nPlease enter another filename, directory or URL, or leave the path blank."), _("Error"), wxICON_ERROR | wxOK);
		txtPgHelpPath->SetFocus();
		return;
	}

	txtEdbHelpPath->SetValue(CleanHelpPath(txtEdbHelpPath->GetValue()));
	if (!HelpPathValid(txtEdbHelpPath->GetValue()))
	{
		wxMessageBox(_("An invalid EnterpriseDB help path was specified.\n\nPlease enter another filename, directory or URL, or leave the path blank."), _("Error"), wxICON_ERROR | wxOK);
		txtEdbHelpPath->SetFocus();
		return;
	}

	txtGpHelpPath->SetValue(CleanHelpPath(txtGpHelpPath->GetValue()));
	if (!HelpPathValid(txtGpHelpPath->GetValue()))
	{
		wxMessageBox(_("An invalid GreenplumDB help path was specified.\n\nPlease enter another filename, directory or URL, or leave the path blank."), _("Error"), wxICON_ERROR | wxOK);
		txtGpHelpPath->SetFocus();
		return;
	}

	txtSlonyHelpPath->SetValue(CleanHelpPath(txtSlonyHelpPath->GetValue()));
	if (!HelpPathValid(txtSlonyHelpPath->GetValue()))
	{
		wxMessageBox(_("An invalid Slony help path was specified.\n\nPlease enter another filename, directory or URL, or leave the path blank."), _("Error"), wxICON_ERROR | wxOK);
		txtSlonyHelpPath->SetFocus();
		return;
	}

	// Logfile
	wxString logFile = pickerLogfile->GetPath();
	wxLogInfo(wxT("Setting logfile to: %s"), logFile.c_str());
	settings->SetLogFile(logFile);

	// Loglevel
	wxString logInfo = radLoglevel->GetStringSelection();
	wxLogInfo(wxT("Setting loglevel to: %s"), logInfo.c_str());
	int sel = radLoglevel->GetSelection();

	switch(sel)
	{
		case(0):
			settings->SetLogLevel(LOG_NONE);
			break;
		case(1):
			settings->SetLogLevel(LOG_ERRORS);
			break;
		case(2):
			settings->SetLogLevel(LOG_NOTICE);
			break;
		case(3):
			settings->SetLogLevel(LOG_SQL);
			break;
		case(4):
			settings->SetLogLevel(LOG_DEBUG);
			break;
		default:
			settings->SetLogLevel(LOG_ERRORS);
			break;
	}

	// Query parameter
	settings->SetMaxRows(StrToLong(txtMaxRows->GetValue()));
	settings->SetMaxColSize(StrToLong(txtMaxColSize->GetValue()));

	settings->SetAskSaveConfirmation(!chkAskSaveConfirm->GetValue());
	settings->SetConfirmDelete(chkAskDelete->GetValue());
	settings->SetShowUsersForPrivileges(chkShowUsersForPrivileges->GetValue());
	settings->SetAutoRowCountThreshold(StrToLong(txtAutoRowCount->GetValue()));
	settings->SetIndentSpaces(StrToLong(txtIndent->GetValue()));
	settings->SetSpacesForTabs(chkSpacesForTabs->GetValue());
	settings->SetCopyQuoting(cbCopyQuote->GetCurrentSelection());
	settings->SetCopyQuoteChar(cbCopyQuoteChar->GetValue());
	settings->SetHistoryMaxQueries(StrToLong(txtHistoryMaxQueries->GetValue()));
	settings->SetHistoryMaxQuerySize(StrToLong(txtHistoryMaxQuerySize->GetValue()));
	settings->SetRefreshOnClick(cbRefreshOnClick->GetSelection());

	wxString copySeparator = cbCopySeparator->GetValue();
	if (copySeparator == _("Tab"))
		copySeparator = wxT("\t");
	settings->SetCopyColSeparator(copySeparator);

	settings->SetStickySql(chkStickySql->GetValue());
	settings->SetIndicateNull(chkIndicateNull->GetValue());
	settings->SetDecimalMark(txtDecimalMark->GetValue());
	settings->SetColumnNames(chkColumnNames->GetValue());
	settings->SetThousandsSeparator(txtThousandsSeparator->GetValue());
	settings->SetAutoRollback(chkAutoRollback->GetValue());
	settings->SetDoubleClickProperties(chkDoubleClickProperties->GetValue());
	settings->SetShowNotices(chkShowNotices->GetValue());

	settings->SetUnicodeFile(chkUnicodeFile->GetValue());
	settings->SetWriteBOM(chkWriteBOM->GetValue());
	settings->SetSystemFont(pickerFont->GetSelectedFont());
	settings->SetSQLFont(pickerSqlFont->GetSelectedFont());
	settings->SetDDFont(pickerFontDD->GetSelectedFont());
	settings->SetSuppressGuruHints(chkSuppressHints->GetValue());
	settings->SetSlonyPath(pickerSlonyPath->GetPath());
	settings->SetPostgresqlPath(pickerPostgresqlPath->GetPath());
	settings->SetEnterprisedbPath(pickerEnterprisedbPath->GetPath());
	settings->SetGPDBPath(pickerGPDBPath->GetPath());

	// Setup PostgreSQL/EnterpriseDB working paths
#if defined(__WXMSW__)
	pgBackupExecutable  = settings->GetPostgresqlPath() + wxT("\\pg_dump.exe");
	pgBackupAllExecutable  = settings->GetPostgresqlPath() + wxT("\\pg_dumpall.exe");
	pgRestoreExecutable = settings->GetPostgresqlPath() + wxT("\\pg_restore.exe");

	edbBackupExecutable  = settings->GetEnterprisedbPath() + wxT("\\pg_dump.exe");
	edbBackupAllExecutable  = settings->GetEnterprisedbPath() + wxT("\\pg_dumpall.exe");
	edbRestoreExecutable = settings->GetEnterprisedbPath() + wxT("\\pg_restore.exe");

	gpBackupExecutable  = settings->GetGPDBPath() + wxT("\\pg_dump.exe");
	gpBackupAllExecutable  = settings->GetGPDBPath() + wxT("\\pg_dumpall.exe");
	gpRestoreExecutable = settings->GetGPDBPath() + wxT("\\pg_restore.exe");
#else
	pgBackupExecutable  = settings->GetPostgresqlPath() + wxT("/pg_dump");
	pgBackupAllExecutable  = settings->GetPostgresqlPath() + wxT("/pg_dumpall");
	pgRestoreExecutable = settings->GetPostgresqlPath() + wxT("/pg_restore");

	edbBackupExecutable  = settings->GetEnterprisedbPath() + wxT("/pg_dump");
	edbBackupAllExecutable  = settings->GetEnterprisedbPath() + wxT("/pg_dumpall");
	edbRestoreExecutable = settings->GetEnterprisedbPath() + wxT("/pg_restore");

	gpBackupExecutable  = settings->GetGPDBPath() + wxT("/pg_dump");
	gpBackupAllExecutable  = settings->GetGPDBPath() + wxT("/pg_dumpall");
	gpRestoreExecutable = settings->GetGPDBPath() + wxT("/pg_restore");
#endif

	if (!wxFile::Exists(pgBackupExecutable))
		pgBackupExecutable = wxEmptyString;
	if (!wxFile::Exists(pgBackupAllExecutable))
		pgBackupAllExecutable = wxEmptyString;
	if (!wxFile::Exists(pgRestoreExecutable))
		pgRestoreExecutable = wxEmptyString;

	if (!wxFile::Exists(edbBackupExecutable))
		edbBackupExecutable = wxEmptyString;
	if (!wxFile::Exists(edbBackupAllExecutable))
		edbBackupAllExecutable = wxEmptyString;
	if (!wxFile::Exists(edbRestoreExecutable))
		edbRestoreExecutable = wxEmptyString;

	if (!wxFile::Exists(gpBackupExecutable))
		gpBackupExecutable = wxEmptyString;
	if (!wxFile::Exists(gpBackupAllExecutable))
		gpBackupAllExecutable = wxEmptyString;
	if (!wxFile::Exists(gpRestoreExecutable))
		gpRestoreExecutable = wxEmptyString;


	settings->SetIgnoreVersion(chkIgnoreVersion->GetValue());

	if (chkResetHints->GetValue())
		frmHint::ResetHints();

	// Set the help paths
	settings->SetPgHelpPath(txtPgHelpPath->GetValue());
	settings->SetEdbHelpPath(txtEdbHelpPath->GetValue());
	settings->SetGpHelpPath(txtGpHelpPath->GetValue());
	settings->SetSlonyHelpPath(txtSlonyHelpPath->GetValue());

	settings->SetSystemSchemas(txtSystemSchemas->GetValue());

	// Save the display options
	bool changed = false;
	for (unsigned int x = 0; x < lstDisplay->GetCount(); x++)
	{
		if (lstDisplay->IsChecked(x) != settings->GetDisplayOption(lstDisplay->GetString(x)))
		{
			changed = true;
			settings->SetDisplayOption(lstDisplay->GetString(x), lstDisplay->IsChecked(x));
		}
	}

	if (chkSystemObjects->GetValue() != settings->GetShowSystemObjects())
	{
		changed = true;
		settings->SetShowSystemObjects(chkSystemObjects->GetValue());
	}

	// Change the status colours
	if (pickerIdleProcessColour->GetColourString() != settings->GetIdleProcessColour())
		changed = true;
	settings->SetIdleProcessColour(pickerIdleProcessColour->GetColourString());

	if (pickerActiveProcessColour->GetColourString() != settings->GetActiveProcessColour())
		changed = true;
	settings->SetActiveProcessColour(pickerActiveProcessColour->GetColourString());

	if (pickerSlowProcessColour->GetColourString() != settings->GetSlowProcessColour())
		changed = true;
	settings->SetSlowProcessColour(pickerSlowProcessColour->GetColourString());

	if (pickerBlockedProcessColour->GetColourString() != settings->GetBlockedProcessColour())
		changed = true;
	settings->SetBlockedProcessColour(pickerBlockedProcessColour->GetColourString());

	// Change files' location
	settings->SetFavouritesFile(pickerFavouritesFile->GetPath());
	settings->SetMacrosFile(pickerMacrosFile->GetPath());
	settings->SetHistoryFile(pickerHistoryFile->GetPath());

	// Change SQL Syntax colours
	if (settings->GetSQLBoxUseSystemBackground() != chkSQLUseSystemBackgroundColour->GetValue())
	{
		changed = true;
		settings->SetSQLBoxUseSystemBackground(chkSQLUseSystemBackgroundColour->GetValue());
	}

	if (settings->GetSQLBoxUseSystemForeground() != chkSQLUseSystemForegroundColour->GetValue())
	{
		changed = true;
		settings->SetSQLBoxUseSystemForeground(chkSQLUseSystemForegroundColour->GetValue());
	}

	if (!settings->GetSQLBoxUseSystemBackground())
	{
		if (pickerSQLBackgroundColour->GetColourString() != settings->GetSQLBoxColourBackground())
			changed = true;
		settings->SetSQLBoxColourBackground(pickerSQLBackgroundColour->GetColourString());
	}

	if (!settings->GetSQLBoxUseSystemForeground())
	{
		if (pickerSQLForegroundColour->GetColourString() != settings->GetSQLBoxColourForeground())
			changed = true;
		settings->SetSQLBoxColourForeground(pickerSQLForegroundColour->GetColourString());
	}

	if (pickerSQLMarginBackgroundColour->GetColourString() != settings->GetSQLMarginBackgroundColour())
		changed = true;
	settings->SetSQLMarginBackgroundColour(pickerSQLMarginBackgroundColour->GetColourString());

	if (pickerSQLCaretColour->GetColourString() != settings->GetSQLColourCaret())
		changed = true;
	settings->SetSQLColourCaret(pickerSQLCaretColour->GetColourString());

	if (pickerSQLColour1->GetColourString() != settings->GetSQLBoxColour(1))
		changed = true;
	settings->SetSQLBoxColour(1, pickerSQLColour1->GetColourString());
	if (pickerSQLColour2->GetColourString() != settings->GetSQLBoxColour(2))
		changed = true;
	settings->SetSQLBoxColour(2, pickerSQLColour2->GetColourString());
	if (pickerSQLColour3->GetColourString() != settings->GetSQLBoxColour(3))
		changed = true;
	settings->SetSQLBoxColour(3, pickerSQLColour3->GetColourString());
	if (pickerSQLColour4->GetColourString() != settings->GetSQLBoxColour(4))
		changed = true;
	settings->SetSQLBoxColour(4, pickerSQLColour4->GetColourString());
	if (pickerSQLColour5->GetColourString() != settings->GetSQLBoxColour(5))
		changed = true;
	settings->SetSQLBoxColour(5, pickerSQLColour5->GetColourString());
	if (pickerSQLColour6->GetColourString() != settings->GetSQLBoxColour(6))
		changed = true;
	settings->SetSQLBoxColour(6, pickerSQLColour6->GetColourString());
	if (pickerSQLColour7->GetColourString() != settings->GetSQLBoxColour(7))
		changed = true;
	settings->SetSQLBoxColour(7, pickerSQLColour7->GetColourString());
	if (pickerSQLColour10->GetColourString() != settings->GetSQLBoxColour(10))
		changed = true;
	settings->SetSQLBoxColour(10, pickerSQLColour10->GetColourString());
	if (pickerSQLColour11->GetColourString() != settings->GetSQLBoxColour(11))
		changed = true;
	settings->SetSQLBoxColour(11, pickerSQLColour11->GetColourString());

	if (settings->GetSQLKeywordsInUppercase() != chkKeywordsInUppercase->GetValue())
	{
		changed = true;
		settings->SetSQLKeywordsInUppercase(chkKeywordsInUppercase->GetValue());
	}

	// Change the language last, as it will affect our tests for changes
	// in the display object types.
	int langNo = cbLanguage->GetCurrentSelection();
	if (langNo >= 0)
	{
		wxLanguage langId;
		if (langNo == 0)
			langId = wxLANGUAGE_DEFAULT;
		else
		{
			const wxLanguageInfo *langInfo = wxLocale::GetLanguageInfo(existingLangs.Item(langNo - 1));
			langId = (wxLanguage) langInfo->Language;
		}

		settings->SetCanonicalLanguage(langId);
	}

	settings->SetOptionsLastTreeItem(menuSelection);

	// Did any display options change? Display this message last, so it's
	// in the selected language.
	if (changed)
		wxMessageBox(_("Changes to the display options may not be visible until the browser tree is refreshed."), _("Display options"), wxICON_INFORMATION | wxOK);

	Destroy();
}


void frmOptions::OnCancel(wxCommandEvent &ev)
{
	Destroy();
}


optionsFactory::optionsFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : actionFactory(list)
{
	mnu->Append(id, _("&Options..."), _("Show options dialog."));
}


wxWindow *optionsFactory::StartDialog(frmMain *form, pgObject *obj)
{
	frmOptions *frm = new frmOptions(form);
	frm->Show();
	return 0;
}

// Enable/disable the copy quote option as required.
void frmOptions::OnChangeCopyQuote(wxCommandEvent &WXUNUSED(ev))
{
	if (cbCopyQuote->GetValue() == _("None"))
		cbCopyQuoteChar->Disable();
	else
		cbCopyQuoteChar->Enable();
}


wxString frmOptions::CheckColour(wxString oldColour)
{
	wxString newColour = wxEmptyString;

	if (oldColour != wxEmptyString)
	{
		wxColour colour;

		if (colour.Set(oldColour))
			newColour = colour.GetAsString(wxC2S_HTML_SYNTAX);
		else
			wxLogError(_("The colour specified is not valid."));
	}

	return newColour;
}

void frmOptions::OnTreeSelChanged(wxTreeEvent &event)
{
	wxTreeItemId sel = event.GetItem();

	if (sel)
		ShowPanel(sel);
}

void frmOptions::ShowPanel(const wxTreeItemId &menuItem)
{
	// Hide everything
	pnlBrowserDisplay->Show(false);
	pnlBrowserProperties->Show(false);
	pnlBrowserBinPath->Show(false);
	pnlBrowserMisc->Show(false);
	pnlQueryToolEditor->Show(false);
	pnlQueryToolColours->Show(false);
	pnlQueryToolResults->Show(false);
	pnlQueryToolFiles->Show(false);
	pnlQueryToolFavourites->Show(false);
	pnlQueryToolMacros->Show(false);
	pnlQueryToolHistoryFile->Show(false);
	pnlDatabaseDesigner->Show(false);
	pnlServerStatus->Show(false);
	pnlMiscUI->Show(false);
	pnlMiscHelpPath->Show(false);
	pnlMiscGuruHints->Show(false);
	pnlMiscLogging->Show(false);

	// Find the one to show
	menuSelection = menus->GetItemText(menuItem);
	if (menuSelection == BROWSER_ITEM || menuSelection == BROWSER_DISPLAY_ITEM)
		pnlBrowserDisplay->Show(true);
	else if (menuSelection == BROWSER_PROPERTIES_ITEM)
		pnlBrowserProperties->Show(true);
	else if (menuSelection == BROWSER_BINPATH_ITEM)
		pnlBrowserBinPath->Show(true);
	else if (menuSelection == BROWSER_MISC_ITEM)
		pnlBrowserMisc->Show(true);

	else if (menuSelection == QUERYTOOL_ITEM || menuSelection == QUERYTOOL_EDITOR_ITEM)
		pnlQueryToolEditor->Show(true);
	else if (menuSelection == QUERYTOOL_COLOURS_ITEM)
	{
		pnlQueryToolColours->Show(true);
		pickerSQLBackgroundColour->UpdateColour();
		pickerSQLForegroundColour->UpdateColour();
		pickerSQLMarginBackgroundColour->UpdateColour();
		pickerSQLColour1->UpdateColour();
		pickerSQLColour2->UpdateColour();
		pickerSQLColour3->UpdateColour();
		pickerSQLColour4->UpdateColour();
		pickerSQLColour5->UpdateColour();
		pickerSQLColour6->UpdateColour();
		pickerSQLColour7->UpdateColour();
		pickerSQLColour10->UpdateColour();
		pickerSQLColour11->UpdateColour();
		pickerSQLCaretColour->UpdateColour();
	}
	else if (menuSelection == QUERYTOOL_RESULTS_ITEM)
		pnlQueryToolResults->Show(true);
	else if (menuSelection == QUERYTOOL_FILES_ITEM)
		pnlQueryToolFiles->Show(true);
	else if (menuSelection == QUERYTOOL_FAVOURITES_ITEM)
		pnlQueryToolFavourites->Show(true);
	else if (menuSelection == QUERYTOOL_MACROS_ITEM)
		pnlQueryToolMacros->Show(true);
	else if (menuSelection == QUERYTOOL_HISTORYFILE_ITEM)
		pnlQueryToolHistoryFile->Show(true);

	else if (menuSelection == DATABASEDESIGNER_ITEM)
		pnlDatabaseDesigner->Show(true);

	else if (menuSelection == SERVERSTATUS_ITEM)
	{
		pnlServerStatus->Show(true);
		pickerIdleProcessColour->UpdateColour();
		pickerActiveProcessColour->UpdateColour();
		pickerSlowProcessColour->UpdateColour();
		pickerBlockedProcessColour->UpdateColour();
	}

	else if (menuSelection == MISC_ITEM || menuSelection == MISC_UI_ITEM)
		pnlMiscUI->Show(true);
	else if (menuSelection == MISC_HELPPATH_ITEM)
		pnlMiscHelpPath->Show(true);
	else if (menuSelection == MISC_GURUHINTS_ITEM)
		pnlMiscGuruHints->Show(true);
	else if (menuSelection == MISC_LOGGING_ITEM)
		pnlMiscLogging->Show(true);

	pnlBrowserDisplay->GetParent()->Layout();
	// we don't need to call GetParent()->Layout() for all panels
	// because they all share the same parent
}

wxTreeItemId frmOptions::GetTreeItemByLabel(const wxTreeItemId &root, const wxString &label)
{
	wxTreeItemIdValue cookie;
	wxTreeItemId child;
	wxTreeItemId notfound;

	if (!root.IsOk())
		return notfound;
	if (label.CompareTo(menus->GetItemText(root)) == 0)
		return root;
	if (!menus->ItemHasChildren(root))
		return notfound;

	child = menus->GetFirstChild(root, cookie);
	while (child.IsOk())
	{
		child = GetTreeItemByLabel(child, label);
		if (child.IsOk())
			return child;
		child = menus->GetNextChild(root, cookie);
	}
	return child;
}