Skip to content
Merged
Show file tree
Hide file tree
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
119 changes: 114 additions & 5 deletions src/main/menu/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMenu } from '../components/menu'
import type { MenuItemConstructorOptions } from 'electron'
import { dialog, app, BrowserWindow } from 'electron'
import { shell, dialog, app, BrowserWindow } from 'electron'
import { version, author } from '../../../package.json'
import os from 'os'

Expand Down Expand Up @@ -78,10 +78,6 @@ const appMenu: MenuItemConstructorOptions[] = [
]

const helpMenu: MenuItemConstructorOptions[] = [
{
label: 'Toogle Dev tools',
role: 'toggleDevTools'
},
{
label: 'About',
click () {
Expand All @@ -100,6 +96,62 @@ const helpMenu: MenuItemConstructorOptions[] = [
`
})
}
},
{
label: 'Website',
click: () => {
shell.openExternal('https://masscode.io')
}
},
{
label: 'Change Log',
click: () => {
shell.openExternal(
'https://github.com/massCodeIO/massCode/blob/master/CHANGELOG.md'
)
}
},
{
label: 'Documentation',
click: () => {
shell.openExternal('https://masscode.io/documentation')
}
},
{
label: 'View in GitHub',
click: () => {
shell.openExternal('https://github.com/massCodeIO/massCode')
}
},
{
label: 'Report Issue',
click: () => {
shell.openExternal(
'https://github.com/massCodeIO/massCode/issues/new/choose'
)
}
},
{
type: 'separator'
},
{
label: 'Donate',
click: () => {
shell.openExternal('https://opencollective.com/masscode')
}
},
{
label: 'Twitter',
click: () => {
shell.openExternal('https://twitter.com/anton_reshetov')
}
},
{
type: 'separator'
},
{
label: 'Toggle Developer Tools',
role: 'toggleDevTools'
}
]

Expand All @@ -110,15 +162,72 @@ if (isDev) {
})
}

const fileMenu: MenuItemConstructorOptions[] = [
{
label: 'New Snippet',
accelerator: 'CommandOrControl+N',
click: () => {
BrowserWindow.getFocusedWindow()?.webContents.send(
'main-menu:new-snippet'
)
}
},
{
label: 'New Fragment',
accelerator: 'CommandOrControl+T',
click: () => {
BrowserWindow.getFocusedWindow()?.webContents.send(
'main-menu:new-fragment'
)
}
},
{
label: 'New Folder',
accelerator: 'CommandOrControl+Shift+N',
click: () => {
BrowserWindow.getFocusedWindow()?.webContents.send('main-menu:new-folder')
}
}
]

const editorMenu: MenuItemConstructorOptions[] = [
{
label: 'Copy Snippet to Clipboard',
accelerator: 'Shift+CommandOrControl+C',
click: () => {
BrowserWindow.getFocusedWindow()?.webContents.send(
'main-menu:copy-snippet'
)
}
},
{
label: 'Preview Markdown',
accelerator: 'Shift+CommandOrControl+M',
click: () => {
BrowserWindow.getFocusedWindow()?.webContents.send(
'main-menu:preview-markdown'
)
}
}
]

const menuItems: MenuItemConstructorOptions[] = [
{
label: 'massCode',
submenu: isMac ? appMenuMac : appMenu
},
{
label: 'File',
submenu: fileMenu
},
{
label: 'Edit',
role: 'editMenu'
},
{
label: 'Editor',
submenu: editorMenu
},
{
label: 'Help',
submenu: helpMenu
Expand Down
30 changes: 29 additions & 1 deletion src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { ipc, store, track } from './electron'
import { useAppStore } from './store/app'
import { repository } from '../../package.json'
import { useSnippetStore } from './store/snippets'
import {
onAddNewSnippet,
onAddNewFragment,
onAddNewFolder,
onCopySnippet
} from '@/composable'

// По какой то причине необходимо явно установить роут в '/'
// для корректного поведения в продакшен сборке
Expand Down Expand Up @@ -84,9 +90,31 @@ ipc.on('main-menu:preferences', () => {
router.push('/preferences')
})

ipc.on('main:update-available', async () => {
ipc.on('main:update-available', () => {
isUpdateAvailable.value = true
})

ipc.on('main-menu:new-folder', async () => {
await onAddNewFolder()
})

ipc.on('main-menu:new-snippet', async () => {
await onAddNewSnippet()
})

ipc.on('main-menu:new-fragment', () => {
onAddNewFragment()
})

ipc.on('main-menu:preview-markdown', async () => {
if (snippetStore.currentLanguage === 'markdown') {
snippetStore.isMarkdownPreview = !snippetStore.isMarkdownPreview
}
})

ipc.on('main-menu:copy-snippet', () => {
onCopySnippet()
})
</script>

<style lang="scss">
Expand Down
16 changes: 14 additions & 2 deletions src/renderer/components/sidebar/SidebarList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>
</div>
<div
ref="listRef"
ref="bodyRef"
class="body"
:class="{ 'is-system': isSystem }"
>
Expand All @@ -46,8 +46,9 @@
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { computed, nextTick, ref } from 'vue'
import type { Tab, Tabs } from '@shared/types/renderer/sidebar'
import { emitter, setScrollPosition } from '@/composable'

interface Props {
title?: string
Expand All @@ -68,6 +69,8 @@ const props = withDefaults(defineProps<Props>(), {
isSystem: false
})

const bodyRef = ref<HTMLElement>()

const activeTab = computed({
get: () => props.modelValue,
set: v => {
Expand All @@ -78,6 +81,15 @@ const activeTab = computed({
const onClickTab = (tab: Tab) => {
activeTab.value = tab
}

emitter.on('scroll-to:folder', id => {
nextTick(() => {
const el = document.querySelector<HTMLElement>(`[data-id='${id}']`)
if (el) {
setScrollPosition(bodyRef.value!, el.getBoundingClientRect().top + 210)
}
})
})
</script>

<style lang="scss" scoped>
Expand Down
10 changes: 3 additions & 7 deletions src/renderer/components/sidebar/TheSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<template #default="{ node }">
<SidebarListItem
:id="node.id"
:data-id="node.id"
:is-folder="true"
:model="node"
@drop="onDrop($event, node.id)"
Expand Down Expand Up @@ -94,9 +95,9 @@ import Trash from '~icons/unicons/trash'
import LabelAlt from '~icons/unicons/label-alt'
import { useFolderStore } from '@/store/folders'
import { useSnippetStore } from '@/store/snippets'
import { ipc, store, track } from '@/electron'
import { ipc, store } from '@/electron'
import { useTagStore } from '@/store/tags'
import { emitter } from '@/composable'
import { emitter, onAddNewFolder } from '@/composable'
import interact from 'interactjs'
import { useAppStore } from '@/store/app'

Expand Down Expand Up @@ -159,11 +160,6 @@ const contextMenuHandler = () => {
})
}

const onAddNewFolder = async () => {
await folderStore.addNewFolder()
track('folders/add-new')
}

const onUpdate = async () => {
await folderStore.updateFoldersTable()
}
Expand Down
21 changes: 2 additions & 19 deletions src/renderer/components/snippets/SnippetHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
</template>

<script setup lang="ts">
import { emitter } from '@/composable'
import { ipc, track } from '@/electron'
import { emitter, onAddNewFragment, onCopySnippet } from '@/composable'
import { useSnippetStore } from '@/store/snippets'
import { useClipboard, useDebounceFn } from '@vueuse/core'
import { useDebounceFn } from '@vueuse/core'
import { computed, ref } from 'vue'
import type { NotificationRequest } from '@shared/types/main'
import { useAppStore } from '@/store/app'

const snippetStore = useSnippetStore()
Expand All @@ -57,21 +55,6 @@ const name = computed({
)
})

const onAddNewFragment = () => {
snippetStore.addNewFragmentToSnippetsById(snippetStore.selectedId!)
snippetStore.fragment = snippetStore.fragmentCount!
track('snippets/add-fragment')
}

const onCopySnippet = () => {
const { copy } = useClipboard({ source: snippetStore.currentContent })
copy()
ipc.invoke<any, NotificationRequest>('main:notification', {
body: 'Snippet copied'
})
track('snippets/copy')
}

const onClickMarkdownPreview = () => {
snippetStore.isMarkdownPreview = !snippetStore.isMarkdownPreview
}
Expand Down
11 changes: 3 additions & 8 deletions src/renderer/components/snippets/SnippetList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</template>

<script setup lang="ts">
import { emitter } from '@/composable'
import { emitter, setScrollPosition } from '@/composable'
import { useAppStore } from '@/store/app'
import { useSnippetStore } from '@/store/snippets'
import { onMounted, ref, watch } from 'vue'
Expand All @@ -45,11 +45,6 @@ const listRef = ref()
const bodyRef = ref<HTMLElement>()
const gutterRef = ref()

const setScrollPosition = (offset: number) => {
const ps = bodyRef.value?.querySelector<HTMLElement>('.ps')
if (ps) ps.scrollTop = offset
}

onMounted(() => {
interact(listRef.value).resizable({
allowFrom: gutterRef.value,
Expand All @@ -71,12 +66,12 @@ watch(
const el = document.querySelector<HTMLElement>(
`[data-id='${snippetStore.selectedId!}']`
)
if (el?.offsetTop) setScrollPosition(el.offsetTop)
if (el?.offsetTop) setScrollPosition(bodyRef.value!, el.offsetTop)
}
)

emitter.on('folder:click', () => {
setScrollPosition(0)
setScrollPosition(bodyRef.value!, 0)
})
</script>

Expand Down
16 changes: 1 addition & 15 deletions src/renderer/components/snippets/SnippetListHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
</template>

<script setup lang="ts">
import { emitter } from '@/composable'
import { useFolderStore } from '@/store/folders'
import { onAddNewSnippet } from '@/composable'
import { useSnippetStore } from '@/store/snippets'
import { useDebounceFn } from '@vueuse/core'
import { computed } from 'vue'
import { track } from '@/electron'

const snippetStore = useSnippetStore()
const folderStore = useFolderStore()

const query = computed({
get: () => snippetStore.searchQuery,
Expand All @@ -43,18 +41,6 @@ const query = computed({
}, 300)
})

const onAddNewSnippet = async () => {
if (folderStore.selectedAlias !== undefined) return
if (!folderStore.selectedId) return

await snippetStore.addNewSnippet()
await snippetStore.getSnippetsByFolderIds(folderStore.selectedIds!)
await snippetStore.getSnippets()

emitter.emit('focus:snippet-name', true)
track('snippets/add-new')
}

const onReset = () => {
snippetStore.searchQuery = undefined
snippetStore.setSnippetsByAlias('all')
Expand Down
Loading