     to_obj: () =>
         nb = @frame.IPython.notebook
         obj = nb.toJSON()
-        obj.metadata.name = nb.notebook_name
-        obj.nbformat = nb.nbformat
+        obj.metadata.name  = nb.notebook_name
+        obj.nbformat       = nb.nbformat
         obj.nbformat_minor = nb.nbformat_minor
         return obj
 
     from_obj: (obj) =>
         nb = @frame.IPython.notebook
         nb.fromJSON(obj)
-
+        nb.dirty = false
+
+    focus: () =>
+        # TODO
+        console.log("ipython notebook focus: todo")
 
 
     show: () =>

                                @_save_checkpoint = @frame.IPython.notebook.save_checkpoint
                                console.log(@_save_checkpoint)
                                @frame.IPython.notebook.save_checkpoint = @save_checkpoint
                    setTimeout(f, 100)

    save_checkpoint: () =>
        console.log("save checkpoint!")
        obj = @to_obj()
        v1 = misc.to_json(obj)
        @doc.live(v1)
        @save_button.icon_spin(true)
        @doc.save () =>
            @save_button.icon_spin(false)
            return
            ###
            console.log("sync'd and got back.")
            v2 = @doc.live()
            if v1 != v2
                console.log("new changes from afar!")
                # here we would somehow merge the two objects obj and obj2
                try
                    @from_obj(misc.from_json(v2))
                catch e
                    console.log("invalid json, so resetting.")
                    @doc.live(v1)
                    @doc.save () =>
                        @doc.save()
            else
                console.log("nothing new")
            ###

    doc_sync: () =>
        console.log("doc sync")
        v1 = @doc.live()
        obj = @to_obj()
        v2 = misc.to_json(obj)
        if v1 != v2
            # TODO -- here *we* would merge the objects defined by v1 and v2, then set live to that and sync it out...
            try
                @from_obj(misc.from_json(v1))
            catch e
                console.log("invalid json, so resetting ", e)
                @from_obj(obj)
                @doc.live(v2)  # definitely good version
                @doc.sync () =>
                    @doc.live(v2)
                    @doc.sync()





    init_buttons: () =>
        @save_button = @element.find("a[href=#save]").click () =>

            opts.cb("unable to connect to remote server")
            return
        $.get(opts.url, (data) ->
            console.log(data.slice(0,100))
            if 'ECONNREFUSED' in data or '404: Not Found' in data
                delay *= opts.factor
                setTimeout(f, delay)
