Index: dlg/dlgIndex.cpp
===================================================================
--- dlg/dlgIndex.cpp	(revision 7497)
+++ dlg/dlgIndex.cpp	(working copy)
@@ -30,17 +30,14 @@
 #define txtWhere        CTRL_TEXT("txtWhere")
 #define txtFillFactor   CTRL_TEXT("txtFillFactor")
 
-#define btnAddCol       CTRL_BUTTON("btnAddCol")
-#define btnRemoveCol    CTRL_BUTTON("btnRemoveCol")
+#define chkDesc         CTRL_CHECKBOX("chkDesc")
+#define rdbNulls        CTRL_RADIOBOX("rdbNulls")
 
 
-
 BEGIN_EVENT_TABLE(dlgIndexBase, dlgCollistProperty)
     EVT_TEXT(XRCID("cbTablespace"),                 dlgProperty::OnChange)
     EVT_COMBOBOX(XRCID("cbTablespace"),             dlgProperty::OnChange)
     EVT_TEXT(XRCID("txtFillFactor"),                dlgProperty::OnChange)
-    EVT_BUTTON(XRCID("btnAddCol"),                  dlgIndexBase::OnAddCol)
-    EVT_BUTTON(XRCID("btnRemoveCol"),               dlgIndexBase::OnRemoveCol)
     EVT_LIST_ITEM_SELECTED(XRCID("lstColumns"),     dlgIndexBase::OnSelectListCol)
     EVT_COMBOBOX(XRCID("cbColumns"),                dlgIndexBase::OnSelectComboCol)
 #ifdef __WXMAC__
@@ -126,38 +123,6 @@
     return returncode;
 }
 
-
-void dlgIndexBase::OnAddCol(wxCommandEvent &ev)
-{
-    wxString col=cbColumns->GetValue();
-    if (!col.IsEmpty())
-    {
-        lstColumns->InsertItem(lstColumns->GetItemCount(), col, columnFactory.GetIconId());
-        cbColumns->Delete(cbColumns->GetCurrentSelection());
-        if (cbColumns->GetCount())
-            cbColumns->SetSelection(0);
-
-        CheckChange();
-        if (!cbColumns->GetCount())
-            btnAddCol->Disable();
-    }
-}
-
-
-void dlgIndexBase::OnRemoveCol(wxCommandEvent &ev)
-{
-    long pos=lstColumns->GetSelection();
-    if (pos >= 0)
-    {
-        wxString col=lstColumns->GetItemText(pos);
-        lstColumns->DeleteItem(pos);
-        cbColumns->Append(col);
-
-        CheckChange();
-        btnRemoveCol->Disable();
-    }
-}
-
 void dlgIndexBase::OnSelectListCol(wxListEvent &ev)
 {
     OnSelectCol();
@@ -215,25 +180,10 @@
 }
 
 
-wxString dlgIndexBase::GetColumns()
-{
-    wxString sql;
-
-    int pos;
-    // iterate cols
-    for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++)
-    {
-        if (pos)
-            sql += wxT(", ");
-
-        sql += qtIdent(lstColumns->GetItemText(pos));
-    }
-    return sql;
-}
-
-
 BEGIN_EVENT_TABLE(dlgIndex, dlgIndexBase)
-    EVT_TEXT(XRCID("cbTablespace"),                 dlgProperty::OnChange)
+    EVT_BUTTON(XRCID("btnAddCol"),                  dlgIndex::OnAddCol)
+    EVT_BUTTON(XRCID("btnRemoveCol"),               dlgIndex::OnRemoveCol)
+    //EVT_TEXT(XRCID("cbTablespace"),                 dlgProperty::OnChange)
     EVT_CHECKBOX(XRCID("chkClustered"),             dlgProperty::OnChange)
 END_EVENT_TABLE();
 
@@ -272,6 +222,23 @@
 }
 
 
+wxString dlgIndex::GetColumns()
+{
+    wxString sql;
+
+    int pos;
+    // iterate cols
+    for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++)
+    {
+        if (pos)
+            sql += wxT(", ");
+
+        sql += lstColumns->GetItemText(pos);
+    }
+    return sql;
+}
+
+
 int dlgIndex::Go(bool modal)
 {
     if (!connection->BackendMinimumVersion(7, 4))
@@ -291,6 +258,8 @@
         chkUnique->Disable();
         chkConcurrent->Disable();
         PrepareTablespace(cbTablespace, index->GetTablespaceOid());
+        chkDesc->Disable();
+        rdbNulls->Disable();
     }
     else
     {
@@ -312,14 +281,85 @@
         if (!this->database->BackendMinimumVersion(8, 2))
             chkConcurrent->Disable();
 
+        if (!this->database->BackendMinimumVersion(8, 3)) {
+            chkDesc->Disable();
+            rdbNulls->Disable();
+        }
+
         // Add the default tablespace 
         cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0);
         cbTablespace->SetSelection(0);
     }
