mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
4d6a633bba
The -*- file variable lines -*- establish per-file settings that Emacs will pick up. This patch makes the following changes to those lines (and touches nothing else): - Never set the buffer's mode. Years ago, Emacs did not have a good JavaScript mode, so it made sense to use Java or C++ mode in .js files. However, Emacs has had js-mode for years now; it's perfectly serviceable, and is available and enabled by default in all major Emacs packagings. Selecting a mode in the -*- file variable line -*- is almost always the wrong thing to do anyway. It overrides Emacs's default choice, which is (now) reasonable; and even worse, it overrides settings the user might have made in their '.emacs' file for that file extension. It's only useful when there's something specific about that particular file that makes a particular mode appropriate. - Correctly propagate settings that establish the correct indentation level for this file: c-basic-offset and js2-basic-offset should be js-indent-level. Whatever value they're given should be preserved; different parts of our tree use different indentation styles. - We don't use tabs in Mozilla JS code. Always set indent-tabs-mode: nil. Remove tab-width: settings, at least in files that don't contain tab characters. - Remove js2-mode settings that belong in the user's .emacs file, like js2-skip-preprocessor-directives.
247 lines
6.7 KiB
JavaScript
247 lines
6.7 KiB
JavaScript
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
const { Cu } = require("chrome");
|
|
const { Class } = require("sdk/core/heritage");
|
|
const { EventTarget } = require("sdk/event/target");
|
|
const { emit } = require("sdk/event/core");
|
|
const { scope, on, forget } = require("projecteditor/helpers/event");
|
|
const prefs = require("sdk/preferences/service");
|
|
const { LocalStore } = require("projecteditor/stores/local");
|
|
const { OS } = Cu.import("resource://gre/modules/osfile.jsm", {});
|
|
const { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
|
|
const promise = require("projecteditor/helpers/promise");
|
|
const { TextEncoder, TextDecoder } = require('sdk/io/buffer');
|
|
const url = require('sdk/url');
|
|
|
|
const gDecoder = new TextDecoder();
|
|
const gEncoder = new TextEncoder();
|
|
|
|
/**
|
|
* A Project keeps track of the opened folders using LocalStore
|
|
* objects. Resources are generally requested from the project,
|
|
* even though the Store is actually keeping track of them.
|
|
*
|
|
*
|
|
* This object emits the following events:
|
|
* - "refresh-complete": After all stores have been refreshed from disk.
|
|
* - "store-added": When a store has been added to the project.
|
|
* - "store-removed": When a store has been removed from the project.
|
|
* - "resource-added": When a resource has been added to one of the stores.
|
|
* - "resource-removed": When a resource has been removed from one of the stores.
|
|
*/
|
|
var Project = Class({
|
|
extends: EventTarget,
|
|
|
|
/**
|
|
* Intialize the Project.
|
|
*
|
|
* @param Object options
|
|
* Options to be passed into Project.load function
|
|
*/
|
|
initialize: function(options) {
|
|
this.localStores = new Map();
|
|
|
|
this.load(options);
|
|
},
|
|
|
|
destroy: function() {
|
|
// We are removing the store because the project never gets persisted.
|
|
// There may need to be separate destroy functionality that doesn't remove
|
|
// from project if this is saved to DB.
|
|
this.removeAllStores();
|
|
},
|
|
|
|
toString: function() {
|
|
return "[Project] " + this.name;
|
|
},
|
|
|
|
/**
|
|
* Load a project given metadata about it.
|
|
*
|
|
* @param Object options
|
|
* Information about the project, containing:
|
|
* id: An ID (currently unused, but could be used for saving)
|
|
* name: The display name of the project
|
|
* directories: An array of path strings to load
|
|
*/
|
|
load: function(options) {
|
|
this.id = options.id;
|
|
this.name = options.name || "Untitled";
|
|
|
|
let paths = new Set(options.directories.map(name => OS.Path.normalize(name)));
|
|
|
|
for (let [path, store] of this.localStores) {
|
|
if (!paths.has(path)) {
|
|
this.removePath(path);
|
|
}
|
|
}
|
|
|
|
for (let path of paths) {
|
|
this.addPath(path);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Refresh all project stores from disk
|
|
*
|
|
* @returns Promise
|
|
* A promise that resolves when everything has been refreshed.
|
|
*/
|
|
refresh: function() {
|
|
return Task.spawn(function*() {
|
|
for (let [path, store] of this.localStores) {
|
|
yield store.refresh();
|
|
}
|
|
emit(this, "refresh-complete");
|
|
}.bind(this));
|
|
},
|
|
|
|
|
|
/**
|
|
* Fetch a resource from the backing storage system for the store.
|
|
*
|
|
* @param string path
|
|
* The path to fetch
|
|
* @param Object options
|
|
* "create": bool indicating whether to create a file if it does not exist.
|
|
* @returns Promise
|
|
* A promise that resolves with the Resource.
|
|
*/
|
|
resourceFor: function(path, options) {
|
|
let store = this.storeContaining(path);
|
|
return store.resourceFor(path, options);
|
|
},
|
|
|
|
/**
|
|
* Get every resource used inside of the project.
|
|
*
|
|
* @returns Array<Resource>
|
|
* A list of all Resources in all Stores.
|
|
*/
|
|
allResources: function() {
|
|
let resources = [];
|
|
for (let store of this.allStores()) {
|
|
resources = resources.concat(store.allResources());
|
|
}
|
|
return resources;
|
|
},
|
|
|
|
/**
|
|
* Get every Path used inside of the project.
|
|
*
|
|
* @returns generator-iterator<Store>
|
|
* A list of all Stores
|
|
*/
|
|
allStores: function*() {
|
|
for (let [path, store] of this.localStores) {
|
|
yield store;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Get every file path used inside of the project.
|
|
*
|
|
* @returns Array<string>
|
|
* A list of all file paths
|
|
*/
|
|
allPaths: function() {
|
|
return [path for (path of this.localStores.keys())];
|
|
},
|
|
|
|
/**
|
|
* Get the store that contains a path.
|
|
*
|
|
* @returns Store
|
|
* The store, if any. Will return null if no store
|
|
* contains the given path.
|
|
*/
|
|
storeContaining: function(path) {
|
|
let containingStore = null;
|
|
for (let store of this.allStores()) {
|
|
if (store.contains(path)) {
|
|
// With nested projects, the final containing store will be returned.
|
|
containingStore = store;
|
|
}
|
|
}
|
|
return containingStore;
|
|
},
|
|
|
|
/**
|
|
* Add a store at the current path. If a store already exists
|
|
* for this path, then return it.
|
|
*
|
|
* @param string path
|
|
* @returns LocalStore
|
|
*/
|
|
addPath: function(path) {
|
|
if (!this.localStores.has(path)) {
|
|
this.addLocalStore(new LocalStore(path));
|
|
}
|
|
return this.localStores.get(path);
|
|
},
|
|
|
|
/**
|
|
* Remove a store for a given path.
|
|
*
|
|
* @param string path
|
|
*/
|
|
removePath: function(path) {
|
|
this.removeLocalStore(this.localStores.get(path));
|
|
},
|
|
|
|
|
|
/**
|
|
* Add the given Store to the project.
|
|
* Fires a 'store-added' event on the project.
|
|
*
|
|
* @param Store store
|
|
*/
|
|
addLocalStore: function(store) {
|
|
store.canPair = true;
|
|
this.localStores.set(store.path, store);
|
|
|
|
// Originally StoreCollection.addStore
|
|
on(this, store, "resource-added", (resource) => {
|
|
emit(this, "resource-added", resource);
|
|
});
|
|
on(this, store, "resource-removed", (resource) => {
|
|
emit(this, "resource-removed", resource);
|
|
})
|
|
|
|
emit(this, "store-added", store);
|
|
},
|
|
|
|
|
|
/**
|
|
* Remove all of the Stores belonging to the project.
|
|
*/
|
|
removeAllStores: function() {
|
|
for (let store of this.allStores()) {
|
|
this.removeLocalStore(store);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Remove the given Store from the project.
|
|
* Fires a 'store-removed' event on the project.
|
|
*
|
|
* @param Store store
|
|
*/
|
|
removeLocalStore: function(store) {
|
|
// XXX: tree selection should be reset if active element is affected by
|
|
// the store being removed
|
|
if (store) {
|
|
this.localStores.delete(store.path);
|
|
forget(this, store);
|
|
emit(this, "store-removed", store);
|
|
store.destroy();
|
|
}
|
|
}
|
|
});
|
|
|
|
exports.Project = Project;
|