MCPcopy
hub / github.com/marktext/marktext / openTabs

Method openTabs

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

* Open new tabs from markdown files with options for editor window.

(
    fileList: { filePath: string; selected: boolean; options: Record<string, unknown> }[]
  )

Source from the content-addressed store, hash-verified

304 * Open new tabs from markdown files with options for editor window.
305 */
306 openTabs(
307 fileList: { filePath: string; selected: boolean; options: Record<string, unknown> }[]
308 ): void {
309 // TODO: Don't allow new files if quitting.
310 if (this.lifecycle === WindowLifecycle.QUITTED) return
311
312 const { browserWindow } = this
313 // eslint-disable-next-line @typescript-eslint/no-explicit-any
314 const { preferences } = this._accessor as any
315 const eol = preferences.getPreferredEol()
316 const { autoGuessEncoding, trimTrailingNewline, autoNormalizeLineEndings } =
317 preferences.getAll()
318
319 for (const { filePath, options, selected } of fileList) {
320 if (this._openedFiles!.includes(filePath)) {
321 // File is already opened - avoid opening it again so we dont have duplicate watchers
322 browserWindow!.webContents.send('mt::switch-tab-by-file_path', filePath)
323 continue
324 }
325 loadMarkdownFile(
326 filePath,
327 eol,
328 autoGuessEncoding,
329 trimTrailingNewline,
330 autoNormalizeLineEndings
331 )
332 // eslint-disable-next-line @typescript-eslint/no-explicit-any
333 .then((rawDocument: any) => {
334 if (this.lifecycle === WindowLifecycle.READY) {
335 this._doOpenTab(rawDocument, options, selected)
336 } else {
337 this._filesToOpen!.push({ doc: rawDocument, options, selected })
338 }
339 })
340 .catch((err: Error) => {
341 const { message, stack } = err
342 log.error(`[ERROR] Cannot open file or directory: ${message}\n\n${stack}`)
343 browserWindow!.webContents.send('mt::show-notification', {
344 title: 'Cannot open tab',
345 type: 'error',
346 message: err.message
347 })
348 })
349 }
350 }
351
352 /**
353 * Open a new untitled tab optional with a markdown string.

Callers 2

openTabMethod · 0.95
openTabsFromPathsMethod · 0.95

Calls 6

_doOpenTabMethod · 0.95
loadMarkdownFileFunction · 0.90
getPreferredEolMethod · 0.80
sendMethod · 0.80
pushMethod · 0.80
getAllMethod · 0.65

Tested by

no test coverage detected