doug24 / ThemeEditor

A basic theme editor for dnGrep
GNU General Public License v3.0
0 stars 0 forks source link

Cannot actually find my new theme... #1

Closed DerellLicht closed 10 months ago

DerellLicht commented 10 months ago

I'm using VS2022 on Windows 10 Pro... I built this project, and copied Sunset.xaml to derelict.xaml to create a new working file... I initially placed derelict.xaml in both d:\apps\dnGrep\Themes (the install folder) and %appdata%\dnGrep\Themes and D:\SourceCode\Git\ThemeEditor\ThemeEditor\Themes (the source code/build folder)

and changed appTheme in App.xaml.cs to "derelict" but ThemeEditor fails with "System.IO.IOException: 'Cannot locate resource 'themes/derelict.xaml'.' "

I noticed that the path in the next line says UriKind.Relative, so I guessed that this was relative to the executable location?? I then tried changing it to: Resources.MergedDictionaries[0].Source = new Uri($"../../Themes/{appTheme}.xaml", UriKind.Relative); (which should be correct relative path from the debug build executable to the Themes folder), but it still cannot find the file...

What am I missing here??

DerellLicht commented 10 months ago

Okay, I changed to Absolute loading, and ran it again: Resources.MergedDictionaries[0].Source = new Uri($"D:/apps/dnGREP/Themes/{appTheme}.xaml", UriKind.Absolute); I've been reading up on Uri class, UriKind member, and this appears to be valid...

Now I get a different failure; System.Windows.Markup.XamlParseException: ''Initialization of 'System.Windows.Media.Imaging.BitmapImage' threw an exception.' Line number '134' and line position '6'.' Inner Exception FileNotFoundException: Could not load file or assembly 'dnGrep, Culture=neutral' or one of its dependencies. The system cannot find the file specified.

I'm guessing this means it now found my file, but something else is missing??

doug24 commented 10 months ago

d:\apps\dnGrep\Themes (the install folder)

This path is only for running in the portable version of dnGrep. Note that you need to fix the references to the 'pin' icons before running in dnGrep as shown in the Theme Editor readme.md file.

The Theme Editor doesn't dynamically load the theme files like dnGrep. For the Theme Editor, you should do two things: 1) add your new file to the project in the same directory as the existing themes 2) set the name as the active appTheme

image

The file properties for the new theme file should be automatically set correctly but just to verify:

DerellLicht commented 10 months ago

First, although I installed dnGrep from the .msi file, it is in fact using the path that I showed above, to find the theme files... when I originally put derelict.xaml in %appdata\dnGrep\Themes, the program did not see it... once I moved it to the install folder, dnGrep sees it properly, and uses it.

Second, I did do what you describe... put derelict.xaml in the editor themes folder, and when I ran the program, I got the errors that I described originally here... I only switched to Absolute because I could not get the program to find the file otherwise, no matter where I put it!!

DerellLicht commented 10 months ago

Okay, here I run the original, again... run error2

theme folder

doug24 commented 10 months ago

I don't know - I'll have to look at it again. I tried it before I replied the first time, and it is working that way for me.

Does the Theme Editor work with DarkBrushes, LightBrushes, and Sunset?

For the dnGrep runtime - I see you installed the *.msi in d:\apps, not in c:\Program Files. In that case, since the path is writable with Administrator rights then yes, it will load it from the Themes directory under the app folder.

DerellLicht commented 10 months ago

I don't know - I'll have to look at it again. I tried it before I replied the first time, and it is working that way for me.

Does the Theme Editor work with DarkBrushes, LightBrushes, and Sunset?

Ahh!! Yes, it does work with Sunset... interesting... I'll try making a change and saving, and see where it writes...

For the dnGrep runtime - I see you installed the *.msi in d:\apps, not in c:\Program Files. In that case, since the path is writable with Administrator rights then yes, it will load it from the Themes directory under the app folder.

That's cool, that's where I would prefer it anyway...

DerellLicht commented 10 months ago

Well, that didn't tell me much, because after I change a color and click SAVE, it doesn't actually save... so no files are updated, and next time I run TE, the original color is still there...

doug24 commented 10 months ago

Check the Readme for Theme Editor

When the color is modified, but not yet committed, click the Revert button to restore it to the previous value.

To commit the color change, click the Save button - this just saves it the runtime, not to file!

When you have a set of changes you want to keep, click the To Clipboard button, and the changed values are copied to the clipboard. Paste those lines back into the theme file, recompile, and restart the Theme Editor.

doug24 commented 10 months ago

I said it was rough :) I'll look at making the Save really work like it should - I can't remember if there was a reason for that or not. And maybe the file being edited should be separate from the project, too.

DerellLicht commented 10 months ago

Wow... that is definitely not how I expected a Windows program to work!! I didn't even read all the instructions, because I thought "I know how a Windows color editor is going to work..." ... Yikes!!

If you do decide to actually implement Save, could you look into implementing Open as well?? That should be a fairly trivial option... it would also completely eliminate the issue of the desired theme file not being found...

Separate question: when the help file says: "Paste those lines back into the theme file, recompile, and restart the Theme Editor." what does 'recompile' mean?? The theme file is a text file...

DerellLicht commented 10 months ago

I said it was rough :) I'll look at making the Save really work like it should - I can't remember if there was a reason for that or not. And maybe the file being edited should be separate from the project, too.

ummm... yeah!! The file being edited, should be the actual theme file...

DerellLicht commented 10 months ago

Another request: It would be really powerful if clicking on an element in the example window, would activate the relevant element in the element-selection list. I know how to do this in a WinAPI/C++ application, but no idea how to do it in C# ...

doug24 commented 10 months ago

Separate question: when the help file says: "Paste those lines back into the theme file, recompile, and restart the Theme Editor." what does 'recompile' mean?? The theme file is a text file...

In the current version of the Theme Editor, the theme files are embedded resources and get loaded from the ThemeEditor.exe. So, to get your previous changes the next time you start the Theme Editor, you have to compile it to update the embedded resources.

In dnGrep, the DarkBrushes and LightBrushes are embedded resources and Sunset is an external file loaded at runtime.

DerellLicht commented 10 months ago

Separate question: when the help file says: "Paste those lines back into the theme file, recompile, and restart the Theme Editor." what does 'recompile' mean?? The theme file is a text file...

In the current version of the Theme Editor, the theme files are embedded resources and get loaded from the ThemeEditor.exe. So, to get your previous changes the next time you start the Theme Editor, you have to compile it to update the embedded resources.

Actually, I think that explains why I couldn't load my new theme... ThemeEditor only has the three files compiled into it, if I understand what you are saying...

doug24 commented 10 months ago

Adding your new file to the project like I showed in my first reply in this thread should have made it so it would also get compiled and embedded. I don't know why it didn't...

DerellLicht commented 10 months ago

Adding your new file to the project like I showed in my first reply in this thread should have made it so it would also get compiled and embedded. I don't know why it didn't...

Oh... now I understand what is going on... the files get compiled into the program, and then are edited within the program... huh... that sounds like a convoluted way to do things, but I understand now...

Actually, I think what I'm going to do is use the editor just to select display colors that I want, then I'll just manually paste them into my theme file and run dnGrep to make sure that they look the same there, and be done with it... all the machinations to get changes back into the compiled program, probably aren't worth the trouble...

However, it would be good if you could fix the one issue that we've identified here, so if I wanted to make new themes in the future, I can start with a new file...

doug24 commented 10 months ago

I just updated the Theme Editor so the editable theme file is outside the build and will save back to the source file directly. New menu items are File - Open and File - Save. You can also load the Dark and Light themes to view them read-only from the File menu, then switch back to your edit theme file.

The readme on the main page has been updated.

DerellLicht commented 10 months ago

Excellent!! I'll check it out today!!

DerellLicht commented 10 months ago

Oops... load still failed on my theme... TE error derelict

I'll include my theme file here; this is the one I'm currently using in dnGrep. TE.derelict.theme.zip

doug24 commented 10 months ago

