-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(main): add context menu ipc, typing
- Loading branch information
1 parent
cc806ba
commit d5c11ee
Showing
4 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { createPopupMenu } from '../../components/menu' | ||
import { dialog, ipcMain } from 'electron' | ||
|
||
export const subscribeToContextMenu = () => { | ||
ipcMain.handle('context-menu:snippet-fragment', async (event, payload) => { | ||
const { name } = payload | ||
|
||
return new Promise(resolve => { | ||
createPopupMenu([ | ||
{ | ||
label: `Rename "${name}"`, | ||
click: () => | ||
resolve({ | ||
action: 'rename', | ||
payload: payload | ||
}) | ||
}, | ||
{ type: 'separator' }, | ||
{ | ||
label: `Delete "${name}"`, | ||
click: () => { | ||
const buttonId = dialog.showMessageBoxSync({ | ||
message: `Are you sure you want to permanently delete "${name}"?`, | ||
detail: 'You cannot undo this action.', | ||
buttons: ['Delete', 'Cancel'], | ||
defaultId: 0, | ||
cancelId: 1 | ||
}) | ||
if (buttonId === 0) { | ||
resolve({ | ||
action: 'delete', | ||
payload: payload | ||
}) | ||
} | ||
} | ||
} | ||
]) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { subscribeToContextMenu } from './context-menu' | ||
|
||
export const subscribeToChannels = () => { | ||
subscribeToContextMenu() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters