Recent

Author Topic: Source Editor - Open Source Folder Option  (Read 3856 times)

Tony Stone

  • Sr. Member
  • ****
  • Posts: 265
Source Editor - Open Source Folder Option
« on: January 26, 2025, 03:03:16 am »
So I started digging through the Lazarus source so I could add an option to the filename tab in the source editor to open its folder.  I figured it shouldn;t be too hard and this is something I wanted for a while and as I am poking around I looked at the full filename and directory in the status bar and thought that would be a great place to have an Open Folder option. 

AND ONLY THEN did I think to right click on it and sure enough an Open Folder menu is there!  That is awesome and I wish I knew that was there.


Either way I have a possible suggestion to improve it... I think the mouse cursor should change when it moves over it to the hyperlink looking folder and a right or left click should show the open folder menu.  Or just simply clicking it should open the folder.

What do you all think?  I am gonna experiment on my own right now and see if I can implement this.

Edit:  And while looking through the source I found double clicking will also open the folder.  This is not apparent at all.  So glad to know this feature is there already. 
« Last Edit: January 26, 2025, 03:11:39 am by Tony Stone »

Tony Stone

  • Sr. Member
  • ****
  • Posts: 265
Re: Source Editor - Open Source Folder Option
« Reply #1 on: January 26, 2025, 04:26:35 am »
Ok I never used git to make a patch.  No clue if this is proper.  But if anyone wants to try what I thought it should look like I made the changes and I think the patch will apply it.
« Last Edit: January 26, 2025, 05:07:37 am by Tony Stone »

Tony Stone

  • Sr. Member
  • ****
  • Posts: 265
Re: Source Editor - Open Source Folder Option
« Reply #2 on: January 26, 2025, 05:32:21 am »


Well this was my fun for tonight.  I think it is very useful like this and would love to see the developers properly implement it.  Thanks.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10788
  • Debugger - SynEdit - and more
    • wiki
Re: Source Editor - Open Source Folder Option
« Reply #3 on: January 26, 2025, 11:29:51 am »
I'll have to see what other (incl team) think. I personally don't like the always underlined look in the status panel.  (according to your image / still have to check the patch).

Also a link implies single click, which then can happen by accident if trying to grab the window border for resizing.


Looking at other editors (they may not all have the filename in the statusbar, but they have click-able items)

- VSCode changes the mouse pointer
- Visual Studio highlight some status panels on mouse over (like speed buttons), other (clickable) panels have no indicator (caret pos => goto dlg)
- Sublime has no indicator
- Notepad++ has no indicator
- Libre office Writer has no indicator, well it shows a hint on hover
- geany - not reacting to clicks
- gedit - no indicator on mouse over, but shows a drop down symbol next to clickable panels


Personally, to me, either mouse-pointer change or highlight (slight color change of the background) on mouse over seems the least intrusive (otherwise an icon next to the text, but that may run out of space). But open minded, to see what others think.

And as indicated, actually preferring the double click. But when you get an indicator (e.g. mouse pointer, then that may not be intuitive) But again lets see.

Also, about double click, there already is an exception: While recording an editor macro, the stop button is single click.

Tony Stone

  • Sr. Member
  • ****
  • Posts: 265
Re: Source Editor - Open Source Folder Option
« Reply #4 on: January 26, 2025, 01:55:45 pm »
Thanks for the response Martin.  Your feedback was exactly what I hoped for.  I have not really used many other editors so I mostly went with what felt intuitive to me.  And honestly now that I know it is there a double click is fine but like I said before I never had an indicator before to realize I could double click.  I thought of a hint also but I feel like it isn't a place someone would often hover their mouse for too long.  Not sure I ever looked for hints in status bars.  Just because in my mind the status at is often the info you want.  To me it is more for just viewing.


So as far as the hyperlink look I think you are right and a lot of people won't like it.


I think maybe it could have a small icon that looks clickable where the mouse cursor changes.  If it looked like a tool bar button with a folder I think it would be very apparent to users that it is there.


I may have more time today to play around with those ideas and see how it looks. 


At the very least if you find the patches useless there is one slightly more important spot I found in the code where the status panel was directly using index 5 instead of the constant for the filename panel.  That should probably be fixed at the least I think.  I'm on my phone so I can't remember the constant name and the procedure I changed it in.
« Last Edit: January 26, 2025, 02:34:31 pm by Tony Stone »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10788
  • Debugger - SynEdit - and more
    • wiki
Re: Source Editor - Open Source Folder Option
« Reply #5 on: January 26, 2025, 03:02:50 pm »
At the very least if you find the patches useless there is one slightly more important spot I found in the code where the status panel was directly using index 5 instead of the constant for the filename panel.  That should probably be fixed at the least I think.  I'm on my phone so I can't remember the constant name and the procedure I changed it in.

Indeed.

I still have to catch up. Just glanced over the msg.

Btw, be aware that there is code to register panels by plugins. So whatever the editor does do its own panels, would be good if it was generally supported for all panels. E.g. Custom mouse pointe (the "mouse over link" image) could be an attribute that the API supports.

I prefer an "mouse over" reaction to a "static indicator" as it takes no space.
An icon takes space, and the path is often enough already cut off, or close to.

Tony Stone

  • Sr. Member
  • ****
  • Posts: 265
Re: Source Editor - Open Source Folder Option
« Reply #6 on: January 26, 2025, 08:04:47 pm »
Wow this forum irritates me some times!  The file I attached was too large, so went back and my entire message I typed out is gone.  >:(
Anyway I tried to address some points you brought up Martin.  Here are some screen shots which I think look way better.

I added an option to truncate the middle of the path if its too long to fit.

I also made it so when you click the icon it will try to open your system file viewer with the file already slected.

Does this look better?

Tony Stone

  • Sr. Member
  • ****
  • Posts: 265
Re: Source Editor - Open Source Folder Option
« Reply #7 on: January 26, 2025, 08:07:41 pm »
I also have this to show it working: https://ibb.co/J50R1K8


Later I will type a message again, I had questions of the plugins suggestion you mentioned and I wanted your input on wether or not it is acceptable to use UTF8 characters such as 📂 which I am currently using protoype my vision here.



n7800

  • Full Member
  • ***
  • Posts: 235
Re: Source Editor - Open Source Folder Option
« Reply #8 on: January 26, 2025, 08:45:31 pm »
In general, when I first needed to open a folder, I expected to see the command in the context menu of the editor tab. It definitely needs to be added there.

I personally don't like the always underlined look in the status panel.
...
Personally, to me, either mouse-pointer change or highlight (slight color change of the background) on mouse over seems the least intrusive (otherwise an icon next to the text, but that may run out of space). But open minded, to see what others think.

I agree. Besides the path bar, there are other clickable panels (macros, coordinates, and others may appear in the future). It turns out that almost everything in the status bar will be underlined. For the same reason, I don't see the point in displaying clickable panels in a different color or adding icons.

I think it's enough to highlight elements only when you hover over them with the mouse (and change the cursor). This will be intuitive and won't change the appearance of the status bar (after all, it's rarely used by the mouse, but it's always visible).

n7800

  • Full Member
  • ***
  • Posts: 235
Re: Source Editor - Open Source Folder Option
« Reply #9 on: January 26, 2025, 09:22:33 pm »
I added an option to truncate the middle of the path if its too long to fit.

This is great. I wonder how you implemented it? There is a function ShortDisplayFilename in LazUtils, but it is based on the number of characters, not their size on the screen. I saw that the path to a certain width adjusts the progress window of the search in files. But it just cuts the path from the left, and does not leave the beginning, like ShortDisplayFilename...

In general, there are different cropping algorithms. Most of them assume that the name is visible in full. And preferably the first two components (at least the drive letter and the first folder). The rest can be supplemented on the left or right.

It would be correct to implement such a function in LazUtils, next to ShortDisplayFilename. We can even make an overload that will accept a Canvas and a width in pixels. Then it can be used both in the IDE and in user applications.

n7800

  • Full Member
  • ***
  • Posts: 235
Re: Source Editor - Open Source Folder Option
« Reply #10 on: January 26, 2025, 09:32:19 pm »
I also made it so when you click the icon it will try to open your system file viewer with the file already slected.

I immediately noticed in the patch that you did not use the OpenDocument function, but implemented the code to open a folder and select a file in it. This is good - I was missing this, which is why I have to use External Tools, assigning them a hotkey.

All this code should be moved to a separate function. This will isolate it, and allow to use it from another place (for example, in the context menu command of the tab).

And since this is a useful function that will be useful in user applications, it will be great to place it in the LCL library, next to the OpenDocument function. Your implementation takes into account several platforms, I hope the developers will accept it.

Another reason is that in the IDE code (namely the IDE itself), developers try not to use {$IFDEF} for OS/widget sets.

n7800

  • Full Member
  • ***
  • Posts: 235
Re: Source Editor - Open Source Folder Option
« Reply #11 on: January 26, 2025, 09:55:19 pm »
By the way, you need to create one patch for all changed files. Just use git diff or git format-patch, depending on how you work. See git help for details.

n7800

  • Full Member
  • ***
  • Posts: 235
Re: Source Editor - Open Source Folder Option
« Reply #12 on: January 26, 2025, 10:00:39 pm »
Actually, I have a patch (almost finished), which adds a context menu not only for the path, but also for other panels of the status bar. In particular, for the path, the "Copy file name to clipboard" command is added, which I often need.

I also added a hint with a double-click tooltip in it a long time ago. Of course, the hint itself is not as noticeable as the highlighting when hovering the mouse, but it does not interfere with it. It is especially needed to explain the panels with the COL/DEF/LINE and INS/OVR abbreviations.

But the hint can also show useful information - the total number of lines when hovering over the coordinates, and the file size when hovering over the path, and etc.

All this is not really relevant to your changes, just for information that there may be more clickable panels.

Tony Stone

  • Sr. Member
  • ****
  • Posts: 265
Re: Source Editor - Open Source Folder Option
« Reply #13 on: January 26, 2025, 10:17:29 pm »
n7800 Thanks for all the feedback!  I was just looking at making a OpenAndSelect function that could be useful elsewhere.  I did not test on any system other than my Linux Mint system so it would need to be tested on other systems.  Currently I am using TProcess in my tests.  I am sure this can easily be made into a useful function elsewhere!

This is what I am testing so far.  Was going to test on Windows.  I will tell you up front I used ChatGPT to give me the "proper command" for other file managers because I just didn't know of other ones but it was not all created by ChatGPT.  So it will need to be tested because ChatGPT often gives me garbage when I ask for code lol


Plus I am sure there is other file managers that are missing.

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TSourceNotebook.OpenFolderMenuItemClick(Sender: TObject);
  3. var
  4.   SourceFilePath, FileManagerCmd, FileDir, FileName: string;
  5.   CurEditor: TSourceEditorInterface;
  6.   AProcess: TProcess;
  7. begin
  8.   CurEditor := GetActiveEditor;
  9.   SourceFilePath := CurEditor.FileName;
  10.   FileDir := ExtractFilePath(SourceFilePath);
  11.   FileName := ExtractFileName(SourceFilePath);
  12.  
  13.  
  14.   if not FileExists(SourceFilePath) then
  15.   begin
  16.     ShowMessage('File not found: ' + SourceFilePath);
  17.     Exit;
  18.   end;
  19.  
  20.  
  21.   {$IFDEF Linux}
  22.   if Pos('GNOME', GetEnvironmentVariable('XDG_CURRENT_DESKTOP')) > 0 then
  23.     FileManagerCmd := 'nautilus --select "' + SourceFilePath + '"'
  24.   else if Pos('KDE', GetEnvironmentVariable('XDG_CURRENT_DESKTOP')) > 0 then
  25.     FileManagerCmd := 'dolphin --select "' + SourceFilePath + '"'
  26.   else if FileExists('/usr/bin/nautilus') then
  27.     FileManagerCmd := 'nautilus --select "' + SourceFilePath + '"'
  28.   else if FileExists('/usr/bin/dolphin') then
  29.     FileManagerCmd := 'dolphin --select "' + SourceFilePath + '"'
  30.   else if FileExists('/usr/bin/thunar') then
  31.     FileManagerCmd := 'thunar "' + SourceFilePath + '"'
  32.   else if FileExists('/usr/bin/nemo') then
  33.     FileManagerCmd := 'nemo "' + SourceFilePath + '"'
  34.   else if FileExists('/usr/bin/pcmanfm') then
  35.     FileManagerCmd := 'pcmanfm --select "' + SourceFilePath + '"'
  36.   else if FileExists('/usr/bin/caja') then
  37.     FileManagerCmd := 'caja "' + SourceFilePath + '"'
  38.   else if FileExists('/usr/bin/krusader') then
  39.     FileManagerCmd := 'krusader "' + FileDir + '"'
  40.   else
  41.     FileManagerCmd := 'xdg-open "' + FileDir + '"';
  42.   {$ENDIF}
  43.  
  44.  
  45.   {$IFDEF Windows}
  46.   FileManagerCmd := 'explorer /select,"' + SourceFilePath + '"';
  47.   {$ENDIF}
  48.  
  49.  
  50.   {$IFDEF Darwin}
  51.   FileManagerCmd := '/usr/bin/open -R "' + SourceFilePath + '"';
  52.   {$ENDIF}
  53.  
  54.  
  55.   // Run the file manager asynchronously
  56.   AProcess := TProcess.Create(nil);
  57.   try
  58.     AProcess.Executable := '/bin/sh';
  59.     AProcess.Parameters.Add('-c');
  60.     AProcess.Parameters.Add(FileManagerCmd);
  61.     AProcess.Options := AProcess.Options + [poNoConsole, poDetached];
  62.     AProcess.Execute;
  63.   finally
  64.     AProcess.Free;
  65.   end;
  66. end;      
  67.  

And thanks for the tip on GIT!  I still struggle with GIT commands.  I will work on that.

I am curious if you think using a UTF8 symbol like the folder is acceptable in general though.  I am currently also working through some existing code to see how they load an image like the stopimage for the macro recorder.  I got lost trying to understand how that works.  I personally really like having the folder icon.  It makes it very apparent there is functionality there. 

Like I said earlier weather I make a useful patch or not I am just having fun here but of course would like to be able to contribute something useful for everyone while having fun.

Tony Stone

  • Sr. Member
  • ****
  • Posts: 265
Re: Source Editor - Open Source Folder Option
« Reply #14 on: January 27, 2025, 03:28:13 am »
So I tested various file managers.  Most work with selecting the file as well.  I made a single patch as n7800 suggested.  It is the best I could do for this weekend.  Maybe next weekend I can play more but this was mostly just an exercise for me.  And while it is not perfect and probably has issues I can't foresee I am leaving my Lazarus IDE like this.  It will be very handy for me.  I really struggled trying to understand how to use an image as the stop recording macro part does.  I really wanted to wrap my head around that but I cant figure out where that stop image is being loaded. 


I would love to hear back if someone could test on Windows and Mac as I am curious if the file managers on those platforms will select the file.



 

TinyPortal © 2005-2018