Le 19/04/2010 13:03, Dave Page a écrit :
> On Sat, Apr 17, 2010 at 7:09 PM, Guillaume Lelarge
> <guilla...@lelarge.info> wrote:
>> What do you want with a right click in a group node? access to the
>> properties?
> 
> Same as other nodes - Add xxx etc. It's not that important though.
> 

Well, we didn't do it for the actual Servers node. I don't think we
should do it for this one.

>>> Y'know - as I type I can't help thinking that the correct way to do
>>> this is to consider the root node to be the group, in which we
>>> currently have a single, fixed group called 'Servers'. Additional
>>> groups would then be additional root nodes... but I don't know if you
>>> can do that on all operating systems.
>>>
>>
>> Done. Seems to work everywhere I checked.
> 
> There's something pretty broken. I'm not sure how to describe it
> though... see if you can make sense of this!
> 
> - I edited a server. It had picked up my 'custom' group correctly, but
> also had a blank entry in the list. I expected to see the default
> 'Servers' there.
> - I moved the server to 'blank'. Nothing seemed to happen.
> - I looked at the properties for the server again. Now I only have 2
> blank groups listed.
> - I restarted pgAdmin. Now I have 2 identical servers under 'Servers'.
> 
> What I would expect to see is:
> 
> - Any existing servers automatically get moved into the 'Servers'
> group on first run of the new version.
> - Any new servers default to the first group in the combo box. This
> will obviously be 'Servers' on a new installation.
> - The Servers group is merely a default that's always available.
> Otherwise it is no different from any other group.
> 

Finally, I had time to work on this. I changed my patch so that it
follows what you expected to see. I was not really able to reproduce the
problem you explain above after my changes.

Can you try this last one? Thanks.


-- 
Guillaume.
 http://www.postgresqlfr.org
 http://dalibo.com
diff --git a/pgadmin/dlg/dlgServer.cpp b/pgadmin/dlg/dlgServer.cpp
index e7a9741..de8f64e 100644
--- a/pgadmin/dlg/dlgServer.cpp
+++ b/pgadmin/dlg/dlgServer.cpp
@@ -1,7 +1,7 @@
 //////////////////////////////////////////////////////////////////////////
 //
 // pgAdmin III - PostgreSQL Tools
-// RCS-ID:      $Id$
+// RCS-ID:      $Id: dlgServer.cpp 8206 2010-03-08 17:57:26Z guillaume $
 // Copyright (C) 2002 - 2010, The pgAdmin Development Team
 // This software is released under the PostgreSQL Licence
 //
@@ -43,6 +43,7 @@
 #define txtPassword     CTRL_TEXT("txtPassword")
 #define txtDbRestriction CTRL_TEXT("txtDbRestriction")
 #define colourPicker    CTRL_COLOURPICKER("colourPicker")
+#define cbGroup         CTRL_COMBOBOX("cbGroup")
 
 
 BEGIN_EVENT_TABLE(dlgServer, dlgProperty)
@@ -59,6 +60,8 @@ BEGIN_EVENT_TABLE(dlgServer, dlgProperty)
     EVT_CHECKBOX(XRCID("chkRestore"),               dlgProperty::OnChange)
     EVT_CHECKBOX(XRCID("chkTryConnect"),            dlgServer::OnChangeTryConnect)
     EVT_COLOURPICKER_CHANGED(XRCID("colourPicker"), dlgServer::OnChangeColour)
+    EVT_TEXT(XRCID("cbGroup"),                      dlgProperty::OnChange)
+    EVT_COMBOBOX(XRCID("cbGroup"),                  dlgProperty::OnChange)
     EVT_BUTTON(wxID_OK,                             dlgServer::OnOK)
 END_EVENT_TABLE();
 
@@ -96,6 +99,24 @@ dlgServer::dlgServer(pgaFactory *f, frmMain *frame, pgServer *node)
         chkTryConnect->SetValue(false);
         chkTryConnect->Disable();
     }
+
+    // Fill the group combobox
+    cbGroup->Append(wxT("Servers"));
+    ctlTree *browser = frame->GetBrowser();
+    wxTreeItemId groupitem;
+    wxTreeItemIdValue groupcookie, servercookie;
+    pgServer *firstserver;
+    if (browser->ItemHasChildren(browser->GetRootItem()))
+    {
+        groupitem = browser->GetFirstChild(browser->GetRootItem(), groupcookie);
+        while (groupitem)
+        {
+            firstserver = (pgServer*)browser->GetObject(browser->GetFirstChild(groupitem, servercookie));
+            if (!firstserver->GetGroup().IsEmpty() && firstserver->GetGroup() != wxT("Servers"))
+                cbGroup->Append(firstserver->GetGroup());
+            groupitem = browser->GetNextChild(browser->GetRootItem(), groupcookie);
+        }
+    }
 }
 
 
@@ -155,10 +176,81 @@ void dlgServer::OnOK(wxCommandEvent &ev)
         wxColour colour = colourPicker->GetColour();
         wxString sColour = colour.GetAsString(wxC2S_HTML_SYNTAX);
         server->iSetColour(sColour);
+        if (cbGroup->GetValue().IsEmpty())
+            cbGroup->SetValue(wxT("Servers"));
+        if (server->GetGroup() != cbGroup->GetValue())
+        {
+            ctlTree *browser = mainForm->GetBrowser();
+            wxTreeItemId oldgroupitem, groupitem, serveritem;
+            wxTreeItemIdValue groupcookie;
+            bool found;
+            int total;
+            wxString label, oldgroupname;
+
+            // Duplicate server object
+            pgServer *newserver = new pgServer(
+                server->GetName(),
+                server->GetDescription(),
+                server->GetDatabaseName(), 
+                server->GetUsername(), 
+                server->GetPort(), 
+                server->GetStorePwd(),
+                server->GetRestore(),
+                server->GetSSL(),
+	        	server->GetColour(),
+                server->GetGroup());
+            newserver->iSetDbRestriction(server->GetDbRestriction().Trim());
+
+            // Drop the old item
+            // (will also take care of dropping the pgServer item)
+            oldgroupitem = browser->GetItemParent(item);
+            oldgroupname = server->GetGroup();
+            if (oldgroupname.IsEmpty())
+                oldgroupname = wxT("Servers");
+            browser->Delete(item);
+
+            // Move the item
+            found = false;
+            if (browser->ItemHasChildren(browser->GetRootItem()))
+            {
+                groupitem = browser->GetFirstChild(browser->GetRootItem(), groupcookie);
+                while (!found && groupitem)
+                {
+                    if (browser->GetItemText(groupitem).StartsWith(cbGroup->GetValue()))
+                        found = true;
+                    else
+                        groupitem = browser->GetNextChild(browser->GetRootItem(), groupcookie);
+                }
+            }
+
+            if (!found)
+                groupitem = browser->AppendItem(browser->GetRootItem(), cbGroup->GetValue(), browser->GetItemImage(browser->GetRootItem()));
+
+            serveritem = browser->AppendItem(groupitem, newserver->GetFullName(), newserver->GetIconId(), -1, newserver);
+            browser->SortChildren(groupitem);
+            browser->Expand(groupitem);
+
+            // Count the number of items in the old group item
+            total = browser->GetChildrenCount(oldgroupitem, false);
+            label = oldgroupname + wxT(" (") + NumToStr((long)total) + wxT(")");
+            browser->SetItemText(oldgroupitem, label);
+
+            // Count the number of items in the new group item
+            total = browser->GetChildrenCount(groupitem, false);
+            label = cbGroup->GetValue() + wxT(" (") + NumToStr((long)total) + wxT(")");
+            browser->SetItemText(groupitem, label);
+
+            // Re-initialize old variables to have their new meanings
+            server = newserver;
+            item = serveritem;
+        }
+        server->iSetGroup(cbGroup->GetValue());
+
+        wxMessageBox(_("Note: some changes to server settings may only take effect the next time pgAdmin connects to the server."), _("Server settings"), wxICON_INFORMATION);
+
         mainForm->execSelChange(server->GetId(), true);
         mainForm->GetBrowser()->SetItemText(item, server->GetFullName());
