Re: A new feature patch and a bug fix - Mailing list pgadmin-hackers

From Guillaume Lelarge
Subject Re: A new feature patch and a bug fix
Date
Msg-id 476CC7AA.5040507@lelarge.info
Whole thread Raw
In response to Re: A new feature patch and a bug fix  (Dave Page <dpage@postgresql.org>)
Responses Re: A new feature patch and a bug fix  ("Dave Page" <dpage@postgresql.org>)
List pgadmin-hackers
Dave Page wrote:
> Guillaume Lelarge wrote:
> [...]
>>>> I'll take a look at the query tool to see how to do this ("present a
>>>> list of databases on the server"). Another call to wxSingleChoiceDialod
>>>> seems a bad way to me... I'll need to add a new dialog, don't you think ?
>>> Yes, I don't think it should be two dialogues.
>>>
>> I'm working on it now.
>
> 'K.
>

I've finally done it. It's the first time I create a new dialog, so it
probably need some tweaks. I attached the patch and a tar.gz file for
the new files.

Regards.


--
Guillaume.
 http://www.postgresqlfr.org
 http://dalibo.com
Index: pgadmin/include/schema/pgRole.h
===================================================================
--- pgadmin/include/schema/pgRole.h    (révision 6919)
+++ pgadmin/include/schema/pgRole.h    (copie de travail)
@@ -75,6 +75,8 @@
     void iSetUpdateCatalog(const bool b) { updateCatalog=b; }
     wxArrayString& GetRolesIn() { return rolesIn; }
     wxArrayString& GetConfigList() { return configList; }
+
+    void ReassignDropOwnedTo(frmMain *form);


     // Tree object creation
@@ -112,6 +114,13 @@
     pgGroupRole(const wxString& newName = wxT(""));
 };

+class reassignDropOwnedFactory : public contextActionFactory
+{
+public:
+    reassignDropOwnedFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar);
+    wxWindow *StartDialog(frmMain *form, pgObject *obj);
+    bool CheckEnable(pgObject *obj);
+};


 #endif
Index: pgadmin/frm/frmMain.cpp
===================================================================
--- pgadmin/frm/frmMain.cpp    (révision 6919)
+++ pgadmin/frm/frmMain.cpp    (copie de travail)
@@ -67,6 +67,7 @@
 #include "schema/pgTable.h"
 #include "schema/pgIndex.h"
 #include "schema/pgTrigger.h"
+#include "schema/pgRole.h"
 #include "schema/pgRule.h"
 #include "schema/pgServer.h"
 #include "slony/slCluster.h"
@@ -326,6 +327,7 @@
     new dropCascadedFactory(menuFactories, editMenu, 0);
     new truncateFactory(menuFactories, editMenu, 0);
     new truncateCascadedFactory(menuFactories, editMenu, 0);
+    new reassignDropOwnedFactory(menuFactories, editMenu, 0);
     editMenu->AppendSeparator();

     new separatorFactory(menuFactories);
Index: pgadmin/schema/pgRole.cpp
===================================================================
--- pgadmin/schema/pgRole.cpp    (révision 6919)
+++ pgadmin/schema/pgRole.cpp    (copie de travail)
@@ -11,12 +11,15 @@

 // wxWindows headers
 #include <wx/wx.h>
+#include <wx/choicdlg.h>

 // App headers
 #include "pgAdmin3.h"
 #include "utils/misc.h"
 #include "schema/pgRole.h"
 #include "frm/frmMain.h"
+#include "dlg/dlgReassignDropOwned.h"
+#include "dlg/dlgSelectConnection.h"
 #include "utils/pgDefs.h"
 #include "schema/pgDatabase.h"
 #include "schema/pgTablespace.h"
