Skip to content

Commit 25e880f

Browse files
committed
Correct new files manager
1 parent 2dcc6fa commit 25e880f

13 files changed

Lines changed: 194 additions & 184 deletions

File tree

addons/aceeditor/addon-built.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

addons/aceeditor/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define([
88
var commands = codebox.require("core/commands");
99
var tabs = codebox.require("utils/tabs");
1010
var settings = codebox.require("utils/settings");
11-
var files = codebox.require("utils/files");
11+
var files = codebox.require("core/files");
1212
var config = codebox.require("config");
1313

1414
// Configure ace

addons/aceeditor/views/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
define([
22
"views/editor",
33
"less!stylesheets/file.less"
4-
], function(FilesBaseView, EditorView) {
4+
], function(EditorView) {
55
var _ = codebox.require("underscore");
66
var $ = codebox.require("jQuery");
77
var hr = codebox.require("hr/hr");

addons/aceeditor/views/tab.js

Lines changed: 0 additions & 89 deletions
This file was deleted.

addons/explorer/addon-built.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

addons/explorer/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
define([
22
"views/explorer"
33
], function(ExplorerView) {
4-
var files = codebox.require("utils/files");
4+
var files = codebox.require("core/files");
55

66
files.addHandler("explorer", {
77
name: "Explorer",

client/core/files.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
define([
2+
'q',
3+
'underscore',
4+
'hr/hr',
5+
'models/file',
6+
'core/box',
7+
'utils/settings',
8+
'utils/dialogs',
9+
'utils/tabs',
10+
'views/tabs/file',
11+
'views/files/base'
12+
], function(Q, _, hr, File, box, settings, dialogs, tabs, FileTab) {
13+
var logging = hr.Logger.addNamespace("files");
14+
15+
// Settings for files manager
16+
var settings = settings.add({
17+
'namespace': "files",
18+
'title': "Files",
19+
'fields': {}
20+
});
21+
22+
// Files handlers map
23+
var handlers = {};
24+
25+
// Add handler
26+
var addHandler = function(handlerId, handler) {
27+
if (!handler
28+
|| !handlerId
29+
|| !handler.name
30+
|| !handler.valid
31+
|| (!handler.View && !handler.open)) {
32+
throw "Invalid files handler format";
33+
}
34+
35+
if (handler.View) {
36+
handler.open = function(file) {
37+
var path = file.path();
38+
var manager = tabs.manager();
39+
40+
var tab = manager.getActiveTabByType("directory");
41+
if (tab != null && !manager.checkTabExists(path)) {
42+
// Change current tab to open the file
43+
tab.view.load(path);
44+
} else {
45+
// Add new tab
46+
tabs.open(FileTab, {
47+
"model": file,
48+
"handler": handler
49+
}, {
50+
"uniqueId": path,
51+
"type": "file",
52+
});
53+
}
54+
};
55+
}
56+
57+
// Add settings
58+
settings.setField(handlerId, {
59+
'label': handler.name,
60+
'type': "checkbox",
61+
'default': true
62+
});
63+
64+
// Register handler
65+
handlers[handlerId] = handler;
66+
};
67+
68+
// Get handler for a file
69+
var getHandlers = function(file, defaultHandler) {
70+
return _.filter(handlers, function(handler) {
71+
return handler.valid(file);
72+
});
73+
};
74+
75+
// Open a file
76+
var openFile = function(file) {
77+
if (_.isString(file)) {
78+
var nfile = new File({
79+
'codebox': box
80+
});
81+
return nfile.getByPath(file).then(function() {
82+
return openFile(nfile);
83+
});
84+
}
85+
86+
var handlers = getHandlers(file);
87+
if (_.size(handlers) == 0) {
88+
dialogs.alert("No handler for this file", "Sorry, No handler has been found to open this file. Try to find and install an addon to manage this file.");
89+
return Q.reject(new Error("No handler for this file"));
90+
}
91+
92+
// todo: dialog to choose the handler
93+
var handler = _.first(handlers);
94+
return Q(handler.open(file));
95+
};
96+
97+
return {
98+
'addHandler': addHandler,
99+
'getHandlers': getHandlers,
100+
'open': openFile
101+
};
102+
});

client/models/addon.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ define([
66
"core/api",
77

88
// addons dependencies
9-
"core/globals",
10-
"utils/themes",
11-
"utils/tabs",
12-
"utils/settings",
13-
"utils/files"
9+
"core/globals"
1410
], function(Q, _, $, hr, api) {
1511
var logging = hr.Logger.addNamespace("addon");
1612

client/models/file.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ define([
33
"underscore",
44
"hr/hr",
55
"core/api",
6-
"core/commands",
76
"utils/url",
87
"utils/languages",
98
"utils/filesync",
109
"utils/uploader"
11-
], function(Q, _, hr, api, commands, Url, Languages, FileSync, Uploader) {
10+
], function(Q, _, hr, api, Url, Languages, FileSync, Uploader) {
1211
var logging = hr.Logger.addNamespace("files");
1312

1413
if (typeof String.prototype.endsWith !== 'function') {
@@ -72,10 +71,8 @@ define([
7271
* Open the tab for this file
7372
*/
7473
open: function(path) {
75-
commands.run("files.open", {
76-
'path': this.path(path)
77-
});
78-
return this;
74+
var files = require("core/files");
75+
return files.open(path ? path : this);
7976
},
8077

8178
/*

client/utils/files.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)