Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An option to change text direction (LTR/RTL) in Console Input #6

Closed
Yaron10 opened this issue Feb 27, 2016 · 42 comments

Comments

Projects
None yet
3 participants
@Yaron10
Copy link

commented Feb 27, 2016

This is important for RTL users.
If, however, it requires some complex work - leave it to a future version.
IMO, you should now be concentrating on providing an option to display user-scripts in the menu. :)

@dail8859

This comment has been minimized.

Copy link
Owner

commented Feb 27, 2016

Agreed it would be nice to have but a bit lower priority. Personally I have no idea how to do it currently.

BTW you can already register Lua functions to be displayed in the menu.

@Yaron10

This comment has been minimized.

Copy link
Author

commented Feb 27, 2016

BTW you can already register Lua functions to be displayed in the menu.

Could you please elaborate a bit?
Can I have editor:LineCopy() displayed in the menu?

Thank you.

@dail8859

This comment has been minimized.

Copy link
Owner

commented Feb 27, 2016

npp.AddShortcut("Line Copy", "Alt+Ctrl+C", function()
    editor:LineCopy()
end)

If you don't want a shortcut key assigned to it but still want it to show up in the menu, use an empty string instead of "Alt+Ctrl+C" (or assign it to any other key you want). See this section of the readme.

@dail8859

This comment has been minimized.

Copy link
Owner

commented Feb 27, 2016

Also I should mention you have to have v0.2.0 and this code must be in the startup script.

@Yaron10

This comment has been minimized.

Copy link
Author

commented Feb 27, 2016

Works like a charm. A major improvement.
Keep up the good work. :)

Thank you.

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 4, 2017

Hi @Yaron10

I was looking into this. I'm trying to figure out the best way to implement this and had a few questions since I don't use RTL at all :)

  • Would you need LTR support in both the input and output? Or just the input?
  • Notepad++ uses Ctrl+Alt+L and Ctrl+Alt+R. Would this be acceptable to toggle the text direction?
  • What about having a LuaScript command such as input:SetTextDirection("RTL")?
  • Does Notepad++ remember the text direction after shutting it down and starting it back up?
    • If not, would it be helpful if LuaScript did remember it?

Thanks!

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 4, 2017

Hello dail,

Thank you for looking into it. I do appreciate it.

Would you need LTR support in both the input and output? Or just the input?

The output is more important as it isn't displayed properly in a RTL layout.

How about forcing the entire console window to LTR even if NPP layout is RTL?

  • I can't think of a reason a RTL user would want the console to be RTL.
  • It would be simpler: no shortcuts or an extra command.

Does Notepad++ remember the text direction after shutting it down and starting it back up?

NPP does not remember the text direction.
Most of the files I use in NPP are LTR, and I've modified NPP code so that the text direction would be LTR (in both views) even in a RTL layout.

If not, would it be helpful if LuaScript did remember it?

If you're referring to NPP in general it would be great; but IMO it would be even better to implement it in NPP (as a major contributor :) ).

If you're referring to LuaScript console - implementing my suggestion above would make this unnecessary.


I haven't yet replaced my Python scripts with Lua scripts. But I do want to that now. :)
May I ask you to have a look at the attached scripts and let me know if all can be implemented with LuaScript?

If and when you have some free time, could you please write the main parts of "Select and Find First" in Lua?
I do hope it's not too much of a trouble; searching the documentation for that might take me a good few hours. :)
I'd highly appreciate it.

And one more question:
I'd like all the scripts to appear in the menu (for toolbar icons and the context-menu).
How do I make a relatively longer script (saved as an independent file) show up in the menu?


I've included a "Show Console" icon in the attached file.
If you like it and/or you have a better idea (e.g. making it more Lua-associated), please let me know.

Best regards.

Scripts and Icon.zip

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 4, 2017

How about forcing the entire console window to LTR even if NPP layout is RTL?

My idea was to make the input and output completely independent from Notepad++'s text direction. When I was referring to Ctrl+Alt+L and Ctrl+Alt+R I was meaning focusing on LuaScript's output window and then pressing the shortcut. This would be easier if a RTL user wants to toggle the text direction back and forth quickly.

My other idea was create a new LuaScript command such that in the startup.lua file you could add something like output:SetTextDirection("RTL") that way it is set to the proper direction as soon as Notepad++ starts up.

