Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added filters for save dialogs. #79

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { app, BrowserWindow, ipcMain, dialog, Menu } from 'electron'
import { app, BrowserWindow, ipcMain, dialog, Menu, FileFilter } from 'electron'
import { OpenProjectMessage, OpenImageMessage, SaveProjectMessage, SaveProjectAsMessage, NewProjectMessage, ExportMessage, ExportType, SetSidePanelVisibilityMessage } from './ipc-messages'
const path = require('path')
const url = require('url')
Expand Down Expand Up @@ -175,7 +175,12 @@ function createWindow() {
onSaveProjectAs: () => {
dialog.showSaveDialog(
window,
{}
{
filters: [
{ name: 'fSpy project files', extensions: ['fspy'] },
{ name: 'All files', extensions: ['*'] }
]
}
).then((result) => {
if (!result.canceled && result.filePath !== undefined) {
window.webContents.send(
Expand Down Expand Up @@ -381,7 +386,12 @@ function createWindow() {
// TODO: DRY
dialog.showSaveDialog(
window,
{}
{
filters: [
{ name: 'fSpy project files', extensions: ['fspy'] },
{ name: 'All files', extensions: ['*'] }
]
}
).then((result) => {
if (!result.canceled && result.filePath) {
window.webContents.send(
Expand All @@ -395,10 +405,20 @@ function createWindow() {
})

ipcMain.on(SpecifyExportPathMessage.type, (_: any, message: SpecifyExportPathMessage) => {
const filters: FileFilter[] = []
switch (message.exportType) {
case ExportType.CameraParametersJSON:
filters.push({ name: 'JSON files', extensions: ['json'] })
break
case ExportType.ProjectImage:
filters.push({ name: 'JPEG images', extensions: ['jpg'] })
break
}
filters.push({ name: 'All files', extensions: ['*'] })
// TODO: DRY
dialog.showSaveDialog(
window,
{}
{ filters }
).then((result) => {
if (!result.canceled && result.filePath) {
let file = openSync(result.filePath, 'w')
Expand Down