Enable printing in Docify

This commit is contained in:
Xuan Sang LE
2021-01-30 17:45:45 +00:00
parent 752b2a6f1d
commit b0c2e088f9
15 changed files with 155 additions and 9 deletions

View File

@ -125,7 +125,7 @@ class DocDialog extends this.OS.GUI.BasicDialog
value: 0
}
@ylist.selected = 0
for y in [1980..new Date().getFullYear()]
for y in [1960..new Date().getFullYear()]
@ylist.push {
text:"#{y}",
value: y,
@ -273,4 +273,57 @@ FilePreviewDialog.scheme = """
</afx-vbox>
</afx-hbox>
</afx-app-window>
"""
class PrintDialog extends this.OS.GUI.BasicDialog
constructor: () ->
super "PrintDialog", PrintDialog.scheme
main: () ->
super.main()
@find("printerName").value = @parent.setting.printer
@find("btnprint").onbtclick = (e) =>
data = {}
data.range = parseInt($('input[name=range]:checked', @scheme).val())
data.pages = @find("txtPageRange").value
data.printer = @find("printerName").value
data.orientation = parseInt($('input[name=orientation]:checked', @scheme).val())
data.side = parseInt($('input[name=side]:checked', @scheme).val())
@handle data if @handle
@quit()
PrintDialog.scheme = """
<afx-app-window width='300' height='300' data-id="DocifyPrintDialog" apptitle = "__(Print)">
<afx-vbox>
<afx-label text = "__(Printer name)" data-height="22"></afx-label>
<input type="text" data-id="printerName" data-height="25"/>
<afx-label text = "__(Range)" data-height="22"></afx-label>
<div>
<input type="radio" name="range" value="0" checked />
<label for="0">All</label><br>
<input type="radio" name="range" value="1" />
<label for="1">Pages: </label>
<input type="text" data-id="txtPageRange" />
</div>
<afx-label text = "__(Orientation)" data-height="22"></afx-label>
<div>
<input type="radio" name="orientation" value="0" checked />
<label for="0">Portrait</label><br>
<input type="radio" name="orientation" value="1" />
<label for="1">Landscape</label>
</div>
<afx-label text = "__(Side)" data-height="22"></afx-label>
<div>
<input type="radio" name="side" value="0" />
<label for="0">One side</label><br>
<input type="radio" name="side" value="1" checked />
<label for="1">Double side long edge</label><br>
<input type="radio" name="side" value="2" />
<label for="2">Double side short edge</label>
</div>
<div data-height="30" style="text-align:right;">
<afx-button text="__(Print)" style="margin-right:5px;" data-id="btnprint"></afx-button>
</div>
</afx-vbox>
</afx-app-window>
"""

View File

@ -4,6 +4,8 @@ class Docify extends this.OS.application.BaseApplication
main: () ->
@setting.printer = "" unless @setting.printer
@catview = @find "catview"
@docview = @find "docview"
@docpreview = @find "preview-canvas"
@ -26,6 +28,18 @@ class Docify extends this.OS.application.BaseApplication
return @error m.error if m.error
@_gui.openWith m.result
.catch (e) => @error e.toString(), e
@find("btprint").onbtclick = (e) =>
item = @docview.selectedItem
return unless item
@openDialog new PrintDialog(), {}
.then (d) =>
return unless d
d.file = item.data.file
@exec("printdoc", d)
.then (r) =>
return @error r.error if r.error
@notify r.result
.catch (e) => @error __("Unable to insert category: {0}", e.toString()), e
@catview.buttons = [
{
text: "",
@ -241,11 +255,12 @@ class Docify extends this.OS.application.BaseApplication
menu: () ->
[
{
text: "__(View)",
text: "__(Options)",
nodes: [
{ text: "__(Owners)", id:"owners"},
{ text: "__(Preview)", id:"preview"},
{ text: "__(Change doc path)", id:"setdocp"}
{ text: "__(Change doc path)", id:"setdocp"},
{ text: "__(Set default printer)", id:"setprinter"}
],
onchildselect: (e) => @fileMenuHandle e.data.item.data.id
}
@ -262,5 +277,9 @@ class Docify extends this.OS.application.BaseApplication
when "setdocp"
@setting.docpath = undefined
@initialize()
when "setprinter"
@openDialog "PromptDialog", {title: __("Default Printer"), label: __("Enter printer name")}
.then (n) =>
@setting.printer = n
this.OS.register "Docify", Docify