You are here: PSPad forum > English discussion forum > assignEditorByName problem

assignEditorByName problem

#1 assignEditorByName problem

Posted by: edo_nick | Date: 2020-01-31 09:21 | IP: IP Logged

Hello,
I have problem with assignEditorByName() in javascript.

If I use it like this

ed = newEditor ();
ed.assignEditorByName("D:\path\Bratislavský.csv");

I get error Microsoft JSkript - chyba počas práce Module:MyModule Line:x Pos:y
Description: Počas operácie automatizácie sa nenašiel názov súboru alebo triedy.
Briefly: filename or classname not found

I have tried check it by assignEditorByIndex and it looks like it cannot compare string with filename right.


for (i = 0; i < 7; i += 1) {
ed.assignEditorByIndex(i);
if (ed.fileName() == "D:\path\Bratislavský.csv") {
logAddLine("Filename [" + i + "]");
exit;
}
logAddLine("Filename [" + ed.fileName() + "]");
}

How to solve it?

Thank you.

Options: Reply | Quote | Up ^


#2 Re: assignEditorByName problem

Posted by: pspad | Date: 2020-01-31 09:42 | IP: IP Logged

Hello
Assign editor by name means:
file is open in PSPad
into editor object is assigned existing filetab with name from parameter. It's for moment, you know your file is open, but you don't know the tab.

If you want to open file from disk into new editor, use command:
openFile(file_name: string): boolean

ed = newEditor ();
ed.openFile("D:\path\Bratislavský.csv");

Options: Reply | Quote | Up ^


#3 Re: assignEditorByName problem

Posted by: hhoefling | Date: 2020-01-31 09:54 | IP: IP Logged

By the way

I use JScript in another Context...
..There i must double the "\" -> "\\"

sample:

Quote:
this.filename = GetFFPathEx(1) + "\\" + name + ".log";

your can try:

Quote:
ed.openFile("D:\\path\\Bratislavský.csv");

--
by HH

Options: Reply | Quote | Up ^


#4 Re: assignEditorByName problem

Posted by: edo_nick | Date: 2020-01-31 11:51 | IP: IP Logged

Thank you for reply. I use it this way. File is open in PSPad.
I have tried to use openFile with same problem as assignEditorByName sad smiley

Options: Reply | Quote | Up ^


#5 Re: assignEditorByName problem

Posted by: edo_nick | Date: 2020-01-31 12:07 | IP: IP Logged

hhoefling:
By the way

I use JScript in another Context...
..There i must double the "\" -> "\\"

sample:

Quote:
this.filename = GetFFPathEx(1) + "\\" + name + ".log";

your can try:

Quote:
ed.openFile("D:\\path\\Bratislavský.csv");

I have tried it. With plain string it works well. But I need change filename dynamically. When I tried to use concatenation or template literal it went wrong. sad smiley

ed.assignEditorByName("D:\\path\\" + filename + ".csv");
ed.assignEditorByName("D:\\path\\${filename}.csv");

Options: Reply | Quote | Up ^


#6 Re: assignEditorByName problem

Posted by: edo_nick | Date: 2020-01-31 15:07 | IP: IP Logged

For today I solve this problem by array of names synchronized with tabs and assigning editor by index.

Options: Reply | Quote | Up ^


#7 Re: assignEditorByName problem

Posted by: pspad | Date: 2020-01-31 15:27 | IP: IP Logged

Hello
it works for me.


var module_name = "FileOpenJS";
var module_ver = "1.0";
var module_title = "FileOpenJS";

function openFile() {
var obj = newEditor();
var filename = 'testfile';
obj.openFile('I:\\' + filename + '.txt');
}

function Init() {
addMenuItem("Open file test", "", "openFile", "");
}

It works for me include files with diacritical sign, e.g. with
filename = 'červený'

Edited 1 time(s). Last edit at 2020-01-31 15:29 by pspad.

Options: Reply | Quote | Up ^


#8 Re: assignEditorByName problem

Posted by: hhoefling | Date: 2020-01-31 16:14 | IP: IP Logged

Assigen it to a variable

Quote:
var fs="D:\\path\\" + filename + ".csv";
ed.assignEditorByName(fs);

maybe it must be a simple Parameter, no expression

--
by HH

Edited 1 time(s). Last edit at 2020-01-31 16:14 by hhoefling.

Options: Reply | Quote | Up ^


#9 Re: assignEditorByName problem

Posted by: pspad | Date: 2020-01-31 16:32 | IP: IP Logged

hhoefling:
Assigen it to a variable

Quote:
var fs="D:\\path\\" + filename + ".csv";
ed.assignEditorByName(fs);

maybe it must be a simple Parameter, no expression

It's not important. See my example above, what works.

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