public void run() {
        // watch dir
        try {
            watcher = FileSystems.getDefault().newWatchService();
            textsPath = FileSystems.getDefault().getPath(Core.textsDir);
            key = textsPath.register(watcher, ENTRY_CREATE, ENTRY_MODIFY);
        } catch (IOException e) {
            e.printStackTrace();
        }

        // io loop
        for (;;) {
            try {
                // listen
                key = watcher.take();
            } catch (InterruptedException x) {
                return;
            }

            for (WatchEvent<?> event : key.pollEvents()) {
                // we have new files
                WatchEvent<Path> pathEvent = (WatchEvent<Path>) event;
                Path filename = pathEvent.context(); // context() is the filename
                if (filename != null) {
                    Path file = textsPath.resolve(filename);
                    Text text = createTextFromFile(file);
                    text.update(null);
                }
            }

            key.reset();
        }
    }