On Sun, 2011-07-24 at 15:09 +0100, Dave Page wrote:
> On Sun, Jul 24, 2011 at 2:23 PM, Guillaume Lelarge
> <guilla...@lelarge.info> wrote:
> > On Sun, 2011-07-24 at 14:11 +0200, Guillaume Lelarge wrote:
> >> On Sun, 2011-07-24 at 12:58 +0100, Dave Page wrote:
> >> > The former fix seems more appropriate. Operations in frmMain shouldn't
> >> > cause dialogues to close.
> >> >
> >>
> >> Fine with me. That should be simpler to do.
> >>
> >> > Simple fix seems to be to store a pointer to the dialog in pgObject;
> >> > if not null, disallow drop, or if trying to view properties, use the
> >> > pointer to raise the existing dialogue. Clear the pointer when the
> >> > dialog is closed.
> >> >
> >>
> >> I thought of something similar, but this is OK with me.
> >>
> >> I expect it to be quite a big patch. Should I work on 1.14 or master?
> >> this is surely a bug, so 1.14 should be OK. But I'm afraid this is too
> >> much changes to code it on a beta release. Any strong opinion on this
> >> matter?
> >>
> >
> > And another question. Let's say I open a table properties' dialog, and I
> > try to refresh the whole database. Should it refresh everything except
> > this table, or nothing and complains about properties' dialogs being
> > open, preventing the object to be refreshed?
> 
> Nothing. "There are properties dialogues open for one or more objects
> that would be refreshed. Please close the properties dialogues and try
> again."
> 

Just a quick update. Still working on it, and I have good results so
far. I'm now able to prevent refresh and drop (refresh for all objects,
drop for schemas only) if an object's properties dialog is open.

Patch attached. Obviously WIP. Not so obvious, it's dirty code (some
wxLogError, not really efficient code, etc). But comments very welcome.


-- 
Guillaume
  http://blog.guillaume.lelarge.info
  http://www.dalibo.com
diff --git a/pgadmin/dlg/dlgProperty.cpp b/pgadmin/dlg/dlgProperty.cpp
index 85d35b0..efbc2fa 100644
--- a/pgadmin/dlg/dlgProperty.cpp
+++ b/pgadmin/dlg/dlgProperty.cpp
@@ -1209,6 +1209,12 @@ dlgProperty *dlgProperty::CreateDlg(frmMain *frame, pgObject *node, bool asNew,
 			wxASSERT(factory);
 
 			dlg->InitDialog(frame, node);
+
+		    if (currentNode)
+            {
+		    	wxLogError(wxT("opening dialog"));
+		    	currentNode->SetWindowPtr(dlg);
+            }
 		}
 	}
 	return dlg;
diff --git a/pgadmin/dlg/dlgSchema.cpp b/pgadmin/dlg/dlgSchema.cpp
index 4f28bb4..f42084e 100644
--- a/pgadmin/dlg/dlgSchema.cpp
+++ b/pgadmin/dlg/dlgSchema.cpp
@@ -38,6 +38,16 @@ dlgSchema::dlgSchema(pgaFactory *f, frmMain *frame, pgSchema *node, pgObject *pa
 }
 
 
+dlgSchema::~dlgSchema()
+{
+    if (GetObject())
+    {
+        wxLogError(wxT("closing dialog"));
+        GetObject()->SetWindowPtr(NULL);
+    }
+}
+
+
 pgObject *dlgSchema::GetObject()
 {
 	return schema;
diff --git a/pgadmin/frm/events.cpp b/pgadmin/frm/events.cpp
index f725d39..0000db2 100644
--- a/pgadmin/frm/events.cpp
+++ b/pgadmin/frm/events.cpp
@@ -801,6 +801,12 @@ bool frmMain::dropSingleObject(pgObject *data, bool updateFinal, bool cascaded)
 		if (!data || !data->CanDrop())
 			return false;
 
+        if (data->GetWindowPtr())
+        {
+            wxLogError(_("Close the properties dialog before dropping the object!"));
+            return false;
+        }
+
 		if (data->GetSystemObject())
 		{
 			wxMessageDialog msg(this, data->GetTranslatedMessage(CANNOTDROPSYSTEM),
diff --git a/pgadmin/frm/frmMain.cpp b/pgadmin/frm/frmMain.cpp
index d59a9d1..a4336ab 100644
--- a/pgadmin/frm/frmMain.cpp
+++ b/pgadmin/frm/frmMain.cpp
@@ -510,11 +510,19 @@ void frmMain::CreateMenus()
 
 void frmMain::Refresh(pgObject *data)
 {
+    bool done = false;
+
 	StartMsg(data->GetTranslatedMessage(REFRESHINGDETAILS));
 	browser->Freeze();
 
 	wxTreeItemId currentItem = data->GetId();
 
+    if (CheckOpenDialogs(currentItem))
+    {
+        wxLogError(wxT("not possible because of an open window"));
+    }
+    else
+    {
 	// Scan the child nodes and make a list of those that are expanded
 	// This is not an exact science as node names may change etc.
 	wxArrayString expandedNodes;
@@ -527,7 +535,7 @@ void frmMain::Refresh(pgObject *data)
 
 	pgObject *newData = data->Refresh(browser, currentItem);
 
-	bool done = !data->GetConnection() || data->GetConnection()->GetStatus() == PGCONN_OK;
+	done = !data->GetConnection() || data->GetConnection()->GetStatus() == PGCONN_OK;
 
 	if (newData != data)
 	{
@@ -575,6 +583,7 @@ void frmMain::Refresh(pgObject *data)
 		// Attempt to expand any child nodes that were previously expanded
 		ExpandChildNodes(currentItem, expandedNodes);
 	}
+    }
 
 	browser->Thaw();
 	EndMsg(done);
@@ -623,6 +632,33 @@ void frmMain::OnCopy(wxCommandEvent &ev)
 	}
 }
 
+bool frmMain::CheckOpenDialogs(wxTreeItemId node)
+{
+    pgObject *obj = browser->GetObject(node);
+    if (obj && obj->GetWindowPtr())
+        return true;
+
+	wxTreeItemIdValue cookie;
+	wxTreeItemId child = browser->GetFirstChild(node, cookie);
+
+	while (child.IsOk())
+	{
+        obj = browser->GetObject(child);
+        if (obj && obj->GetWindowPtr())
+            return true;
+
+		if (browser->IsExpanded(child))
+		{
+			if (CheckOpenDialogs(child))
+                return true;
+		}
+
+		child = browser->GetNextChild(node, cookie);
+	}
+
+    return false;
+}
+
 void frmMain::GetExpandedChildNodes(wxTreeItemId node, wxArrayString &expandedNodes)
 {
 	wxTreeItemIdValue cookie;
diff --git a/pgadmin/include/dlg/dlgSchema.h b/pgadmin/include/dlg/dlgSchema.h
index 48d19d1..33cb153 100644
--- a/pgadmin/include/dlg/dlgSchema.h
+++ b/pgadmin/include/dlg/dlgSchema.h
@@ -29,6 +29,9 @@ public:
 	pgObject *CreateObject(pgCollection *collection);
 	pgObject *GetObject();
 
+protected:
+	~dlgSchema();
+
 private:
 	pgSchema *schema;
 	ctlSeclabelPanel *seclabelPage;
diff --git a/pgadmin/include/frm/frmMain.h b/pgadmin/include/frm/frmMain.h
index e76f3ac..ee3df05 100644
--- a/pgadmin/include/frm/frmMain.h
+++ b/pgadmin/include/frm/frmMain.h
@@ -232,6 +232,7 @@ private:
 	bool reportError(const wxString &error, const wxString &msgToIdentify, const wxString &hint);
 	wxTreeItemId RestoreEnvironment(pgServer *server);
 
+    bool CheckOpenDialogs(wxTreeItemId node);
 	void GetExpandedChildNodes(wxTreeItemId node, wxArrayString &expandedNodes);
 	void ExpandChildNodes(wxTreeItemId node, wxArrayString &expandedNodes);
 
diff --git a/pgadmin/include/schema/pgObject.h b/pgadmin/include/schema/pgObject.h
index 0562b32..29a7066 100644
--- a/pgadmin/include/schema/pgObject.h
+++ b/pgadmin/include/schema/pgObject.h
@@ -351,6 +351,12 @@ public:
 
 	wxString qtDbString(const wxString &str);
 
+    void SetWindowPtr(dlgProperty *dlgprop);
+    dlgProperty* GetWindowPtr()
+    {
+        return dlg;
+    }
+
 protected:
 	void CreateList3Columns(ctlListView *properties, const wxString &left = _("Object"), const wxString &middle = _("Owner"), const wxString &right = _("Value"));
 	void CreateListColumns(ctlListView *properties, const wxString &left = _("Property"), const wxString &right = _("Value"));
@@ -375,6 +381,7 @@ private:
 	int type;
 	OID oid, xid;
 	wxString providers, labels;
+    dlgProperty *dlg;
 
 	friend class pgaFactory;
 };
diff --git a/pgadmin/schema/pgObject.cpp b/pgadmin/schema/pgObject.cpp
index e339c2f..6598f2e 100644
--- a/pgadmin/schema/pgObject.cpp
+++ b/pgadmin/schema/pgObject.cpp
@@ -155,6 +155,7 @@ pgObject::pgObject(pgaFactory &_factory, const wxString &newName)
 	expandedKids = false;
 	needReread = false;
 	hintShown = false;
+    dlg = NULL;
 }
 
 
@@ -173,6 +174,7 @@ pgObject::pgObject(int newType, const wxString &newName)
 	expandedKids = false;
 	needReread = false;
 	hintShown = false;
+    dlg = NULL;
 }
 
 
@@ -1796,4 +1798,8 @@ wxString pgObject::GetPrivilegeName(wxChar privilege)
 	}
 }
 
+void pgObject::SetWindowPtr(dlgProperty *dlgprop)
+{
+    dlg = dlgprop;
+}
 
-- 
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