Friday, March 8, 2013

Capture Modified Line Upon Saving

If the edit box has a modified line, it needs to be reported before the program is saved.  This is accomplished by calling the capture modified line routine (currently called when the cursor is moved from a modified line) in the save program routine.  This required the capture function to be made public.  This function already contains a check if there is a modified line before reporting a change, so if there is not a modified line, no action is taken.

[commit 0561cc9a64]

Save Action Enabling

There is a feature in LibreOffice where the save action (menu and tool bar) is only enabled when the document has been modified, otherwise it is disabled.  Microsoft Office does not have this feature.  This feature was simple to add and only required the edit box's document's modification changed signal to be connected to the save action's enabled slot.

[commit 93c856dcb4]

Select All Correction

While testing, it was noticed that when using the Select All (Control+A) key sequence to select the entire document, a cursor position change signal was not being received.  The prevented a line changed signal from being emitted if the current line was modified.  The cursor should be moved to the end of the document.  Using Select All from either the Edit menu or the context menu did work correctly.  This problem was corrected by intercepting the Select All key sequence and calling the select all function that was connected to the menu actions.

[commit 6a7c9c57e4]

Detecting Changes With Undo/Redo

Curiously, when the document's contents change signal is received for an undo or redo operation, the cursor has not been moved yet, so the current cursor position cannot be used to determine the number of lines changed from its line number and whether the cursor is now at the end of the line.

The beginning of the document changed slot function was modified to get the current text cursor and set its position to the position of the change.  The line number of this position and whether this position is at the beginning of the line is obtained.  This cursor is then moved to the end of the change by moving the cursor right by the number of characters added by the change.  This method also works for all of the other types of document changes.  Several of the local variables in the function were renamed to make the code clearer.

The reimplemented undo and redo functions are no longer deleted and were removed along with the checks for the undo and redo key sequences in the key press event handler.  It is also no longer necessary to keep track of the undo and redo operations on the current modified line, so the undo added slot was removed along with the modified line count and undo active variables.  This mechanism was originally implemented to keep track of changes on the current line so that unnecessary line change signals were not emitted, but now the receiver of this signal is will be responsible for detecting actual line changes (see post on March 3).

[commit a9db922c4d]

Before Selection Not Needed

Previously, information about the selection before a document change operation was saved.  This information was used to figure out what text was replaced by the operation.  This is no longer needed because this information can be determined from the position received in the document's contents change signal and from the current cursor position, which is at the end of the change.

Therefore, the before selection no longer needs to be saved.  Also, since this was the only use of the Selection class, this class was also removed.

[commit ebffb4445c]