Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

Commit

Permalink
remove use of deprecated atom.showSaveDialogSync()
Browse files Browse the repository at this point in the history
fixes #55
  • Loading branch information
josa42 committed Oct 11, 2018
1 parent 114c41c commit 57aa7ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
17 changes: 6 additions & 11 deletions lib/svg-preview-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,30 +353,25 @@ class SvgPreviewView extends View {
}

exportTo (outputType) {
let filePath, outputFilePath, projectPath
if (this.loading) {
return
}

filePath = this.getPath()

let filePath = this.getPath()
if (filePath) {
filePath = path.join(
path.dirname(filePath),
path.basename(
filePath,
path.extname(filePath)
)
).concat(`.${outputType}`)
path.basename(filePath, path.extname(filePath))
)
} else {
filePath = `untitled.${outputType}`
projectPath = atom.project.getPaths()[0]
filePath = 'export'
const projectPath = atom.project.getPaths()[0]
if (projectPath) {
filePath = path.join(projectPath, filePath)
}
}

outputFilePath = atom.showSaveDialogSync(filePath)
const outputFilePath = atom.applicationDelegate.showSaveDialog(`${filePath}.${outputType}`)
if (outputFilePath) {
this.getSvgSource().then((source) => {
svgToRaster.transform(source, outputType, (result) => {
Expand Down
16 changes: 11 additions & 5 deletions spec/svg-preview-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import wrench from 'wrench'
import SvgPreviewView from '../lib/svg-preview-view'
import { TextEditor } from 'atom'

const { atom, describe, it, expect, beforeEach, jasmine, waitsFor, runs, spyOn, waitsForPromise } = global
temp.track()

const { atom, describe, it, expect, beforeEach, afterEach, jasmine, waitsFor, runs, spyOn, waitsForPromise } = global

describe('SVG preview package', () => {
let preview, editor, workspaceElement
Expand All @@ -28,6 +30,10 @@ describe('SVG preview package', () => {
waitsForPromise(() => atom.packages.activatePackage('svg-preview'))
})

afterEach(() => {
temp.cleanupSync()
})

const expectPreviewInSplitPane = function () {
waitsFor('svg editor to be created', () => {
editor = atom.workspace.getPanes()[0].getActiveItem()
Expand Down Expand Up @@ -277,7 +283,7 @@ describe('SVG preview package', () => {
})

it('saves a PNG and opens it', () => {
let outputPath = `${temp.path()}subdir/file with space.png`
let outputPath = path.join(temp.mkdirSync(), 'subdir__file with space.png')
let previewPaneItem = null

waitsForPromise(() => atom.workspace.open('subdir/file with space.svg'))
Expand All @@ -288,7 +294,7 @@ describe('SVG preview package', () => {
return previewPaneItem
})
runs(() => {
spyOn(atom, 'showSaveDialogSync').andReturn(outputPath)
spyOn(atom.applicationDelegate, 'showSaveDialog').andReturn(outputPath)
atom.commands.dispatch(previewPaneItem.element, 'svg-preview:export-to-png')
})

Expand All @@ -302,7 +308,7 @@ describe('SVG preview package', () => {
})

it('saves a JPEG and opens it', () => {
let outputPath = `${temp.path()}subdir/file with space.jpeg`
let outputPath = path.join(temp.mkdirSync(), 'subdir__file with space.jpeg')
let previewPaneItem = null

waitsForPromise(() => atom.workspace.open('subdir/file with space.svg'))
Expand All @@ -313,7 +319,7 @@ describe('SVG preview package', () => {
return previewPaneItem
})
runs(() => {
spyOn(atom, 'showSaveDialogSync').andReturn(outputPath)
spyOn(atom.applicationDelegate, 'showSaveDialog').andReturn(outputPath)
atom.commands.dispatch(previewPaneItem.element, 'svg-preview:export-to-jpeg')
})

Expand Down

0 comments on commit 57aa7ba

Please sign in to comment.