Exemplo n.º 1
0
    def cut_items(self, no_confirm=False):
        if core_api.block_databases():
            # get_tree_selections() arguments must be compatible with the
            # ones used in self.delete_items()
            selection = wxgui_api.get_tree_selections(self.filename,
                                                none=False, descendants=True)

            if selection:
                items = []

                for item in selection:
                    id_ = wxgui_api.get_tree_item_id(self.filename, item)

                    if not wxgui_api.close_editor(self.filename, id_,
                                    ask='quiet' if no_confirm else 'discard'):
                        core_api.release_databases()
                        return False

                    items.append(id_)

                copypaste_api.copy_items(self.filename, items)

                wxgui_api.delete_items(self.filename, items,
                                description='Cut {} items'.format(len(items)))
                wxgui_api.refresh_history(self.filename)
                cut_items_event.signal()

            core_api.release_databases()
Exemplo n.º 2
0
    def paste_items_as_siblings(self, no_confirm=False):
        if core_api.block_databases():
            if no_confirm or copypaste_api.can_paste_safely(self.filename) or \
                    msgboxes.unsafe_paste_confirm().ShowModal() == wx.ID_OK:
                # Do not use none=False in order to allow pasting in an empty
                # database
                selection = wxgui_api.get_tree_selections(self.filename,
                                                          many=False)

                # If multiple items are selected, selection will be False
                if selection is not False:
                    if len(selection) > 0:
                        baseid = wxgui_api.get_tree_item_id(
                            self.filename, selection[0])

                        roots, ids = copypaste_api.paste_items_as_siblings(
                            self.filename, baseid, description='Paste items')
                    else:
                        roots, ids = copypaste_api.paste_items_as_children(
                            self.filename, 0, description='Paste items')

                    wxgui_api.refresh_history(self.filename)

                    items_pasted_event.signal(filename=self.filename,
                                              roots=roots,
                                              ids=ids)

            core_api.release_databases()
Exemplo n.º 3
0
    def paste_items_as_siblings(self, no_confirm=False):
        if core_api.block_databases():
            if no_confirm or copypaste_api.can_paste_safely(self.filename) or \
                    msgboxes.unsafe_paste_confirm().ShowModal() == wx.ID_OK:
                # Do not use none=False in order to allow pasting in an empty
                # database
                selection = wxgui_api.get_tree_selections(self.filename,
                                                                    many=False)

                # If multiple items are selected, selection will be False
                if selection is not False:
                    if len(selection) > 0:
                        baseid = wxgui_api.get_tree_item_id(self.filename,
                                                                selection[0])

                        roots, ids = copypaste_api.paste_items_as_siblings(
                            self.filename, baseid, description='Paste items')
                    else:
                        roots, ids = copypaste_api.paste_items_as_children(
                                self.filename, 0, description='Paste items')

                    wxgui_api.refresh_history(self.filename)

                    items_pasted_event.signal(filename=self.filename,
                                                        roots=roots, ids=ids)

            core_api.release_databases()
Exemplo n.º 4
0
    def cut_items(self, no_confirm=False):
        if core_api.block_databases():
            # get_tree_selections() arguments must be compatible with the
            # ones used in self.delete_items()
            selection = wxgui_api.get_tree_selections(self.filename,
                                                      none=False,
                                                      descendants=True)

            if selection:
                items = []

                for item in selection:
                    id_ = wxgui_api.get_tree_item_id(self.filename, item)

                    if not wxgui_api.close_editor(
                            self.filename,
                            id_,
                            ask='quiet' if no_confirm else 'discard'):
                        core_api.release_databases()
                        return False

                    items.append(id_)

                copypaste_api.copy_items(self.filename, items)

                wxgui_api.delete_items(self.filename,
                                       items,
                                       description='Cut {} items'.format(
                                           len(items)))
                wxgui_api.refresh_history(self.filename)
                cut_items_event.signal()

            core_api.release_databases()
