Verify modes of the session config file
ClosedPublic

Authored by nibags on Tue, Nov 19, 7:17 AM.

Details

Summary

The session config file $HOME/.config/katemetainfos stores the mode of the last open files. However, it may contain invalid or non-existent modes, for example, when applying an highlighting mode of a custom XML file that will be renamed or deleted. Therefore, a verification is added, only existing modes will be applied.

Changes:

  • The KTextEditor::DocumentPrivate::updateFileType() function now returns a boolean, which is false if the mode name entered in the parameter doesn't exist or is invalid.
  • Modes with empty names are considered invalid, since KateModeManager::fileType(const QString &name) returns an empty KateFileType object if the name of the parameter doesn't exist. It's understood that the name of a mode shouldn't be empty, since it acts as a unique identifier.
  • When reading the session config file (KTextEditor::DocumentPrivate::readSessionConfig()), it's checked if the stored mode is valid. If the mode is invalid, it will not be applied and the default mode will be used, depending on the file extension or MIME-type.
Test Plan

TEST 1:

  1. Create a custom XML highlighting file, which we will call "TestMode".
  2. Open any file, for example $HOME/test.c.
  3. Apply the mode "TestMode". Now, when the file is opened, the "TestMode" mode will be used by default.
  4. Close Kate and delete the custom XML file of "TestMode" or rename the definition name.
  5. Reopen test.c. Now the "TestMode" mode is invalid:

    Before: The "Normal" mode was used and an empty string was displayed as the mode name in the status bar.

    Now: The default mode, defined by the file extension or MIME-type, is used.

TEST 2:

  1. Open any file, for example $HOME/test.c.
  2. Open $HOME/.config/katemetainfos, search for the previous file and modify the value of Mode=, by entering an invalid or empty one.
  3. Reopen test.c

Diff Detail

Repository
R39 KTextEditor
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
nibags created this revision.Tue, Nov 19, 7:17 AM
Restricted Application added projects: Kate, Frameworks. · View Herald TranscriptTue, Nov 19, 7:17 AM
Restricted Application added subscribers: kde-frameworks-devel, kwrite-devel. · View Herald Transcript
nibags requested review of this revision.Tue, Nov 19, 7:17 AM
nibags edited the summary of this revision. (Show Details)Tue, Nov 19, 7:21 AM
nibags edited the test plan for this revision. (Show Details)
nibags added reviewers: KTextEditor, cullmann, dhaumann.
cullmann accepted this revision.Tue, Nov 19, 12:14 PM

Sounds reasonable, code looks better, too!
Thanks!

This revision is now accepted and ready to land.Tue, Nov 19, 12:14 PM
This revision was automatically updated to reflect the committed changes.