Index: src/dlg/dlgProperty.cpp =================================================================== --- src/dlg/dlgProperty.cpp (revision 5598) +++ src/dlg/dlgProperty.cpp (working copy) @@ -1531,3 +1531,29 @@ // so it's Good Enough (tm) for now. return obj != 0 && !obj->IsCreatedBy(serverFactory.GetCollectionFactory()); } + + +disconnectDatabaseFactory::disconnectDatabaseFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) : contextActionFactory(list) +{ + mnu->Append(id, _("Disconnect"), _("Disconnect from the selected database.")); +} + + +wxWindow *disconnectDatabaseFactory::StartDialog(frmMain *form, pgObject *obj) +{ + pgDatabase *database = (pgDatabase*)obj; + database->Disconnect(); + database->UpdateIcon(form->GetBrowser()); + form->GetBrowser()->DeleteChildren(obj->GetId()); + //form->execSelChange(obj->GetId(), true); + return 0; +} + + +bool disconnectDatabaseFactory::CheckEnable(pgObject *obj) +{ + if (obj && obj->IsCreatedBy(databaseFactory)) + return ((pgDatabase*)obj)->GetConnected(); + + return false; +} \ No newline at end of file Index: src/frm/frmMain.cpp =================================================================== --- src/frm/frmMain.cpp (revision 5598) +++ src/frm/frmMain.cpp (working copy) @@ -309,6 +309,8 @@ new connectServerFactory(menuFactories, toolsMenu, 0); new disconnectServerFactory(menuFactories, toolsMenu, 0); + new disconnectDatabaseFactory(menuFactories, toolsMenu, 0); + new startServiceFactory(menuFactories, toolsMenu, 0); new stopServiceFactory(menuFactories, toolsMenu, 0); @@ -968,4 +970,53 @@ statusBar->SetStatusText(wxEmptyString, 2); } +int frmMain::ReconnectDatabase(pgDatabase *database) +{ + // Create a server object and connect it. + wxBusyInfo waiting(wxString::Format(_("Connecting to database %s"), database->GetName().c_str()), this); + int res = database->Connect(); + + // Check the result, and handle it as appropriate + wxTreeItemId item; + switch (res) + { + case PGCONN_OK: + { + StartMsg(_("Establishing connection")); + + wxLogInfo(wxT("pgDatabase object initialised as required.")); + + database->ShowTreeDetail(browser); + + if (item) + { + browser->SelectItem(item); + + wxSafeYield(); + browser->Expand(item); + browser->EnsureVisible(item); + } + EndMsg(true); + return res; + } + case PGCONN_DNSERR: + /* + // looks strange to me. Shouldn_t server be removed from the tree as well? + delete server; + OnAddServer(wxCommandEvent()); + break; + */ + case PGCONN_BAD: + ReportConnError(database->GetServer()); + break; + + default: + wxLogInfo(wxT("pgServer object didn't initialise because the user aborted.")); + break; + } + + database->GetServer()->Disconnect(this); + return res; +} + Index: src/include/dlgProperty.h =================================================================== --- src/include/dlgProperty.h (revision 5598) +++ src/include/dlgProperty.h (working copy) @@ -248,5 +248,13 @@ bool CheckEnable(pgObject *obj); }; +class disconnectDatabaseFactory : public contextActionFactory +{ +public: + disconnectDatabaseFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar); + wxWindow *StartDialog(frmMain *form, pgObject *obj); + bool CheckEnable(pgObject *obj); +}; + #endif Index: src/include/frmMain.h =================================================================== --- src/include/frmMain.h (revision 5598) +++ src/include/frmMain.h (working copy) @@ -79,6 +79,7 @@ ctlListView *GetReferencedByCtl(); void StoreServers(); int ReconnectServer(pgServer *server, bool restore = true); + int ReconnectDatabase(pgDatabase *database); void ReportConnError(pgServer *server); pgServerCollection *GetServerCollection() { return serversObj; } pgServer *ConnectToServer(const wxString& servername, bool restore = false); Index: src/include/pgDatabase.h =================================================================== --- src/include/pgDatabase.h (revision 5598) +++ src/include/pgDatabase.h (working copy) @@ -150,6 +150,7 @@ wxString GetQuotedSchemaPrefix(const wxString &schemaname) const; bool CanDrop(); + bool CanDisconnect(); bool CanEdit() { return true; } bool CanCreate(); Index: src/main/events.cpp =================================================================== --- src/main/events.cpp (revision 5598) +++ src/main/events.cpp (working copy) @@ -395,6 +395,7 @@ if (!data) return; pgServer *server; + pgDatabase *database; wxCommandEvent nullEvent; if (data->IsCreatedBy(serverFactory)) @@ -412,6 +413,19 @@ } else { + if (data->IsCreatedBy(databaseFactory)) + { + database = (pgDatabase *)data; + if (!database->GetConnected()) + { + if (ReconnectDatabase(database) == PGCONN_OK) + { + // prevent from being collapsed immediately + denyCollapseItem=item; + } + } + } + if (settings->GetDoubleClickProperties() && propFactory->CheckEnable(data)) { propFactory->StartDialog(this, data); Index: src/schema/pgObject.cpp =================================================================== --- src/schema/pgObject.cpp (revision 5598) +++ src/schema/pgObject.cpp (working copy) @@ -798,6 +798,11 @@ } +bool pgDatabaseObject::CanDisconnect() +{ + return true; +} + bool pgDatabaseObject::CanCreate() { return database->GetCreatePrivilege();