From 1732871c98497cbdf10a291ae58dbb44f662adf3 Mon Sep 17 00:00:00 2001
From: Guillaume Lelarge <guillaume@lelarge.info>
Date: Sun, 6 Mar 2011 16:08:30 +0100
Subject: [PATCH] Disabled triggers are displayed with another icon

The "other" icon is the old one with a red cross on it. It helps to know which
triggers are enabled and which aren't.

Idea from Erika.
---
 pgadmin/include/images/triggerbad.xpm |  102 +++++++++++++++++++++++++++++++++
 pgadmin/include/schema/pgTrigger.h    |   12 ++++-
 pgadmin/pgAdmin3.vcproj               |    4 +
 pgadmin/schema/pgTable.cpp            |    2 +-
 pgadmin/schema/pgTrigger.cpp          |   17 +++++-
 5 files changed, 132 insertions(+), 5 deletions(-)
 create mode 100644 pgadmin/include/images/triggerbad.xpm

diff --git a/pgadmin/include/images/triggerbad.xpm b/pgadmin/include/images/triggerbad.xpm
new file mode 100644
index 0000000..9c21ce5
--- /dev/null
+++ b/pgadmin/include/images/triggerbad.xpm
@@ -0,0 +1,102 @@
+/* XPM */
+static const char * triggerbad_xpm[] = {
+"16 16 83 1",
+" 	c None",
+".	c #85BEC9",
+"+	c #2F91A3",
+"@	c #74F2E2",
+"#	c #CAFFF8",
+"$	c #FDFFFF",
+"%	c #F7F8F8",
+"&	c #FAFAFB",
+"*	c #F8F7F8",
+"=	c #FCFEFE",
+"-	c #CAEAE7",
+";	c #D76262",
+">	c #C50000",
+",	c #D05759",
+"'	c #C4C4C8",
+")	c #C6FDF6",
+"!	c #9394A1",
+"~	c #C5474B",
+"{	c #DD6969",
+"]	c #438799",
+"^	c #C55B5D",
+"/	c #F67777",
+"(	c #C4474B",
+"_	c #A5A9B0",
+":	c #BE3D42",
+"<	c #F15757",
+"[	c #587E8F",
+"}	c #F67676",
+"|	c #F67272",
+"1	c #F56E6E",
+"2	c #BC3B40",
+"3	c #F15656",
+"4	c #EF4F4F",
+"5	c #EE4849",
+"6	c #5E7B8C",
+"7	c #CA5154",
+"8	c #F56D6D",
+"9	c #F46868",
+"0	c #F36262",
+"a	c #F05555",
+"b	c #EF4E4F",
+"c	c #EE4848",
+"d	c #388C9E",
+"e	c #98BEBC",
+"f	c #F36161",
+"g	c #F15B5B",
+"h	c #F05454",
+"i	c #EF4D4E",
+"j	c #EE4747",
+"k	c #36AFA0",
+"l	c #A3C0BD",
+"m	c #DA6565",
+"n	c #F05354",
+"o	c #EF4D4D",
+"p	c #EE4646",
+"q	c #AA2C33",
+"r	c #8FC2BE",
+"s	c #D66262",
+"t	c #F05353",
+"u	c #EF4C4C",
+"v	c #EE4545",
+"w	c #EC3E3F",
+"x	c #EB3838",
+"y	c #4D8394",
+"z	c #BA4446",
+"A	c #F05252",
+"B	c #EF4B4B",
+"C	c #ED4445",
+"D	c #EB3737",
+"E	c #EA3131",
+"F	c #E92B2B",
+"G	c #836C7C",
+"H	c #F05151",
+"I	c #EE4A4A",
+"J	c #ED4344",
+"K	c #99434A",
+"L	c #E92A2B",
+"M	c #E82525",
+"N	c #E72020",
+"O	c #ED4243",
+"P	c #C4464A",
+"Q	c #99444B",
+"R	c #E71F20",
+"                ",
+"   .+++.        ",
+"   +@@@+        ",
+"   +####+       ",
+"   +$%&*=+      ",
+"   +-;>,')!~>{  ",
+"   ]^>/>(_:><>{ ",
+"   [>}|1>2>345> ",
+"   67>890>abc>{ ",
+"   de;>fghij>{  ",
+"   +klm>nop>q   ",
+"   +rs>tuvwx>{  ",
+"   yz>ABC>DEF>{ ",
+"   G>HIJ>K>LMN> ",
+"   G7>O>P Q>R>{ ",
+"     q>qG  q>{  "};
diff --git a/pgadmin/include/schema/pgTrigger.h b/pgadmin/include/schema/pgTrigger.h
index 084dc92..d26bd9a 100644
--- a/pgadmin/include/schema/pgTrigger.h
+++ b/pgadmin/include/schema/pgTrigger.h
@@ -43,6 +43,14 @@ public:
 	pgTriggerFactory();
 	virtual dlgProperty *CreateDialog(frmMain *frame, pgObject *node, pgObject *parent);
 	virtual pgObject *CreateObjects(pgCollection *obj, ctlTree *browser, const wxString &restr = wxEmptyString);
