"Save As" defaults to root directory

When I do File > Save As on an Untitled document, the dialog defaults to the root “/” directory rather than my home directory.

I’ve done all that I can think of to specify the default directory:

  • I’ve specified the starting workspace on the command line: yarn theia start /home ...
  • The home directory is set correctly in /etc/passwd
  • I’ve tried changing the ENTRYPOINT in the Dockerfile to do an explicit cd /home before starting up Theia

When I open a Terminal, it defaults to the home directly correctly. It’s only the Save As dialog that uses the root directory as its default.

How do I change this behavior?

Hey @bebrown,

which version of Theia are you using? As of 1.25.0, the SAVE_AS command should always use the current working directory as the default, just like the terminal. Anyway, you can always override the DefaultFileDialogService#getRootNode method to change the root of your save dialog.

Thanks for the response. I’m running 1.28.0. Previously I was using 1.22 so, of course, Theia would prompt for the filename first, before opening the file. In that version, the dialog box worked correctly, showing the home directory by default.

When I launch a Terminal, it defaults to the home directory correctly. What are some other ways of setting the CWD?

Note: my Theia is running in a Docker container. Is there a Dockerfile environment variable I can set to force the CWD to be the home directory?

I’ve looked at docs about writing my own extensions and plugins, but I’m unsure how it would apply to overriding existing code. Where can I find documentation on how to override methods that are already part of the Theia core classes?

@bebrown what type of customization are you looking to perform (it might be best to answer your question with your actual use-case). As highlighted in the docs we use Inversify.JS (inversion of control) to help extend or re-implement functionality in the base framework.

I want to override the DefaultFileDialogService.getRootNode method, as suggested by @msujew, so that the home directory is chosen by default. I’ll have to hard-code the home directory, as I’ve tried everything else I can think of to resolve the issue.

@bebrown it’s quite simple once you get used to it, I create a small repo for you to check (GitHub - vince-fugnitto/custom-file-dialog).


import { injectable } from '@theia/core/shared/inversify';
import { DefaultFileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
import { DirNode } from '@theia/filesystem/lib/browser/file-tree';
import { FileStat } from '@theia/filesystem/lib/common/files';

export class CustomFileDialogService extends DefaultFileDialogService {

    protected async getRootNode(folderToOpen?: FileStat): Promise<DirNode | undefined> {
        console.log('custom getRootNode called.');
       // Add proper code.


import { ContainerModule } from '@theia/core/shared/inversify';
import { FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
import { CustomFileDialogService } from './custom-file-dialog-service';

export default new ContainerModule((bind, _unbind, _isBound, rebind) => {
    // Bind the new class.
    // Rebind the `FileDialogService` to use your new class.