winmerge icon indicating copy to clipboard operation
winmerge copied to clipboard

Do not save compare options changed on the fly.

Open SamuelPlentz opened this issue 4 years ago • 12 comments

I usually want to compare everything:

  • all whitespace differences
  • all case sensitive differences
  • all empty line differences
  • all linebreak differences
  • all codepage differences
  • all comment differences

But in special cases I have to deactivate 1 or 2 rules (especially "whitespace" and "case sensitive") of that list. If I do this and restart Winmerge, the rules are still deactivated and I probably miss important differences.

I want to reset my compare options on each restart of Winmerge to my defaults. IMO other options are not affected.

What are your ideas to handle this use case? Is it even possible yet?

I propose to add an option and a button:

  • [x] Save compare options automatically

Save compare options now

Implementing note: Some options like "compare whitespace" can be changed on the fly. They need to be reverted as well.

SamuelPlentz avatar Oct 17 '20 23:10 SamuelPlentz

@sdottaka: I consider to create a pull request for this, but I don't want to start, before you comment on this. I am open for other ideas facing that issue.

SamuelPlentz avatar Oct 18 '20 12:10 SamuelPlentz

I agree with your idea, but I prefer all options, not just the comparison option.

FYI, you can call CRegOptionsMgr::SetSerializeing(false) to prevent the settings from being saved in the registry.

sdottaka avatar Oct 19 '20 00:10 sdottaka

I made a mockup, how it could look:

Winmerge

Colors and strings could be adjusted. I think it is a good idea to provide some kind of warning banner. Do you agree with the position (section General below the Language entry) and the additional banner?

I'm not sure about the strings.

Instead of: The option "save options automatically" is disabled. Changes are lost on restart.

It could be: As "save options automatically" is disabled, changes are lost on restart of Winmerge.

SamuelPlentz avatar Oct 19 '20 12:10 SamuelPlentz

Probably the banner should be yellow (warning) instead of red (error), because everything works like intended.

SamuelPlentz avatar Oct 19 '20 15:10 SamuelPlentz

Do you agree with the position (section General below the Language entry) and the additional banner? I agree with you. If the implementation is cumbersome, you can implement it by displaying a message box instead.

sdottaka avatar Oct 19 '20 23:10 sdottaka

I propose to make buttons presets on the toolbar for different options of user settings.

mrLithe avatar Oct 20 '20 05:10 mrLithe

Mh, my motivation to implement this is somewhat reduced, as I found a neat workaround suitable for me.

I use the newly introduced winmerge.ini from #248. Thank you! By adding the attribute readonly to that file, WinMerge uses it to read the options, but not to write them. That is exactly what I wanted and this works really well!

Probably this could even be improved like this: When starting WinMerge it first reads the file winmerge.ini and after that it reads the file winmerge readonly.ini. When closing WinMerge it only writes the file winmerge.ini.

Every option contained in the file winmerge readonly.ini would be reverted to its default. Other options would still be changed and saved. For example my winmerge readonly.ini would look like this.

[WinMerge]
Settings/IgnoreSpace=0
Settings/IgnoreBlankLines=0
Settings/IgnoreCase=0
Settings/IgnoreEol=0
Settings/IgnoreCodepage=0

Another name for the file could be winmerge defaultoptions.ini, winmerge defaults.ini, defaults.ini or something similar.

SamuelPlentz avatar Nov 30 '21 09:11 SamuelPlentz

I tried to look into an implementation. The right place should be in the code inserted in pull request #750, correct?

If I understand it correctly there is no read the whole file at startup (as I assumed). Instead if an option is needed it is queried (and cached for further use) from the file or from the registry directly.

So the plan should be adjusted to: When an option is read, one should first try to read it from winmerge readonly.ini and if that fails read it from winmerge.ini. Write it to winmerge.ini.

So the following code should be adjusted. If a winmerge readonly.ini file exists query that file first (another call to GetPrivateProfileString and an duplicated function GetFilePath returning the winmerge readonly.ini file path). If the result is empty query winmerge.ini (as already implemented).

String CIniOptionsMgr::ReadValueFromFile(const String& name)
{
	const int size = 100;
	LPWSTR buffor = new TCHAR[size];
	DWORD result = GetPrivateProfileString(lpAppName, name.c_str(), NULL, buffor, size, GetFilePath());
	return buffor;
}

Can you please confirm that a pull request like this would be included? Can you also clarify what name such a file should have? Currently I think defaults.ini is a good choice.

SamuelPlentz avatar Dec 01 '21 14:12 SamuelPlentz

WinMerge has a command-line option /inifile that specifies the path to the INI file.

For this reason, this option also needs to be changed to accept multiple INI files.

Instead, I prefer to store separate sections in the same INI file, as shown below.

winmerge.ini

[WinMerge]
....

[Defaults]
Settings/IgnoreSpace=0
Settings/IgnoreBlankLines=0
Settings/IgnoreCase=0
Settings/IgnoreEol=0
Settings/IgnoreCodepage=0

sdottaka avatar Dec 01 '21 23:12 sdottaka

Good idea to add another section to the winmerge.ini file. I had the /inifile command-line option in mind and wanted to duplicate it, but this approach is better.

I created the pull request #1071 to implement that behavior.

SamuelPlentz avatar Dec 06 '21 11:12 SamuelPlentz

I just tested the new "Defaults" section of the ini file in the current beta. Everything works as intended.

SamuelPlentz avatar Dec 20 '21 10:12 SamuelPlentz

As the corresponding feature has been implemented, I think this issue may be closed.

I would have preferred a less ambiguous name for the INI section, like "[Startup]" or "[Overrides]", but no biggie, as it is an "hidden, advanced feature", and nevertheless it works as it is.

vlakoff avatar Mar 01 '24 04:03 vlakoff