-
-        wxMessageBox(_("Note: changes to server settings will take effect the next time the server is connected."), _("Server settings"), wxICON_INFORMATION);
+        mainForm->SetItemBackgroundColour(item, wxColour(server->GetColour()));
     }
 
     if (IsModal())
@@ -254,6 +346,7 @@ int dlgServer::Go(bool modal)
         chkRestore->SetValue(server->GetRestore());
         txtDbRestriction->SetValue(server->GetDbRestriction());
         colourPicker->SetColour(server->GetColour());
+        cbGroup->SetValue(server->GetGroup());
 
         stPassword->Disable();
         txtPassword->Disable();
@@ -270,6 +363,7 @@ int dlgServer::Go(bool modal)
     else
     {
         SetTitle(_("Add server"));
+        cbGroup->SetValue(wxT("Servers"));
     }
 
     return dlgProperty::Go(modal);
@@ -295,7 +389,8 @@ pgObject *dlgServer::CreateObject(pgCollection *collection)
     pgServer *obj=new pgServer(GetName(), txtDescription->GetValue(), cbDatabase->GetValue(), 
         txtUsername->GetValue(), StrToLong(txtPort->GetValue()), 
         chkTryConnect->GetValue() && chkStorePwd->GetValue(), 
-        chkRestore->GetValue(), cbSSL->GetCurrentSelection());
+        chkRestore->GetValue(), cbSSL->GetCurrentSelection(),
+		colourPicker->GetColourString(), cbGroup->GetValue());
 
     obj->iSetDbRestriction(txtDbRestriction->GetValue().Trim());
 
@@ -338,7 +433,8 @@ void dlgServer::CheckChange()
                || chkStorePwd->GetValue() != server->GetStorePwd()
                || chkRestore->GetValue() != server->GetRestore()
                || txtDbRestriction->GetValue() != server->GetDbRestriction()
-               || sColour != sColour2;
+               || sColour != sColour2
+               || cbGroup->GetValue() != server->GetGroup();
     }
 
 
