   importData: (data)->
     try
       console.log "importing #{data}"
-      @cells = importField parseFieldData data
+      match = data.match /^(\d+)\$(\d+)\$(.*)$/
+      throw new Error("Data format unrecognized") unless match?
+      n = parseIntChecked match[1]
+      m = parseIntChecked match[2]
+
+      if n isnt @getGroup().n or m isnt @getGroup().m
+        console.log "Need to change grid"
+        @setGridImpl n, m
+      @cells = importField parseFieldData match[3]
       console.log "Imported #{@cells.count} cells"
     catch e
       alert "Faield to import data: #{e}"

    visibleCells.put translatedCell, state
  return exportField visibleCells

showExporDialog = (sdata) ->
  E('export').value = sdata
  E('export-dialog').style.display = ''
  E('export').focus()
  E('export').select()
  
doExportVisible = ->
  showExporDialog stringifyFieldData encodeVisible()
  
doShowImport = ->
  E('import-dialog').style.display = ''

#  return parts.join " "
  
doExport = ->
  data = stringifyFieldData exportField application.cells
  n = application.getGroup().n
  m = application.getGroup().m
  showExportDialog "#{n}$#{m}$#{data}"

doExportClose = ->
  E('export-dialog').style.display = 'none'
