Skip to content

Commit

Permalink
Added GUI settings for simple folder search plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Jun 13, 2019
1 parent 322cb77 commit ddc9d0e
Show file tree
Hide file tree
Showing 20 changed files with 370 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"typescript": "^3.4.5",
"vue": "^2.6.10",
"vue-color": "^2.7.0",
"webpack": "^4.32.0",
"webpack": "^4.32.2",
"webpack-cli": "^3.3.2",
"windows-system-icon": "0.0.5",
"winston": "^3.2.1"
Expand Down
2 changes: 1 addition & 1 deletion src/common/config/default-simple-folder-search-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { homedir } from "os";
export const defaultSimpleFolderSearchOptions: SimpleFolderSearchOptions = {
folders: [
{
excludeHiddenFiles: false,
excludeHiddenFiles: true,
folderPath: homedir(),
recursive: false,
},
Expand Down
2 changes: 1 addition & 1 deletion src/common/config/simple-folder-search-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface SimpleFolderSearchOptions {
folders: SimpleFolderSearchFolderOption[];
}

interface SimpleFolderSearchFolderOption {
export interface SimpleFolderSearchFolderOption {
folderPath: string;
recursive: boolean;
excludeHiddenFiles: boolean;
Expand Down
6 changes: 5 additions & 1 deletion src/common/translation/english-translation-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export const englishTranslationSet: TranslationSet = {

shortcutSettings: "Shortcuts",
shortcutSettingsDescription: `This plugin enables you to quickly open files or websites by setting up your own shortcuts.`,
shortcutSettingsShortcut: "Shortcuts",
shortcutSettingsTableType: "Type",
shortcutSettingsTableName: "Name",
shortcutSettingsTableExecutionArgument: "Execution argument",
Expand Down Expand Up @@ -270,6 +269,11 @@ export const englishTranslationSet: TranslationSet = {

simpleFolderSearch: "Simple folder search",
simpleFolderSearchDescription: "This plugin enables you to quickly search for files or folders",
simpleFolderSearchRecursive: "Recursive file scan",
simpleFolderSearchExcludeHiddenFiles: "Exclude hidden files",
simpleFolderSearchFolderPath: "Folder path",
simpleFolderSearchAddFolder: "Add folder",
simpleFolderSearchEditFolder: "Edit folder",

cancel: "Cancel",
save: "Save",
Expand Down
6 changes: 5 additions & 1 deletion src/common/translation/german-translation-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export const germanTranslationSet: TranslationSet = {

shortcutSettings: "Shortcuts",
shortcutSettingsDescription: `Dieses Plugin erlaubt es dir Dateien und Webseiten schnell zu öffnen indem du eigene Shorctus erstellst.`,
shortcutSettingsShortcut: "Shortcuts",
shortcutSettingsTableType: "Typ",
shortcutSettingsTableName: "Name",
shortcutSettingsTableExecutionArgument: "Ausführungsargument",
Expand Down Expand Up @@ -270,6 +269,11 @@ export const germanTranslationSet: TranslationSet = {

simpleFolderSearch: "Einfache Ordnersuche",
simpleFolderSearchDescription: "Dieses Plugin erlaubt es dir, schnell Dateien und Ordner zu finden.",
simpleFolderSearchRecursive: "Rekursiver Dateiscan",
simpleFolderSearchExcludeHiddenFiles: "Versteckte Dateien ausblenden",
simpleFolderSearchFolderPath: "Dateipfad",
simpleFolderSearchAddFolder: "Ordner hinzufügen",
simpleFolderSearchEditFolder: "Ordner bearbeiten",

cancel: "Abbrechen",
save: "Speichern",
Expand Down
6 changes: 5 additions & 1 deletion src/common/translation/translation-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export interface TranslationSet {

shortcutSettings: string;
shortcutSettingsDescription: string;
shortcutSettingsShortcut: string;
shortcutSettingsTableType: string;
shortcutSettingsTableName: string;
shortcutSettingsTableExecutionArgument: string;
Expand Down Expand Up @@ -267,6 +266,11 @@ export interface TranslationSet {

simpleFolderSearch: string;
simpleFolderSearchDescription: string;
simpleFolderSearchRecursive: string;
simpleFolderSearchExcludeHiddenFiles: string;
simpleFolderSearchFolderPath: string;
simpleFolderSearchAddFolder: string;
simpleFolderSearchEditFolder: string;

cancel: string;
save: string;
Expand Down
2 changes: 1 addition & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ function registerAllIpcListeners() {
const newUserInput = direction === "next"
? userInputHistoryManager.getNext()
: userInputHistoryManager.getPrevious();
event.sender.send(IpcChannels.userInputUpdated, newUserInput);
event.sender.send(IpcChannels.userInputUpdated, newUserInput, true);
});

ipcMain.on(IpcChannels.ueliCommandExecuted, (command: UeliCommand) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ export class SimpleFolderSearchPlugin implements SearchPlugin {

public refreshIndex(): Promise<void> {
return new Promise((resolve, reject) => {
if (this.config.folders.length === 0) {
const handleEmptyResult = () => {
this.items = [];
resolve();
};

if (this.config.folders.length === 0) {
handleEmptyResult();
} else {
const filePromises = this.config.folders.map((folderOption) => {
return folderOption.recursive
Expand All @@ -52,8 +56,7 @@ export class SimpleFolderSearchPlugin implements SearchPlugin {
: [];

if (iconPromises.length === 0) {
this.items = [];
resolve();
handleEmptyResult();
} else {
Promise.all(iconPromises)
.then((iconResults) => {
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { tagsEditingComponent } from "./settings/tags-editing-component";
import { TranslationSet } from "../common/translation/translation-set";
import { simpleFolderSearchSettingsComponent } from "./settings/simple-folder-search-settings-component";
import { GeneralOptions } from "../common/config/general-options";
import { simpleFolderSearchEditingModalComponent } from "./settings/modals/simple-folder-search-editing-modal-component";

Vue.component("user-input", userInputComponent);
Vue.component("search-results", searchResultsComponent);
Expand Down Expand Up @@ -85,6 +86,7 @@ Vue.component("workflow-settings", workflowSettingsComponent);
Vue.component("workflow-editing-modal", workflowEditingModal);
Vue.component("commandline-settings", commandlineSettingsComponent);
Vue.component("simple-folder-search-settings", simpleFolderSearchSettingsComponent);
Vue.component("simple-folder-search-editing", simpleFolderSearchEditingModalComponent);

const initialConfig = new ElectronStoreConfigRepository(cloneDeep(defaultUserConfigOptions)).getConfig();

Expand Down Expand Up @@ -179,8 +181,8 @@ const app = new Vue({
vueEventDispatcher.$emit(VueEventChannels.mainWindowHasBeenShown);
});

ipcRenderer.on(IpcChannels.userInputUpdated, (event: Electron.Event, updatedUserInput: string) => {
vueEventDispatcher.$emit(VueEventChannels.userInputUpdated, updatedUserInput);
ipcRenderer.on(IpcChannels.userInputUpdated, (event: Electron.Event, updatedUserInput: string, selectText?: boolean) => {
vueEventDispatcher.$emit(VueEventChannels.userInputUpdated, updatedUserInput, selectText);
});

ipcRenderer.on(IpcChannels.notification, (event: Electron.Event, message: string, type?: NotificationType) => {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/settings/modals/modal-edit-mode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum ModalEditMode {
Edit = "Edit Shortcut",
Add = "Add new Shortcut",
Edit = "Edit",
Add = "Add",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import Vue from "vue";
import { vueEventDispatcher } from "../../vue-event-dispatcher";
import { VueEventChannels } from "../../vue-event-channels";
import { SimpleFolderSearchOptions, SimpleFolderSearchFolderOption } from "../../../common/config/simple-folder-search-options";
import { cloneDeep } from "lodash";
import { ModalEditMode } from "./modal-edit-mode";
import { NotificationType } from "../../../common/notification-type";
import { existsSync, lstatSync } from "fs";
import { getFolderPath } from "../../dialogs";
import { TranslationSet } from "../../../common/translation/translation-set";
import { homedir } from "os";
import { join } from "path";

const initialFolderOptions: SimpleFolderSearchFolderOption = {
excludeHiddenFiles: false,
folderPath: "",
recursive: false,
};

const folderPathValidator = (folderPath: string): boolean => {
return folderPath.length > 0
&& existsSync(folderPath)
&& lstatSync(folderPath).isDirectory();
};

export const simpleFolderSearchEditingModalComponent = Vue.extend({
data() {
return {
editMode: ModalEditMode.Add,
options: cloneDeep(initialFolderOptions),
saveIndex: undefined,
visible: false,
};
},
methods: {
getModalTitle(): string {
const translations: TranslationSet = this.translations;
const editMode: ModalEditMode = this.editMode;
switch (editMode) {
case ModalEditMode.Add:
return translations.simpleFolderSearchAddFolder;
case ModalEditMode.Edit:
return translations.simpleFolderSearchEditFolder;
}
},
closeModal() {
this.editMode = ModalEditMode.Add;
this.options = cloneDeep(initialFolderOptions);
this.saveIndex = 0;
this.visible = false;
},
openFolderDialog() {
getFolderPath()
.then((folderPath) => {
const options: SimpleFolderSearchFolderOption = this.options;
options.folderPath = folderPath;
})
.catch((err) => {
// do nothing if no folder is selected
});
},
saveButtonClick() {
const options: SimpleFolderSearchFolderOption = this.options;
if (folderPathValidator(options.folderPath)) {
vueEventDispatcher.$emit(VueEventChannels.simpleFolderSearchOptionSaved, this.options, this.editMode, this.saveIndex);
this.closeModal();
} else {
vueEventDispatcher.$emit(VueEventChannels.notification, "Invalid folder path", NotificationType.Error);
}
},
formIsValid(): boolean {
const options: SimpleFolderSearchFolderOption = this.options;
return folderPathValidator(options.folderPath);
},
getFolderPathPlaceholder(): string {
const translations: TranslationSet = this.translations;
return `${translations.forExample}: ${join(homedir(), "Downloads")}`;
},
},
mounted() {
vueEventDispatcher.$on(VueEventChannels.openSimpleFolderSearchEditingModal, (folderOptions?: SimpleFolderSearchOptions, editMode?: ModalEditMode, saveIndex?: number) => {
if (editMode) {
this.editMode = editMode;
}

if (folderOptions) {
this.options = folderOptions;
}

if (saveIndex) {
this.saveIndex = saveIndex;
}

this.visible = true;
});
},
props: ["translations"],
template: `
<div class="modal" :class="{ 'is-active' : visible }">
<div class="modal-background" @click="closeModal"></div>
<div class="modal-content">
<div class="message">
<div class="message-header">
<p>{{ getModalTitle() }}</p>
<button class="delete" @click="closeModal" aria-label="delete"></button>
</div>
<div class="message-body">
<div class="field">
<label class="label">
{{ translations.simpleFolderSearchFolderPath }}
</label>
</div>
<div class="field has-addons">
<div class="control is-expanded">
<input class="input" type="text" v-model="options.folderPath" :placeholder="getFolderPathPlaceholder()">
</div>
<div class="control">
<button class="button" @click="openFolderDialog" autofocus>
<span class="icon">
<i class="fas fa-folder"></i>
</span>
</button>
</div>
</div>
<div class="field">
<label class="label">
{{ translations.simpleFolderSearchRecursive }}
</label>
<div class="control is-expanded">
<input class="is-checkradio" id="recursiveCheckbox" type="checkbox" name="recursiveCheckbox" v-model="options.recursive">
<label for="recursiveCheckbox"></label>
<div class="field">
<input class="is-checkradio is-block is-success" id="recursiveCheckbox" type="checkbox" name="recursiveCheckbox" checked="checked">
</div>
</div>
</div>
<div class="field">
<label class="label">
{{ translations.simpleFolderSearchExcludeHiddenFiles }}
</label>
<div class="control is-expanded">
<input class="is-checkradio" id="excludeHiddenFilexCheckbox" type="checkbox" name="excludeHiddenFilexCheckbox" v-model="options.excludeHiddenFiles">
<label for="excludeHiddenFilexCheckbox"></label>
<div class="field">
<input class="is-checkradio is-block is-success" id="excludeHiddenFilexCheckbox" type="checkbox" name="excludeHiddenFilexCheckbox" checked="checked">
</div>
</div>
</div>
<div class="field is-grouped is-grouped-right">
<div class="control">
<button class="button is-danger" @click="closeModal">
<span class="icon">
<i class="fas fa-times"></i>
</span>
<span>
{{ translations.cancel }}
</span>
</button>
<button class="button is-success" :disabled="!formIsValid()" @click="saveButtonClick">
<span class="icon">
<i class="fas fa-check"></i>
</span>
<span>
{{ translations.save }}
</span>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
`,
});
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ export const workflowEditingModal = Vue.extend({
<div class="control">
<button disabled class="button" :class="getExecutionArgumentTypeClass(executionStep.executionArgumentType)">
<span class="icon">
<i :class="getExecutionArgumentTypeIcon(executionStep.executionArgumentType)">
</span
<i :class="getExecutionArgumentTypeIcon(executionStep.executionArgumentType)"></i>
</span>
</button>
</div>
<div class="control is-expanded">
Expand Down
1 change: 1 addition & 0 deletions src/renderer/settings/plugin-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export enum PluginSettings {
CurrencyConverter = "Currency Converter",
Workflow = "Workflow",
Commandline = "Commandline",
SimpleFolderSearch = "Simple Folder Search",
}
2 changes: 2 additions & 0 deletions src/renderer/settings/setting-menu-item-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const settingMenuItemComponent = Vue.extend({
return translations.currencyConverter;
case PluginSettings.Commandline:
return translations.commandline;
case PluginSettings.SimpleFolderSearch:
return translations.simpleFolderSearch;
case SettingOsSpecific.Everything:
return translations.everythingSearch;
case SettingOsSpecific.MdFind:
Expand Down
1 change: 1 addition & 0 deletions src/renderer/settings/settings-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const settingsComponent = Vue.extend({
<currency-converter-settings :config="config" :translations="translations"></currency-converter-settings>
<workflow-settings :config="config" :translations="translations"></workflow-settings>
<commandline-settings :config="config" :translations="translations"></commandline-settings>
<simple-folder-search-settings :config="config" :translations="translations"></simple-folder-search-settings>
</div>
</div>
`,
Expand Down
5 changes: 0 additions & 5 deletions src/renderer/settings/shortcut-settings-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ export const shortcutSettingsComponent = Vue.extend({
<div class="settings__setting-content">
<div v-if="!config.shortcutOptions.isEnabled" class="settings__setting-disabled-overlay"></div>
<div class="settings__setting-content-item box">
<div class="settings__setting-content-item-title">
<div class="title is-5">
{{ translations.shortcutSettingsShortcut }}
</div>
</div>
<div class="table-container">
<table class="table is-striped is-fullwidth" v-if="config.shortcutOptions.shortcuts.length > 0">
<thead>
Expand Down
Loading

0 comments on commit ddc9d0e

Please sign in to comment.