diff --git a/pgadmin/frm/events.cpp b/pgadmin/frm/events.cpp
index f705333..1bc743c 100644
--- a/pgadmin/frm/events.cpp
+++ b/pgadmin/frm/events.cpp
@@ -361,8 +361,6 @@ void frmMain::execSelChange(wxTreeItemId item, bool currentNode)
 
 void frmMain::setDisplay(pgObject *data, ctlListView *props, ctlSQLBox *sqlbox)
 {
-    browser->RemoveDummyChild(data);
-
     pgServer *server=0;
 
 
diff --git a/pgadmin/frm/frmMain.cpp b/pgadmin/frm/frmMain.cpp
index d0134a8..d9b7d90 100644
--- a/pgadmin/frm/frmMain.cpp
+++ b/pgadmin/frm/frmMain.cpp
@@ -130,7 +130,7 @@ frmMain::frmMain(const wxString& title)
     CreateMenus();
     
     // Setup the object browser
-    browser = new ctlTree(this, CTL_BROWSER, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS | wxSIMPLE_BORDER);
+    browser = new ctlTree(this, CTL_BROWSER, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS | wxSIMPLE_BORDER | wxTR_HIDE_ROOT);
     browser->SetImageList(imageList);
 
     // Setup the listview
@@ -207,12 +207,12 @@ frmMain::frmMain(const wxString& title)
 
     // Add the root node
     serversObj = new pgServerCollection(serverFactory.GetCollectionFactory());
-    wxTreeItemId servers = browser->AddRoot(wxGetTranslation(serverFactory.GetCollectionFactory()->GetTypeName()),
+    wxTreeItemId root = browser->AddRoot(wxGetTranslation(serverFactory.GetCollectionFactory()->GetTypeName()),
         serversObj->GetIconId(), -1, serversObj);
+    browser->AppendItem(root, wxT("Servers"), serversObj->GetIconId(), -1);
 
     // Load servers
     RetrieveServers();
-    browser->Expand(servers);
 }
 
 
@@ -1130,43 +1130,53 @@ void frmMain::StoreServers()
     gethostname(buf, 255); 
     wxString hostname = wxString(buf, wxConvUTF8);
 
-    // Write the individual servers
-    // Iterate through all the child nodes of the Servers node
-    treeObjectIterator servers(browser, serversObj);
-
-    while ((server = (pgServer*)servers.GetNextObject()) != 0)
+    wxTreeItemIdValue foldercookie;
+    wxTreeItemId folderitem = browser->GetFirstChild(browser->GetRootItem(), foldercookie);
+    while (folderitem)
     {
-        if (server->IsCreatedBy(serverFactory))
+        if (browser->ItemHasChildren(folderitem))
         {
-            wxString key;
-            ++numServers;
-
-            key.Printf(wxT("Servers/%d/"), numServers);
-            settings->Write(key + wxT("Server"), server->GetName());
-            settings->Write(key + wxT("Description"), server->GetDescription());
-            settings->Write(key + wxT("ServiceID"), server->GetServiceID());
-            settings->Write(key + wxT("DiscoveryID"), server->GetDiscoveryID());
-            settings->Write(key + wxT("Port"), server->GetPort());
-            settings->Write(key + wxT("StorePwd"), server->GetStorePwd());
-            settings->Write(key + wxT("Restore"), server->GetRestore());
-            settings->Write(key + wxT("Database"), server->GetDatabaseName());
-            settings->Write(key + wxT("Username"), server->GetUsername());
-            settings->Write(key + wxT("LastDatabase"), server->GetLastDatabase());
-            settings->Write(key + wxT("LastSchema"), server->GetLastSchema());
-            settings->Write(key + wxT("DbRestriction"), server->GetDbRestriction());
-            settings->Write(key + wxT("Colour"), server->GetColour());
-            settings->Write(key + wxT("SSL"), server->GetSSL());
-
-            pgCollection *coll=browser->FindCollection(databaseFactory, server->GetId());
-            if (coll)
+            wxTreeItemIdValue servercookie;
+            wxTreeItemId serveritem = browser->GetFirstChild(folderitem, servercookie);
+            while (serveritem)
             {
-                treeObjectIterator dbs(browser, coll);
-                pgDatabase *db;
+                server = (pgServer*)browser->GetItemData(serveritem);
+                if (server->IsCreatedBy(serverFactory))
+                {
+                    wxString key;
+                    ++numServers;
+
+                    key.Printf(wxT("Servers/%d/"), numServers);
+                    settings->Write(key + wxT("Server"), server->GetName());
+                    settings->Write(key + wxT("Description"), server->GetDescription());
+                    settings->Write(key + wxT("ServiceID"), server->GetServiceID());
+                    settings->Write(key + wxT("DiscoveryID"), server->GetDiscoveryID());
+                    settings->Write(key + wxT("Port"), server->GetPort());
+                    settings->Write(key + wxT("StorePwd"), server->GetStorePwd());
+                    settings->Write(key + wxT("Restore"), server->GetRestore());
+                    settings->Write(key + wxT("Database"), server->GetDatabaseName());
+                    settings->Write(key + wxT("Username"), server->GetUsername());
+                    settings->Write(key + wxT("LastDatabase"), server->GetLastDatabase());
+                    settings->Write(key + wxT("LastSchema"), server->GetLastSchema());
+                    settings->Write(key + wxT("DbRestriction"), server->GetDbRestriction());
+                    settings->Write(key + wxT("Colour"), server->GetColour());
+                    settings->Write(key + wxT("SSL"), server->GetSSL());
+                    settings->Write(key + wxT("Group"), server->GetGroup());
+
+                    pgCollection *coll=browser->FindCollection(databaseFactory, server->GetId());
+                    if (coll)
+                    {
+                        treeObjectIterator dbs(browser, coll);
+                        pgDatabase *db;
 
-                while ((db=(pgDatabase*)dbs.GetNextObject()) != 0)
-                    settings->Write(key + wxT("Databases/") + db->GetName() + wxT("/SchemaRestriction"), db->GetSchemaRestriction());
+                        while ((db=(pgDatabase*)dbs.GetNextObject()) != 0)
+                            settings->Write(key + wxT("Databases/") + db->GetName() + wxT("/SchemaRestriction"), db->GetSchemaRestriction());
+                    }
+                }
+                serveritem = browser->GetNextChild(folderitem, servercookie);
             }
         }
+        folderitem = browser->GetNextChild(browser->GetRootItem(), foldercookie);
     }
 
     // Write the server count
@@ -1177,15 +1187,28 @@ void frmMain::StoreServers()
 
 void frmMain::RetrieveServers()
 {
+    wxString label;
+    int total = 0;
+    wxTreeItemIdValue groupcookie;
+    wxTreeItemId groupitem;
+
     // Retrieve previously stored servers
     wxLogInfo(wxT("Reloading servers..."));
 
+    // Create all servers' nodes
     serverFactory.CreateObjects(serversObj, browser);
     
-    // Reset the Servers node text
-    wxString label;
-    label.Printf(_("Servers (%d)"), browser->GetChildrenCount(serversObj->GetId(), false));
-    browser->SetItemText(serversObj->GetId(), label);
+    // Count number of servers and groups
+    groupitem = browser->GetFirstChild(browser->GetRootItem(), groupcookie);
+    while (groupitem)
+    {
+        total = browser->GetChildrenCount(groupitem, false);
+        label = browser->GetItemText(groupitem) + wxT(" (") + NumToStr((long)total) + wxT(")");
+        browser->SetItemText(groupitem, label);
+        browser->SortChildren(groupitem);
+        browser->Expand(groupitem);
+        groupitem = browser->GetNextChild(browser->GetRootItem(), groupcookie);
+    }
 }
 
 pgServer *frmMain::ConnectToServer(const wxString& servername, bool restore)
@@ -1251,6 +1274,23 @@ void frmMain::SetStatusText(const wxString &msg)
     statusBar->SetStatusText(wxEmptyString, 2);
 }
 
+void frmMain::SetItemBackgroundColour(wxTreeItemId item, wxColour colour)
+{
+    wxTreeItemIdValue cookie;
+
+    browser->SetItemBackgroundColour(item, wxColour(colour));
+    if (browser->ItemHasChildren(item))
+    {
+        wxTreeItemId childitem = browser->GetFirstChild(item, cookie);
+        while (childitem)
+        {
+            SetItemBackgroundColour(childitem, colour);
+            childitem = browser->GetNextChild(item, cookie);
+        }
+    }
+}
+
+
 /////////////////////////////////////////
 
 
diff --git a/pgadmin/include/frm/frmMain.h b/pgadmin/include/frm/frmMain.h
index 1e1ea01..05f8e58 100644
--- a/pgadmin/include/frm/frmMain.h
+++ b/pgadmin/include/frm/frmMain.h
@@ -121,6 +121,8 @@ public:
     void UpdateAllFavouritesList();
     void UpdateAllMacrosList();
 
+    void SetItemBackgroundColour(wxTreeItemId item, wxColour colour);
+
 private:
     wxAuiManager manager;
     ctlTree *browser;
diff --git a/pgadmin/include/schema/pgServer.h b/pgadmin/include/schema/pgServer.h
index 776ffd0..35af774 100644
--- a/pgadmin/include/schema/pgServer.h
+++ b/pgadmin/include/schema/pgServer.h
@@ -1,7 +1,7 @@
 //////////////////////////////////////////////////////////////////////////
 //
 // pgAdmin III - PostgreSQL Tools
-// RCS-ID:      $Id$
+// RCS-ID:      $Id: pgServer.h 8271 2010-04-16 21:11:41Z guillaume $
 // Copyright (C) 2002 - 2010, The pgAdmin Development Team
 // This software is released under the PostgreSQL Licence
 //
@@ -38,7 +38,7 @@ extern pgServerFactory serverFactory;
 class pgServer : public pgObject
 {
 public:
-	pgServer(const wxString& newServer = wxT(""), const wxString& newDescription = wxT(""), const wxString& newDatabase = wxT(""), const wxString& newUsername = wxT(""), int newPort = 5432, bool storePwd=false, bool restore=true, int sslMode=0, const wxString &colour = wxEmptyString);
+	pgServer(const wxString& newServer = wxT(""), const wxString& newDescription = wxT(""), const wxString& newDatabase = wxT(""), const wxString& newUsername = wxT(""), int newPort = 5432, bool storePwd=false, bool restore=true, int sslMode=0, const wxString &colour = wxEmptyString, const wxString &group = wxEmptyString);
     ~pgServer();
     int GetIconId();
 
@@ -123,6 +123,9 @@ public:
 	void iSetColour(const wxString &s) { colour = s; }
 	wxString GetColour() { return colour; }
 
+	void iSetGroup(const wxString &s) { group = s; }
+	wxString GetGroup() { return group; }
+
     bool HasPrivilege(const wxString &objTyp, const wxString &objName, const wxString &priv) { return conn->HasPrivilege(objTyp, objName, priv); }
     bool ExecuteVoid(const wxString& sql) { return conn->ExecuteVoid(sql); }
     wxString ExecuteScalar(const wxString& sql) { return conn->ExecuteScalar(sql); }
@@ -163,6 +166,7 @@ private:
     wxString versionNum;
     wxString dbRestriction;
 	wxString colour;
+	wxString group;
 
     bool inRecovery;
     wxString receiveLoc, replayLoc;
diff --git a/pgadmin/schema/pgServer.cpp b/pgadmin/schema/pgServer.cpp
index 46ca382..52d2f73 100644
--- a/pgadmin/schema/pgServer.cpp
+++ b/pgadmin/schema/pgServer.cpp
@@ -1,7 +1,7 @@
 //////////////////////////////////////////////////////////////////////////
 //
 // pgAdmin III - PostgreSQL Tools
-// RCS-ID:      $Id$
+// RCS-ID:      $Id: pgServer.cpp 8271 2010-04-16 21:11:41Z guillaume $
 // Copyright (C) 2002 - 2010, The pgAdmin Development Team
 // This software is released under the PostgreSQL Licence
 //
@@ -39,7 +39,7 @@
 
 #define DEFAULT_PG_DATABASE wxT("postgres")
 
-pgServer::pgServer(const wxString& newName, const wxString& newDescription, const wxString& newDatabase, const wxString& newUsername, int newPort, bool _storePwd, bool _restore, int _ssl, const wxString &_colour)
+pgServer::pgServer(const wxString& newName, const wxString& newDescription, const wxString& newDatabase, const wxString& newUsername, int newPort, bool _storePwd, bool _restore, int _ssl, const wxString &_colour, const wxString &_group)
 : pgObject(serverFactory, newName)
 {  
     description = newDescription;
@@ -48,7 +48,9 @@ pgServer::pgServer(const wxString& newName, const wxString& newDescription, cons
     port = newPort;
     ssl=_ssl;
     colour = _colour;
-    serverIndex=0;
+    group = _group;
+
+	serverIndex=0;
 
     connected = false;
     lastSystemOID = 0;
@@ -1114,10 +1116,14 @@ bool pgServerObjCollection::CanCreate()
 
 pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, const wxString &restr)
 {
+    wxTreeItemId groupitem, serveritem;
+    wxTreeItemIdValue groupcookie;
+    bool found;
+
     long numServers=settings->Read(wxT("Servers/Count"), 0L);
 
     long loop, port, ssl=0;
-    wxString key, servername, description, database, username, lastDatabase, lastSchema, storePwd, restore, serviceID, discoveryID, dbRestriction, colour;
+    wxString key, servername, description, database, username, lastDatabase, lastSchema, storePwd, restore, serviceID, discoveryID, dbRestriction, colour, group;
     pgServer *server=0;
 
     wxArrayString discoveredServers;
@@ -1127,6 +1133,7 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
     gethostname(buf, 255); 
     wxString hostname = wxString(buf, wxConvUTF8);
 
+    //wxLogError(wxT("Loading previously registered servers"));
     wxLogInfo(wxT("Loading previously registered servers"));
 
     for (loop = 1; loop <= numServers; ++loop)
@@ -1146,9 +1153,11 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
         settings->Read(key + wxT("LastSchema"), &lastSchema, wxEmptyString);
         settings->Read(key + wxT("DbRestriction"), &dbRestriction, wxEmptyString);
         settings->Read(key + wxT("Colour"), &colour, wxEmptyString);
+        settings->Read(key + wxT("Group"), &group, wxT("Servers"));
 
         // Sanitize the colour
         colour = colour.Trim();
+
         if (!colour.IsEmpty())
         {
             wxColour cColour;
@@ -1160,11 +1169,24 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
                 colour = wxEmptyString;
         }
 
+        if (colour.IsEmpty())
+        {
+            wxColour cColour;
+            cColour.Set(wxT("#FFFFFF"));
+            colour = cColour.GetAsString(wxC2S_HTML_SYNTAX);
+        }
+
         // SSL mode
 #ifdef SSL
         settings->Read(key + wxT("SSL"), &ssl, 0);
 #endif
 
+        // Sanitize the group
+        if (group.IsEmpty())
+        {
+            group = wxT("Servers");
+        }
+
         // Add the Server node
         server = new pgServer(servername, description, database, username, port, StrToBool(storePwd), StrToBool(restore), ssl);
         server->iSetLastDatabase(lastDatabase);
@@ -1174,16 +1196,35 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
         server->iSetDiscovered(false);
         server->iSetDbRestriction(dbRestriction);
         server->iSetColour(colour);
+        server->iSetGroup(group);
         server->iSetServerIndex(loop);
-        wxTreeItemId itm = browser->AppendItem(obj->GetId(), server->GetFullName(), server->GetIconId(), -1, server);
-        browser->SortChildren(obj->GetId());
+
+        found = false;
+        if (browser->ItemHasChildren(obj->GetId()))
+        {
+            groupitem = browser->GetFirstChild(obj->GetId(), groupcookie);
+            while (!found && groupitem)
+            {
+                if (browser->GetItemText(groupitem).StartsWith(group))
+                    found = true;
+                else
+                    groupitem = browser->GetNextChild(obj->GetId(), groupcookie);
+            }
+        }
+
+        if (!found)
+        {
+            groupitem = browser->AppendItem(obj->GetId(), group, obj->GetIconId());
+        }
+
+        serveritem = browser->AppendItem(groupitem, server->GetFullName(), server->GetIconId(), -1, server);
+        browser->SortChildren(groupitem);
         if (!server->GetColour().IsEmpty())
-            browser->SetItemBackgroundColour(itm, wxColour(server->GetColour()));
+            browser->SetItemBackgroundColour(serveritem, wxColour(server->GetColour()));
 
         // Note if we're reloading a discovered server
         if (!discoveryID.IsEmpty())
             discoveredServers.Add(discoveryID);
-
     }
 
 #ifdef WIN32
@@ -1223,7 +1264,7 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
                 server->iSetDiscoveryID(svcName);
                 server->iSetDiscovered(true);
                 server->iSetServiceID(svcName);
-                browser->AppendItem(obj->GetId(), server->GetFullName(), server->GetIconId(), -1, server);
+                browser->AppendItem(browser->GetFirstChild(obj->GetId(), groupcookie), server->GetFullName(), server->GetIconId(), -1, server);
                 browser->SortChildren(obj->GetId());
             }
             // Get the next one...
@@ -1275,7 +1316,7 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
                         server = new pgServer(servername, description, wxT("postgres"), username, port, false, 0);
                         server->iSetDiscoveryID(cnf->GetPath() + wxT("/") + version);
                         server->iSetDiscovered(true);
-                        browser->AppendItem(obj->GetId(), server->GetFullName(), server->GetIconId(), -1, server);
+                        browser->AppendItem(browser->GetFirstChild(obj->GetId(), groupcookie), server->GetFullName(), server->GetIconId(), -1, server);
                     }
                 }
             }
