2020-05-20 23:13:28 +02:00
|
|
|
# Copyright 2017-2018 Xuan Sang LE <xsang.le AT gmail DOT com>
|
|
|
|
|
|
|
|
# AnTOS Web desktop is is licensed under the GNU General Public
|
|
|
|
# License v3.0, see the LICENCE file for more information
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of
|
|
|
|
# the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
#along with this program. If not, see https://www.gnu.org/licenses/.
|
|
|
|
|
2020-06-05 17:45:07 +02:00
|
|
|
class MarkOn extends this.OS.application.BaseApplication
|
2020-05-20 23:13:28 +02:00
|
|
|
constructor: (args) ->
|
|
|
|
super "MarkOn", args
|
|
|
|
|
|
|
|
main: () ->
|
|
|
|
markarea = @find "markarea"
|
|
|
|
@container = @find "mycontainer"
|
|
|
|
@previewOn = false
|
|
|
|
if @args and @args.length > 0
|
|
|
|
@currfile = @args[0].path.asFileHandle()
|
|
|
|
else
|
|
|
|
@currfile = "Untitled".asFileHandle()
|
|
|
|
@editormux = false
|
|
|
|
@editor = new SimpleMDE
|
|
|
|
element: markarea
|
2020-05-23 20:19:50 +02:00
|
|
|
autoDownloadFontAwesome: false
|
2020-05-20 23:13:28 +02:00
|
|
|
autofocus: true
|
|
|
|
tabSize: 4
|
|
|
|
indentWithTabs: true
|
|
|
|
toolbar: [
|
|
|
|
"bold", "italic", "heading", "|", "quote", "code",
|
|
|
|
"unordered-list", "ordered-list", "|", "link",
|
|
|
|
"image", "table", "horizontal-rule", "|",
|
|
|
|
{
|
|
|
|
name: "preview",
|
|
|
|
className: "fa fa-eye no-disable",
|
|
|
|
action: (e) =>
|
|
|
|
@previewOn = !@previewOn
|
|
|
|
SimpleMDE.togglePreview e
|
|
|
|
#if(self.previewOn) toggle the highlight
|
|
|
|
#{
|
|
|
|
# var container = self._scheme.find(self,"Text")
|
|
|
|
# .$element.getElementsByClassName("editor-preview");
|
|
|
|
# if(container.length == 0) return;
|
|
|
|
# var codes = container[0].getElementsByTagName('pre');
|
|
|
|
# codes.forEach(function(el){
|
|
|
|
# hljs.highlightBlock(el);
|
|
|
|
# });
|
|
|
|
# //console.log(code);
|
|
|
|
#}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
@editor.codemirror.on "change", () =>
|
|
|
|
return if @editormux
|
|
|
|
if @currfile.dirty is false
|
|
|
|
@currfile.dirty = true
|
2020-06-05 17:45:07 +02:00
|
|
|
@scheme.apptitle = "#{@currfile.basename}*"
|
2020-05-20 23:13:28 +02:00
|
|
|
@on "hboxchange", (e) => @resizeContent()
|
|
|
|
@bindKey "ALT-N", () => @actionFile "#{@name}-New"
|
|
|
|
@bindKey "ALT-O", () => @actionFile "#{@name}-Open"
|
|
|
|
@bindKey "CTRL-S", () => @actionFile "#{@name}-Save"
|
|
|
|
@bindKey "ALT-W", () => @actionFile "#{@name}-Saveas"
|
|
|
|
@resizeContent()
|
|
|
|
@open @currfile
|
|
|
|
|
|
|
|
resizeContent: () ->
|
|
|
|
children = ($ @container).children()
|
|
|
|
titlebar = (($ @scheme).find ".afx-window-top")[0]
|
|
|
|
toolbar = children[1]
|
|
|
|
statusbar = children[4]
|
|
|
|
cheight = ($ @scheme).height() - ($ titlebar).height() - ($ toolbar).height() - ($ statusbar).height() - 40
|
|
|
|
($ children[2]).css("height", cheight + "px")
|
|
|
|
|
|
|
|
open: (file) ->
|
|
|
|
#find table
|
|
|
|
return if file.path is "Untitled"
|
|
|
|
file.dirty = false
|
|
|
|
file.read()
|
|
|
|
.then (d) =>
|
|
|
|
@currfile = file
|
|
|
|
@editormux = true
|
|
|
|
@editor.value d
|
2020-06-05 17:45:07 +02:00
|
|
|
@scheme.apptitle = "#{@currfile.basename}"
|
2020-05-20 23:13:28 +02:00
|
|
|
@editormux = false
|
|
|
|
.catch (e) => @error __("Unable to open: {0}", file.path), e
|
|
|
|
|
|
|
|
|
|
|
|
save: (file) ->
|
|
|
|
file.write("text/plain")
|
|
|
|
.then (d) =>
|
|
|
|
return @error __("Error saving file {0}: {1}", file.basename, d.error) if d.error
|
|
|
|
file.dirty = false
|
|
|
|
file.text = file.basename
|
2020-06-05 17:45:07 +02:00
|
|
|
@scheme.apptitle = "#{@currfile.basename}"
|
2020-05-20 23:13:28 +02:00
|
|
|
.catch (e) => @error __("Unable to save file: {0}", file.path), e
|
|
|
|
|
|
|
|
menu: () ->
|
|
|
|
menu = [{
|
|
|
|
text: "__(File)",
|
2020-06-05 17:45:07 +02:00
|
|
|
nodes: [
|
2020-05-20 23:13:28 +02:00
|
|
|
{ text: "__(New)", dataid: "#{@name}-New", shortcut: "A-N" },
|
|
|
|
{ text: "__(Open)", dataid: "#{@name}-Open", shortcut: "A-O" },
|
|
|
|
{ text: "__(Save)", dataid: "#{@name}-Save", shortcut: "C-S" },
|
|
|
|
{ text: "__(Save as)", dataid: "#{@name}-Saveas", shortcut: "A-W" }
|
|
|
|
],
|
2020-06-05 17:45:07 +02:00
|
|
|
onchildselect: (e) => @actionFile e.data.item.data.dataid
|
2020-05-20 23:13:28 +02:00
|
|
|
}]
|
|
|
|
menu
|
|
|
|
|
|
|
|
actionFile: (e) ->
|
|
|
|
saveas = () =>
|
|
|
|
@openDialog("FileDialog", {
|
|
|
|
title: __("Save as"),
|
|
|
|
file: @currfile
|
|
|
|
})
|
|
|
|
.then (f) =>
|
|
|
|
d = f.file.path.asFileHandle()
|
|
|
|
d = d.parent() if f.file.type is "file"
|
|
|
|
@currfile.setPath "#{d.path}/#{f.name}"
|
|
|
|
@save @currfile
|
|
|
|
|
|
|
|
switch e
|
|
|
|
when "#{@name}-Open"
|
|
|
|
@openDialog("FileDialog", {
|
|
|
|
title: __("Open file")
|
|
|
|
})
|
|
|
|
.then (f) =>
|
|
|
|
@open f.file.path.asFileHandle()
|
|
|
|
|
|
|
|
when "#{@name}-Save"
|
|
|
|
@currfile.cache = @editor.value()
|
|
|
|
return @save @currfile if @currfile.basename
|
|
|
|
saveas()
|
|
|
|
when "#{@name}-Saveas"
|
|
|
|
@currfile.cache = @editor.value()
|
|
|
|
saveas()
|
|
|
|
when "#{@name}-New"
|
|
|
|
@currfile = "Untitled".asFileHandle()
|
|
|
|
@currfile.cache = ""
|
|
|
|
@editor.value("")
|
|
|
|
|
|
|
|
cleanup: (evt) ->
|
|
|
|
return unless @currfile.dirty
|
|
|
|
evt.preventDefault()
|
2020-05-22 18:27:14 +02:00
|
|
|
@.openDialog("YesNoDialog", {
|
|
|
|
title: __("Quit"),
|
|
|
|
text: __("Quit without saving ?")
|
|
|
|
}).then (d) =>
|
2020-05-20 23:13:28 +02:00
|
|
|
if d
|
|
|
|
@currfile.dirty = false
|
|
|
|
@quit()
|
|
|
|
|
|
|
|
MarkOn.dependencies = [
|
2020-12-18 21:52:44 +01:00
|
|
|
"pkg://SimpleMDE/main.js",
|
|
|
|
"pkg://SimpleMDE/main.css"
|
2020-05-20 23:13:28 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
this.OS.register "MarkOn", MarkOn
|