Patch review below.

On Sat, Sep 10, 2011 at 09:39:40PM +0200, ferry jeremie wrote:
> +    def duplicate_layer(self, widget):
> +        doc = self.app.doc.model
> +        layer = doc.layers[doc.layer_idx]
> +        name = layer.name
> +        if name:
> +          name = "copy of %s" % name
> +        else:
> +          layer_num = self.anon_layer_num.get(id(layer), None)
> +          name = 'copy of %s' % _("Untitled layer #%d" % layer_num)
> +        print name
> +        doc.duplicate_layer(doc.layer_idx, name)

Please fix the indentation to match the rest of the code. Please mark the
string "copy of" for translation (like "Untitles layer" already is).

> +class DuplicateLayer(Action):
> +    def __init__(self, doc, insert_idx=None, name=''):
> +        self.doc = doc
> +        self.insert_idx = insert_idx
> +        snapshot = self.doc.layers[self.insert_idx].save_snapshot()
> +        self.new_layer = layer.Layer(name)
> +        self.new_layer.load_snapshot(snapshot)
> +        self.new_layer.surface.observers.append(self.doc.layer_modified_cb)
> +    def redo(self):
> +        self.doc.layers.insert(self.insert_idx+1, self.new_layer)
> +        self._notify_document_observers()
> +    def undo(self):
> +        moved_layer = self.doc.layers[self.insert_idx+1]
> +        self.doc.layers.remove(moved_layer)
> +        self._notify_document_observers()

I think you are not using the insert_idx parameter at all, please remove it. 
And if you have a variable named "insert_idx", please use it as insert
index, and not "insert_idx+1", when inserting.

And there is a glitch: you need to call the canvas observers, too. Right now
the display does not update until you paint over the duplicated layer.

-- 
Martin Renold

_______________________________________________
Mypaint-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/mypaint-discuss

Reply via email to