May I ask you to have a look at the attached scripts...

When I get some free time I think it would be good to look at these "real world" scripts and see if there are any other areas that LuaScript can improve. :)

...could you please write the main parts of "Select and Find First" in Lua?

I will certainly try to do what I can.

I'd like all the scripts to appear in the menu

They won't automatically appear, but you can create new menu items for example:

npp.AddShortcut("the shortcut name", "Alt+Ctrl+C", the_function_to_run)

Currently it's not yet possible to add toolbar icons but it is not a bad idea. It would need a bit of investigating.

How do I make a relatively longer script (saved as an independent file) show up in the menu?

The general idea is to use Lua's require function (similar to Python's import) and then you can have access to those functions in the other files (and then register them as a shortcut). However I need to look into this a bit more because there are certain paths in Lua you have to set in order for it to "find" the other files easily.

I've included a "Show Console" icon in the attached file.

The most recent release of LuaScript (v0.6.0) has a toolbar icon to toggle the console window and it uses the official Lua icon.

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 5, 2017

Hello dail,

Thanks for replying. I appreciate it.

As a RTL user I think that making the entire console window LTR would be great even without an option to change direction.
Adding an option to control the direction would obviously make the console more flexible (but - as I've mentioned - I can't think of a reason a RTL user would want the console to be RTL).
If you tend to prefer better flexibility, the best approach IMO would be as follows:
The default window layout should be LTR.
An option in startup.lua to change the entire window layout. That is to say: both input and output.


When I get some free time I think it would be good to look at these "real world" scripts and see if there are any other areas that LuaScript can improve.
...
I will certainly try to do what I can.

Special thanks for that. Highly appreciated.


The general idea is to use Lua's require function (similar to Python's import) and then you can have access to those functions in the other files (and then register them as a shortcut). However I need to look into this a bit more because there are certain paths in Lua you have to set in order for it to "find" the other files easily.

I don't want to be ungrateful to Dave. His PythonScript Plugin is absolutely great.
Your LuaScript Plugin has a major advantage: it's lightweight and doesn't require the extra libraries.
Yet, the ability to easily add scripts to the menu (via a command or by just creating a Scripts folder) would be more important to the average user.
Please don't mind my writing this: I've been watching this repo and waiting for this option. :)
I think this should be your No. 1 priority.


Currently it's not yet possible to add toolbar icons but it is not a bad idea. It would need a bit of investigating.

I meant adding an icon via Customize Toolbar. For that I need a menu command.
And, again, allow me to share a user perspective: the option to add icons via LuaScript certainly should not be a high priority.


The most recent release of LuaScript (v0.6.0) has a toolbar icon to toggle the console window and it uses the official Lua icon.

Yes, I'm using v0.6.0. Just another option. :)


Thank you for your great work.

Best regards.

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 5, 2017

As a RTL user I think that making the entire console window LTR would be great even without an option to change direction.

I can't think of a reason a RTL user would want the console to be RTL

I'm not sure I understand exactly what you are saying in these sentences. This may be just because I'm so unfamiliar with non-english alphabets. When I say "LTR" and "RTL" this is my understanding:

rtlltr


An option in startup.lua to change the entire window layout. That is to say: both input and output.

Yes I figured something as in:

output:SetTextDirection("RTL")
input:SetTextDirection("RTL")

It is far easier to implement it this way instead of a single command to do both at the same time.


Yet, the ability to easily add scripts to the menu

What exactly are you referring to? You mean like this?

menu

I meant adding an icon via Customize Toolbar.

Oh. I've never used that before. I may take a look at it sometime.

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 5, 2017

Hello dail,

There's LTR/RTL text direction and LTR/RTL layout.

Please change your NPP interface language to Hebrew and restart it.
The entire window layout is transformed/flipped (title bar, menu, tabs etc.).

You can also modify english.xml and restart NPP (remember to modify nativeLang.xml as well).
<Native-Langue name="English" filename="english.xml" to <Native-Langue name="English" RTL="yes" filename="english.xml".

This is LuaScript console in LTR and this in RTL.
My initial request was to enable changing the test direction only.
But I now think that forcing the entire layout to LTR is better.

