-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2979d64
commit a86bb30
Showing
6 changed files
with
147 additions
and
0 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
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,38 @@ | ||
////////////////////////////////////////////////////////////////////////////////////////// | ||
// _ _ ____ _ _ ___ ____ // | ||
// |_/ |__| |\ | | \ | | This file belongs to Kando, the cross-platform // | ||
// | \_ | | | \| |__/ |__| pie menu. Read more on github.com/menu/kando // | ||
// // | ||
////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de> | ||
// SPDX-License-Identifier: MIT | ||
|
||
import { IMenuItem } from '../index'; | ||
import { IItemAction } from '../item-action-registry'; | ||
import { DeepReadonly } from '../../main/settings'; | ||
import { IItemData } from './file-item-type'; | ||
import { shell } from 'electron'; | ||
|
||
/** This action opens files with the default application. */ | ||
export class FileItemAction implements IItemAction { | ||
/** | ||
* Files are opened immediately. | ||
* | ||
* @returns False | ||
*/ | ||
delayedExecution() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Opens a file with the default application. | ||
* | ||
* @param item The item for which the action should be executed. | ||
* @returns A promise which resolves when the file has been opened. | ||
*/ | ||
async execute(item: DeepReadonly<IMenuItem>) { | ||
await shell.openPath((item.data as IItemData).path); | ||
return; | ||
} | ||
} |
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,48 @@ | ||
////////////////////////////////////////////////////////////////////////////////////////// | ||
// _ _ ____ _ _ ___ ____ // | ||
// |_/ |__| |\ | | \ | | This file belongs to Kando, the cross-platform // | ||
// | \_ | | | \| |__/ |__| pie menu. Read more on github.com/menu/kando // | ||
// // | ||
////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de> | ||
// SPDX-License-Identifier: MIT | ||
|
||
import i18next from 'i18next'; | ||
|
||
import { IMenuItem } from '..'; | ||
import { IItemConfig } from '../item-config-registry'; | ||
import { IItemData } from './file-item-type'; | ||
import * as utils from './utils'; | ||
|
||
/** This class provides the configuration widgets for file items. */ | ||
export class FileItemConfig implements IItemConfig { | ||
/** @inheritdoc */ | ||
public getTipOfTheDay(): string { | ||
const tips = [i18next.t('items.file.tip-1')]; | ||
|
||
return tips[Math.floor(Math.random() * tips.length)]; | ||
} | ||
|
||
/** @inheritdoc */ | ||
public getConfigWidget(item: IMenuItem): DocumentFragment | null { | ||
const fragment = utils.renderTemplate( | ||
require('../../renderer/editor/properties/templates/text-option.hbs'), | ||
{ | ||
placeholder: i18next.t('items.common.not-configured'), | ||
label: i18next.t('items.file.file'), | ||
} | ||
); | ||
|
||
// Get the input element and set the current value. | ||
const input = fragment.querySelector('input'); | ||
input.value = (item.data as IItemData).path || ''; | ||
|
||
// Listen for changes and update the item. | ||
input.addEventListener('input', () => { | ||
(item.data as IItemData).path = input.value; | ||
}); | ||
|
||
return fragment; | ||
} | ||
} |
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,55 @@ | ||
////////////////////////////////////////////////////////////////////////////////////////// | ||
// _ _ ____ _ _ ___ ____ // | ||
// |_/ |__| |\ | | \ | | This file belongs to Kando, the cross-platform // | ||
// | \_ | | | \| |__/ |__| pie menu. Read more on github.com/menu/kando // | ||
// // | ||
////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de> | ||
// SPDX-License-Identifier: MIT | ||
|
||
import i18next from 'i18next'; | ||
|
||
import { IMenuItem } from '../index'; | ||
import { IItemType } from '../item-type-registry'; | ||
|
||
/** | ||
* For this type of menu items, the user can configure a path that will be opened when the | ||
* item is clicked. | ||
*/ | ||
export interface IItemData { | ||
path: string; | ||
} | ||
|
||
/** This class provides meta information for menu items that open a file. */ | ||
export class FileItemType implements IItemType { | ||
get hasChildren(): boolean { | ||
return false; | ||
} | ||
|
||
get defaultName(): string { | ||
return i18next.t('items.file.name'); | ||
} | ||
|
||
get defaultIcon(): string { | ||
return 'folder_open'; | ||
} | ||
|
||
get defaultIconTheme(): string { | ||
return 'material-symbols-rounded'; | ||
} | ||
|
||
get defaultData(): IItemData { | ||
return { | ||
path: '', | ||
}; | ||
} | ||
|
||
get genericDescription(): string { | ||
return i18next.t('items.file.description'); | ||
} | ||
|
||
getDescription(item: IMenuItem): string { | ||
return (item.data as IItemData).path || i18next.t('items.common.not-configured'); | ||
} | ||
} |