-    return dlgIndexBase::Go(modal);
+
+    int returnCode = dlgIndexBase::Go(modal);
+
+    // convert column combobox to quoted column name
+    if (!index)
+        for (int itemIdx=0, itemCount=cbColumns->GetCount(); itemIdx<itemCount; itemIdx++)
+            cbColumns->SetString(itemIdx, qtIdent(cbColumns->GetString(itemIdx)));
+
+    return returnCode;
 }
-       
 
+
+void dlgIndex::OnAddCol(wxCommandEvent &ev)
+{
+    wxString colDef=cbColumns->GetValue();
+
+    if (!colDef.IsEmpty())
+    {
+        if (this->database->BackendMinimumVersion(8, 3)) {
+            if (chkDesc->GetValue()) {
+                colDef += wxT(" DESC");
+
+                // not default
+                if (rdbNulls->GetSelection()==2)
+                    colDef += wxT(" NULLS LAST");
+            } else
+                if (rdbNulls->GetSelection()==1)
+                    colDef += wxT(" NULLS FIRST");
+
+        }
+
+        lstColumns->InsertItem(lstColumns->GetItemCount(), colDef, columnFactory.GetIconId());
+        cbColumns->Delete(cbColumns->GetCurrentSelection());
+        // back to default value
+        chkDesc->SetValue(false);
+        rdbNulls->SetSelection(0);
+        if (cbColumns->GetCount())
+            cbColumns->SetSelection(0);
+
+        CheckChange();
+        if (!cbColumns->GetCount())
+            btnAddCol->Disable();
+    }
+}
+
+
+void dlgIndex::OnRemoveCol(wxCommandEvent &ev)
+{
+    long pos=lstColumns->GetSelection();
+    if (pos >= 0)
+    {
+        wxString colDef=lstColumns->GetItemText(pos);
+        wxString colName;
+        if (this->database->BackendMinimumVersion(8, 3)) {
+            if (colDef.EndsWith(wxT(" NULLS FIRST"), &colName))
+                colDef=colName;
+            if (colDef.EndsWith(wxT(" NULLS LAST"), &colName))
+                colDef=colName;
+            if (!colDef.EndsWith(wxT(" DESC"), &colName))
+                colName=colDef;
+        } else colName=colDef;
+
+        lstColumns->DeleteItem(pos);
+        cbColumns->Append(colName);
+
+        CheckChange();
+        btnRemoveCol->Disable();
+    }
+}
+
 wxString dlgIndex::GetSql()
 {
     wxString sql;
Index: dlg/dlgIndexConstraint.cpp
===================================================================
--- dlg/dlgIndexConstraint.cpp	(revision 7497)
+++ dlg/dlgIndexConstraint.cpp	(working copy)
@@ -23,10 +23,14 @@
 #include "schema/pgIndexConstraint.h"
 
 
-
 #define cbTablespace    CTRL_COMBOBOX("cbTablespace")
 
+BEGIN_EVENT_TABLE(dlgIndexConstraint, dlgIndexBase)
+    EVT_BUTTON(XRCID("btnAddCol"),                  dlgIndexConstraint::OnAddCol)
+    EVT_BUTTON(XRCID("btnRemoveCol"),               dlgIndexConstraint::OnRemoveCol)
+END_EVENT_TABLE();
 
+
 dlgIndexConstraint::dlgIndexConstraint(pgaFactory *f, frmMain *frame, const wxString &resName, pgIndexBase *index, pgTable *parentNode)
 : dlgIndexBase(f, frame, resName, index, parentNode)
 {
@@ -39,6 +43,23 @@
 }
 
 
+wxString dlgIndexConstraint::GetColumns()
+{
+    wxString sql;
+
+    int pos;
+    // iterate cols
+    for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++)
+    {
+        if (pos)
+            sql += wxT(", ");
+
+        sql += qtIdent(lstColumns->GetItemText(pos));
+    }
+    return sql;
+}
+
+
 int dlgIndexConstraint::Go(bool modal)
 {
     PrepareTablespace(cbTablespace);
@@ -69,6 +90,38 @@
 }
 
 
+void dlgIndexConstraint::OnAddCol(wxCommandEvent &ev)
+{
+    wxString col=cbColumns->GetValue();
+    if (!col.IsEmpty())
+    {
+        lstColumns->InsertItem(lstColumns->GetItemCount(), col, columnFactory.GetIconId());
+        cbColumns->Delete(cbColumns->GetCurrentSelection());
+        if (cbColumns->GetCount())
+            cbColumns->SetSelection(0);
+
+        CheckChange();
+        if (!cbColumns->GetCount())
+            btnAddCol->Disable();
+    }
+}
+
+
+void dlgIndexConstraint::OnRemoveCol(wxCommandEvent &ev)
+{
+    long pos=lstColumns->GetSelection();
+    if (pos >= 0)
+    {
+        wxString col=lstColumns->GetItemText(pos);
+        lstColumns->DeleteItem(pos);
+        cbColumns->Append(col);
+
+        CheckChange();
+        btnRemoveCol->Disable();
+    }
+}
+
+
 wxString dlgIndexConstraint::GetDefinition()
 {
     wxString sql;
Index: include/dlg/dlgIndex.h
===================================================================
--- include/dlg/dlgIndex.h	(revision 7497)
+++ include/dlg/dlgIndex.h	(working copy)
@@ -19,6 +19,9 @@
 class pgIndex;
 class pgIndexBase;
 
+#define btnAddCol       CTRL_BUTTON("btnAddCol")
+#define btnRemoveCol    CTRL_BUTTON("btnRemoveCol")
+
 class dlgIndexBase : public dlgCollistProperty
 {
 public:
@@ -30,7 +33,6 @@
     void OnSelectCol();
     void CheckChange();
     pgObject *GetObject();
-    wxString GetColumns();
     int Go(bool modal);
 
 protected:
@@ -41,9 +43,6 @@
     void OnChangeSize(wxSizeEvent &ev);
 #endif
 
-    void OnAddCol(wxCommandEvent &ev);
-    void OnRemoveCol(wxCommandEvent &ev);
-
     DECLARE_EVENT_TABLE()
 };
 
@@ -55,10 +54,14 @@
 
     int Go(bool modal);
     void CheckChange();
+    wxString GetColumns();
     wxString GetSql();
     pgObject *CreateObject(pgCollection *collection);
 
 private:
+    void OnAddCol(wxCommandEvent &ev);
+    void OnRemoveCol(wxCommandEvent &ev);
+
     DECLARE_EVENT_TABLE()
 };
 
Index: include/dlg/dlgIndexConstraint.h
===================================================================
--- include/dlg/dlgIndexConstraint.h	(revision 7497)
+++ include/dlg/dlgIndexConstraint.h	(working copy)
@@ -34,9 +34,15 @@
 
     int Go(bool modal);
     wxString GetDefinition();
+    wxString GetColumns();
     wxString GetSql();
     wxString GetHelpPage() const { return wxT("pg/sql-altertable"); }
 
+private:
+    void OnAddCol(wxCommandEvent &ev);
+    void OnRemoveCol(wxCommandEvent &ev);
+
+    DECLARE_EVENT_TABLE()
 };
 
 
Index: ui/dlgIndex.xrc
===================================================================
--- ui/dlgIndex.xrc	(revision 7497)
+++ ui/dlgIndex.xrc	(working copy)
@@ -183,7 +183,8 @@
                 </object>
                 <object class="sizeritem">
                   <object class="wxFlexGridSizer">
-                    <cols>5</cols>
+                    <cols>3</cols>
+		            <rows>1</rows>
                     <growablecols>0</growablecols>
                     <object class="sizeritem">
                       <object class="wxComboBox" name="cbColumns">
@@ -193,6 +194,52 @@
                       <flag>wxGROW|wxALIGN_CENTRE_VERTICAL</flag>
                     </object>
                     <object class="spacer">
+                      <size>10,3d</size>
+                    </object>
+                    <object class="sizeritem">
+                      <object class="wxCheckBox" name="chkDesc">
+                        <label>DESC</label>
+                      </object>
+                      <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                    </object>
+				  </object>
+                  <flag>wxEXPAND|wxALL</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxFlexGridSizer">
+                    <cols>3</cols>
+                    <object class="sizeritem">
+                      <object class="wxStaticText" name="stNulls">
+                        <label>NULLS</label>
+                      </object>
+                      <flag>wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                    </object>
+                    <object class="spacer">
+                      <size>10,3d</size>
+                    </object>
+                    <object class="sizeritem">
+                      <object class="wxRadioBox" name="rdbNulls">
+                        <label></label>
+                        <content>
+                          <item>DEFAULT</item>
+                          <item>FIRST</item>
+                          <item>LAST</item>
+                        </content>
+                        <selection>0</selection>
+                        <dimension>1</dimension>
+                        <style>wxRA_SPECIFY_ROWS</style>
+                      </object>
+                    </object>
+                  </object>
+				  <flag>wxEXPAND|wxALL</flag>
+				  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxFlexGridSizer">
+                    <cols>4</cols>
+                    <growablecols>0</growablecols>
+                    <object class="spacer">
                       <size>3,3d</size>
                     </object>
                     <object class="sizeritem">