Here is an example which might help:
My NPP layout is RTL. Still, personally I prefer the Status Bar in LTR (it's all Latin).

In StatusBar.cpp I've added the following line:

	// Change to LTR. "WS_CHILD & (~WS_EX_LAYOUTRTL)" above won't work because WS_EX_LAYOUTRTL is added AFTER the bar has been created and inherited the RTL layout.
	::SetWindowLongPtr(_hSelf, GWL_EXSTYLE, ::GetWindowLongPtr(_hSelf, GWL_EXSTYLE) & (~WS_EX_LAYOUTRTL));

after

	if (!_hSelf)
		throw std::runtime_error("StatusBar::init : CreateWindowEx() function return null");

What exactly are you referring to? You mean like this?

Indeed. But without having to add the scripts to startup.lua.
What's the main use of LuaScript? Isn't it the ability to add scripts and use them regularly?
When the user installs LuaScript this is the first option he expects and should see.

In PythonScript you have a "New Script" command. Logically, this is the first command.
And this should be in LuaScript as well: "New Script" or "Add Script" which would create a LuaScripts folder and add its files to the menu.

In PythonScript the scripts are displayed by default in the sub-menu "Scripts", and you have an option to move them to the main menu (this option is necessary for using the scripts in NPP context-menu).
IMO adding the scripts to the main menu is good enough. Separators above and below the scripts would be nicer.

Thank you.
BR

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 5, 2017

The entire window layout is transformed/flipped (title bar, menu, tabs etc.).

I think I am starting to understand better now. I think it comes down to the difference of setting the style bit on the N++ application HWND (and thus effecting all of its child HWNDs) or just setting it on say the specific Scintilla HWND (which is how Ctrl+Alt+L and Ctrl+Alt+R currently operate for Notepad++).

My initial request was to enable changing the test direction only.
But I now think that forcing the entire layout to LTR is better.

"entire layout" as in what exactly? Notepad++? The docked dialog (which contains the input/output/button)?


Maybe a specific example will help :) I made some code changes real quick . I set the language for N++ to Hebrew and then set the input/output to LTR. Would this be sufficient?

untitled


Indeed. But without having to add the scripts to startup.lua.

I will get back to answering this at a later time since it starts to deviate a good bit from the core topic.

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 5, 2017

I think I am starting to understand better now. I think it comes down to the difference of setting the style bit on the N++ application HWND (and thus effecting all of its child HWNDs) or just setting it on say the specific Scintilla HWND (which is how Ctrl+Alt+L and Ctrl+Alt+R currently operate for Notepad++).

You got that perfectly. :)

"entire layout" as in what exactly? Notepad++? The docked dialog (which contains the input/output/button)?

The LuaScript console window.

Would this be sufficient?

That would be great!

I will get back to answering this at a later time since it starts to deviate a good bit from the core topic.

Should I open a separate issue/request for that?

Thank you very much.

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 5, 2017

That would be great!

Oh good to know :) This is what I was trying to figure out.

Indeed. But without having to add the scripts to startup.lua.

So getting back to this. I deviated from the PythonScript architecture of using shortcuts to run "scripts" and went for "functions". Here are a few of the major reasons why:

  • Large parts of the underlying Lua architecture came from SciTE; Though it did not have anything like AddShortcut, it did make it easier to implement it this way.
  • Straight win32 programming really isn't that fun for me; I know I can certainly take alot of existing code for PythonScript and use it in a similar way but there are things I'd want to change/modify...and digging into it doesn't appeal to me.
  • It worked for what I needed at the time, and still does.
  • I figured why not use a Lua-based solution as opposed to lots of C and GUI code.

So in short it is really just an architectural base decision. I'm not saying the way PythonScript does its "wrong" or "bad" or that I would be opposed to ever using it. It just seemed to be too much work/effort/maintenance for me when a similar result could be achieved with the current implementation.


However you can still keep Lua code in separate scripts. For example, if you put this in startup.lua:

package.path = package.path .. ";" .. npp:GetPluginsConfigDir() .. "\\?.lua"

require "Copy All"

Then in the same directory as startup.lua, create a "Copy All.lua" which contains:

npp.AddShortcut("Copy All", "Ctrl+Shift+A", function()
	editor:SelectAll()
	editor:Copy()
end)

