Recent

Author Topic: Question about bookmarks in editor  (Read 1458 times)

whiffee

  • New member
  • *
  • Posts: 16
Question about bookmarks in editor
« on: August 27, 2018, 04:46:06 pm »
Hi All,
Under Project>Project_Options>Session there is the checkbox for 'Save in .lps file in project directory.' I have this (default location) checked.  If I open the .lps I see the bookmarks and locations. So if I move my .pas, .lfm, .lpr, and .lps to a different directory and open the project, I would expect to get my bookmarks back. It doesn't happen, why not?

(version 1.84)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4949
    • wiki
Re: Question about bookmarks in editor
« Reply #1 on: August 27, 2018, 05:38:38 pm »
Files are identified with their relative path to the project file.

So if you move the entire project, then this should (mostly / see below) work.

If you move just one file, well it depends.
1) If you move it outside the IDE, then the IDE just does not know
2) not tested: If you do "save as", then the IDE should know (and it might ask you if it should delete the old file)

Just open the lps in a text editor:

Code: [Select]
      <Unit10>
        <Filename Value="frames\editor_indent_options.pas"/>
        <IsPartOfProject Value="True"/>
        <Bookmarks Count="1">
          <Item0 X="1" Y="513" ID="6"/>
        </Bookmarks>
      </Unit10>
You can see the relative path.

As far as I can see, units from packages, are also stored with relative path. This means that if you move the entire project, units in packages will not be found in the session. But the package is still there. (And the project still compiles).
IMHO package files should be referred in a more clever way... So for files in packages there may be a bug. (not tested)

Also note, that when you put units in your "uses" clause, the compiler will find all files in the project dir (or any additional search path you have given). But when you add new files, you should do so in the IDE, and make sure that they are part of the project (see project inspector). Otherwise the IDE may handle them differently (not sure when it matters)

whiffee

  • New member
  • *
  • Posts: 16
Re: Question about bookmarks in editor
« Reply #2 on: August 27, 2018, 06:20:32 pm »
Okay, I am a little better off. A short .lps file:
Code: Pascal  [Select]
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <CONFIG>
  3.   <ProjectSession>
  4.     <Version Value="10"/>
  5.     <BuildModes Active="Default"/>
  6.     <Units Count="2">
  7.       <Unit0>
  8.         <Filename Value="project1.lpr"/>
  9.         <IsPartOfProject Value="True"/>
  10.         <EditorIndex Value="-1"/>
  11.         <UsageCount Value="34"/>
  12.       </Unit0>
  13.       <Unit1>
  14.         <Filename Value="unit1.pas"/>
  15.         <ComponentName Value="Form1"/>
  16.         <HasResources Value="True"/>
  17.         <ResourceBaseClass Value="Form"/>
  18.         <UnitName Value="Unit1"/>
  19.         <IsVisibleTab Value="True"/>
  20.         <EditorIndex Value="-1"/>
  21.         <TopLine Value="2621"/>
  22.         <CursorPos X="47" Y="2635"/>
  23.         <UsageCount Value="17"/>
  24.         <Bookmarks Count="3">
  25.           <Item0 X="2" Y="2563" ID="1"/>
  26.           <Item1 X="6" Y="1629" ID="3"/>
  27.           <Item2 X="26" Y="4952" ID="2"/>
  28.         </Bookmarks>
  29.       </Unit1>
  30.     </Units>
  31.     <General>
  32.       <ActiveWindowIndexAtStart Value="-1"/>
  33.     </General>
  34.     <JumpHistory HistoryIndex="-1"/>
  35.   </ProjectSession>
  36. </CONFIG>          

It only shows 2 units. The bookmarks are listed under Unit 1. Unit 1 is already listed in the Uses section of the .lpr file. Is there a change to a Uses clause that would bring the .lps and its bookmark information into view?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4949
    • wiki
