Open document shortcut
This commit is contained in:
parent
af798120d1
commit
5ed951d308
@ -115,7 +115,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<textarea id="wmd-input" class="ui-layout-center hide"></textarea>
|
<textarea id="wmd-input" class="ui-layout-center mousetrap hide"></textarea>
|
||||||
<div class="ui-layout-east preview-container hide"></div>
|
<div class="ui-layout-east preview-container hide"></div>
|
||||||
<div class="ui-layout-south preview-container hide"></div>
|
<div class="ui-layout-south preview-container hide"></div>
|
||||||
|
|
||||||
|
@ -363,6 +363,7 @@ define([
|
|||||||
if(shownModalId != modalId) {
|
if(shownModalId != modalId) {
|
||||||
// Hack to avoid conflict with tabs, collapse, tooltips events
|
// Hack to avoid conflict with tabs, collapse, tooltips events
|
||||||
shownModalId = modalId;
|
shownModalId = modalId;
|
||||||
|
Mousetrap.pause();
|
||||||
_.defer(function(elt) {
|
_.defer(function(elt) {
|
||||||
elt.find("input:enabled:visible:first").focus();
|
elt.find("input:enabled:visible:first").focus();
|
||||||
}, $(this));
|
}, $(this));
|
||||||
@ -372,6 +373,7 @@ define([
|
|||||||
var modalId = $(this).attr("id");
|
var modalId = $(this).attr("id");
|
||||||
if(shownModalId == modalId && $(this).is(":hidden")) {
|
if(shownModalId == modalId && $(this).is(":hidden")) {
|
||||||
shownModalId = undefined;
|
shownModalId = undefined;
|
||||||
|
Mousetrap.unpause();
|
||||||
_.defer(function() {
|
_.defer(function() {
|
||||||
$("#wmd-input").focus();
|
$("#wmd-input").focus();
|
||||||
});
|
});
|
||||||
|
@ -40,7 +40,7 @@ define([
|
|||||||
function createHook(hookName) {
|
function createHook(hookName) {
|
||||||
var callbackList = getExtensionCallbackList(hookName);
|
var callbackList = getExtensionCallbackList(hookName);
|
||||||
return function() {
|
return function() {
|
||||||
logger.debug(hookName, arguments);
|
logger.log(hookName, arguments);
|
||||||
var callbackArguments = arguments;
|
var callbackArguments = arguments;
|
||||||
_.each(callbackList, function(callback) {
|
_.each(callbackList, function(callback) {
|
||||||
callback.apply(null, callbackArguments);
|
callback.apply(null, callbackArguments);
|
||||||
@ -62,7 +62,7 @@ define([
|
|||||||
|
|
||||||
// Load/Save extension config from/to settings
|
// Load/Save extension config from/to settings
|
||||||
extensionMgr["onLoadSettings"] = function() {
|
extensionMgr["onLoadSettings"] = function() {
|
||||||
logger.debug("onLoadSettings");
|
logger.log("onLoadSettings");
|
||||||
_.each(extensionList, function(extension) {
|
_.each(extensionList, function(extension) {
|
||||||
utils.setInputChecked("#input-enable-extension-" + extension.extensionId, extension.config.enabled);
|
utils.setInputChecked("#input-enable-extension-" + extension.extensionId, extension.config.enabled);
|
||||||
var onLoadSettingsCallback = extension.onLoadSettings;
|
var onLoadSettingsCallback = extension.onLoadSettings;
|
||||||
@ -70,7 +70,7 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
extensionMgr["onSaveSettings"] = function(newExtensionSettings, event) {
|
extensionMgr["onSaveSettings"] = function(newExtensionSettings, event) {
|
||||||
logger.debug("onSaveSettings");
|
logger.log("onSaveSettings");
|
||||||
_.each(extensionList, function(extension) {
|
_.each(extensionList, function(extension) {
|
||||||
var newExtensionConfig = _.extend({}, extension.defaultConfig);
|
var newExtensionConfig = _.extend({}, extension.defaultConfig);
|
||||||
newExtensionConfig.enabled = utils.getInputChecked("#input-enable-extension-" + extension.extensionId);
|
newExtensionConfig.enabled = utils.getInputChecked("#input-enable-extension-" + extension.extensionId);
|
||||||
@ -124,7 +124,7 @@ define([
|
|||||||
// The number of times we expect tryFinished to be called
|
// The number of times we expect tryFinished to be called
|
||||||
var nbAsyncPreviewCallback = onAsyncPreviewCallbackList.length + 1;
|
var nbAsyncPreviewCallback = onAsyncPreviewCallbackList.length + 1;
|
||||||
extensionMgr["onAsyncPreview"] = function() {
|
extensionMgr["onAsyncPreview"] = function() {
|
||||||
logger.debug("onAsyncPreview");
|
logger.log("onAsyncPreview");
|
||||||
// Call onPreviewFinished callbacks when all async preview are finished
|
// Call onPreviewFinished callbacks when all async preview are finished
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
function tryFinished() {
|
function tryFinished() {
|
||||||
@ -171,7 +171,7 @@ define([
|
|||||||
}).each(createSettings);
|
}).each(createSettings);
|
||||||
|
|
||||||
// Create extension buttons
|
// Create extension buttons
|
||||||
logger.debug("onCreateButton");
|
logger.log("onCreateButton");
|
||||||
var onCreateButtonCallbackList = getExtensionCallbackList("onCreateButton");
|
var onCreateButtonCallbackList = getExtensionCallbackList("onCreateButton");
|
||||||
_.each(onCreateButtonCallbackList, function(callback) {
|
_.each(onCreateButtonCallbackList, function(callback) {
|
||||||
$("#extension-buttons").append($('<div class="btn-group">').append(callback()));
|
$("#extension-buttons").append($('<div class="btn-group">').append(callback()));
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
"file-system"
|
"file-system",
|
||||||
|
"libs/mousetrap",
|
||||||
], function($, _, fileSystem) {
|
], function($, _, fileSystem) {
|
||||||
|
|
||||||
var documentSelector = {
|
var documentSelector = {
|
||||||
extensionId: "documentSelector",
|
extensionId: "documentSelector",
|
||||||
extensionName: "Document selector",
|
extensionName: "Document selector",
|
||||||
/*
|
|
||||||
defaultConfig: {
|
defaultConfig: {
|
||||||
keyShortcut: 223
|
sortBy: "mru",
|
||||||
|
keyPrevious: "[",
|
||||||
|
keyNext: "]"
|
||||||
},
|
},
|
||||||
*/
|
|
||||||
settingsBloc: '<p>Builds the "Open document" dropdown menu.</p>'
|
settingsBloc: '<p>Builds the "Open document" dropdown menu.</p>'
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -21,6 +22,8 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var liMap = undefined;
|
var liMap = undefined;
|
||||||
|
var liArray = undefined;
|
||||||
|
var sortFunction = undefined;
|
||||||
var buildSelector = function() {
|
var buildSelector = function() {
|
||||||
|
|
||||||
function composeTitle(fileDesc) {
|
function composeTitle(fileDesc) {
|
||||||
@ -40,9 +43,7 @@ define([
|
|||||||
|
|
||||||
liMap = {};
|
liMap = {};
|
||||||
$("#file-selector li:not(.stick)").empty();
|
$("#file-selector li:not(.stick)").empty();
|
||||||
_.chain(fileSystem).sortBy(function(fileDesc) {
|
_.chain(fileSystem).sortBy(sortFunction).each(function(fileDesc) {
|
||||||
return fileDesc.title.toLowerCase();
|
|
||||||
}).each(function(fileDesc) {
|
|
||||||
var a = $('<a href="#">').html(composeTitle(fileDesc)).click(function() {
|
var a = $('<a href="#">').html(composeTitle(fileDesc)).click(function() {
|
||||||
if(!liMap[fileDesc.fileIndex].is(".disabled")) {
|
if(!liMap[fileDesc.fileIndex].is(".disabled")) {
|
||||||
fileMgr.selectFile(fileDesc);
|
fileMgr.selectFile(fileDesc);
|
||||||
@ -52,12 +53,13 @@ define([
|
|||||||
liMap[fileDesc.fileIndex] = li;
|
liMap[fileDesc.fileIndex] = li;
|
||||||
$("#file-selector").append(li);
|
$("#file-selector").append(li);
|
||||||
});
|
});
|
||||||
|
liArray = _.values(liMap);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var selectFileDesc = undefined;
|
||||||
documentSelector.onFileSelected = function(fileDesc) {
|
documentSelector.onFileSelected = function(fileDesc) {
|
||||||
if(liMap === undefined) {
|
selectFileDesc = fileDesc;
|
||||||
buildSelector();
|
buildSelector();
|
||||||
}
|
|
||||||
$("#file-selector li:not(.stick)").removeClass("disabled");
|
$("#file-selector li:not(.stick)").removeClass("disabled");
|
||||||
var li = liMap[fileDesc.fileIndex];
|
var li = liMap[fileDesc.fileIndex];
|
||||||
if(li === undefined) {
|
if(li === undefined) {
|
||||||
@ -65,7 +67,7 @@ define([
|
|||||||
// selector)
|
// selector)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
liMap[fileDesc.fileIndex].addClass("disabled");
|
li.addClass("disabled");
|
||||||
};
|
};
|
||||||
|
|
||||||
documentSelector.onFileCreated = buildSelector;
|
documentSelector.onFileCreated = buildSelector;
|
||||||
@ -94,8 +96,26 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
documentSelector.onReady = function() {
|
documentSelector.onReady = function() {
|
||||||
|
if(documentSelector.config.sortBy == "title") {
|
||||||
|
sortFunction = function(fileDesc) {
|
||||||
|
return fileDesc.title.toLowerCase();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if(documentSelector.config.sortBy == "mru") {
|
||||||
|
sortFunction = function(fileDesc) {
|
||||||
|
return -fileDesc.selectTime;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var shortcutClick = false;
|
||||||
$(".action-open-file").click(function() {
|
$(".action-open-file").click(function() {
|
||||||
|
if($("#file-selector:parent").is(".open")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
filterFileSelector();
|
filterFileSelector();
|
||||||
|
if(shortcutClick === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_.defer(function() {
|
_.defer(function() {
|
||||||
$("#file-search").val("").focus();
|
$("#file-search").val("").focus();
|
||||||
});
|
});
|
||||||
@ -110,12 +130,45 @@ define([
|
|||||||
}).click(function(event) {
|
}).click(function(event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
});
|
});
|
||||||
/*
|
|
||||||
$("#wmd-input").keydown(function(event) {
|
// Handle key shortcut
|
||||||
if(event.ctrlKey && event.keyCode == documentSelector.config.keyShortcut) {
|
var shortcutLi = undefined;
|
||||||
console.log(event.keyCode);
|
Mousetrap.bind('ctrl+' + documentSelector.config.keyPrevious, function() {
|
||||||
|
shortcutClick = true;
|
||||||
|
if(shortcutLi === undefined) {
|
||||||
|
$(".action-open-file").click();
|
||||||
|
shortcutLi = liMap[selectFileDesc.fileIndex];
|
||||||
}
|
}
|
||||||
});*/
|
var liIndex = _.indexOf(liArray, shortcutLi) - 1;
|
||||||
|
if(liIndex === -2) {
|
||||||
|
liIndex = -1;
|
||||||
|
}
|
||||||
|
shortcutLi = liArray[(liIndex + liArray.length) % liArray.length];
|
||||||
|
_.defer(function() {
|
||||||
|
shortcutLi.find("a").focus();
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
Mousetrap.bind('ctrl+' + documentSelector.config.keyNext, function() {
|
||||||
|
shortcutClick = true;
|
||||||
|
if(shortcutLi === undefined) {
|
||||||
|
$(".action-open-file").click();
|
||||||
|
shortcutLi = liMap[selectFileDesc.fileIndex];
|
||||||
|
}
|
||||||
|
var liIndex = _.indexOf(liArray, shortcutLi) + 1;
|
||||||
|
shortcutLi = liArray[liIndex % liArray.length];
|
||||||
|
_.defer(function() {
|
||||||
|
shortcutLi.find("a").focus();
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
Mousetrap.bind('ctrl', function() {
|
||||||
|
shortcutClick = false;
|
||||||
|
if(shortcutLi !== undefined) {
|
||||||
|
shortcutLi.find("a").click();
|
||||||
|
shortcutLi = undefined;
|
||||||
|
}
|
||||||
|
}, "keyup");
|
||||||
};
|
};
|
||||||
|
|
||||||
return documentSelector;
|
return documentSelector;
|
||||||
|
@ -42,7 +42,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
function showMessage(message, iconClass, options) {
|
function showMessage(message, iconClass, options) {
|
||||||
logger.log(message);
|
logger.info(message);
|
||||||
if(!message) {
|
if(!message) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -19,50 +19,72 @@ define([
|
|||||||
this._editorStart = parseInt(localStorage[fileIndex + ".editorStart"]) || 0;
|
this._editorStart = parseInt(localStorage[fileIndex + ".editorStart"]) || 0;
|
||||||
this._editorEnd = parseInt(localStorage[fileIndex + ".editorEnd"]) || 0;
|
this._editorEnd = parseInt(localStorage[fileIndex + ".editorEnd"]) || 0;
|
||||||
this._previewScrollTop = parseInt(localStorage[fileIndex + ".previewScrollTop"]) || 0;
|
this._previewScrollTop = parseInt(localStorage[fileIndex + ".previewScrollTop"]) || 0;
|
||||||
|
this._selectTime = parseInt(localStorage[fileIndex + ".selectTime"]) || 0;
|
||||||
this.syncLocations = syncLocations || {};
|
this.syncLocations = syncLocations || {};
|
||||||
this.publishLocations = publishLocations || {};
|
this.publishLocations = publishLocations || {};
|
||||||
this.__defineGetter__("title", function() {
|
Object.defineProperty(this, 'title', {
|
||||||
return this._title;
|
get: function() {
|
||||||
|
return this._title;
|
||||||
|
},
|
||||||
|
set: function(title) {
|
||||||
|
this._title = title;
|
||||||
|
localStorage[this.fileIndex + ".title"] = title;
|
||||||
|
extensionMgr.onTitleChanged(this);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.__defineSetter__("title", function(title) {
|
Object.defineProperty(this, 'content', {
|
||||||
this._title = title;
|
get: function() {
|
||||||
localStorage[this.fileIndex + ".title"] = title;
|
return localStorage[this.fileIndex + ".content"];
|
||||||
extensionMgr.onTitleChanged(this);
|
},
|
||||||
|
set: function(content) {
|
||||||
|
localStorage[this.fileIndex + ".content"] = content;
|
||||||
|
extensionMgr.onContentChanged(this);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.__defineGetter__("content", function() {
|
Object.defineProperty(this, 'editorScrollTop', {
|
||||||
return localStorage[this.fileIndex + ".content"];
|
get: function() {
|
||||||
|
return this._editorScrollTop;
|
||||||
|
},
|
||||||
|
set: function(editorScrollTop) {
|
||||||
|
this._editorScrollTop = editorScrollTop;
|
||||||
|
localStorage[this.fileIndex + ".editorScrollTop"] = editorScrollTop;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.__defineSetter__("content", function(content) {
|
Object.defineProperty(this, 'editorStart', {
|
||||||
localStorage[this.fileIndex + ".content"] = content;
|
get: function() {
|
||||||
extensionMgr.onContentChanged(this);
|
return this._editorStart;
|
||||||
|
},
|
||||||
|
set: function(editorStart) {
|
||||||
|
this._editorStart = editorStart;
|
||||||
|
localStorage[this.fileIndex + ".editorStart"] = editorStart;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.__defineGetter__("editorScrollTop", function() {
|
Object.defineProperty(this, 'editorEnd', {
|
||||||
return this._editorScrollTop;
|
get: function() {
|
||||||
|
return this._editorEnd;
|
||||||
|
},
|
||||||
|
set: function(editorEnd) {
|
||||||
|
this._editorEnd = editorEnd;
|
||||||
|
localStorage[this.fileIndex + ".editorEnd"] = editorEnd;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.__defineSetter__("editorScrollTop", function(editorScrollTop) {
|
Object.defineProperty(this, 'previewScrollTop', {
|
||||||
this._editorScrollTop = editorScrollTop;
|
get: function() {
|
||||||
localStorage[this.fileIndex + ".editorScrollTop"] = editorScrollTop;
|
return this._previewScrollTop;
|
||||||
|
},
|
||||||
|
set: function(previewScrollTop) {
|
||||||
|
this._previewScrollTop = previewScrollTop;
|
||||||
|
localStorage[this.fileIndex + ".previewScrollTop"] = previewScrollTop;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.__defineGetter__("editorStart", function() {
|
Object.defineProperty(this, 'selectTime', {
|
||||||
return this._editorStart;
|
get: function() {
|
||||||
});
|
return this._selectTime;
|
||||||
this.__defineSetter__("editorStart", function(editorStart) {
|
},
|
||||||
this._editorStart = editorStart;
|
set: function(selectTime) {
|
||||||
localStorage[this.fileIndex + ".editorStart"] = editorStart;
|
this._selectTime = selectTime;
|
||||||
});
|
localStorage[this.fileIndex + ".selectTime"] = selectTime;
|
||||||
this.__defineGetter__("editorEnd", function() {
|
}
|
||||||
return this._editorEnd;
|
|
||||||
});
|
|
||||||
this.__defineSetter__("editorEnd", function(editorEnd) {
|
|
||||||
this._editorEnd = editorEnd;
|
|
||||||
localStorage[this.fileIndex + ".editorEnd"] = editorEnd;
|
|
||||||
});
|
|
||||||
this.__defineGetter__("previewScrollTop", function() {
|
|
||||||
return this._previewScrollTop;
|
|
||||||
});
|
|
||||||
this.__defineSetter__("previewScrollTop", function(previewScrollTop) {
|
|
||||||
this._previewScrollTop = previewScrollTop;
|
|
||||||
localStorage[this.fileIndex + ".previewScrollTop"] = previewScrollTop;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +132,7 @@ define([
|
|||||||
|
|
||||||
if(fileMgr.isCurrentFile(fileDesc) === false) {
|
if(fileMgr.isCurrentFile(fileDesc) === false) {
|
||||||
fileMgr.setCurrentFile(fileDesc);
|
fileMgr.setCurrentFile(fileDesc);
|
||||||
|
fileDesc.selectTime = new Date().getTime();
|
||||||
|
|
||||||
// Notify extensions
|
// Notify extensions
|
||||||
extensionMgr.onFileSelected(fileDesc);
|
extensionMgr.onFileSelected(fileDesc);
|
||||||
|
@ -29,6 +29,9 @@ requirejs.config({
|
|||||||
'libs/jquery.mousewheel': [
|
'libs/jquery.mousewheel': [
|
||||||
'jquery'
|
'jquery'
|
||||||
],
|
],
|
||||||
|
'libs/jquery.hotkeys': [
|
||||||
|
'jquery'
|
||||||
|
],
|
||||||
'libs/layout': [
|
'libs/layout': [
|
||||||
'libs/jquery-ui'
|
'libs/jquery-ui'
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user