@@ -1307,7 +1348,7 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
                         server = new pgServer(servername, description, wxT("edb"), username, port, false, 0);
                         server->iSetDiscoveryID(cnf->GetPath() + wxT("/") + version);
                         server->iSetDiscovered(true);
-                        browser->AppendItem(obj->GetId(), server->GetFullName(), server->GetIconId(), -1, server);
+                        browser->AppendItem(browser->GetFirstChild(obj->GetId(), groupcookie), server->GetFullName(), server->GetIconId(), -1, server);
                     }
                 }
             }
@@ -1366,8 +1407,6 @@ wxWindow *addServerFactory::StartDialog(frmMain *form, pgObject *obj)
     dlgServer dlg(&serverFactory, form, 0);
     dlg.CenterOnParent();
 
-    ctlTree *browser=form->GetBrowser();
-
     while (rc != PGCONN_OK)
     {
         if (dlg.GoNew() != wxID_OK)
@@ -1397,18 +1436,43 @@ wxWindow *addServerFactory::StartDialog(frmMain *form, pgObject *obj)
             case PGCONN_OK:
             {
                 int icon;
+                ctlTree *browser = form->GetBrowser();
+                wxTreeItemId groupitem, parentitem;
+                wxTreeItemIdValue groupcookie;
+                int total;
+                wxString label;
+
                 if (server->GetConnected())
                     icon = serverFactory.GetIconId();
                 else
                     icon = serverFactory.GetClosedIconId();
                 wxLogInfo(wxT("pgServer object initialised as required."));
-                browser->AppendItem(form->GetServerCollection()->GetId(), server->GetFullName(), icon, -1, server);
-                browser->SortChildren(form->GetServerCollection()->GetId());
 
-                browser->Expand(form->GetServerCollection()->GetId());
-                wxString label;
-                label.Printf(_("Servers (%d)"), form->GetBrowser()->GetChildrenCount(form->GetServerCollection()->GetId(), false));
-                browser->SetItemText(form->GetServerCollection()->GetId(), label);
+                // Add the new server in its group
+                wxString group = server->GetGroup();
+                if (group.Length() == 0)
+                    group = wxT("Servers");
+
+                // Get the parent group
+                groupitem = browser->GetFirstChild(browser->GetRootItem(), groupcookie);
+                while (!parentitem && groupitem)
+                {
+                    if (browser->GetItemText(groupitem).StartsWith(group))
+                        parentitem = groupitem;
+                    groupitem = browser->GetNextChild(browser->GetRootItem(), groupcookie);
+                }
+
+                if (!parentitem)
+                    parentitem = browser->AppendItem(browser->GetRootItem(), group, icon, -1);
+
+                browser->AppendItem(parentitem, server->GetFullName(), icon, -1, server);
+                browser->SortChildren(parentitem);
+                browser->Expand(parentitem);
+
+                total = browser->GetChildrenCount(parentitem, false);
+                label = group + wxT(" (") + NumToStr((long)total) + wxT(")");
+                browser->SetItemText(parentitem, label);
+
                 form->StoreServers();
                 return 0;
             }
diff --git a/pgadmin/ui/dlgServer.xrc b/pgadmin/ui/dlgServer.xrc
index e534149..e6886ba 100644
--- a/pgadmin/ui/dlgServer.xrc
+++ b/pgadmin/ui/dlgServer.xrc
@@ -2,7 +2,7 @@
 <resource>
   <object class="wxDialog" name="dlgServer">
     <title></title>
-    <size>220,280d</size>
+    <size>220,300d</size>
     <style>wxDEFAULT_DIALOG_STYLE|wxCAPTION|wxSYSTEM_MENU|wxRESIZE_BORDER|wxRESIZE_BOX|wxTHICK_FRAME</style>
     <object class="wxFlexGridSizer">
       <cols>1</cols>
@@ -10,7 +10,7 @@
       <growablecols>0</growablecols>
       <object class="sizeritem">
         <object class="wxNotebook" name="nbNotebook">
-          <size>216,255d</size>
+          <size>216,275d</size>
           <selected>0</selected>
           <object class="notebookpage">
             <label>Properties</label>
@@ -195,6 +195,21 @@
                   <flag>wxEXPAND|wxALIGN_CENTRE_VERTICAL|wxALL</flag>
                   <border>4</border>
                 </object>
+                <object class="sizeritem">
+                  <object class="wxStaticText" name="stGroup">
+                    <label>Group</label>
+                  </object>
+                  <flag>wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxComboBox" name="cbGroup">
+                    <style>wxCB_DROPDOWN</style>
+                    <content/>
+                  </object>
+                  <flag>wxEXPAND|wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
               </object>
             </object>
           </object>
-- 
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to