Recent

Author Topic: Example projects window  (Read 59641 times)

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Example projects window
« Reply #90 on: February 21, 2022, 10:48:20 am »
Just remove the existing one as I initially suggested. I don't know why you want to keep it there.
OK, I'll do a fork, remove existing examples, replace it with my version of that directory and merge. A pull request or a diff file ?

Quote
I think online is the way to go. Supporting both local and online examples would be best.
Yep, thats what I'll do.

Quote
.... settings .... Tools->Options.
IdeIntf has an API for it. I can find an example package that already does it later. ToDoList maybe...
When you get a chance, yes please. But its not holding me up now.

What is holding me up right now is I cannot find a way to read the LazarusDirectory from a package. Must be possible but right now, I am considering reading LazConfDir/EnvironmentOptions.xml - and I'll watch to see who laughs !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

balazsszekely

  • Guest
Re: Example projects window
« Reply #91 on: February 21, 2022, 12:01:19 pm »
Quote
What is holding me up right now is I cannot find a way to read the LazarusDirectory from a package. Must be possible but right now, I am considering reading LazConfDir/EnvironmentOptions.xml - and I'll watch to see who laughs !
Nobody gonna laugh. You can read LazarusDirectory form EnvironmentOptions.xml like this:
Code: Pascal  [Select][+][-]
  1. uses LazIDEIntf, LazFileUtils, Laz2_XMLCfg;
  2.  
  3. function GetLazarusDirectory: String;
  4. var
  5.   XML: TXMLConfig;
  6.   ConfigPath: String;
  7. begin
  8.   Result := '';
  9.   ConfigPath := AppendPathDelim(LazarusIDE.GetPrimaryConfigPath) + 'environmentoptions.xml';
  10.   XML := TXMLConfig.Create(ConfigPath);
  11.   try
  12.     Result := XML.GetValue('EnvironmentOptions/LazarusDirectory/Value', '');
  13.     if Trim(Result) <> '' then
  14.       Result := AppendPathDelim(Result);
  15.   finally
  16.     XML.Free;
  17.   end;
  18. end;

also since the package is running inside the IDE:
Code: Pascal  [Select][+][-]
  1. LazarusDirectory := ExtractFilePath(ParamStr(0));
should be enough.

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Example projects window
« Reply #92 on: February 21, 2022, 01:11:28 pm »
OK thanks Getmem, I have just done something similar but, as I'd expect, yours is shorter and neater. I'll need to sit and have a good read of that, has stuff I am unaware of. TXMLConfig.  Sigh...

I'll skip the ParamStr(0) approach because its frowned upon in the Unix world. 

Thanks, I feel a lot better now (that I know no one is laughing) !

Davo  :D

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

PascalDragon

  • Hero Member
  • *****
  • Posts: 5755
  • Compiler Developer
Re: Example projects window
« Reply #93 on: February 21, 2022, 01:22:38 pm »
also since the package is running inside the IDE:
Code: Pascal  [Select][+][-]
  1. LazarusDirectory := ExtractFilePath(ParamStr(0));
should be enough.

If the Lazarus executable was rebuild to a different location, because the original location is readonly, this will not be true.

balazsszekely

  • Guest
Re: Example projects window
« Reply #94 on: February 21, 2022, 01:40:03 pm »
@PascalDragon
Quote
If the Lazarus executable was rebuild to a different location, because the original location is readonly, this will not be true.
The option dialog does the same(IDE/frames/file_options.pas):
Code: Pascal  [Select][+][-]
  1. LazarusDirComboBox.Items.Add(ProgramDirectoryWithBundle);  
where ProgramDirectoryWithBundle is a function in fileutil(lazutils), which uses function ProgramDirectory, which begins with:
Code: Pascal  [Select][+][-]
  1. Result:=ParamStrUTF8(0)


PascalDragon

  • Hero Member
  • *****
  • Posts: 5755
  • Compiler Developer
Re: Example projects window
« Reply #95 on: February 21, 2022, 01:44:59 pm »
But that dialog uses that only to fill in the suggestions.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: Example projects window
« Reply #96 on: February 22, 2022, 09:59:13 am »
The API should have a way to get LazarusDirectory directly. I think it is a missing feature.
Or does it impose some potential problem?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

balazsszekely

  • Guest
Re: Example projects window
« Reply #97 on: February 22, 2022, 10:49:21 am »
@JuhaManninen
Quote
The API should have a way to get LazarusDirectory directly. I think it is a missing feature.
Yes. LazarusIDE from LazIDEIntf already expose GetPrimaryConfigPath, shouldn't be too difficult to add LazarusDirectory.
Although in my opinion the best place to put LazarusDirectory is TIDEEnvironmentOptionsfrom form IDEOptionsIntf, which is the base class for TEnvironmentOptions

Quote
Or does it impose some potential problem?
No potential problem AFAICS. It's just a getter.

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Example projects window
« Reply #98 on: February 22, 2022, 11:39:08 am »
The API should have a way to get LazarusDirectory directly. I think it is a missing feature.
Or does it impose some potential problem?

Yes, I agree. If nothing else, I spent quite some time going through that API because I was sure it should show LazarusDirectory and must have been overlooking it. Perhaps, I thought, it has some other name ....

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: Example projects window
« Reply #99 on: February 22, 2022, 03:12:47 pm »
Quote
.... settings .... Tools->Options.
IdeIntf has an API for it. I can find an example package that already does it later. ToDoList maybe...
When you get a chance, yes please. But its not holding me up now.
Ok, ToDoList does not have it. All its settings are on the main GUI form.
Jedi Code Format package has it. The initialization section of unit frFiles has:
  RegisterIDEOptionsEditor(JCFOptionsGroup, TfFiles, JCFOptionFormatFile);

