Sunday, December 30, 2012

GUI – File Operations - Functions

A couple of helper functions were implemented to support the file operation functions.  The first is a function check if it is okay to continue, which checks if the file has been modified and if it has, ask if the file should be saved or the operation canceled.  This check is needed on the new, open and close program functions.

The second helper function sets a new member variable that holds the current program file path and sets the window title to the base file name of the current program file path.  The window title is set to the string "<file name>[*] ‑ IBCP" where the [*] is a placeholder for whether the file has been modified.  Qt handles this in a platform specific way.  Qt handles this in a platform specific way.  Generally on Windows and Linux, it  simple puts an asterisk after the file name, but on MAC, a dot is put in the close bubble.  If the program file path is blank, the program name is set to the "Untitled" string.

In the main window constructor, a connection was added to the edit box document's modification changed signal to the main windows set window modified slot.  Whenever the document is modified, this signal causes the file modified indicator to appear.

Two support functions were also implemented that load and save the program into or from memory, though right now they simply read and write a text file to or from the edit box document as plain text.  Eventually when a program is loaded, it will need to be parsed, translated, encoded and stored in memory.  Details of the main file operation functions can be found by clicking Continue...

[commit ea1b7585bb]

File Operation Function Details

New: The new function first checks if it is okay to continue, then clears the edit box, clears the window modified flag (because the clear operation sets it) and sets the current program name to blank.

Open: The open function first checks if it is okay to continue, then requests a file using the open file name function of the QFileDialog class, which opens a platform specific file open box.  If a file name was entered (the open file dialog was not canceled), the program is loaded by calling the load program support function.

Save: The save function either calls the save as function if there is no program name (set to "Untitled") or calls the save program support function.  This function was also changed to return a boolean success status flag, which does not affect the auto-connection to the function (only the function's argument matter for auto-connection).  This function is called by the is okay to continue helper function when the user requests that the current file be saved.

Save As: The function starts by requesting a file name using the save file name function of the QFileDialog class, which opens a platform specific file save box.  This dialog also handles if the file already exists by asking the user if the file should be overwritten.  If a file name was entered (the save file dialog was not canceled), the program is saved by calling the save program support function.

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)