Import files from disk

This commit is contained in:
benweet 2013-06-16 19:29:54 +01:00
parent e5cc6e907b
commit 835ec4da5a
10 changed files with 111 additions and 40 deletions

View File

@ -635,6 +635,12 @@ input[type="file"] {
color: #bbb; color: #bbb;
} }
#modal-import-harddrive-html textarea {
width: 500px;
max-width: 500px;
height: 100px;
}
#md-section-helper { #md-section-helper {
position: absolute; position: absolute;
top: -100px; top: -100px;

View File

@ -71,11 +71,12 @@
class="icon-hdd"></i> Open from...</a> class="icon-hdd"></i> Open from...</a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a data-toggle="modal" <li><a data-toggle="modal"
data-target="#modal-import-harddrive-markdown" class="action-reset-input" data-target="#modal-import-harddrive-markdown"
href="#">Import from hard drive</a></li> class="action-reset-input" href="#">Import from hard drive</a></li>
<li><a data-toggle="modal" <li><a data-toggle="modal"
data-target="#modal-import-harddrive-html" class="action-reset-input" data-target="#modal-import-harddrive-html"
href="#">Convert HTML to Markdown</a></li> class="action-reset-input" href="#">Convert HTML to
Markdown</a></li>
</ul></li> </ul></li>
<li class="dropdown-submenu"><a href="#"><i <li class="dropdown-submenu"><a href="#"><i
class="icon-hdd"></i> Save as...</a> class="icon-hdd"></i> Save as...</a>
@ -244,10 +245,12 @@
<h3>Import from hard drive</h3> <h3>Import from hard drive</h3>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p>Please select the Markdown files to import:</p> <p>Please select your Markdown files here:</p>
<p><input type="file" id="input-file-import-harddrive-markdown" multiple /></p> <p><input type="file" id="input-file-import-harddrive-markdown"
<p>Or drag and drop the Markdown files here:</p> multiple /></p>
<div id="dropzone-import-harddrive-markdown" class="drop-zone">Drop zone</div> <p>Or drag and drop your Markdown files here:</p>
<p id="dropzone-import-harddrive-markdown" class="drop-zone">Drop
files here</p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a> <a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>
@ -258,16 +261,21 @@
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" <button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button> aria-hidden="true">&times;</button>
<h3>Import from hard drive</h3> <h3>Convert HTML to Markdown</h3>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p>Please select the HTML files to import:</p> <p>Please select your HTML files here:</p>
<p><input type="file" id="input-file-import-harddrive-html" multiple /></p> <p><input type="file" id="input-file-import-harddrive-html"
<p>Or drag and drop the HTML files here:</p> multiple /></p>
<div id="dropzone-import-harddrive-html" class="drop-zone">Drop zone</div> <p>Or drag and drop your HTML files here:</p>
<p id="dropzone-import-harddrive-html" class="drop-zone">Drop
files here</p>
<p>Or insert your HTML code here:</p> <textarea id="input-convert-html"></textarea>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a> <a href="#" class="btn" data-dismiss="modal">Close</a> <a
href="#" class="btn btn-primary action-convert-html"
data-dismiss="modal">OK</a>
</div> </div>
</div> </div>

View File