Then everything works fine. If you add another script in that directory just add the appropriate require. And this is just one way of doing it. I prefer to give the user as much flexibility as possible.

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 5, 2017

Also, here are the Lua versions if the scripts you zipped up. Please note I haven't actually tested them but they should be very close to functional. In most cases every call to "editor" just needs tweaked a bit.

As discussed in the previous post, you'd have to wrap these in a call to AddShortcut so they show up in the menu. The only problem I ran into was in "Select and Find First.py". Since Lua runs synchronously it doesn't make sense to put the thread to sleep. Since PythonScript executes the code in a separate thread it does work when using Python.

LuaScripts.zip

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 5, 2017

Oh good to know :) This is what I was trying to figure out.

Great.
I just want to make sure I understand you correctly.
I can't make it work with the current version; - you do have to make some changes in the code. Correct?

So getting back to this. I deviated from the PythonScript...

Thanks for the explanation.
I understand your approach better now.

However you can still keep Lua code in separate scripts. For example, if you put this in startup.lua:

It's clearer now. I'm beginning to like it more and more. :)
Can I create a LuaScripts folder under "plugins" or "config" and put all my scripts (including startup.lua) there?


I've just seen your last post.
Many thanks for that. It's really kind of you.
I'll try the scripts shortly.

BR

@OwnageIsMagic

This comment has been minimized.

Copy link
Contributor

commented Jan 5, 2017

Just add this 4 lines to startup.lua

local pcdir = npp:GetPluginsConfigDir()
package.path = pcdir .. "\\luaAutoRun\\?.lua;" .. package.path
local files = io.popen('dir /b "' .. pcdir .. "\\luaAutoRun\\*.lua" .. '"'):lines()
for file in files do xpcall(require, npp.WriteError, file:gsub(".lua$", "")) end

it will independently require all scripts in Config\luaAutoRun folder on start

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 5, 2017

you do have to make some changes in the code. Correct?

Yes. Hopefully tomorrow I will commit the change and I can give you a dev build to try out.

Can I create a LuaScripts folder under "plugins" or "config" and put all my scripts (including startup.lua) there?

startup.lua cannot be moved, however any other Lua can be in other locations and @OwnageIsMagic just posted a great example. I'm glad to see solutions like being written in Lua whenever possible. It gives the user as much flexibility without forcing a solution on them.

@OwnageIsMagic That's really cool. I'll definitely be using that myself :)

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 5, 2017

Yes. Hopefully tomorrow I will commit the change and I can give you a dev build to try out.

Thank you. I'll be looking forward to it.

Just add this 3 lines to startup.lua
...
startup.lua cannot be moved, however any other Lua can be

Thank you dail and @OwnageIsMagic. I appreciate it.

It doesn't work for me.
Are the lines @OwnageIsMagic posted the only ones startup.lua should contain?
What am I missing?

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 5, 2017

OK, I got it.
I was using

editor:SelectAll()
editor:Copy()

instead of

npp.AddShortcut("Copy All", "Ctrl+Shift+A", function()
	editor:SelectAll()
	editor:Copy()
end)

Two points:

  1. Using @OwnageIsMagic's code makes NPP start considerably more slowly.
  2. The title bar is grayed; NPP doesn't have the focus.

@dail8859,
Thanks again for the converted scripts. :)
I'll try them more thoroughly later.

BR

@OwnageIsMagic

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2017

Two points:

Using @OwnageIsMagic's code makes NPP start considerably more slowly.
The title bar is grayed; NPP doesn't have the focus.

I don't have an idea why windows creates new console window when input is redirected to process
there is no way to list directory in pure lua, so it calls dir.exe for this
like dail stated here, you should rely on 3 party libs for interacting with system

@OwnageIsMagic

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2017

updated script slightly

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 6, 2017

@OwnageIsMagic,
Thanks again. I appreciate it.

@dail8859.
Regarding the converted scripts:
All work like a charm except "Select and Find First" which gets some errors.
I'll have to find some free time to work on that.
BTW, try reading the errors in a RTL layout. A complete mess. :)
And allow me to thank you again. I do appreciate your kindness.

Best regards.

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 6, 2017

@OwnageIsMagic,
Just saw the update. I'll try it tomorrow.
Thanks.

@OwnageIsMagic

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2017

