Skip to content

Commit

Permalink
Add "find all" window for cross-collection searching. Fix some window…
Browse files Browse the repository at this point in the history
… close issues.
  • Loading branch information
jtsage committed Nov 19, 2022
1 parent 13e11a2 commit e5542a1
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 32 deletions.
57 changes: 44 additions & 13 deletions modAssist_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const settingsSchema = {
confirm : { type : 'object', default : {}, properties : winDef(750, 500), additionalProperties : false },
debug : { type : 'object', default : {}, properties : winDef(1000, 500), additionalProperties : false },
detail : { type : 'object', default : {}, properties : winDef(800, 500), additionalProperties : false },
find : { type : 'object', default : {}, properties : winDef(800, 600), additionalProperties : false },
folder : { type : 'object', default : {}, properties : winDef(800, 500), additionalProperties : false },
main : { type : 'object', default : {}, properties : winDef(1000, 700), additionalProperties : false },
notes : { type : 'object', default : {}, properties : winDef(800, 500), additionalProperties : false },
Expand Down Expand Up @@ -225,6 +226,7 @@ const windows = {
confirm : null,
debug : null,
detail : null,
find : null,
folder : null,
load : null,
main : null,
Expand Down Expand Up @@ -272,6 +274,11 @@ mcStore.set('cache_version', app.getVersion())
( \/\/ )(_ _)( \( )( _ \ ( _ )( \/\/ )/ __)
) ( _)(_ ) ( )(_) ) )(_)( ) ( \__ \
(__/\__)(____)(_)\_)(____/ (_____)(__/\__)(___/ */
function destroyAndFocus(winName) {
windows[winName] = null
if ( windows.main !== null ) { windows.main.focus() }
}

function getRealCenter(winName) {
const realCenter = { x : null, y : null }
const winSettings = mcStore.get(`wins.${winName}`)
Expand All @@ -297,7 +304,7 @@ function createSubWindow(winName, {noSelect = true, show = true, parent = null,

const winOptions = {
minimizable : !fixed,
alwaysOnTop : fixed && !devDebug,
alwaysOnTop : fixed,
maximizable : !fixed,
fullscreenable : !fixed,
}
Expand Down Expand Up @@ -382,8 +389,10 @@ function createMainWindow () {
}
})
windows.main.on('closed', () => {
windows.main = null
if ( tray ) { tray.destroy() }
windows.load.destroy()
app.quit()
})

if ( !devDebug ) {
Expand Down Expand Up @@ -450,7 +459,7 @@ function createConfirmFav(mods, destinations) {

windows.confirm.loadFile(path.join(pathRender, 'confirm-multi.html'))

windows.confirm.on('closed', () => { windows.confirm = null; windows.main.focus() })
windows.confirm.on('closed', () => { destroyAndFocus('confirm') })
}

function createConfirmWindow(type, modRecords, origList) {
Expand All @@ -469,7 +478,7 @@ function createConfirmWindow(type, modRecords, origList) {

windows.confirm.loadFile(path.join(pathRender, file_HTML))

windows.confirm.on('closed', () => { windows.confirm = null; windows.main.focus() })
windows.confirm.on('closed', () => { destroyAndFocus('confirm') })
}

function createChangeLogWindow() {
Expand All @@ -481,7 +490,7 @@ function createChangeLogWindow() {
windows.change = createSubWindow('change', { parent : 'main', fixed : true, preload : 'aChangelogWindow' })

windows.change.loadFile(path.join(pathRender, 'a_changelog.html'))
windows.change.on('closed', () => { windows.change = null; windows.main.focus() })
windows.change.on('closed', () => { destroyAndFocus('change') })
}

function createFolderWindow() {
Expand All @@ -498,7 +507,7 @@ function createFolderWindow() {
})

windows.folder.loadFile(path.join(pathRender, 'folders.html'))
windows.folder.on('closed', () => { windows.folder = null; windows.main.focus(); processModFolders() })
windows.folder.on('closed', () => { destroyAndFocus('folder'); processModFolders() })
}

function createDetailWindow(thisModRecord) {
Expand All @@ -519,29 +528,47 @@ function createDetailWindow(thisModRecord) {
})

windows.detail.loadFile(path.join(pathRender, 'detail.html'))
windows.detail.on('closed', () => { windows.detail = null; windows.main.focus() })
windows.detail.on('closed', () => { destroyAndFocus('detail') })

windows.detail.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url)
return { action : 'deny' }
})
}

function createFindWindow() {
if ( windows.find ) {
windows.find.focus()
windows.find.webContents.send('fromMain_modRecords', modList)
return
}

windows.find = createSubWindow('find', { preload : 'findWindow' })

windows.find.webContents.on('did-finish-load', async (event) => {
event.sender.send('fromMain_modRecords', modList)
if ( devDebug ) { windows.find.webContents.openDevTools() }
})

windows.find.loadFile(path.join(pathRender, 'find.html'))
windows.find.on('closed', () => { destroyAndFocus('find') })
}

function createDebugWindow() {
if ( windows.debug ) {
windows.debug.focus()
windows.debug.webContents.send('fromMain_debugLog', log.htmlLog)
return
}

windows.debug = createSubWindow('debug', { parent : 'main', preload : 'debugWindow' })
windows.debug = createSubWindow('debug', { preload : 'debugWindow' })

windows.debug.webContents.on('did-finish-load', (event) => {
event.sender.send('fromMain_debugLog', log.htmlLog)
})

windows.debug.loadFile(path.join(app.getAppPath(), 'renderer', 'debug.html'))
windows.debug.on('closed', () => { windows.debug = null; windows.main.focus() })
windows.debug.on('closed', () => { destroyAndFocus('debug') })
}

function createPrefsWindow() {
Expand All @@ -558,7 +585,7 @@ function createPrefsWindow() {
})

windows.prefs.loadFile(path.join(pathRender, 'prefs.html'))
windows.prefs.on('closed', () => { windows.prefs = null; windows.main.focus() })
windows.prefs.on('closed', () => { destroyAndFocus('prefs') })
}

function createSavegameWindow(collection) {
Expand All @@ -576,7 +603,7 @@ function createSavegameWindow(collection) {
})

windows.save.loadFile(path.join(pathRender, 'savegame.html'))
windows.save.on('closed', () => { windows.save = null; windows.main.focus() })
windows.save.on('closed', () => { destroyAndFocus('save') })
}

function createNotesWindow(collection) {
Expand All @@ -594,7 +621,7 @@ function createNotesWindow(collection) {
})

windows.notes.loadFile(path.join(pathRender, 'notes.html'))
windows.notes.on('closed', () => { windows.notes = null; windows.main.focus(); processModFolders() })
windows.notes.on('closed', () => { destroyAndFocus('notes'); processModFolders() })
}

function createResolveWindow(modSet, shortName) {
Expand All @@ -612,7 +639,7 @@ function createResolveWindow(modSet, shortName) {
})

windows.resolve.loadFile(path.join(pathRender, 'resolve.html'))
windows.resolve.on('closed', () => { windows.resolve = null; windows.version.focus() })
windows.resolve.on('closed', () => { destroyAndFocus('resolve') })
}

function createVersionWindow() {
Expand All @@ -630,7 +657,7 @@ function createVersionWindow() {
})

windows.version.loadFile(path.join(pathRender, 'versions.html'))
windows.version.on('closed', () => { windows.version = null; windows.main.focus() })
windows.version.on('closed', () => { destroyAndFocus('version') })
}

function loadingWindow_open(l10n) {
Expand Down Expand Up @@ -908,6 +935,10 @@ ipcMain.on('toMain_startFarmSim', () => {
})
/** END: game launcher */

/** Find window operation */
ipcMain.on('toMain_openFind', () => { createFindWindow() })
/** END : Find window operation*/

/** Preferences window operation */
ipcMain.on('toMain_openPrefs', () => { createPrefsWindow() })
ipcMain.on('toMain_getPref', (event, name) => { event.returnValue = mcStore.get(name) })
Expand Down
48 changes: 48 additions & 0 deletions renderer/find.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<link rel="stylesheet" href="inc/bootstrap.min.css">
<link rel="stylesheet" href="inc/icons.css">
<script src="renderJS/fsg_util.js"></script>
<script src="renderJS/find_ui.js"></script>
<script type="text/javascript">
document.onkeydown = function(evt) {
evt = evt || window.event
if (evt.keyCode == 27) {
document.activeElement.blur()
window.mods.closeWindow()
}
}
window.onerror = function (message, file, line, col, error) {
window.log.debug(error.message, 'find'); return false
}
</script>
</head>
<body>

<div class="container-fluid px-1 user-select-none">
<div class="sticky-top pt-3 pb-2 bg-body border-bottom mb-3">
<div class="row w-100">
<div class="col-7">
<h2 class="ps-2 mastHead"><l10n name="app_name"></l10n> <l10n class="ver" name="app_version"></l10n></h2>
</div>
<div class="col-5">
<div class="badge bg-primary mx-auto w-100 d-block shadow rounded-pill"><l10n name="search_all_window" class="h4"></l10n></div>
</div>
</div>
</div>

<div class="input-group input-group-sm mb-4">
<span class="input-group-text bg-gradient"><l10n name="filter_only"></l10n></span>
<input type="text" id="mods__filter" onkeyup="clientFilter()" class="form-control mod-row-filter">
<span id="mods__filter_clear" onclick="clientClearInput()" class="form-control-clear gg-erase form-control-feedback position-absolute d-none" style="right:10px; cursor:pointer; z-index:100; top:5px; color:black;"></span>
</div>

<table class="w-100 py-0 my-0 table table-sm table-hover table-striped" id="full_table"></table>
</div>

</body>
</html>
21 changes: 9 additions & 12 deletions renderer/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,16 @@
<div class="fixed-top pt-2 pb-2 bg-body" id="main-header">
<div class="row w-100 mb-2">
<div class="col-6 border-bottom">
<h2 class="ps-2 mastHead"><l10n name="app_name"></l10n> <l10n class="ver" name="app_version"></l10n></h2>
<h2 class="ps-2 mastHead">
<l10n name="app_name"></l10n> <l10n class="ver" name="app_version"></l10n>
</h2>

</div>
<div class="col-3">
<div class="row float-end">
<div class="col-1">
<label for="language_select" class="pt-1 col-form-label"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-globe2" viewBox="0 0 16 16">
<path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm7.5-6.923c-.67.204-1.335.82-1.887 1.855-.143.268-.276.56-.395.872.705.157 1.472.257 2.282.287V1.077zM4.249 3.539c.142-.384.304-.744.481-1.078a6.7 6.7 0 0 1 .597-.933A7.01 7.01 0 0 0 3.051 3.05c.362.184.763.349 1.198.49zM3.509 7.5c.036-1.07.188-2.087.436-3.008a9.124 9.124 0 0 1-1.565-.667A6.964 6.964 0 0 0 1.018 7.5h2.49zm1.4-2.741a12.344 12.344 0 0 0-.4 2.741H7.5V5.091c-.91-.03-1.783-.145-2.591-.332zM8.5 5.09V7.5h2.99a12.342 12.342 0 0 0-.399-2.741c-.808.187-1.681.301-2.591.332zM4.51 8.5c.035.987.176 1.914.399 2.741A13.612 13.612 0 0 1 7.5 10.91V8.5H4.51zm3.99 0v2.409c.91.03 1.783.145 2.591.332.223-.827.364-1.754.4-2.741H8.5zm-3.282 3.696c.12.312.252.604.395.872.552 1.035 1.218 1.65 1.887 1.855V11.91c-.81.03-1.577.13-2.282.287zm.11 2.276a6.696 6.696 0 0 1-.598-.933 8.853 8.853 0 0 1-.481-1.079 8.38 8.38 0 0 0-1.198.49 7.01 7.01 0 0 0 2.276 1.522zm-1.383-2.964A13.36 13.36 0 0 1 3.508 8.5h-2.49a6.963 6.963 0 0 0 1.362 3.675c.47-.258.995-.482 1.565-.667zm6.728 2.964a7.009 7.009 0 0 0 2.275-1.521 8.376 8.376 0 0 0-1.197-.49 8.853 8.853 0 0 1-.481 1.078 6.688 6.688 0 0 1-.597.933zM8.5 11.909v3.014c.67-.204 1.335-.82 1.887-1.855.143-.268.276-.56.395-.872A12.63 12.63 0 0 0 8.5 11.91zm3.555-.401c.57.185 1.095.409 1.565.667A6.963 6.963 0 0 0 14.982 8.5h-2.49a13.36 13.36 0 0 1-.437 3.008zM14.982 7.5a6.963 6.963 0 0 0-1.362-3.675c-.47.258-.995.482-1.565.667.248.92.4 1.938.437 3.008h2.49zM11.27 2.461c.177.334.339.694.482 1.078a8.368 8.368 0 0 0 1.196-.49 7.01 7.01 0 0 0-2.275-1.52c.218.283.418.597.597.932zm-.488 1.343a7.765 7.765 0 0 0-.395-.872C9.835 1.897 9.17 1.282 8.5 1.077V4.09c.81-.03 1.577-.13 2.282-.287z"/>
</svg></label>
</div>
<div class="col-auto">
<select onchange="clientChangeL10N()" class="form-select" id="language_select"></select>
</div>
</div>
<div class="col-1">
<button class="btn btn-outline-light w-100" onclick="window.mods.openFindAll()"><l10n name="search_all"></l10n></button>
</div>
<div class="col-2">
<select onchange="clientChangeL10N()" class="form-select" id="language_select"></select>
</div>
<div class="col-3 text-end">
<button onclick="window.mods.startFarmSim()" class="btn btn-info w-75" id="open_prefs"><l10n name="launch_fs22"></l10n></button>
Expand Down
52 changes: 52 additions & 0 deletions renderer/preload/preload-findWindow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* _______ __ _______ __ __
| | |.-----.--| | _ |.-----.-----.|__|.-----.| |_
| || _ | _ | ||__ --|__ --|| ||__ --|| _|
|__|_|__||_____|_____|___|___||_____|_____||__||_____||____|
(c) 2022-present FSG Modding. MIT License. */

// Detail window preLoad

const {contextBridge, ipcRenderer} = require('electron')

contextBridge.exposeInMainWorld(
'log', {
log : (text, process) => { ipcRenderer.send('toMain_log', 'debug', `render-${process}`, text) },
debug : (text, process) => { ipcRenderer.send('toMain_log', 'debug', `render-${process}`, text) },
info : (text, process) => { ipcRenderer.send('toMain_log', 'info', `render-${process}`, text) },
notice : (text, process) => { ipcRenderer.send('toMain_log', 'notice', `render-${process}`, text) },
warning : (text, process) => { ipcRenderer.send('toMain_log', 'warning', `render-${process}`, text) },
danger : (text, process) => { ipcRenderer.send('toMain_log', 'danger', `render-${process}`, text) },
}
)

contextBridge.exposeInMainWorld(
'l10n', {
getText_send : ( text ) => { ipcRenderer.send('toMain_getText_send', text) },
receive : ( channel, func ) => {
const validChannels = [
'fromMain_getText_return',
'fromMain_getText_return_title',
'fromMain_l10n_refresh'
]

if ( validChannels.includes( channel ) ) {
ipcRenderer.on( channel, ( event, ...args ) => func( ...args ))
}
},
}
)

contextBridge.exposeInMainWorld(
'mods', {
closeWindow : ( ) => { ipcRenderer.send('toMain_closeSubWindow', 'find') },
receive : ( channel, func ) => {
const validChannels = [
'fromMain_modRecords',
]

if ( validChannels.includes( channel ) ) {
ipcRenderer.on( channel, ( event, ...args ) => func( ...args ))
}
},
}
)
1 change: 1 addition & 0 deletions renderer/preload/preload-mainWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ contextBridge.exposeInMainWorld(
'mods', {
startFarmSim : () => { ipcRenderer.send('toMain_startFarmSim') },
openPreferences : () => { ipcRenderer.send('toMain_openPrefs') },
openFindAll : () => { ipcRenderer.send('toMain_openFind') },
addFolder : () => { ipcRenderer.send('toMain_addFolder') },
editFolders : () => { ipcRenderer.send('toMain_editFolders') },
refreshFolders : () => { ipcRenderer.send('toMain_refreshFolders') },
Expand Down
Loading

0 comments on commit e5542a1

Please sign in to comment.