@ -13,7 +13,6 @@ define([
this.finished = false; this.finished = false;
this.timeout = ASYNC_TASK_DEFAULT_TIMEOUT; this.timeout = ASYNC_TASK_DEFAULT_TIMEOUT;
this.retryCounter = 0; this.retryCounter = 0;
this.callPath = [];
this.runCallbacks = []; this.runCallbacks = [];
this.successCallbacks = []; this.successCallbacks = [];
this.errorCallbacks = []; this.errorCallbacks = [];
@ -50,7 +49,7 @@ define([
* onRun callback during execution, bypassing the onRun queue. * onRun callback during execution, bypassing the onRun queue.
*/ */
AsyncTask.prototype.chain = function(callback) { AsyncTask.prototype.chain = function(callback) {
this.callPath.unshift(printStackTrace()[5]); utils.logStackTrace();
if(this.finished === true) { if(this.finished === true) {
return; return;
} }
@ -80,11 +79,11 @@ define([
* ends the task by throwing an exception. * ends the task by throwing an exception.
*/ */
AsyncTask.prototype.error = function(error) { AsyncTask.prototype.error = function(error) {
this.callPath.unshift(printStackTrace()[5]); utils.logStackTrace();
if(this.finished === true) { if(this.finished === true) {
return; return;
} }
error = error || new Error("Unknown error|\n" + this.callPath.join("\n")); error = error || new Error("Unknown error");
if(error.message) { if(error.message) {
extensionMgr.onError(error); extensionMgr.onError(error);
} }
@ -110,7 +109,6 @@ define([
var delay = Math.pow(2, this.retryCounter++) * 1000; var delay = Math.pow(2, this.retryCounter++) * 1000;
currentTaskStartTime = utils.currentTime + delay; currentTaskStartTime = utils.currentTime + delay;
currentTaskRunning = false; currentTaskRunning = false;
this.callPath = [];
runTask(); runTask();
}; };
@ -136,7 +134,7 @@ define([
if(currentTaskRunning === true) { if(currentTaskRunning === true) {
// If the current task takes too long // If the current task takes too long
if(currentTaskStartTime + currentTask.timeout < utils.currentTime) { if(currentTaskStartTime + currentTask.timeout < utils.currentTime) {
currentTask.error(new Error("A timeout occurred.|\n" + currentTask.callPath.join("\n"))); currentTask.error(new Error("A timeout occurred."));
} }
return; return;
} }
@ -163,7 +161,8 @@ define([
} }
}); });
} }
// Run runTask function periodically
// Call runTask function periodically
core.addPeriodicCallback(runTask); core.addPeriodicCallback(runTask);
function runSafe(task, callbacks, param) { function runSafe(task, callbacks, param) {

View File

@ -27,6 +27,7 @@ define([
"Prettify": "https://code.google.com/p/google-code-prettify/", "Prettify": "https://code.google.com/p/google-code-prettify/",
"RequireJS": "http://requirejs.org/", "RequireJS": "http://requirejs.org/",
"stacktrace.js": "http://stacktracejs.com/", "stacktrace.js": "http://stacktracejs.com/",
"to-markdown": "https://github.com/domchristie/to-markdown",
"UI Layout": "http://layout.jquery-dev.net/", "UI Layout": "http://layout.jquery-dev.net/",
"Underscore.js": "http://underscorejs.org/", "Underscore.js": "http://underscorejs.org/",
"waitForImages": "https://github.com/alexanderdickson/waitForImages" "waitForImages": "https://github.com/alexanderdickson/waitForImages"

View File

@ -43,7 +43,7 @@ define([
})); }));
lineElement.append($(removeButtonTemplate).click(function() { lineElement.append($(removeButtonTemplate).click(function() {
fileDesc.removePublishLocation(publishAttributes); fileDesc.removePublishLocation(publishAttributes);
extensionMgr.onPublishRemoved(publishFileDesc, publishAttributes); extensionMgr.onPublishRemoved(fileDesc, publishAttributes);
})); }));
publishList.append(lineElement); publishList.append(lineElement);
}); });

View File

@ -1,14 +1,15 @@
define([ define([
"jquery", "jquery",
"underscore", "underscore",
"utils",
"toMarkdown", "toMarkdown",
"config", "config",
], function($, _, toMarkdown) { ], function($, _, utils, toMarkdown) {
var dialogOpenHarddrive = { var dialogOpenHarddrive = {
extensionId: "dialogOpenHarddrive", extensionId: "dialogOpenHarddrive",
extensionName: 'Dialog "Open from"', extensionName: 'Dialog "Open from"',
settingsBloc: '<p>Handles the "Open from hard drive" and the "Convert HTML to Markdown" dialog boxes.</p>' settingsBloc: '<p>Handles the "Import from hard drive" and the "Convert HTML to Markdown" dialog boxes.</p>'
}; };
var fileMgr = undefined; var fileMgr = undefined;
@ -87,6 +88,19 @@ define([
this.addEventListener('dragover', handleDragOver, false); this.addEventListener('dragover', handleDragOver, false);
this.addEventListener('drop', handleHtmlImport, false); this.addEventListener('drop', handleHtmlImport, false);
}); });
$(".action-convert-html").click(function(e) {
var content = utils.getInputTextValue("#input-convert-html", e);
if(content === undefined) {
return;
}
content = converter.makeMd(content);
if(content === undefined) {
extensionMgr.onError(importedFile.name + " is not a valid HTML file.");
return;
}
var fileDesc = fileMgr.createFile(undefined, content);
fileMgr.selectFile(fileDesc);
});
}; };
return dialogOpenHarddrive; return dialogOpenHarddrive;

View File

@ -1,9 +1,10 @@
define([ define([
"jquery", "jquery",
"underscore", "underscore",
"utils",
"settings", "settings",
"config", "config",
], function($, _, settings) { ], function($, _, utils, settings) {
var googleAnalytics = { var googleAnalytics = {
extensionId: "googleAnalytics", extensionId: "googleAnalytics",
@ -31,6 +32,19 @@ define([
} }
}; };
var lastPageView = 0;
function trackPageView() {
if(utils.currentTime - lastPageView > 180000) {
_gaq.push([
'_trackPageview'
]);
lastPageView = utils.currentTime;
}
}
googleAnalytics.onPeriodicRun = function() {
trackPageView();
};
googleAnalytics.onReady = function() { googleAnalytics.onReady = function() {
// First configure GA // First configure GA
@ -38,9 +52,7 @@ define([
'_setAccount', '_setAccount',
GOOGLE_ANALYTICS_ACCOUNT_ID GOOGLE_ANALYTICS_ACCOUNT_ID
]); ]);
_gaq.push([ trackPageView();
'_trackPageview'
]);
// Collect informations about user settings // Collect informations about user settings
_gaq.push([ _gaq.push([
@ -96,8 +108,8 @@ define([
_gaq.push([ _gaq.push([
"_trackEvent", "_trackEvent",
"Error", "Error",
url, message,
message + " (" + line + ")" url + ":" + line + utils.formatEventList()
]); ]);
}; };
@ -195,7 +207,7 @@ define([
'_trackEvent', '_trackEvent',
"Error", "Error",
"message", "message",
error.message error.message + utils.formatEventList()
]); ]);
}; };

View File

@ -1,6 +1,6 @@
<blockquote>StackEdit is a free, open-source Markdown <p>StackEdit is a free, open-source Markdown editor based on
editor based on PageDown, the Markdown library used by Stack Overflow PageDown, the Markdown library used by Stack Overflow and the other
and the other Stack Exchange sites.</blockquote> Stack Exchange sites.</p>
<dl> <dl>
<dt>About:</dt> <dt>About:</dt>

View File

@ -61,6 +61,8 @@ define([
// Dequeue a synchronized location // Dequeue a synchronized location
var syncAttributes = uploadSyncAttributesList.pop(); var syncAttributes = uploadSyncAttributesList.pop();
utils.logValue(syncAttributes.syncIndex + localStorage[syncAttributes.syncIndex]);
// Use the specified provider to perform the upload // Use the specified provider to perform the upload
syncAttributes.provider.syncUp(uploadContent, uploadContentCRC, uploadTitle, uploadTitleCRC, syncAttributes, function(error, uploadFlag) { syncAttributes.provider.syncUp(uploadContent, uploadContentCRC, uploadTitle, uploadTitleCRC, syncAttributes, function(error, uploadFlag) {
if(uploadFlag === true) { if(uploadFlag === true) {

View File

@ -1,7 +1,8 @@
define([ define([
"jquery", "jquery",
"underscore", "underscore",
"libs/FileSaver" "libs/FileSaver",
"libs/stacktrace",
], function($, _) { ], function($, _) {
var utils = {}; var utils = {};
@ -118,7 +119,7 @@ define([
// Reset input control in all modals // Reset input control in all modals
utils.resetModalInputs = function() { utils.resetModalInputs = function() {
$(".modal input[type=text]:not([disabled]), .modal input[type=password]").val(""); $(".modal input[type=text]:not([disabled]), .modal input[type=password], .modal textarea").val("");
}; };
// Basic trim function // Basic trim function
@ -237,6 +238,34 @@ define([
} }
}; };
var eventList = [];
utils.logValue = function(value) {
eventList.unshift(value);
if(eventList.length > 5) {
eventList.pop();
}
};
utils.logStackTrace = function() {
eventList.unshift(printStackTrace());
if(eventList.length > 5) {
eventList.pop();
}
};
utils.formatEventList = function() {
var result = [];
_.each(eventList, function(event) {
result.push("\n");
if(_.isString(event)) {
result.push(event);
}
else if(_.isArray(event)) {
result.push(event[5] || "");
result.push(event[6] || "");
}
});
return result.join("");
};
// Base64 conversion // Base64 conversion
utils.encodeBase64 = function(str) { utils.encodeBase64 = function(str) {
if(str.length === 0) { if(str.length === 0) {