@Yaron10 I just changed directory (cause I prefer require scripts and already use lua dir for myself) and add xpcall to allow remain scripts load if one of them failed
UPD:
Replacing dir /b with cmd /d /c dir /b magically stops stealing focus
UPD: no, it doesn't

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 6, 2017

you should rely on 3 party libs for interacting with system

Currently the huge problem is #22. I've tried to fix this a few times but it never works the way I'd like.

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 6, 2017

Hi @Yaron10

Here is a new version you can try. If this works well for you then I will push the change to GitHub and close this issue.

Within the LuaScript window there are 2 Scintilla instances, the "console" (i.e. the output) and the "input". These have their text directions set independently. In your startup script you can add:

console:set_text_direction("LTR")
input:set_text_direction("LTR")

Just extract and copy over your existing LuaScript.DLL file.

LuaScript.zip

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 6, 2017

Also, two immediate problems I found with "Select and Find First".

The function getExpression() needs this at the end of the function:

    return editor:textrange(sPos, ePos)

Also the definition of flashSel() function needs moved above the definition of highlightFirst().

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 6, 2017

Hello dail,

Here is a new version you can try. If this works well for you then I will push the change to GitHub and close this issue.

It works like a charm. A huge improvement. 👍
Thank you very much.


Also, two immediate problems I found with "Select and Find First".
...

I noticed yesterday the missing return line but, without looking it up in the documentation, I added return editor:GetTextRange(sPos, ePos) which obviously didn't work.

Now, after a quick test, it seems to be working properly.
Thanks again. I highly appreciate it.

Could you please think of an alternative to flashSel()?
I suppose that flashing the window wouldn't work either.
I'd like to get some feedback if the selection/expression is the first occurrence.


local pcdir = npp:GetPluginsConfigDir()
package.path = pcdir .. "\\LuaScripts\\?.lua;" .. package.path
local files = io.popen('cmd /d /c dir /b "' .. pcdir .. "\\LuaScripts\\*.lua" .. '"'):lines()
for file in files do xpcall(require, npp.WriteError, file:gsub(".lua$", "")) end

NPP still doesn't get the focus on my machine.

Best regards.

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 6, 2017

Hello @OwnageIsMagic,

Thanks again for the code. I appreciate it.

Best regards.

@dail8859 dail8859 closed this in 8fed28f Jan 6, 2017

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 6, 2017

Could you please think of an alternative to flashSel()?

I'm not aware of any way to replicate this behavior.

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 6, 2017

I'm not aware of any way to replicate this behavior.

Thank you. You can't always get what you want. :)

Is the icon you use 32bpp?
Here is the official 32bpp.

BR

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 6, 2017

There are two images I use. A bmp used for the toolbar, and an ico used for the docked dialog.

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 6, 2017

They are 256. :)
Lua 32bpp ico and bmp.zip

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 6, 2017

What's the problem with the current images being used?

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 6, 2017

The 32bpp images are much clearer and sharper.
Not really important.

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 6, 2017

The newer images (on the right, and of course ignoring the black background for now) do not look as clear for me. For such small icons, the less detail the better.

before

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 6, 2017

OK. :)
Thanks again for your great work.

BR

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 6, 2017

One more question:
I'm thinking of replacing flashSel() with a beep.
I've searched for "beep", "alert" and "sound" but to no avail.
Is that available?

Thank you.

@OwnageIsMagic

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2017

maybe rename to SetTextDirection ?

@dail8859

This comment has been minimized.

Copy link
Owner

commented Jan 6, 2017

I've searched for "beep", "alert" and "sound" but to no avail.
Is that available?

Nothing from LuaScript and AFAIK nothing from Lua itself.

The only other think I could think of doing is using indicators to highlight certain matches differently but not sure how much effort you want to put into it since it would be more than just a simple call.

maybe rename to SetTextDirection ?

The original naming convention came from SciTE. It used camel case naming for direct Scintilla calls and lowercase/underscore names for any "helper" functions so I've just followed this. I'm honestly not a fan of set_text_direction but I'm OK with it since it is following this convention.

@Yaron10

This comment has been minimized.

Copy link
Author

commented Jan 7, 2017

Nothing from LuaScript and AFAIK nothing from Lua itself.

The only other...

I'll leave it as it is.
Thank you dail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.