コード例 #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 Drop(self, data, before=None, after=None):
        if not self.doc.CanEdit():
            return False

        rolename = data.get('rolename')
        if rolename:
            uri = data.get('templateuri')

            if not rolename or not uri or uri != self.uri:
                return False

            node = None
            for c in self.parent.children:
                if c.role['name'] == rolename:
                    node = c

            if not node:
                return False

            wasindex = node.role['index']
            newindex = self.role['index']

            if newindex < 0:
                newindex = 0

            roles = self.doc.grGetTemplateRoles(self.uri)
            maxindex = max([v['index'] for v in roles.itervalues()])

            if newindex > maxindex:
                newindex = maxindex

            alst = []

            for v in roles.itervalues():
                if v['index'] == wasindex:
                    alst.append(actions.ChangeTemplateRoleIndex(self.doc, self.uri, v['name'], newindex))
                elif v['index'] >= newindex and v['index'] <= wasindex:
                    alst.append(actions.ChangeTemplateRoleIndex(self.doc, self.uri, v['name'], v['index']+1))
                elif v['index'] >= wasindex and v['index'] <= newindex:
                    alst.append(actions.ChangeTemplateRoleIndex(self.doc, self.uri, v['name'], v['index']-1))

            self.tree.UnselectAll()
            self.doc << MultiAction(alst)
            return True

        type_uri = data.get('uri')
        if not type_uri:
            qname = data.get('qname')
            if qname:
                type_uri = self.doc.infExpandQname(qname)
        if not type_uri:
            return False

        self.role['type_uri'] = type_uri
        self.role['is_literal'] = type_uri.startswith(kb.ns_xsd)
        self.doc << actions.UpdateTemplateRole(self.doc, self.uri, self.role)
        return True
コード例 #3
0
    def Paste(self):
        if not self.document.CanEdit():
            return

        selected = self.wnd_tree.selected
        if util.CheckClipboard('application/x-dot15926-patterns'):
            if not selected or (len(selected) == 1
                                and selected[0] is self.provnode):
                lst = []
                data = util.GetClipboard('application/x-dot15926-patterns')
                for v in data:
                    lst.append(
                        actions.DocumentModifyPatterns(self.document,
                                                       v,
                                                       new=False))
                self.document << MultiAction(lst)

        elif util.CheckClipboard('application/x-dot15926-pattern-options'):
            if selected:
                if all(isinstance(x, PatternNode) for x in selected):
                    lst = []
                    data = util.GetClipboard(
                        'application/x-dot15926-pattern-options')
                    for x in selected:
                        for v in data:
                            lst.append(
                                actions.DocumentModifyPatternOptions(
                                    x.pattern, v, new=False))
                    self.document << MultiAction(lst)

        elif util.CheckClipboard('application/x-dot15926-pattern-parts'):
            if selected:
                if all(
                        isinstance(x, PatternOptionEntryNode)
                        for x in selected):
                    lst = []
                    data = util.GetClipboard(
                        'application/x-dot15926-pattern-parts')
                    for x in selected:
                        for v in data:
                            lst.append(
                                actions.DocumentModifyPatternOptionParts(
                                    x.option, v))
                    self.document << MultiAction(lst)
コード例 #4
0
    def Cut(self):
        selected = self.wnd_tree.selected

        if not selected:
            return

        if all(isinstance(x, PatternNode) for x in selected):
            data = []
            lst = []
            for v in selected:
                data.append(v.pattern)
                lst.append(
                    actions.DocumentModifyPatterns(self.document, v.pattern,
                                                   True))
            util.SetClipboard('', {'application/x-dot15926-patterns': data})
            self.document << MultiAction(lst)

        if all(isinstance(x, PatternOptionEntryNode) for x in selected):
            data = []
            lst = []
            for v in selected:
                data.append(v.option)
                lst.append(
                    actions.DocumentModifyPatternOptions(
                        v.pattern, v.option, True))
            util.SetClipboard('',
                              {'application/x-dot15926-pattern-options': data})
            self.document << MultiAction(lst)

        if all(isinstance(x, PatternOptionPartNode) for x in selected):
            data = []
            lst = []
            for v in selected:
                data.append(v.part)
                lst.append(
                    actions.DocumentModifyPatternOptionParts(
                        v.option, v.part, True))
            util.SetClipboard('',
                              {'application/x-dot15926-pattern-parts': data})
            self.document << MultiAction(lst)
コード例 #5
0
    def Cut(self):
        selected = self.wnd_tree.selected
        data     = {}    
        triples  = []
        folders  = data.setdefault('folders', {})
        entities = []

        for v in selected:
            f = getattr(v, 'GetContent', None)
            if f:
                if getattr(v,'is_property', None):                
                    triples += f()
                else:
                    res = f()
                    entities += res
                    if isinstance(v, FolderNode):
                        folders.setdefault(v.vis_label, set()).update(res)

        only_triples = True if triples else False

        entities = set(entities)
        uris = set(entities)
        for v in triples:
            uris.add(v.s)

        lst = []
        for t in triples:
            lst.append(actions.RemoveProperty(self.document, t))

        for v in entities:
            triples += self.document.grCollectEntityTriples(v, True)

        for uri in entities:
            triples += self.document.grTriplesForSubj(uri)

        self.document<<MultiAction(lst + [actions.RemoveEntity(self.document, uri) for uri in entities])

        mime = {}
        if triples:
            data['triples'] = set(triples)
            if not only_triples:
                mime['application/x-dot15926-graph-records'] = data
            mime['application/x-dot15926-graph-triples'] = data

        util.SetClipboard(', '.join(uris), mime)

        notify = tm.main.notify_clipboard
        if not only_triples:
            notify += tm.main.notify_records_copied.format(len(entities))
        notify += tm.main.notify_triples_copied.format(len(triples))
        appdata.topwindow.AddNotify(notify, 2000)
コード例 #6
0
 def OnDblClick(self):
     if getattr(self, 'change', None):
         action = self.MakeAction()
         if action:
             self.doc << action
     else:
         lst = []
         props = set(self.doc.grTriplesForSubj(self.uri))
         diff = self.tree.view.diff
         props_del = set(diff.deletions.grTriplesForSubj(self.uri)) & props
         props_add = set(diff.insertions.grTriplesForSubj(self.uri)) - props
         for t in props_del:
             lst.append(actions.RemoveProperty(self.doc, t))
         for t in props_add:
             lst.append(actions.AddProperty(self.doc, t))
         self.doc << MultiAction(lst)
     return True
コード例 #7
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
コード例 #8
0
    def OnAcceptAll(self):
        if len(self.subjects) > 1000:
            if dialogs.Choice(tm.main.apply_diff_warning):
                self.pnode.DestroyChildren()
                for v in self.subjects:
                    for t in self.diff.deletions.grTriplesForSubj(
                            expand_uri(v)):
                        t.deletefrom(self.document)
                    for t in self.diff.insertions.grTriplesForSubj(
                            expand_uri(v)):
                        t.insertto(self.document)
                self.document.ChangeState(self.document.state_changed)
                self.Seed()
            return

        lst = []
        for v in self.subjects:
            for t in self.diff.deletions.grTriplesForSubj(expand_uri(v)):
                lst.append(actions.RemoveProperty(self.document, t))
            for t in self.diff.insertions.grTriplesForSubj(expand_uri(v)):
                lst.append(actions.AddProperty(self.document, t))

        self.document << MultiAction(lst)