Exemplo n.º 1
0
frmMain::~frmMain()
{
	// Store the servers, to ensure we store the last database/schema etc
	StoreServers();

	settings->Write(wxT("frmMain/Perspective-") + wxString(FRMMAIN_PERSPECTIVE_VER), manager.SavePerspective());
	manager.UnInit();

	// Clear the treeview
	browser->DeleteAllItems();

	if (treeContextMenu)
		delete treeContextMenu;

#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
	if(pgadminTunnelThread && pgadminTunnelThread->IsAlive())
	{
		pgadminTunnelThread->Cleanup();
		pgadminTunnelThread = NULL;
	}
#endif
}
Exemplo n.º 2
0
bool frmMain::dropSingleObject(pgObject *data, bool updateFinal, bool cascaded)
{
	if (updateFinal)
	{
		// accelerator can bypass disabled menu, so we need to check
		if (!data || !data->CanDrop())
			return false;

		if (data->CheckOpenDialogs(browser, browser->GetSelection()))
		{
			wxString msg = _("There are properties dialogues open for one or more objects that would be dropped. Please close the properties dialogues and try again.");
			wxMessageBox(msg, _("Cannot drop object"), wxICON_WARNING | wxOK);
			return false;
		}

		if (data->GetSystemObject())
		{
			wxMessageDialog msg(this, data->GetTranslatedMessage(CANNOTDROPSYSTEM),
			                    _("Trying to drop system object"), wxICON_EXCLAMATION);
			msg.ShowModal();
			return false;
		}

		if (cascaded || data->RequireDropConfirm() || settings->GetConfirmDelete())
		{
			wxString text, caption;
			if (cascaded)
			{
				text = data->GetTranslatedMessage(DROPINCLUDINGDEPS);
				caption = data->GetTranslatedMessage(DROPCASCADETITLE);
			}
			else
			{
				/*
				*  currentObject is set using the following command.
				*  i.e. currentObject = browser->GetObject(item);
				*  While fetching this object using this code, somehow it looses its virtual table pointer.
				*  Hence, it is not able to call the GetFullIdentifier - virtual function from the
				*  particular class, but it will always call this functions from pgObject class always.
				*  To rectify this problem, we need to explicitly check the meta data type and call the
				*  function from the particular class.
				*/
				if (data->GetMetaType() == PGM_SERVER)
					text = wxString::Format(_("Are you sure you wish to drop server \"%s\"?"),
					                        ((pgServer *)data)->GetFullIdentifier().c_str());
				else if (data->GetMetaType() == EDB_SYNONYM)
					text = ((edbPrivateSynonym *)data)->GetTranslatedMessage(DROPEXCLUDINGDEPS);
				else
					text = data->GetTranslatedMessage(DROPEXCLUDINGDEPS);
				caption = data->GetTranslatedMessage(DROPTITLE);
			}
			wxMessageDialog msg(this, text, caption, wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT);
			if (msg.ShowModal() != wxID_YES)
			{
				return false;
			}
		}
	}
	bool done = data->DropObject(this, browser, cascaded);

	if (done)
	{
		wxLogInfo(wxT("Dropping %s %s"), data->GetTypeName().c_str(), data->GetIdentifier().c_str());

		wxTreeItemId parentItem = browser->GetItemParent(data->GetId());

		if (updateFinal)
		{
			wxTreeItemId nextItem;
			if (browser->IsVisible(data->GetId()))
				nextItem = browser->GetNextVisible(data->GetId());

			if (nextItem)
			{
				pgObject *nextData = browser->GetObject(nextItem);
				if (!nextData || nextData->GetType() != data->GetType())
					nextItem = browser->GetPrevSibling(data->GetId());
			}
			else
				nextItem = browser->GetPrevSibling(data->GetId());

			if (nextItem)
				browser->SelectItem(nextItem);
		}
		pgaFactory *droppedCollFactory = data->GetFactory()->GetCollectionFactory();

		wxTreeItemId oldgroupitem;
		wxString oldgroupname;
		if (data->IsCreatedBy(serverFactory))
		{
			oldgroupname = ((pgServer *)data)->GetGroup();
			oldgroupitem = browser->GetItemParent(data->GetId());
		}

		browser->Delete(data->GetId());
		// data is invalid now

		if (updateFinal)
		{
			if (!oldgroupname.IsEmpty())
			{
				int total = browser->GetChildrenCount(oldgroupitem, false);
				if (total == 0)
					browser->Delete(oldgroupitem);
				else
				{
					wxString label = oldgroupname + wxT(" (") + NumToStr((long)total) + wxT(")");
					browser->SetItemText(oldgroupitem, label);
				}
			}
			else
			{
				pgCollection *collection = 0;

				while (parentItem)
				{
					collection = (pgCollection *)browser->GetObject(parentItem);
					if (collection && collection->IsCollection() && collection->GetFactory() == droppedCollFactory)
					{
						collection->UpdateChildCount(browser);
						break;
					}
					parentItem = browser->GetItemParent(parentItem);
				}
			}
		}

		// Update the server list, if we dropped a server
		StoreServers();
	}
	return done;
}