Probably you have already read my introductory article about Mahou , in it I described how I created the first function and described what the program does in general. Since then, not a little time has passed in Mahou. A lot of things have changed and been added, and this article will be discussed in fact.
The interface has changed a lot, for the better, everything has become convenient and visible, this is how Mahou looked like before:
And now it looks like this:
The function "Hint of the current layout near the text cursor (carriage)" got the ability to display in Sublime Text 3, using a plugin which I wrote specifically for this.
It all started when I was looking for an opportunity to take a position on which the text cursor is now, searched for a method and found it on the Sublime Text → view.rowcol(view.sel()[0].begin())
that returned a line and the number of letters on which is now a text cursor, it was what you need. Then I thought, "How do you transfer this data to Mahou from Sublime Text?", And remembered the sockets (I knew about them quite a bit) and decided to write a server that will work on 127.0.0.1 (localhost) and port 7777 , at first nothing worked, then I read a couple of articles about sockets and began to understand how they work. Then I started reading the Sublime Text 3 API , then I started creating a plugin:
First, I initialized the server to which the data will be issued, then I created EvenListener with listening to the events:
Then I began to look for a way to get the X, Y coordinates of the carriage position, from ST3API I learned that you can get the height of the line and the width of the text, if you multiply them by lines and the number of letters, you can get the necessary coordinates. But there was one problem - the tab character was considered as 1 character, so I decided that it was necessary to count the number of Tabs per line and multiply them by 3 and add to the number of letters - and it worked!
Then I added the definition of the sidebar width, but it wasn’t as simple as when it was hidden / shown, it uses animation, and the EventListener returned the width before the animation finished, looking at other possible APIs, I came to the conclusion that another solution to this problem except how to add time to wait for the end of the animation before sending data to the server - no, and added 300 ms of waiting - and it worked fine!
Then I created the settings for the plugin, created a client that received data from the server in Mahou and everything worked.
Previously, when a timer tick is valid for the flags of countries in the tray, the icon always changed, which ultimately put a heavy load on the CPU and sometimes even drove GDI +, so I decided to implement a variable that will store the name of the last changed language, and the condition that The current language is equal to the previous one, then not to change the icon, which significantly reduced the load on the CPU, I improved the other functions in a similar way.
What does it mean? This means that earlier when reading a particular setting, a disk was used, creating an extra load, I decided to create variables for each setting in order not to use the disk but to use them (RAM). Now, reading / writing from / to disk occurs only when saving / loading settings.
Source: https://habr.com/ru/post/324592/
All Articles