Please search for "RegisterIDEOptionsEditor" under Components directory. They are plenty.

Quote
What is holding me up right now is I cannot find a way to read the LazarusDirectory from a package. Must be possible but right now, I am considering reading LazConfDir/EnvironmentOptions.xml - and I'll watch to see who laughs !
Can you please add the LazarusDirectory getter. True, it should be in class TIDEEnvironmentOptions which is part of BuildIntf. This setting has no dependency for GUI and may be needed by cmd line tools as well.
Maybe GetPrimaryConfigPath and GetSecondaryConfigPath should be there, too, but that is another issue.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Example projects window
« Reply #100 on: February 23, 2022, 05:43:13 am »

Can you please add the LazarusDirectory getter. True, it should be in class TIDEEnvironmentOptions which is part of BuildIntf. This setting has no dependency for GUI and may be needed by cmd line tools as well.
Maybe GetPrimaryConfigPath and GetSecondaryConfigPath should be there, too, but that is another issue.

OK, TIDEEnvironmentOptions is defined in IDEOptionsIntf.pas And a var IDEEnvironmentOptions of that type is declared.

In ide/EnvironmentOpts.pp we  define
 TEnvironmentOptions = class(TIDEEnvironmentOptions)
and add the property LazarusDirectory, along with quite a lot of other useful stuff.

We then declare a var EnvironmentOptions of that type.

But in ide/BuildManager.pas we go backwards, we create the (EnvironmentOpts.pp)EnvironmentOptions var and assign it to the (IDEOptionsIntf.pas) IDEEnvironmentOptions var so losing access to LazarusDirectory.

Now, we cannot (easily) see either  ide/BuildManager.pas nor  ide/EnvironmentOpts.pp so need to get by with the quite uninformed  TIDEEnvironmentOptions.

From where I sit, it would make more sense to move "LazarusDirectory" to the parent, TIDEEnvironmentOptions, but that raises questions about the Get and Set functions.

Easier to add a "TheLazarusDirectory" (as a string ??, no such thing as an abstract property ? ) to TIDEEnvironmentOptions and do
    IDEEnvironmentOptions.TheLazarusDirectory  := EnvironmentOptions.LazarusDirectory;
in BuildManager, ugly IMHO.

So, must be a better approach, what ?

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

balazsszekely

  • Guest
Re: Example projects window
« Reply #101 on: February 23, 2022, 07:24:55 am »
@davo

It turned out that is already a function named GetParsedLazarusDirectory in EnvironmentOpts. I made it available for packages in trunk/main. Please use it like this:
Code: Pascal  [Select][+][-]
  1. uses IDEOptionsIntf;
  2.  
  3. var
  4.   LazarusDirectory: String;
  5. begin
  6.   LazarusDirectory := IDEEnvironmentOptions.GetParsedLazarusDirectory;        
  7.   //...
  8. end;

PS: Sorry for the confusion!
« Last Edit: February 23, 2022, 07:31:57 am by GetMem »

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Example projects window
« Reply #102 on: February 24, 2022, 01:16:45 pm »
@davo

It turned out that is already a function named GetParsedLazarusDirectory in EnvironmentOpts. I made it available for packages in trunk/main. Please use it like this:
Code: Pascal  [Select][+][-]
  1. uses IDEOptionsIntf;
  2.  
  3. var
  4.   LazarusDirectory: String;
  5. begin
  6.   LazarusDirectory := IDEEnvironmentOptions.GetParsedLazarusDirectory;        
  7.   //...
  8. end;

PS: Sorry for the confusion!

OK, that seems to work. Thanks Getmem, thats a lot tidier solution. I looked for a solution there but clearly did not have a good enough look. Will have to examine your handicraft.

Sorry I have been so slow to answer, discovering the joys of CamelCase in a case sensitive OS. Going to have to revisit my Examples list .....

Davos
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

PascalDragon

  • Hero Member
  • *****
  • Posts: 5755
  • Compiler Developer
Re: Example projects window
« Reply #103 on: February 25, 2022, 03:46:58 pm »
Sorry I have been so slow to answer, discovering the joys of CamelCase in a case sensitive OS. Going to have to revisit my Examples list .....

Yes, that's very much a joy. That's why Lazarus stores units by default as lowercase and FPC searches for as-is, lowercase and uppercase. ;)

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Example projects window
« Reply #104 on: February 27, 2022, 01:02:36 am »
Yes, its a cute issue.

Many examples have camelcase names, makes it heaps easier to understand so I wanted to preserve that. But that name also needs to be reflected in the project directory. So, I now require the spelling but not the case to match, and have a custom DirectoryExits function that is NOT case sensitive for the last term. Works ...

Juha, I have a forked Lazarus gitlab repo, it now contains my worked over ~/examples directory.  How do you suggest I submit that 'stage one' to Lazarus, as a pull request or an old school diff file ? 

I have the 'package' that provides the new Lazarus Examples Window all working nicely with local examples (instead of online as you suggested). All it needs now is to pick up its one necessary config item (alt place to store working examples) from the lazarus config system, you have sent me a pointer to do that so its just a matter of finding time.

But maybe a policy matter ?  Its currently called Online Examples (in, eg, the menu item).  As its not exclusively OnLine and may never be, is a different name appropriate ?  I don't want to call it "New Examples" and at some stage it will be old, any suggestions ?

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018