MCPcopy
hub / github.com/marktext/marktext / openFolder

Method openFolder

packages/desktop/src/main/windows/editor.ts:370–398  ·  view source on GitHub ↗

* Open a (new) directory and replaces the old one.

(pathname: string)

Source from the content-addressed store, hash-verified

368 * Open a (new) directory and replaces the old one.
369 */
370 openFolder(pathname: string): void {
371 // TODO: Don't allow new files if quitting.
372 if (
373 !pathname ||
374 this.lifecycle === WindowLifecycle.QUITTED ||
375 isSamePathSync(pathname, this._openedRootDirectory ?? '')
376 ) {
377 return
378 }
379
380 if (this.lifecycle === WindowLifecycle.READY) {
381 const { browserWindow } = this
382 // eslint-disable-next-line @typescript-eslint/no-explicit-any
383 const _accessor = this._accessor as any
384 const { menu: appMenu, preferences } = _accessor
385
386 if (this._openedRootDirectory) {
387 ipcMain.emit('watcher-unwatch-directory', browserWindow, this._openedRootDirectory)
388 }
389
390 preferences.setItems({ lastOpenedFolder: pathname })
391 appMenu.addRecentlyUsedDocument(pathname)
392 this._openedRootDirectory = pathname
393 ipcMain.emit('watcher-watch-directory', browserWindow, pathname)
394 browserWindow!.webContents.send('mt::open-directory', pathname)
395 } else {
396 this._directoryToOpen = pathname
397 }
398 }
399
400 /**
401 * Add a new path to the file list and watch the given path.

Callers 5

createWindowMethod · 0.95
_doOpenFilesToOpenMethod · 0.95
_restoreAllStateMethod · 0.95
clickFunction · 0.80
_listenForIpcMainMethod · 0.80

Calls 5

isSamePathSyncFunction · 0.90
emitMethod · 0.80
sendMethod · 0.80
setItemsMethod · 0.45

Tested by

no test coverage detected