[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8652 - in trunk/gnue-forms/src: . GFObjects
From: |
reinhard |
Subject: |
[gnue] r8652 - in trunk/gnue-forms/src: . GFObjects |
Date: |
Tue, 5 Sep 2006 10:18:41 -0500 (CDT) |
Author: reinhard
Date: 2006-09-05 10:18:40 -0500 (Tue, 05 Sep 2006)
New Revision: 8652
Modified:
trunk/gnue-forms/src/GFForm.py
trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
Added GFBlock.get_possible_operations() function.
Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py 2006-09-04 22:22:54 UTC (rev 8651)
+++ trunk/gnue-forms/src/GFForm.py 2006-09-05 15:18:40 UTC (rev 8652)
@@ -1032,7 +1032,8 @@
# Is the current entry changed?
# FIXME: should only cause the form to appear unsaved if the entry is
bound
# to a field.
- if (self._currentEntry._type != 'GFButton' and \
+ if (self._currentEntry is not None and \
+ self._currentEntry._type != 'GFButton' and \
self._currentEntry._field._bound and \
self._currentEntry._displayHandler.isPending()):
return False
@@ -1518,86 +1519,50 @@
@return: None
"""
- block = self._currentBlock
+ if self._currentBlock is not None:
+ record_status = self._currentBlock.get_record_status()
+ possible_operations = self._currentBlock.get_possible_operations()
+ else:
+ record_status = None
+ possible_operations = []
+
dispatchEvent = self.dispatchEvent
- if not block:
- # No current block - for example a form with only buttons on it
- dispatchEvent('cannotCANCELQUERY')
- dispatchEvent('cannotEXECQUERY')
- dispatchEvent('cannotENTERQUERY')
- dispatchEvent('cannotPREVRECORD')
- dispatchEvent('cannotFIRSTRECORD')
- dispatchEvent('cannotNEXTRECORD')
- dispatchEvent('cannotLASTRECORD')
- dispatchEvent('cannotCOMMIT')
- dispatchEvent('cannotROLLBACK')
- dispatchEvent('cannotJUMPPROMPT')
- dispatchEvent('cannotNEWRECORD')
- dispatchEvent('cannotMARKFORDELETE')
- return
- if block.mode == 'query':
- dispatchEvent('canCANCELQUERY')
- dispatchEvent('canEXECQUERY')
- dispatchEvent('cannotENTERQUERY')
- dispatchEvent('cannotPREVRECORD')
- dispatchEvent('cannotFIRSTRECORD')
- dispatchEvent('cannotNEXTRECORD')
- dispatchEvent('cannotLASTRECORD')
+ for operation, event in (
+ ('first_record', 'FIRSTRECORD'),
+ ('prev_record', 'PREVRECORD'),
+ ('next_record', 'NEXTRECORD'),
+ ('last_record', 'LASTRECORD'),
+ ('goto_record', 'JUMPPROMPT'),
+ ('new_record', 'NEWRECORD'),
+ ('delete_record', 'MARKFORDELETE'),
+ ('undelete_record', 'UNDELETE'),
+ ('init_query', 'ENTERQUERY'),
+ ('cancel_query', 'CANCELQUERY'),
+ ('execute_query', 'EXECQUERY')):
+ if operation in possible_operations:
+ dispatchEvent('can' + event)
+ else:
+ dispatchEvent('cannot' + event)
+
+ if record_status in ('void', 'deleted'):
+ dispatchEvent('beginMARKFORDELETE')
+ else:
+ dispatchEvent('endMARKFORDELETE')
+
+ if self._currentBlock is not None \
+ and self._currentBlock.mode == 'query':
dispatchEvent('cannotCOMMIT')
dispatchEvent('cannotROLLBACK')
- dispatchEvent('cannotJUMPPROMPT')
- dispatchEvent('cannotNEWRECORD')
- dispatchEvent('cannotMARKFORDELETE')
else:
- dispatchEvent('canENTERQUERY')
- dispatchEvent('cannotCANCELQUERY')
- dispatchEvent('cannotEXECQUERY')
-
if not self.isSaved():
dispatchEvent('canCOMMIT')
else:
dispatchEvent('cannotCOMMIT')
-
dispatchEvent('canROLLBACK')
- dispatchEvent('canJUMPPROMPT')
- dispatchEvent('canMARKFORDELETE')
- if block._resultSet.isFirstRecord():
- dispatchEvent('cannotPREVRECORD')
- dispatchEvent('cannotFIRSTRECORD')
- else:
- dispatchEvent('canPREVRECORD')
- dispatchEvent('canFIRSTRECORD')
- if block._resultSet.isLastRecord():
- if block._resultSet.current.isEmpty():
- dispatchEvent('cannotNEXTRECORD')
- else:
- dispatchEvent('canNEXTRECORD')
- dispatchEvent('cannotLASTRECORD')
- else:
- dispatchEvent('canNEXTRECORD')
- dispatchEvent('canLASTRECORD')
- dispatchEvent('canNEWRECORD')
-
- if block._resultSet.current.isEmpty():
- dispatchEvent('cannotNEWRECORD')
- else:
- dispatchEvent('canNEWRECORD')
-
- if block._resultSet.current.isDeleted () \
- or block._resultSet.current.isVoid ():
- dispatchEvent('cannotMARKFORDELETE')
- dispatchEvent('canUNDELETE')
- dispatchEvent('beginMARKFORDELETE')
- else:
- dispatchEvent('endMARKFORDELETE')
- dispatchEvent('canMARKFORDELETE')
- dispatchEvent('cannotUNDELETE')
-
-
- # -------------------------------------------------------------------------
+ # ------------------------------------------------------------------------
# Called whenever an event source has requested that the
# focus change to the next data entry block
# -------------------------------------------------------------------------
Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py 2006-09-04 22:22:54 UTC (rev
8651)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py 2006-09-05 15:18:40 UTC (rev
8652)
@@ -511,6 +511,57 @@
# ---------------------------------------------------------------------------
+ def get_possible_operations(self):
+ """
+ Return a list of possible operations for this block.
+
+ The form can use this function to enable or disable commanders (menu
+ items or toolbar buttons) that are bound to the respective action.
+
+ The return value is basically a list of method names that can be called
+ for this block in the current state.
+ """
+
+ result = []
+
+ if self.mode == 'query':
+ result.append('cancel_query')
+ result.append('execute_query')
+ else:
+ rs = self._resultSet
+ if rs is not None:
+ rec = self._resultSet.current
+ status = self.get_record_status()
+
+ if rec is not None:
+ if not rs.isFirstRecord():
+ result.append('first_record')
+ result.append('prev_record')
+ if not rs.isLastRecord():
+ result.append('next_record')
+ result.append('last_record')
+ result.append('goto_record')
+
+ if not self._form.readonly:
+ if self.editable in ('Y', 'new') and status != 'empty':
+ result.append('new_record')
+ result.append('duplicate_record')
+ if self.autoCreate and rs.isLastRecord():
+ result.append('next_record')
+
+ if self.deletable:
+ if status not in ('void', 'deleted'):
+ result.append('delete_record')
+ else:
+ result.append('undelete_record')
+
+ result.append('init_query')
+ result.append('copy_query')
+
+ return result
+
+ # ---------------------------------------------------------------------------
+
def isSaved (self):
"""
Returns True if the datasource the block is associated with is not pending
@@ -772,14 +823,6 @@
# tests here could be removed so trigger code can still insert new
# records while the user can't.
- if self._form.readonly:
- self._form.alert_message(u_("Form is readonly"))
- return
-
- if self.editable not in ('Y', 'new'):
- event._form.alert_message(u_('Block does not allow insert'))
- return
-
# Focus out
self.processTrigger ('PRE-FOCUSOUT')
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8652 - in trunk/gnue-forms/src: . GFObjects,
reinhard <=