From ae9d31106b2a69e9b45faaa372930bc29879b9a5 Mon Sep 17 00:00:00 2001
From: Guillaume Lelarge <guillaume@lelarge.info>
Date: Tue, 12 Oct 2010 00:02:02 +0200
Subject: [PATCH] Add an option to put keywords in uppercase

The user can check an option, so that every keyword he enters in a SQL box is
automatically in uppercase.

Implements #250.
---
 pgadmin/ctl/ctlSQLBox.cpp           |    5 +++++
 pgadmin/frm/frmOptions.cpp          |    9 +++++++++
 pgadmin/include/utils/sysSettings.h |    2 ++
 pgadmin/ui/frmOptions.xrc           |    9 ++++++++-
 4 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/pgadmin/ctl/ctlSQLBox.cpp b/pgadmin/ctl/ctlSQLBox.cpp
index 3cd5577..c5b007f 100644
--- a/pgadmin/ctl/ctlSQLBox.cpp
+++ b/pgadmin/ctl/ctlSQLBox.cpp
@@ -114,6 +114,11 @@ void ctlSQLBox::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons
 		StyleSetFont(i, fntSQLBox);
 	}
 
+    // Keywords in uppercase?
+
+    if (settings->GetSQLKeywordsInUppercase())
+        StyleSetCase(5, wxSTC_CASE_UPPER);
+
 	// Margin style
 	StyleSetBackground(wxSTC_STYLE_LINENUMBER, settings->GetSQLMarginBackgroundColour());
 
diff --git a/pgadmin/frm/frmOptions.cpp b/pgadmin/frm/frmOptions.cpp
index ce28d14..a846aef 100644
--- a/pgadmin/frm/frmOptions.cpp
+++ b/pgadmin/frm/frmOptions.cpp
@@ -97,6 +97,7 @@
 #define pickerSQLColour7            CTRL_COLOURPICKER("pickerSQLColour7")
 #define pickerSQLColour10           CTRL_COLOURPICKER("pickerSQLColour10")
 #define pickerSQLColour11           CTRL_COLOURPICKER("pickerSQLColour11")
+#define chkKeywordsInUppercase      CTRL_CHECKBOX("chkKeywordsInUppercase")
 
 BEGIN_EVENT_TABLE(frmOptions, pgDialog)
     EVT_MENU(MNU_HELP,                                            frmOptions::OnHelp)
@@ -269,6 +270,8 @@ frmOptions::frmOptions(frmMain *parent)
 	pickerSQLColour10->SetColour(settings->GetSQLBoxColour(10));
 	pickerSQLColour11->SetColour(settings->GetSQLBoxColour(11));
 
+	chkKeywordsInUppercase->SetValue(settings->GetSQLKeywordsInUppercase());
+
     cbLanguage->Append(_("Default"));
     int sel=0;
     wxLanguage langId=settings->GetCanonicalLanguage();
@@ -693,6 +696,12 @@ void frmOptions::OnOK(wxCommandEvent &ev)
         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();
diff --git a/pgadmin/include/utils/sysSettings.h b/pgadmin/include/utils/sysSettings.h
index 7caae55..f52a3a1 100644
--- a/pgadmin/include/utils/sysSettings.h
+++ b/pgadmin/include/utils/sysSettings.h
@@ -161,6 +161,8 @@ public:
 
     wxString GetSQLMarginBackgroundColour() const { wxString s; Read(wxT("ctlSQLBox/MarginBackgroundColour"), &s, wxT("#dddddd")); return s; }
 	void SetSQLMarginBackgroundColour(const wxString &newval) { Write(wxT("ctlSQLBox/MarginBackgroundColour"), newval); }
+    bool GetSQLKeywordsInUppercase() const { bool b; Read(wxT("KeywordsInUppercase"), &b, false); return b; }
+	void SetSQLKeywordsInUppercase(const bool newval) { Write(wxT("KeywordsInUppercase"), newval); }
 
     // Misc options
     long GetAutoRowCountThreshold() const { long l; Read(wxT("AutoRowCount"), &l, 2000L); return l; }
diff --git a/pgadmin/ui/frmOptions.xrc b/pgadmin/ui/frmOptions.xrc
index dfbd706..358c9c0 100644
--- a/pgadmin/ui/frmOptions.xrc
+++ b/pgadmin/ui/frmOptions.xrc
@@ -810,6 +810,13 @@
                           <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
                           <border>4</border>
                         </object>
+                        <object class="sizeritem">
+                          <object class="wxCheckBox" name="chkKeywordsInUppercase">
+                            <label>Keywords in uppercase</label>
+                          </object>
+                          <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                          <border>4</border>
+                        </object>
                       </object>
                       <flag>wxEXPAND|wxALIGN_CENTRE|wxALL</flag>
                       <border>3</border>
@@ -982,4 +989,4 @@
       </object>
     </object>
   </object>
-</resource>
\ No newline at end of file
+</resource>
-- 
1.7.0.4