Exemplo n.º 5
0
    def link_to_selection(self):
        filename = wxgui_api.get_selected_database_filename()

        if filename:
            selection = wxgui_api.get_tree_selections(filename, none=False,
                                                                    many=False)

            if selection:
                self.target = wxgui_api.get_tree_item_id(filename,
                                                                selection[0])
Exemplo n.º 6
0
    def link_to_selection(self):
        filename = wxgui_api.get_selected_database_filename()

        if filename:
            selection = wxgui_api.get_tree_selections(filename, none=False,
                                                                    many=False)

            if selection:
                self.target = wxgui_api.get_tree_item_id(filename,
                                                                selection[0])
Exemplo n.º 7
0
    def _handle_enable_tree_menus(self, kwargs):
        filename = kwargs['filename']

        # filename is None is no database is open
        if filename:
            sel = wxgui_api.get_tree_selections(filename)

            if len(sel) == 1:
                self.mcut.Enable()
                self.mcopy.Enable()

                if copypaste_api.has_copied_items(filename):
                    self.mpaste.Enable()
                    self.mpaste.SetItemLabel(self.mpaste_label_2)
                    self.mpaste.SetHelp(self.mpaste_help_2)
                    self.mpastesub.Enable()

                else:
                    self.mpaste.Enable(False)
                    self.mpaste.SetItemLabel(self.mpaste_label_1)
                    self.mpaste.SetHelp(self.mpaste_help_1)
                    self.mpastesub.Enable(False)

            elif len(sel) > 1:
                self.mcut.Enable()
                self.mcopy.Enable(False)
                self.mcopy.Enable()
                self.mpaste.Enable(False)
                self.mpaste.SetItemLabel(self.mpaste_label_1)
                self.mpaste.SetHelp(self.mpaste_help_1)
                self.mpastesub.Enable(False)

            elif copypaste_api.has_copied_items(filename):
                self.mcut.Enable(False)
                self.mcopy.Enable(False)
                self.mpaste.Enable()
                self.mpaste.SetItemLabel(self.mpaste_label_1)
                self.mpaste.SetHelp(self.mpaste_help_1)
                self.mpastesub.Enable(False)

            else:
                self.mcut.Enable(False)
                self.mcopy.Enable(False)
                self.mpaste.Enable(False)
                self.mpaste.SetItemLabel(self.mpaste_label_1)
                self.mpaste.SetHelp(self.mpaste_help_1)
                self.mpastesub.Enable(False)

        else:
            self.mcut.Enable(False)
            self.mcopy.Enable(False)
            self.mpaste.Enable(False)
            self.mpaste.SetItemLabel(self.mpaste_label_1)
            self.mpaste.SetHelp(self.mpaste_help_1)
            self.mpastesub.Enable(False)
Exemplo n.º 8
0
    def _handle_enable_tree_menus(self, kwargs):
        filename = kwargs['filename']

        # filename is None is no database is open
        if filename:
            sel = wxgui_api.get_tree_selections(filename)

            if len(sel) == 1:
                self.mcut.Enable()
                self.mcopy.Enable()

                if copypaste_api.has_copied_items(filename):
                    self.mpaste.Enable()
                    self.mpaste.SetItemLabel(self.mpaste_label_2)
                    self.mpaste.SetHelp(self.mpaste_help_2)
                    self.mpastesub.Enable()

                else:
                    self.mpaste.Enable(False)
                    self.mpaste.SetItemLabel(self.mpaste_label_1)
                    self.mpaste.SetHelp(self.mpaste_help_1)
                    self.mpastesub.Enable(False)

            elif len(sel) > 1:
                self.mcut.Enable()
                self.mcopy.Enable(False)
                self.mcopy.Enable()
                self.mpaste.Enable(False)
                self.mpaste.SetItemLabel(self.mpaste_label_1)
                self.mpaste.SetHelp(self.mpaste_help_1)
                self.mpastesub.Enable(False)

            elif copypaste_api.has_copied_items(filename):
                self.mcut.Enable(False)
                self.mcopy.Enable(False)
                self.mpaste.Enable()
                self.mpaste.SetItemLabel(self.mpaste_label_1)
                self.mpaste.SetHelp(self.mpaste_help_1)
                self.mpastesub.Enable(False)

            else:
                self.mcut.Enable(False)
                self.mcopy.Enable(False)
                self.mpaste.Enable(False)
                self.mpaste.SetItemLabel(self.mpaste_label_1)
                self.mpaste.SetHelp(self.mpaste_help_1)
                self.mpastesub.Enable(False)

        else:
            self.mcut.Enable(False)
            self.mcopy.Enable(False)
            self.mpaste.Enable(False)
            self.mpaste.SetItemLabel(self.mpaste_label_1)
            self.mpaste.SetHelp(self.mpaste_help_1)
            self.mpastesub.Enable(False)
Exemplo n.º 9
0
def _select_items(many):
    filename = wxgui_api.get_selected_database_filename()
    ids = core_api.get_items_ids(filename)

    if ids:
        w = 0 if many else 1
        modes = ((40, 80)[w] * ['select_one'] +
                 (10, 0)[w] * ['reselect_many'] +
                 (10, 0)[w] * ['select_some'] + (10, 0)[w] * ['select_all'] +
                 (20, 0)[w] * ['unselect_some'] +
                 (10, 20)[w] * ['unselect_all'])
        mode = random.choice(modes)

        if mode == 'unselect_some':
            selection = wxgui_api.get_tree_selections(filename)
            if selection:
                sids = [
                    wxgui_api.get_tree_item_id(filename, i) for i in selection
                ]
                remids = random.sample(ids, random.randint(1, len(ids)))
                wxgui_api.simulate_remove_items_from_selection(
                    filename, remids)
        else:
            if mode in ('select_one', 'reselect_many', 'unselect_all'):
                wxgui_api.simulate_unselect_all_items(filename)

            addids = {
                'select_one': (random.choice(ids), ),
                'reselect_many':
                random.sample(
                    ids, random.randint(2 if len(ids) > 1 else 1, len(ids))),
                'select_some':
                random.sample(ids, random.randint(1, len(ids))),
                'select_all':
                ids,
                'unselect_all': (),
            }

            wxgui_api.simulate_add_items_to_selection(filename, addids[mode])

    return wxgui_api.get_tree_selections(filename)
Exemplo n.º 10
0
def _select_items(many):
    filename = wxgui_api.get_selected_database_filename()
    ids = core_api.get_items_ids(filename)

    if ids:
        w = 0 if many else 1
        modes = (
            (40, 80)[w] * ['select_one'] +
            (10, 0)[w] * ['reselect_many'] +
            (10, 0)[w] * ['select_some'] +
            (10, 0)[w] * ['select_all'] +
            (20, 0)[w] * ['unselect_some'] +
            (10, 20)[w] * ['unselect_all']
        )
        mode = random.choice(modes)

        if mode == 'unselect_some':
            selection = wxgui_api.get_tree_selections(filename)
            if selection:
                sids = [wxgui_api.get_tree_item_id(filename, i) for i in
                                                                    selection]
                remids = random.sample(ids, random.randint(1, len(ids)))
                wxgui_api.simulate_remove_items_from_selection(filename,
                                                                        remids)
        else:
            if mode in ('select_one', 'reselect_many', 'unselect_all'):
                wxgui_api.simulate_unselect_all_items(filename)

            addids = {
                'select_one': (random.choice(ids), ),
                'reselect_many': random.sample(ids, random.randint(
                                        2 if len(ids) > 1 else 1, len(ids))),
                'select_some': random.sample(ids, random.randint(1, len(ids))),
                'select_all': ids,
                'unselect_all': (),
            }

            wxgui_api.simulate_add_items_to_selection(filename, addids[mode])

    return wxgui_api.get_tree_selections(filename)