+
+	int GetClosedIconId()
+	{
+		return closedId;
+	}
+
+protected:
+	int closedId;
 };
 extern pgTriggerFactory triggerFactory;
 
@@ -53,6 +61,8 @@ public:
 	pgTrigger(pgSchema *newSchema, const wxString &newName = wxT(""));
 	~pgTrigger();
 
+	int GetIconId();
+
 	wxString GetTranslatedMessage(int kindOfMessage) const;
 	void ShowTreeDetail(ctlTree *browser, frmMain *form = 0, ctlListView *properties = 0, ctlSQLBox *sqlPane = 0);
 	bool CanDropCascaded()
@@ -115,7 +125,7 @@ public:
 	{
 		return enabled;
 	}
-	void SetEnabled(const bool b);
+	void SetEnabled(ctlTree *browser, const bool b);
 	void iSetEnabled(const bool b)
 	{
 		enabled = b;
diff --git a/pgadmin/pgAdmin3.vcproj b/pgadmin/pgAdmin3.vcproj
index b91d673..6995ccb 100644
--- a/pgadmin/pgAdmin3.vcproj
+++ b/pgadmin/pgAdmin3.vcproj
@@ -2334,6 +2334,10 @@
 					>
 				</File>
 				<File
+					RelativePath=".\include\images\triggerbad.xpm"
+					>
+				</File>
+				<File
 					RelativePath=".\include\images\triggerfunction.xpm"
 					>
 				</File>
diff --git a/pgadmin/schema/pgTable.cpp b/pgadmin/schema/pgTable.cpp
index 1b9835e..75466eb 100644
--- a/pgadmin/schema/pgTable.cpp
+++ b/pgadmin/schema/pgTable.cpp
@@ -1156,7 +1156,7 @@ void pgTable::iSetTriggersEnabled(ctlTree *browser, bool enable)
 		pgTrigger *trigger;
 		while ((trigger = (pgTrigger *)trgIt.GetNextObject()) != 0)
 		{
-			trigger->iSetEnabled(enable);
+			trigger->SetEnabled(browser, enable);
 		}
 	}
 }
diff --git a/pgadmin/schema/pgTrigger.cpp b/pgadmin/schema/pgTrigger.cpp
index 7572b40..c0c9085 100644
--- a/pgadmin/schema/pgTrigger.cpp
+++ b/pgadmin/schema/pgTrigger.cpp
@@ -104,6 +104,15 @@ wxString pgTrigger::GetTranslatedMessage(int kindOfMessage) const
 	return message;
 }
 
+int pgTrigger::GetIconId()
+{
+	if (GetEnabled())
+		return triggerFactory.GetIconId();
+	else
+		return triggerFactory.GetClosedIconId();
+}
+
+
 bool pgTrigger::IsUpToDate()
 {
 	wxString sql = wxT("SELECT xmin FROM pg_trigger WHERE oid = ") + this->GetOidStr();
@@ -122,7 +131,7 @@ bool pgTrigger::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
 }
 
 
-void pgTrigger::SetEnabled(const bool b)
+void pgTrigger::SetEnabled(ctlTree *browser, const bool b)
 {
 	if (GetQuotedFullTable().Len() > 0 && ((enabled && !b) || (!enabled && b)))
 	{
@@ -134,8 +143,8 @@ void pgTrigger::SetEnabled(const bool b)
 		sql += wxT(" TRIGGER ") + GetQuotedIdentifier();
 		GetDatabase()->ExecuteVoid(sql);
 	}
-
 	enabled = b;
+	UpdateIcon(browser);
 }
 
 
@@ -481,12 +490,14 @@ wxString pgTriggerCollection::GetTranslatedMessage(int kindOfMessage) const
 /////////////////////////////
 
 #include "images/trigger.xpm"
+#include "images/triggerbad.xpm"
 #include "images/triggers.xpm"
 
 pgTriggerFactory::pgTriggerFactory()
 	: pgSchemaObjFactory(__("Trigger"), __("New Trigger..."), __("Create a new Trigger."), trigger_xpm)
 {
 	metaType = PGM_TRIGGER;
+	closedId = addIcon(triggerbad_xpm);
 }
 
 
@@ -501,7 +512,7 @@ enabledisableTriggerFactory::enabledisableTriggerFactory(menuFactoryList *list,
 
 wxWindow *enabledisableTriggerFactory::StartDialog(frmMain *form, pgObject *obj)
 {
-	((pgTrigger *)obj)->SetEnabled(!((pgTrigger *)obj)->GetEnabled());
+	((pgTrigger *)obj)->SetEnabled(form->GetBrowser(), !((pgTrigger *)obj)->GetEnabled());
 
 	wxTreeItemId item = form->GetBrowser()->GetSelection();
 	if (obj == form->GetBrowser()->GetObject(item))
-- 
1.7.1

