You are here: PSPad forum > English discussion forum > Re: How to create new file in javascript

Re: How to create new file in javascript

#1 How to create new file in javascript

Posted by: edo_nick | Date: 2020-02-28 09:47 | IP: IP Logged

Hi,
I want to open new file in javascript just like click button Open file.
No open file dialog box just new tab (editor) appears.
When I use

neweditor.openFile(filename);

It went to error because file doesn't exist. (But I just want to create it.)

Thanks in advance.

Options: Reply | Quote | Up ^


#2 Re: How to create new file in javascript

Posted by: pspad | Date: 2020-02-28 10:35 | IP: IP Logged

There is few ways how to do it:
1. new file dialog: Ctrl+N, start typing: ja, move to Java script and confirm

2. always new file as JavaScript: program settings / Files - New default: Javascript. If you check Always this type, new file will be always Javascript. With unchecked option, new file will be same type as current file.

3. Click on the small arrow next new file button and choose JavaScript

Options: Reply | Quote | Up ^


#3 Re: How to create new file in javascript

Posted by: edo_nick | Date: 2020-02-28 11:12 | IP: IP Logged

Sorry, you quite don't understand my problem.
I want to use javascript to open new file (tab/editor).
I have written script to transform content of opened file and I want to put output of transformation into new file.

Options: Reply | Quote | Up ^


#4 Re: How to create new file in javascript

Posted by: vbr | Date: 2020-02-28 11:40 | IP: IP Logged

edo_nick:
...
I want to use javascript to open new file (tab/editor).
I have written script to transform content of opened file and I want to put output of transformation into new file.

Hi,
it should be possible to use the methods of the editor object via scripting:

newFile([file_name: string]) //... to create a new file tab in PSPad with the optional file name

text(string) // to set the file content

saveFile()
or possibly:
saveFileAs(file_name: string)
to actually save the file on disk.

(I am not sure, how the directory path is handled in this case - I personally use rather unsaved editor tabs for such output (via newFile(...) and text(...) only) and handle then the saving or discarding manually.)

hth,
vbr

Options: Reply | Quote | Up ^


#5 Re: How to create new file in javascript

Posted by: edo_nick | Date: 2020-02-28 11:47 | IP: IP Logged

Thank you. It works like that


var neweditor = newEditor ();
neweditor.newFile(filename);
text = newlines.join ("\n");
neweditor.text (text);

Options: Reply | Quote | Up ^


#6 Re: How to create new file in javascript

Posted by: Qwanturank26 | Date: 2020-03-04 14:43 | IP: IP Logged

Thanks for your response and script js ! It helped me alot !

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR