Пример #1
0
    def CommitData(self, editor):
        role, value = editor.GetRoleAndValue()

        tp = None
        if role != 'type' and 'type' in self.part:
            tp = self.part['type']

        if role in ('type', 'uri'):
            values = []
            for v in value.split('|'):
                values.append(
                    appdata.datamodel.ResolveNameOrUri(v, tp,
                                                       not self.doc.use_names))
            value = list2value(values)
        else:
            value = appdata.datamodel.ResolveNameOrUri(value, tp,
                                                       not self.doc.use_names)

        if self.part not in self.option['parts']:
            if role:
                if self.role:
                    del self.part[self.role]
                self.role = role
                self.part[self.role] = value
                lst = []
                lst.append(
                    actions.DocumentModifyPatternOptionParts(
                        self.option, self.part))
                #lst.append(actions.DocumentModifyPatternOptionPartRoles(self.option, self.part, role, value = value, action = actions.ROLE_ADD))
                self.doc << MultiAction(lst)
                return True
            else:
                return False

        if not self.role:
            if role:
                self.role = role
                self.doc << actions.DocumentModifyPatternOptionPartRoles(
                    self.option,
                    self.part,
                    role,
                    value=value,
                    action=actions.ROLE_ADD)
                return True
            else:
                return False

        if not role:
            return False

        self.doc << actions.DocumentModifyPatternOptionPartRoles(
            self.option,
            self.part,
            self.role,
            value=(role, value),
            action=actions.ROLE_MODIFY)
        return True
Пример #2
0
    def CommitData(self, editor):
        name_old = self.part.get('self', '')
        name = editor.GetText().strip()

        if name in self.part:
            return False

        if name == name_old:
            return True

        if name_old and name:
            self.doc << actions.DocumentModifyPatternOptionPartRoles(
                self.option, self.part, 'self', name, action=actions.ROLE_BIND)
        elif name:
            self.doc << actions.DocumentModifyPatternOptionPartRoles(
                self.option, self.part, 'self', name, action=actions.ROLE_ADD)
        elif name_old:
            self.doc << actions.DocumentModifyPatternOptionPartRoles(
                self.option, self.part, 'self', action=actions.ROLE_DELETE)
        return True
Пример #3
0
 def Drop(self, data, before=None, after=None):
     if not self.doc.CanEdit():
         return False
     if data.get('uri'):
         tp = None
         if self.role != 'type' and 'type' in self.part:
             tp = self.part['type']
         value = appdata.datamodel.ResolveNameOrUri(data['uri'], tp,
                                                    not self.doc.use_names)
         self.doc << actions.DocumentModifyPatternOptionPartRoles(
             self.option,
             self.part,
             self.role,
             value=value,
             action=actions.ROLE_BIND)
         return True
     elif data.get('qname'):
         qname = data['qname']
         if qname.startswith('part2:'):
             qname = qname.replace(':', '.')
             self.doc << actions.DocumentModifyPatternOptionPartRoles(
                 self.option,
                 self.part,
                 self.role,
                 value=qname,
                 action=actions.ROLE_BIND)
             return True
         else:
             return False
     elif data.get('pattern'):
         if 'type' != self.role:
             return False
         self.doc << actions.DocumentModifyPatternOptionPartRoles(
             self.option,
             self.part,
             self.role,
             value='patterns.' + data['pattern'],
             action=actions.ROLE_BIND)
         return True
     else:
         return False
Пример #4
0
 def Drop(self, data, before=None, after=None):
     if not self.doc.CanEdit():
         return False
     if 'uri' in data:
         tp = None
         if 'type' in self.part:
             tp = self.part['type']
         value = appdata.datamodel.ResolveNameOrUri(data['uri'], tp,
                                                    not self.doc.use_names)
         node = PatternRoleNode(self, '')
         self.Expand()
         node.Edit(value)
         return True
     elif 'pattern' in data:
         if 'type' in self.part:
             return False
         self.doc << actions.DocumentModifyPatternOptionPartRoles(
             self.option,
             self.part,
             'type',
             'patterns.' + data['pattern'],
             action=actions.ROLE_ADD)
         return True
     elif data.get('patternpart'):
         part = data['patternpart']
         lst = []
         try:
             parts = [dict(x) for x in self.option['parts']]
             idx = parts.index(dict(part))
             part = self.option['parts'][idx]
         except:
             lst.append(
                 actions.DocumentModifyPatternOptionParts(
                     self.option, part))
             idx = len(self.option['parts'])
         newidx = self.option['parts'].index(self.part)
         if newidx != idx:
             lst.append(
                 actions.DocumentChangePatternOptionPartIndex(
                     self.option, part, newidx))
         if lst:
             self.doc << MultiAction(lst)
         return True
     else:
         return False
Пример #5
0
 def DoDelete(self):
     self.doc << actions.DocumentModifyPatternOptionPartRoles(
         self.option, self.part, self.role, action=actions.ROLE_DELETE)