Theme Configuration: Think about how to support OK/Cancel mechanism
Open, LowPublic

Description

The simple way is: editing colors directly changes the themes, without cancel / revert support.

However, what happens, if the user changes many colors / themes / hl text attributes for specific languages, and then presses Cancel?

Do we create a 2nd Repository, and modify this one, and on cancel just discard it, and on OK save, and then tell the global Repository to reload ?

To be discussed.

dhaumann created this task.Oct 8 2016, 7:22 PM
dhaumann renamed this task from Theme: Think about how to support OK/Cancel mechanism to Theme Configuration: Think about how to support OK/Cancel mechanism.
vkrause added a subscriber: vkrause.Oct 9 2016, 9:51 AM

One Theme instance contains everything user-editable, right? So the editor could work on a copy of the Theme instance, and only commit this back into Repository when saving I think. Or do you want to support more than one "unsaved" Theme at a time?

Hm. yes, we need to configure everything that is in one theme.

And since the itemDatas can be overwritten by themes, these custom changes to itemDatas are also part of the Theme, so yes, if I understand correctly, it's part of the theme.

It would be really nice to just copy the Theme, since we can easily discard or apply it then.

Does that require a Theme::clone(const QString & newName = QString()), since Theme::Theme(const Theme & copy) is just a sharing constructor?

Internally it's just a matter of calling m_data.detach() to get a deep copy. Could be done in setters or in an explicit copy/clone function, yes.

So there are two scenarios:

  1. The user configures an existing Theme.

The dialog opens, KTextEditor uses ::clone() to work on a copy. This copy is either discarded when the user clicks "Cancel", or this copy is applied though OK / Apply.
--> We could use a void Theme::swap(Theme other);

  1. The user wants to create a new Theme by copying an existing one.

The dialog opens, the user clicks copy (he specifies a new unique Theme name), then changes colors.
Now the user clicks "Cancel" -> everything is just discarded. Or the user clicks OK / Apply, then the newly created Theme needs to be saved to disk, and added to the Repository. Adding to Repo is either done through a Repo::reload(), or an explicit call of Repo::addTheme(Theme).

In summary, we need to add:

  • Theme Theme::clone() const;
  • void Theme::swap(Theme other);
  • void Repository::addTheme(Theme theme);

Is this correct? Or is the swap() thing ugly?