Just comment out the two bitmap images while editing in Theme Editor and then uncomment them when running in dnGrep.

    <!-- Toggle Button -->
    <!--<BitmapImage x:Key="pinBitmap" UriSource="/dnGrep;component/Images/pinDark.png" />-->
    <!--<BitmapImage x:Key="unpinBitmap" UriSource="/dnGrep;component/Images/unpinDark.png" />-->
DerellLicht commented 10 months ago

Excellent, thanks...

doug24 commented 10 months ago

I just pushed a few more changes:

Using one of the original dnGrep themes, click the Sync checkbox and select the Button.Default.Border. Adjust the button border color, and the group box borders will also be updated.

DerellLicht commented 10 months ago

That's cool!! In fact, with that box checked, when I adjust color of one element, all of the linked items all change color, live on the screen!! That is very cool!!

DerellLicht commented 10 months ago

Is there any chance of modifying the Theme Editor to avoid the BitmapImage error that I documented above?? I modified my theme like this:

    <!-- Toggle Button -->
    <!-- 
    <BitmapImage x:Key="pinBitmap" UriSource="pack://application:,,,/dnGrep;component/Images/pinDark.png" />
    <BitmapImage x:Key="unpinBitmap" UriSource="pack://application:,,,/dnGrep;component/Images/unpinDark.png" />
    -->

and while that works well enough - I just cut-and-paste the closing comment to be before or after the BitmapImage lines, it still requires me to keep the theme file in my editor while I'm editing in ThemeEditor; not the end of the world, but not very clean!!

DerellLicht commented 10 months ago

One other question: what is the purpose of the scrolling green bar on the Status Bar, right next to the word 'Ready!' ?? It doesn't really seem to serve any purpose... at first I thought it was saying that it was busy loading or something, but it just seems to always be there...

doug24 commented 10 months ago

The bitmap resources were added after I stopped using the Theme Editor 5 years ago. If I knew the problems they created, I would have put a boolean flag in instead of the actual images to select the light vs. dark images. I don't know of any way around the problem because loading the xaml file loads all the resources and puts them in a dictionary. I don't have a way of filtering all the resources with the API I'm using. Maybe there is some low-level API to load each resource individually.

The scrolling green bar is just another sample control to allow you to adjust the colors: ProgressBar.*

DerellLicht commented 10 months ago

Oh my... okay, well I can live with it, it's just odd!! If anyone else tried to use the editor, they would probably be back with all the same questions that I had - but then, it sounds like I'm the only user, so we're fine!!

And the progress bar... HAH!! Yeah, I shoulda been able to figure that one out...

Anyway, I am very pleased with the editor in its current state!! Thank you so much for your prompt, effective support!!

DerellLicht commented 10 months ago

and I think we are finished with this thread... Theme Editor is hot now!!

doug24 commented 9 months ago

@DerellLicht In the February release of dnGrep (next week) I made two breaking changes to the theme files based on the problems with the Theme Editor:

1) The key "GradientBackground" is changed to "Window.Background"

2) The Pin and Unpin bitmaps have been removed from the theme file and replaced with this:

    <sys:Boolean x:Key="ToggleButton.DarkImages">true</sys:Boolean>

Now you can use the same file in the same location for both the Theme Editor and dnGrep.

I have updated the Theme Editor to use .NET 8, to match dnGrep, and put a release package in github. I added three new controls to the Theme Editor:

DerellLicht commented 9 months ago

Excellent!! I will definitely test out both as they become available! It will certainly be wonderful to not have to edit the files back and forth; makes it accessible to far more people!!

I have definitely been happy with my Deviant Dark theme that I've been using on dnGrep...

DerellLicht commented 9 months ago

hmmm... okay, there's something I don't understand here... I did the following steps:

  1. go to the ThemeEditor folder in my Git repository, and ran 'git pull' ... It appeared to update everything properly.
  2. download and install .NET 8.0 SDK, Windows x64 installer
  3. double-click on ThemeEditor.sln to load project... file date is 02/11/24 1809, which sounds current,
  4. Visual Studio 2022 load failed with: D:\SourceCode\Git\ThemeEditor\ThemeEditor\ThemeEditor.csproj : error : The SDK 'Microsoft.NET.Sdk' specified could not be found. D:\SourceCode\Git\ThemeEditor\ThemeEditor\ThemeEditor.csproj