@@ -51,7 +54,7 @@

 bool pgRole::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
 {
-    if (GetUpdateCatalog())
+    if (GetUpdateCatalog())
     {
         wxMessageDialog dlg(frame,
             _("Deleting a superuser might result in unwanted behaviour (e.g. when restoring the database).\nAre you
sure?"),
@@ -276,8 +279,43 @@
     }
 }

+void pgRole::ReassignDropOwnedTo(frmMain *form)
+{
+    wxString query;
+
+    dlgReassignDropOwned rdo(form, GetConnection(), this);
+    if (rdo.ShowModal() != wxID_CANCEL)
+    {
+        pgConn *conn;
+        conn = new pgConn(GetConnection()->GetHost(),
+                     rdo.GetDatabase(),
+                     GetConnection()->GetUser(),
+                     GetConnection()->GetPassword(),
+                     GetConnection()->GetPort(),
+                     GetConnection()->GetSslMode());
+
+        if (conn->GetStatus() == PGCONN_OK)
+        {
+            if (rdo.IsReassign())
+            {
+                if (wxMessageBox(_("Are you sure you wish to reassign all objets owned by the selected role?"),
_("Reassignobjects"), wxYES_NO) == wxNO) 
+                    return;

+                query = wxT("REASSIGN OWNED BY ") + GetQuotedFullIdentifier() + wxT(" TO ") + rdo.GetRole();
+            }
+            else
+            {
+                if (wxMessageBox(_("Are you sure you wish to drop all objets owned by the selected role?"), _("Drop
objects"),wxYES_NO) == wxNO) 
+                    return;

+                query = wxT("DROP OWNED BY ") + GetQuotedFullIdentifier();
+            }
+            conn->ExecuteVoid(query);
+        }
+    }
+}
+
+
 pgObject *pgRole::Refresh(ctlTree *browser, const wxTreeItemId item)
 {
     pgObject *role=0;
@@ -394,3 +432,22 @@

 pgGroupRoleFactory groupRoleFactory;
 static pgaCollectionFactory gcf(&groupRoleFactory, __("Group Roles"), roles_xpm);
+
+
+reassignDropOwnedFactory::reassignDropOwnedFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) :
contextActionFactory(list)
+{
+    mnu->Append(id, _("Reassign/Drop Owned..."), _("Reassigned or drop objects owned by the selected role."));
+}
+
+
+wxWindow *reassignDropOwnedFactory::StartDialog(frmMain *form, pgObject *obj)
+{
+    ((pgRole*)obj)->ReassignDropOwnedTo(form);
+
+    return 0;
+}
+
+bool reassignDropOwnedFactory::CheckEnable(pgObject *obj)
+{
+    return obj && obj->IsCreatedBy(loginRoleFactory) && ((pgRole*)obj)->GetConnection()->BackendMinimumVersion(8, 2);
+}
Index: pgadmin/dlg/module.mk
===================================================================
--- pgadmin/dlg/module.mk    (révision 6919)
+++ pgadmin/dlg/module.mk    (copie de travail)
@@ -35,6 +35,7 @@
     $(srcdir)/dlg/dlgPackage.cpp \
     $(srcdir)/dlg/dlgPgpassConfig.cpp \
     $(srcdir)/dlg/dlgProperty.cpp \
+    $(srcdir)/dlg/dlgReassignDropOwned.cpp \
     $(srcdir)/dlg/dlgRole.cpp \
     $(srcdir)/dlg/dlgRule.cpp \
     $(srcdir)/dlg/dlgSchema.cpp \
Index: pgadmin/ui/module.mk
===================================================================
--- pgadmin/ui/module.mk    (révision 6919)
+++ pgadmin/ui/module.mk    (copie de travail)
@@ -39,6 +39,7 @@
     $(srcdir)/ui/dlgOperator.xrc \
     $(srcdir)/ui/dlgPackage.xrc \
     $(srcdir)/ui/dlgPgpassConfig.xrc \
+    $(srcdir)/ui/dlgReassignDropOwned.xrc \
     $(srcdir)/ui/dlgRepCluster.xrc \
     $(srcdir)/ui/dlgRepClusterUpgrade.xrc \
     $(srcdir)/ui/dlgRepListen.xrc \

Attachment

pgadmin-hackers by date:

Previous
From: svn@pgadmin.org
Date:
Subject: SVN Commit by dpage: r6919 - in trunk/pgadmin3: . pgadmin/schema
Next
From: svn@pgadmin.org
Date:
Subject: SVN Commit by guillaume: r6920 - branches/REL-1_8_0_PATCHES/pgadmin3/pgadmin/dlg