MCPcopy
hub / github.com/CodeboxIDE/codebox / openFile

Function openFile

client/core/files.js:177–225  ·  view source on GitHub ↗
(file, options)

Source from the content-addressed store, hash-verified

175
176 // Open a file
177 var openFile = function(file, options) {
178 options = _.defaults({}, options || {}, {
179 'userChoice': null,
180 'useFallback': true,
181 'line': null
182 });
183
184 // Options for the file handler
185 var fileOptions = _.pick(options, ["line", "pattern"]);
186
187 if (_.isString(file)) {
188 var nfile = new File({
189 'codebox': box
190 });
191 return nfile.getByPath(file).then(function() {
192 return openFile(nfile, options);
193 });
194 }
195
196 var possibleHandlers = getHandlers(file);
197
198 // Get fallbacks
199 if (_.size(possibleHandlers) == 0 && options.useFallback) {
200 possibleHandlers = getFallbacks();
201 }
202
203 // All choices
204 if (_.size(possibleHandlers) == 0) {
205 return openFileWith(file, fileOptions);
206 }
207
208 if (_.size(possibleHandlers) == 1 || (options.userChoice != true)) {
209 return Q(openFileHandler(_.first(possibleHandlers), file, fileOptions));
210 }
211
212 var choices = {};
213 _.each(possibleHandlers, function(handler) {
214 choices[handler.id] = handler.name;
215 })
216
217 if (_.size(choices) == 0) {
218 return Q.reject(new Error("No handlers for this file"));
219 }
220
221 return dialogs.select("Open with...", "Select one of the following handlers to open this file:", choices).then(function(value) {
222 var handler = handlers[value];
223 return Q(openFileHandler(handler, file, fileOptions));
224 });
225 };
226
227 // Open a new file
228 var openNew = function(name, content, options) {

Callers 4

getDirChangesFunction · 0.85
localfs.jsFile · 0.85
files.jsFile · 0.85
openNewFunction · 0.85

Calls 5

getHandlersFunction · 0.85
getFallbacksFunction · 0.85
openFileWithFunction · 0.85
QFunction · 0.85
openFileHandlerFunction · 0.85

Tested by

no test coverage detected