I... ummm... don't know what to do here; I installed that SDK... I thought??

Sadly, I'm not familiar with Visual Studio; I use MinGW toolchain for my builds (which don't support c#)

Help?

doug24 commented 9 months ago

I don't install .NET 8 SDK separately, so I don't know what is wrong there. In the Visual Studio Installer, I have the .NET "workload" installed, update to the latest version, and it takes care of installing everything needed.

Select this in the Visual Studio Installer - you can make changes to your Visual Studio installation at any time:

Or, you can now just download the V1.1.0 release from the Theme Editor github page and skip building it.

DerellLicht commented 9 months ago

Hah!! At this point, the executable is actually all I need!! I'll download that now, then look into getting the .NET desktop addons installed into Visual Studio... I think I want to check out doing console development with C# and .NET; I noticed that there's a tutorial for that on the .NET web page...

DerellLicht commented 9 months ago

It turns out that I already have .NET 8 SDK installed within Visual Studio, but the project still doesn't see it...

I've been doing some reading online, and there were hints that the error that I'm getting can be caused if one Installs some components in non-default locations; I did that, because I have relatively low available storage on C:, but have a 4TB D: SSD... the article said I need to change locations in the project files, but I don't see anything in either your .sln nor your .csproj, that have anything to do with these locations...

For now, I'm just going to run with the released executables; thank you for releasing that package! When I get ready to pursue C# in Visual Studio, I'll take up this issue on the VS support forums...

DerellLicht commented 9 months ago

Both of these tools are now seriously professional tools!! Thank you again for all of your support and efforts... BTW, you might want to think about including ThemeEditor along with dnGrep... the main package is 72MB, the theme editor is only 6.5MB... it would be an inconsequential impact on size...

Another thing you might look into, if you have a little time, especially if you include the editor with the main app, is putting together an executable installer; I've used Inno Setup before, it is free, easy to learn, super configurable... https://jrsoftware.org/isinfo.php

Then you could have the installer create a Programs menu entry, with links to dnGrep, editor, and the readme file!!

However, I am utterly impressed and content with what you have now!!!!

doug24 commented 9 months ago

Thank-you!

I'd like to see the Theme Editor with a linear gradient brush editor before making it more widely available.

Installers are my least favorite part of app development, and I have something working now, so I'm reluctant to change. I haven't used Inno Setup before, but it is available on the AppVeyor build server where we do the dnGrep builds. I also wonder if changing to a different installer would make a discontinuity between versions?

DerellLicht commented 9 months ago
  1. Theme Editor At this point, the editor is a fully-functional application... I feel that it could be released with pride at this point... A new feature like the linear gradient brush editor, when added later, would just be a version upgrade...

Also, I still think that it would be more intuitive, if user could click on an element in the example dialog (left pane), and have the editor jump to the relevant item in the center pane; that would be more accessible than reading through the names and trying to figure out what name goes with what element... and yeah, I know that adds alot of work, since you would have to trap left-click messages for all of the elements - I've done this in Windows applications...

In any case, having said that, now that you've renamed the oddly-named fields, this isn't a show-stopper, just a nice-to-have... it could also just be a version upgrade later...

  1. Installers Okay, this was an oversight on my part! I forgot that you already have an installer!! I've been downloading the zip file, which is a manual install... no, if you already have an installer, there's no reason to change, unless you are dissatisfied with the current one for some reason. Also, you mentioned using a build server; I have no experience with integrating Inno Setup into a build server, so no idea what that might require. It's probably just as well to stick with what you've got.

  2. one more item: field naming This is very minor, just a passing comment... You've renamed several other ambiguously-named fields, which is very good... There is one more that you might wish to reconsider: AvalonEdit ... I presume that is the name of an after-market library that you use for the code-example pane??
    That library name shouldn't really be an outward-facing name - it won't mean anything to the user... When I was initially using the editor, I just ignored that group. Maybe rename to something like CodeExamplePane or something...