Share Tips, Code Samples, etc. with the Visual Prolog community.
Steve Lympany
VIP Member
Posts: 56
Joined: 31 Mar 2001 23:01

File Management – Skeleton Startup Project

Unread post by Steve Lympany »

Class Descriptions

1) taskwindow_support::

Here are some of the object predicates in this class:

Code: Select all

        onfilenew   :() determ ().         onfilenew   :(remember_files::a_file File) determ (i).         onfilesave  :()->adl_db::saved_result procedure ().         onfilesaveas:()->adl_db::saved_result procedure ().         onfileOpen  :() determ ().         onfileOpen  :(remember_files::a_file File) determ (i).         onfileOpen_last  :() determ ().         onfileOpen_nth  :(unsigned) determ (i).         onfileClose :(adl_db::save_dom)->adl_db::closed_result procedure (i).         onfileExit  :(adl_db::save_dom)->adl_db::closed_result procedure (i).         onClose     :(adl_db::save_dom)->adl_db::closed_result procedure (i).  


These are called from the taskwindow menu item calls e.g.

Code: Select all

predicates     onFileSave : window::menuItemListener. clauses     onFileSave(_Source, _MenuTag):-         A=xtaskwin_support:onfileSave(),         stdio::write("\n SAVE - ",A),!.     onFileSave(_Source, _MenuTag).   predicates     onClose : frameDecoration::closeResponder. clauses     onClose(_Source) = frameDecoration::defaultCloseHandling():-         Closed_Result=xtaskwin_support:onClose(save_it(save_it_ask)),         stdio::write("\n CLOSE - ",Closed_Result),         not(Closed_Result=adl_DB::close_cancelled),!,         xtaskwin_support:modify_onshow_tw_menu(This).       onClose(_Source) = frameDecoration::denyClose():-         xtaskwin_support:modify_onshow_tw_menu(This).  


So your taskwindow.pro becomes very simple to develop. Almost all the file management coding is provided in the supplied classes.

2) remember_files::

This class stores the names of the data files the end-user opens so that the taskwindow menu can be modified the next time the application is run. The remembered files are stored in a fact file which is located in the same location as the application itself. The facts are file::saved() and file::consulted().

3) modify_menu::

This class uses remember_files to modify a menu. So taskwindow.pro calls it with its menu, and then reapplies the modified menu, displaying the last opened files. If the files no longer exist, they will be displayed disabled (greyed out). It also disables file-close and file-save (if no file is open), file-new (if a file is already open) etc.

4) adl_db::

This class creates an external database object. It contains the db_create to make the chainDB for your program. You pass the adl_db object around your own program, and use adl_get_chainDB()->ChainDB to get the ChainDB to store/modify your program data.

File Versioning

Code: Select all

predicates     onFileVersioningOn : window::menuItemListener. clauses     onFileVersioningOn(_Source, _MenuTag):-         opp(xtaskwin_support:versioning_state(),Opp),         xtaskwin_support:switch_on_versioning(Opp),         menuCheck(resourceIdentifiers::id_file_versioning_on,Opp).   predicates     opp:(booleanint,boolean) procedure (i,o). clauses     opp(b_true,false):-!.     opp(_,true).  
InstructionsTesting

When running this example project, create a new file or open an old one. The chainDB will only be set as modified if you press menu item MODIFY DB. If the chainDB is not modified, it will not be saved.




Attachments
dev_version_control.zip
File management classes
(39.18 KiB) Downloaded 1437 times
Post Reply