-
Notifications
You must be signed in to change notification settings - Fork 67
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
Scan for external color schemes and combine with the built-in ones #293
Scan for external color schemes and combine with the built-in ones #293
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a bit of rework is needed to bring this code more in line more with the IDE code conventions (String variable naming, use of braces, etc.). Otherwise, good work.
Could you also add a small section documenting this to the manual? (Documentation/English/Reference/ide_preferences.txt
)
PureBasicIDE/ColorSchemes.pb
Outdated
|
||
|
||
; These (from Preferences.pb) are used | ||
Global PreferenceToolsPanelFrontColor, PreferenceToolsPanelBackColor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variables that are needed in multiple files should be moved to Common.pb
. In a similar way, procedure declarations used outside of one file go in Declarations.pb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
PureBasicIDE/ColorSchemes.pb
Outdated
Protected Result.i = #True | ||
|
||
For i = 0 To #COLOR_Last | ||
If ((i <> #COLOR_Selection) And (i <> #COLOR_SelectionFront)) ; selection colors may follow OS, so skip them for scheme match check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove unneeded braces. Only add them when there are multiple And/Or statement to avoid ambiguity. Especially when there is only one statement, adding braces only reduces readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. In this highlighted example, would you remove just the outer parentheses, or all the parentheses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove all of them. Only use parentheses when they make a difference. The only exception to this is when And/Or are mixed in a statement because PB has a bit weird precedence rules here, so I tend to add them in this case just so it is clear to everybody what is happening.
PureBasicIDE/ColorSchemes.pb
Outdated
|
||
|
||
; Returns #True if the specified color scheme matches the user's current color settings, otherwise #False | ||
Procedure.i ColorSchemeMatchesCurrentSettings(*ColorScheme.ColorSchemeStruct) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integer is the default type. So adding it to procedure declarations is unneeded. The same goes for variable declarations.
The general style in the IDE sources is:
- Integer variables without any type declaration
- String variables always in the
Variable$
style - Float or double variables always with type (even outside of the declaration)
PureBasicIDE/ColorSchemes.pb
Outdated
|
||
; Color Scheme structure | ||
Structure ColorSchemeStruct | ||
Name.s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the Name$
style to declare string variables as it is done in the rest of the IDE sources.
PureBasicIDE/ColorSchemes.pb
Outdated
; Basic validation of color scheme file... | ||
If (OpenPreferences(File)) | ||
Name.s = GetFilePart(File, #PB_FileSystem_NoExtension) | ||
If (#True);(PreferenceGroup("Sections") And (ReadPreferenceLong("IncludeColors", 0) = 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you asking about the If (#True) ? I was doing some basic prefs validation there, but then I bypassed it to make the code more lenient in what it accepts as a color scheme file. The comment just shows what logic was formerly there. I can remove it completely or re-enable it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So either remove it or uncomment the original check. Leaving it as it is does not really make sense in the long term.
PureBasicIDE/ColorSchemes.pb
Outdated
EndIf | ||
|
||
If (*ColorScheme) | ||
With *ColorScheme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better readability, the With
statement should be avoided, especially in larger code blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
PureBasicIDE/ColorSchemes.pb
Outdated
If (*ColorScheme) ; struct already specified - part of InitColorSchemes() list | ||
; Intentionally overwrite schemes of existing names - allows you to tweak the default themes, if desired | ||
RemoveColorSchemeIfExists(Name) | ||
Else ; NULL --> dynamically allocate a struct now - NOT part of InitColorSchemes() list! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use of this code? I only see LoadColorSchemeFromFile()
being called with a valid pointer as input, so this code should not be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good detective work 🕵️ The option to load a scheme file SEPARATE from the initialization list is needed for another feature built off this fork, which I've already implemented and I'm using, but I don't know if it would be accepted into the official IDE. (The feature is I can define an External Tool as scheme://<file>
to instantly change to an arbitrary color scheme. scheme://<name>
also works if it's in the scanned list.) Is that OK or should I delete it from this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That change should be part of the other PR then, if and when it happens. Introducing code that might be used at some point in the future is a good way to generate dead code. I especially don't like this when it comes to pointer based code, because here correctness is especially important (bugs lead to a crash or memory leak easily). So we should focus only on code that is actually needed.
PureBasicIDE/ColorSchemes.pb
Outdated
If (DirectoryEntryType(Dir) = #PB_DirectoryEntry_File) | ||
File.s = PureBasicPath$ + #DEFAULT_ThemePath + #PS$ + DirectoryEntryName(Dir) | ||
Select (LCase(GetExtensionPart(File))) | ||
Case "prefs", "scheme", "theme", "ini" ; only attempt to load certain file extensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why allow so many different file extensions? We define the format for this, so we can also define what extension is to be used. In my opinion, prefs
alone is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again just trying to follow the "strict in what output you generate, but lenient in what input you accept" style. Yes it could only accept prefs
. I thought at least one other extension (scheme
?) would be nice so users could differentiate standalone color scheme files from true "IDE preferences" files.
I think a separate folder makes more sense. It may also be a good idea to move most of the existing themes out of the data sections and put them there as files as well:
I would leave just one scheme as builtin without a file (maybe the standard PB one). This ensures that the IDE always works even if somebody removes all the files. It is done the same way with the Icon themes as well. Maybe the "Accessibility" one should be treated separately as well. |
Thanks for all the thoughtful feedback.
If you're OK with it, sure we can move the default color schemes into external files which the user could modify or delete. I'll just leave the |
The word "Schemes" alone is too generic in my opinion and could mean many things. I think I'd call it "ColorSchemes" / "colorschemes", or maybe just "Colors" if you prefer it short. |
I vote for subfolder name |
If we plan to add more subdirs, it should be done in a 'IDE' dir or something, because it will mix up with other PB dirs |
If we make an I don't mind submitting "behind the scenes" IDE features, but restructuring subfolders seems like a bigger decision you should decide, not me... 🙂 I'll update this PR with whatever you prefer. |
Well, just go for the colorscheme subfolder, we will refactor it if there is more |
… the built-in ones
…her than 'Themes'
ecb1e72
to
c5e255f
Compare
Hi @t-harter @alphasnd , I pushed an update that hopefully addresses all of your feedback. They're small individual commits for easy review, but I can squash it all down again if everything looks good. Two caveats:
|
Looks good, thanks ! |
Here's an IDE feature I've wanted for a while...
In the Preferences window, we're given a list of Default Color Schemes, which come hard-coded in a DataSection.
We are able to distribute custom color schemes as
*.prefs
files, but it's a cumbersome process to usePreferences > Import Settings > Browse > Open > Include Color Settings > Import Settings
to change between them, especially if you use 2 or 3 often or at least light & dark.This PR adds the functionality to scan for external color scheme files, combine them with the built-in default themes, and present them all in the Preferences window dropdown list for easy scheme switching.
You can test with some of the
*.prefs
color schemes I have shared here or here. Drop them in your PBthemes
subfolder.Some info:
ColorSchemeStruct
containing an array of color values)ColorSchemes.pb
file. this actually reduces much code elsewhere in other files!PureBasicPath$ + #DEFAULT_ThemePath
(thethemes
subfolder) just like scanning for custom icon themes. perhaps this should scan a different/new subfolder?*.prefs
extension, but will also accept a few othersWith this basis, we could add more features such as: