Skip to content

Add new "Re-run compilation..." menu item (2nd PR) - #5111

Merged
kduske merged 9 commits into
TrenchBroom:masterfrom
1000nettles:add-rerun-compilation-menu-item-incremental
Mar 7, 2026
Merged

kduske merged 9 commits into
TrenchBroom:masterfrom
1000nettles:add-rerun-compilation-menu-item-incremental

Conversation

@1000nettles

Copy link
Copy Markdown
Contributor

This is the second PR for the "Re-run compilation..." menu item addition, but with incremental commits showcasing the individual features added. I'll copy and paste some of the relevant details from the previous PR. Original PR can be found here.


This PR addresses some of the discussion in #1971.

Something to note: functionality that's missing from your comment is "or the first compilation profile if no profile has been run yet". Determining what the first profile is and keeping that in sync added some complexity which (to me) felt overkill, and instead I went with the flow outlined below. If you'd like me to add this in though, I can probably find an elegant way to do it.

  • We added a new "Re-run compilation" menu item which changes based on context, inspired by the logic found within the "Undo" menu item
  • This menu item transforms based on if there is a compilation profile which was previously run. It remains disabled if it has not recorded one ever being run
  • If a re-run was attempted and could not be found, the stored settings value is removed, and thus the menu item is "reset" to its disabled state until another compilation run is attempted
  • The solution may be overkill with using optional in here. I did it because I tested and technically you can have a compilation profile as an empty string which throws off if there's a valid compilation profile or not. So, in the end we deal with null vs. any string at all. Happy to change this if you don't want optional in here

@kduske kduske left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for splitting this up! Reviewing the individual commits was much easier. I left a bunch of comments, please have a look. Hope I'm not too nitpicky...

Comment thread lib/TbUiLib/include/ui/CompilationProfileManager.h Outdated
Comment thread lib/TbUiLib/src/CompilationProfileManager.cpp Outdated
Comment thread lib/TbUiLib/src/MapWindow.cpp Outdated
Comment thread lib/TbUiLib/include/ui/MapWindow.h Outdated
Comment thread lib/TbUiLib/src/MapWindow.cpp Outdated
Comment thread lib/TbUiLib/include/ui/CompilationDialog.h Outdated
Comment thread lib/TbUiLib/src/MapWindow.cpp Outdated
1000nettles added a commit to 1000nettles/TrenchBroom that referenced this pull request Mar 1, 2026
* Fixed bad newline removal changes
* Refactored `selectProfileByIndex` into `selectProfileByName`. This encapsulates more
  logic for finding a profile within the manager, rather than having CompilationDialog
  do the heavy-lifting.
* Adjusted method order in CompilationProfileManager.h.
* Simplify validity logic in `loadLastCompilationProfileName` by using
  a ternary.
* Rename signal `compilationProfileUsed` to `compilationProfileStarted` to
  avoid the use of the vague word "used".
@1000nettles

Copy link
Copy Markdown
Contributor Author

Thanks for splitting this up! Reviewing the individual commits was much easier. I left a bunch of comments, please have a look. Hope I'm not too nitpicky...

Not nitpicky at all, thanks for being thorough. Sorry about the newline changes, I think I need to adjust the formatter in CLion. The feedback has been addressed in the latest commit, happy to make any other changes before merge. 😄

@kduske

kduske commented Mar 2, 2026

Copy link
Copy Markdown
Collaborator

Please create individual fixups for the changes I requested so that they get squashed into the correct commits. I'd like to keep the history nice and clean instead of putting a cleanup commit on top.

@kduske

kduske commented Mar 2, 2026

Copy link
Copy Markdown
Collaborator

Thank you for addressing my feedback, the changes look good!

@1000nettles
1000nettles force-pushed the add-rerun-compilation-menu-item-incremental branch from 881e225 to e6d749b Compare March 3, 2026 01:21
@1000nettles

Copy link
Copy Markdown
Contributor Author

Thank you for addressing my feedback, the changes look good!

No problem and great! I have broken up the individual fixups as individual commits and removed the "PR cleanup" commit.

@kduske

kduske commented Mar 3, 2026

Copy link
Copy Markdown
Collaborator

Thank you for addressing my feedback, the changes look good!

No problem and great! I have broken up the individual fixups as individual commits and removed the "PR cleanup" commit.

Sorry, this isn't what I meant. I meant to reduce the total number of commits back down by creating fixup commits that we can then squash before merging. For example, the commit history now adds a selectProfileByIndex function, only to replace it with a selectProfileByName function a couple of commits later. That makes no sense, why not introduce selectProfileByName in the first place?

The idea is to have the history reflect the "ideal" path to the outcome and not the steps that you did as a developer. Rather imagine if you had to redo the PR but with 20/20 hindsight.

@kduske

kduske commented Mar 3, 2026

Copy link
Copy Markdown
Collaborator

If you feel this is too much trouble to go through that is fine, for a PR as small as this it would also be OK to squash everything into one commit. But I'd prefer to have a nice history.

@1000nettles

Copy link
Copy Markdown
Contributor Author