Re: Question about bookmarks in editor
« Reply #3 on: August 27, 2018, 06:48:01 pm »
When you open the project, does the IDE open an editor for the unit1? (That is, is there a tab for unit1?)
If it does, does it set the "topline" (first line, scrolled to) 2621?


If yes, then the session should work.

If no, then try the below:
There may be an issue with the session file, but I am not sure (and not sure how it could have happen);
"  <EditorIndex Value="-1"/>" makes no sense for unit 1.
Remove this line from the file.

whiffee

  • New member
  • *
  • Posts: 16
Re: Question about bookmarks in editor
« Reply #4 on: August 28, 2018, 03:37:19 am »
(After moving around most of the day, I'm back at a terminal now.)

I lost the last .lps file while doing some experimenting, below is a replacement from the same project:
Code: XML  [Select]
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <CONFIG>
  3.   <ProjectSession>
  4.     <Version Value="10"/>
  5.     <BuildModes Active="Default"/>
  6.     <Units Count="4">
  7.       <Unit0>
  8.         <Filename Value="project1.lpr"/>
  9.         <IsPartOfProject Value="True"/>
  10.         <EditorIndex Value="-1"/>
  11.         <CursorPos X="15" Y="10"/>
  12.         <UsageCount Value="21"/>
  13.       </Unit0>
  14.       <Unit1>
  15.         <Filename Value="unit1.pas"/>
  16.         <ComponentName Value="Form1"/>
  17.         <HasResources Value="True"/>
  18.         <ResourceBaseClass Value="Form"/>
  19.         <UnitName Value="Unit1"/>
  20.         <EditorIndex Value="-1"/>
  21.         <WindowIndex Value="-1"/>
  22.         <TopLine Value="348"/>
  23.         <CursorPos X="37" Y="393"/>
  24.         <UsageCount Value="10"/>
  25.         <Bookmarks Count="5">
  26.           <Item0 X="49" Y="35" ID="9"/>
  27.           <Item1 X="13" Y="129" ID="1"/>
  28.           <Item2 X="31" Y="193" ID="2"/>
  29.           <Item3 X="29" Y="300" ID="3"/>
  30.           <Item4 X="15" Y="409" ID="4"/>
  31.         </Bookmarks>
  32.       </Unit1>
  33.       <Unit2>
  34.         <Filename Value="project1.lps"/>
  35.         <IsVisibleTab Value="True"/>
  36.         <TopLine Value="14"/>
  37.         <CursorPos X="31" Y="53"/>
  38.         <UsageCount Value="10"/>
  39.         <Loaded Value="True"/>
  40.         <DefaultSyntaxHighlighter Value="XML"/>
  41.       </Unit2>
  42.       <Unit3>
  43.         <Filename Value="projec.lps"/>
  44.         <EditorIndex Value="-1"/>
  45.         <TopLine Value="21"/>
  46.         <CursorPos X="64" Y="48"/>
  47.         <UsageCount Value="10"/>
  48.         <DefaultSyntaxHighlighter Value="XML"/>
  49.       </Unit3>
  50.     </Units>
  51.     <JumpHistory HistoryIndex="-1"/>
  52.   </ProjectSession>
  53. </CONFIG>
  54.  

(I notice it has the same -1 index value, but this does not seem to be consistent.)

I should mention that I do have a habit of sticking the three basic files into a new directory at regular intervals, in order to keep strict version control. Doing this often is why I'm interested in trying to preserve bookmarks. If I could change a path or a uses clause, it would be great.

I already have a workaround, which I may as well describe. If I copy all the project files, i.e. the .pas, .lfm, .lps, .lpr, and .lpi files to a new directory, then I can get the bookmarks back, though it takes a little trick. The trick is this. When the project opens, right-clicking for a pop-up menu and then selecting Goto Bookmark shows an empty list. However, the bookmark balloons in the margin can still be seen. So I just un-toggle one of those, then retoggle it, and after that all the bookmarks can be seen when looking at the Goto Bookmark menu. But I'm interested in an easier way if there is one.

« Last Edit: August 29, 2018, 10:47:43 pm by whiffee »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4949
    • wiki
Re: Question about bookmarks in editor
« Reply #5 on: August 28, 2018, 12:26:01 pm »
If they are in the gutter (margin) but not in the menu, then that is a bug. Please report it.

I am not sure about the EditorIndex, I have to play around with it when I have more time.

whiffee

  • New member
  • *
  • Posts: 16
Re: Question about bookmarks in editor
« Reply #6 on: August 29, 2018, 12:19:50 am »
@Martin_fr/The sample I uploaded to the report was not actually affected, sorry about that.  :-\The problem is not as prevalent or as general as I believed. From a project instance that does have the problem I copied the five relevant files and put them in a new directory, then found that the IDE performed correctly when the new instance was opened. This seemed very odd. I put the .lps files from both locations into Meld and compared them. Without any editing or intervention the copied version (the one on the right in the attached) has changed and apparently repaired itself. 

I can't say I understand what is happening, but it seems more familiar now.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4949
    • wiki
Re: Question about bookmarks in editor
« Reply #7 on: August 29, 2018, 04:19:28 am »
It will be a while till I can look into this in depth.

I will have to find when/why the IDE writes the -1. I suspect this happens, when the file was moved by you, and is not found (it may for some reason be found again at a later time).
Some of this may be correct behaviour (although it may have room for improvement)


The 2nd is the inconsistency between what is shown in the gutter, and what is in the menu.
This is clearly wrong. It should either be both or none.
The "Loaded" line may be a hint. If the IDE believes it has not loaded the unit (because maybe the path did not match) then it would not know the bookmarks. But that leaves the question how the gutter knows.


Btw, something to look out for.
The same bookmark can be in 2 or more units.
- IF you set bookmark 1 to unit 1.
- close unit 1
- set bookmark 1 to unit 2.
IIRC the IDE will still know about unit1, and if you close unit2 before opening unit1 again, then it will be restored.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4949
    • wiki
Re: Question about bookmarks in editor
« Reply #8 on: October 31, 2018, 06:45:31 pm »
Please check the updates/questions on https://bugs.freepascal.org/view.php?id=34194#c111709

Especially pay attention to:
Quote
Note: Bookmarks for any file in the session that is NOT open in any editor, are not present in the IDE (not in the menu, no key-shortcut, no other reference). This has been like this before, and is by design.
Quote
Please verify, that any bookmark "lost" while copying a project to a new directory, is only checked/expected to exist, if the file (in which it is set) is open in an editor.

----------------------------
I noted from your session, that all editors are closed for your project. Why would that be?

If all editors are closed, then there would/should be no bookmarks in the menu.
Bookmarks will be (re-)added to the menu, when you open files. The bookmarks will only appear after you open the file in which they are.

Check, if after applying the fix in revision 59402, you still "loose" bookmarks (that is they are missing, even though you have the file open in an editor).

If they are still missing, check if the file has a different relative path in your session. The file must be in the same relative folder to the project dir, as it was before.

----------------
About the fact that all your editors are closed:
I suspect you may be using "Close all" from the file menu. Maybe you are trying to close the project?
"Close all" from the file menu, only closes the editors. The project will still be open.

The only way to close the project, is by opening another project. Or in the project menu, use "Close Project", which will force you to open a new project.

When you start the IDE, it will always open a project. You can specify in the option, if it should open the last project, or if it should open a new empty project. But it will open a project, there is no way to prevent this.

If you start the IDE, after you had before done "Close all", it will still open the project, you will just not see any units in any editor.

You can always check, via "project inspector" from the project menu. You will also see, that "run" will still run your project.

-------------
I also noted, that for some reason unit1 is not part of the project. That is no problem, but you may want to go to the project inspector and add it anyway (this is not related to any bookmark behaviour)