Exemplo n.º 11
0
    def copy_items(self):
        if core_api.block_databases():
            # get_tree_selections() arguments must be compatible with the
            # ones used in self.delete_items()
            selection = wxgui_api.get_tree_selections(self.filename, none=False, descendants=True)

            if selection:
                items = []

                for item in selection:
                    items.append(wxgui_api.get_tree_item_id(self.filename, item))

                copypaste_api.copy_items(self.filename, items)

            core_api.release_databases()
Exemplo n.º 12
0
    def copy_items(self):
        if core_api.block_databases():
            # get_tree_selections() arguments must be compatible with the
            # ones used in self.delete_items()
            selection = wxgui_api.get_tree_selections(self.filename,
                                                      none=False,
                                                      descendants=True)

            if selection:
                items = []

                for item in selection:
                    items.append(
                        wxgui_api.get_tree_item_id(self.filename, item))

                copypaste_api.copy_items(self.filename, items)

            core_api.release_databases()
Exemplo n.º 13
0
    def paste_items_as_children(self, no_confirm=False):
        if core_api.block_databases():
            selection = wxgui_api.get_tree_selections(self.filename, none=False, many=False)

            if selection and (
                no_confirm
                or copypaste_api.can_paste_safely(self.filename)
                or msgboxes.unsafe_paste_confirm().ShowModal() == wx.ID_OK
            ):
                baseid = wxgui_api.get_tree_item_id(self.filename, selection[0])

                roots, ids = copypaste_api.paste_items_as_children(self.filename, baseid, description="Paste sub-items")

                wxgui_api.refresh_history(self.filename)

                items_pasted_event.signal(filename=self.filename, roots=roots, ids=ids)

            core_api.release_databases()
Exemplo n.º 14
0
    def _handle_popup_tree_context_menu(self, kwargs):
        filename = kwargs['filename']
        sel = wxgui_api.get_tree_selections(filename)

        if len(sel) == 1:
            self.cut.Enable()
            self.copy.Enable()

            if copypaste_api.has_copied_items(filename):
                self.paste.Enable()
                self.paste.SetItemLabel(self.cpaste_label_2)
                self.pastesub.Enable()

        elif len(sel) > 1:
            self.cut.Enable()
            self.copy.Enable()

        elif copypaste_api.has_copied_items(filename):
            self.paste.Enable()
Exemplo n.º 15
0
    def _handle_popup_tree_context_menu(self, kwargs):
        filename = kwargs['filename']
        sel = wxgui_api.get_tree_selections(filename)

        if len(sel) == 1:
            self.cut.Enable()
            self.copy.Enable()

            if copypaste_api.has_copied_items(filename):
                self.paste.Enable()
                self.paste.SetItemLabel(self.cpaste_label_2)
                self.pastesub.Enable()

        elif len(sel) > 1:
            self.cut.Enable()
            self.copy.Enable()

        elif copypaste_api.has_copied_items(filename):
            self.paste.Enable()
Exemplo n.º 16
0
    def paste_items_as_children(self, no_confirm=False):
        if core_api.block_databases():
            selection = wxgui_api.get_tree_selections(self.filename,
                                                      none=False,
                                                      many=False)

            if selection and (no_confirm
                              or copypaste_api.can_paste_safely(self.filename)
                              or msgboxes.unsafe_paste_confirm().ShowModal()
                              == wx.ID_OK):
                baseid = wxgui_api.get_tree_item_id(self.filename,
                                                    selection[0])

                roots, ids = copypaste_api.paste_items_as_children(
                    self.filename, baseid, description='Paste sub-items')

                wxgui_api.refresh_history(self.filename)

                items_pasted_event.signal(filename=self.filename,
                                          roots=roots,
                                          ids=ids)

            core_api.release_databases()