Ah okay sorry about that! I get what you're after now. I'm happy to go back and rewrite the commits, I'll do that this evening.

@1000nettles
1000nettles force-pushed the add-rerun-compilation-menu-item-incremental branch from e6d749b to e3fd695 Compare March 4, 2026 00:59
@1000nettles

Copy link
Copy Markdown
Contributor Author

@kduske I have completed the fixups in 4 clean commits. Note that I ended up just taking all of the changes and making 4 fresh commits based on the relevant hunks in each file, as some of the commits to be fixup'd were straddling multiple base commits.

Regardless, the spirit of what you're asking for should be here.

@kduske
kduske force-pushed the add-rerun-compilation-menu-item-incremental branch 2 times, most recently from 8f70953 to 9307574 Compare March 5, 2026 18:12
@kduske

kduske commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator

@1000nettles To speed things up, I have pushed a bunch of fixups to make some changes:

  • Disable the menu item when no profile with the stored name can be found instead of opening the dialog and doing nothing.
  • Don't clear the last used profile name if no item can be found since it cannot bother us.
  • Don't select profiles by name, just find the profile and select it.
  • Add a separator before the Re-run menu item.
  • Minor style nitpicks.

Please take a look at my changes and test it a bit. I hope I haven't broken anything! I might push some additional tests later.

@kduske
kduske force-pushed the add-rerun-compilation-menu-item-incremental branch from 9307574 to 8d484a5 Compare March 5, 2026 20:40
@kduske

kduske commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator

I have pushed a preparation commit that adds a few tests for CompilationProfileManager and then a fixup that adds a test for the new selectProfile function.

@1000nettles 1000nettles left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes make sense and generally look good, other than the styling issue I mentioned!

With regards to "Don't clear the last used profile name if no item can be found since it cannot bother us.", this is fine but just FYI the old profile name will still be displayed in the disabled menu item:

Image


auto* addProfileButton = createBitmapButton("Add.svg", "Add profile");
m_removeProfileButton = createBitmapButton("Remove.svg", "Remove the selected profile");
addProfileButton->setObjectName("CompilationProfileManager_AddProfileButton");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these object name changes are causing issues with the styling of these buttons. The initial object name (I think) is "toolButton_borderless" and set in lib/TbUiLib/src/BitmapButton.cpp, which is used for styling purposes. Here's how the compilation dialog looks on my machine:

Image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I missed that. It should be fixed now.

@kduske
kduske force-pushed the add-rerun-compilation-menu-item-incremental branch from dbecf6f to fc93463 Compare March 6, 2026 19:01
@kduske

kduske commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

The changes make sense and generally look good, other than the styling issue I mentioned!

With regards to "Don't clear the last used profile name if no item can be found since it cannot bother us.", this is fine but just FYI the old profile name will still be displayed in the disabled menu item:

Yep, I actually like it this way because it gives the user a chance to understand why the Re-run" action is greyed out. They can go into their Compile dialog and check whether the profile is available.

@kduske

kduske commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

@1000nettles I think everything works now. Could you give this one last test, too?

kduske added 2 commits March 6, 2026 20:04
We want to write tests for some classes that want to load image resources, so we
copy these resources to make them available.
@kduske
kduske force-pushed the add-rerun-compilation-menu-item-incremental branch from fc93463 to 4aac2e9 Compare March 6, 2026 19:04
@1000nettles

Copy link
Copy Markdown
Contributor Author

@1000nettles I think everything works now. Could you give this one last test, too?

Looks like the builds are failing. I also tried on my local machine and they're failing on the same issue.

kduske added 2 commits March 6, 2026 23:31
This allows us to use the object names to identify widgets in tests.
1000nettles and others added 5 commits March 6, 2026 23:31
We will use this function a later commit to pre-select a compilation profile and
then run it.
…gnal

selectAndRunProfile can be used to re-run the last used compilation profile in a
future commit. The signal is used to store the name of the last used compilation
profile.
We want to add a menu item to re-run the last used compilation profile, so we
need to remember the name of that profile. We use QSettings to persist this
across restarts.
We add a new menu item to re-run the last used compilation profile based on the
name that we stored. If no such profile can be found (because it has been
renamed or deleted or we are now using a different game), then the menu item is
disabled.
@kduske
kduske force-pushed the add-rerun-compilation-menu-item-incremental branch from 4aac2e9 to 2be3a3b Compare March 6, 2026 22:31
@kduske

kduske commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

@1000nettles I think everything works now. Could you give this one last test, too?

Looks like the builds are failing. I also tried on my local machine and they're failing on the same issue.

Yeah I missed an include. It's fixed now.

@1000nettles

Copy link
Copy Markdown
Contributor Author

@kduske nice - everything's looking good! The changes are working as expected, and the button styling is fixed. 🙂

@kduske

kduske commented Mar 7, 2026

Copy link
Copy Markdown
Collaborator

Thank you for testing it again, and for your contribution!

@kduske
kduske merged commit ec74dad into TrenchBroom:master Mar 7, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants