07-13-2008, 01:04 AM
Hi All,
Here it is - a TagList Manager based on ComboBox in Dialog. It is fully commented for learning purposes. I learned a huge amount on this little project. Output is currently only a mes statement but you can do with it whatever you want.
If anybody sees better or more elegant ways of doing some of the things I describe in the comments, please let me know.
For example,
Here it is - a TagList Manager based on ComboBox in Dialog. It is fully commented for learning purposes. I learned a huge amount on this little project. Output is currently only a mes statement but you can do with it whatever you want.
If anybody sees better or more elegant ways of doing some of the things I describe in the comments, please let me know.
For example,
- (1) I am not sure why in the declaration the int has to be global. SInce it is at initiation of the dialog, won't it be established already before anything else has to see it? It seems to work fine being global, but I always try to avoid the global variables if possible
Thanks,
Stuart
Function TagListManager
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
str controls = "8"
str cb8 c3Add
if(dir("$my qm$\TagList.txt"));; checks to see if a tag list already exists
,cb8.getfile("$my qm$\TagList.txt");; if so preloads it into the ComboBox string
else cb8.setfile("$my qm$\TagList.txt");; if not, uses 'setfile' to create an empty txt doc and loads it
if(!ShowDialog("TagListManager" &TagListManager &controls)) ret
str SelectedComboBox = cb8;;gets the CB selection at close of the dialog
if(TO_CBGetItem(SelectedComboBox)!=-1);;removes the index number from the string text and messages only if not empty
,mes SelectedComboBox;; messages the selection. You can do anything with this selection..i.e. save it to a file, fill a cell in Excel, etc
;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 146 87 "TagList"
;1 Button 0x54030001 0x4 26 71 48 14 "OK"
;2 Button 0x54030000 0x4 76 71 48 14 "Cancel"
;7 Button 0x54032000 0x0 26 57 98 12 "Clear Tag List"
;6 Button 0x54032000 0x0 26 39 98 14 "Delete Selected Tag"
;8 ComboBox 0x54230242 0x0 26 5 98 213 ""
;3 Button 0x54032000 0x0 26 21 98 14 "Add New Tag to Tag List"
;END DIALOG
;DIALOG EDITOR: "" 0x2030000 "" "" ""
ret
;messages
sel message
,case WM_INITDIALOG;;upon initiation of the Dialog
,,int+ hcb= id(8 hDlg);;establishes an int name (hcb) for the CB box which happens to be id 8
,,int i;;establishes a reusable counting integer
,case WM_DESTROY;;upon closing of the Dialog
,,str CBEntryFieldText.getwintext(hcb);; gets whatever is in EntryField, whether selected (i.e. pre-existing tag) or newly entered
,,int IsTagNew=CB_FindItem((hcb) CBEntryFieldText 0 1);; checks if CBEntryFieldText is a new tag; 0 1 = must match whole tag from the beginning
,,if IsTagNew=-1;;no matches, therefore a new tag
,,,if CBEntryFieldText=""; ret; else;;since want to ignore cases where no CB item is selected or no text entered (which returns returns ""))
,,,,if(mes("Add new tag ''%s'' to Tag List?" "TagList" "YN?a" CBEntryFieldText)!='Y') ret
,,,,CBEntryFieldText.setfile("$my qm$\TagList.txt" -1 -1 1);;appends new tag to Taglist (-1 -1 1 = appens all of 'SelectedText' as a new line at the end of the file
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3;;add Tag
,,CBEntryFieldText.getwintext(hcb);; gets whatever is in CB EntryField, whether selected (i.e. pre-existing tag) or newly entered
,,IsTagNew=CB_FindItem((hcb) CBEntryFieldText 0 1);; checks if CBEntryFieldText is a new tag; 0 1 = must match whole tag from the beginning
,,if IsTagNew >=0; mes("The tag ''%s'' already exists in your Tag List" "TagList" "i" CBEntryFieldText);ret ;;if there is a tag match (greater than or equal to 0), informs user
,,if IsTagNew=-1;;no matches, therefore a new tag
,,,if CBEntryFieldText=""; ret; else;;since want to ignore cases where no CB item is selected or no text entered (which returns returns ""))
,,,,if(mes("Add new tag ''%s'' to Tag List?" "TagList" "YN?a" CBEntryFieldText)!='Y') ret
,,,,int NewItemNum=CB_Add(hcb CBEntryFieldText)
,,,,CBEntryFieldText.setfile("$my qm$\TagList.txt" -1 -1 1);;appends new tag to Taglist (-1 -1 1 = appens all of 'SelectedText' as a new line at the end of the file
,case 6;;delete tag
,,str TagToDelete
,,_i=CB_SelectedItem(hcb TagToDelete)
,,if _i = -1; mes("Must have tag selected in order to delete from the Tag List" "TagList" "i");ret ;;gets selected tag and only continues if there is indeed a selected tag;; i.e. not if CB entry field is empty ("" i.e. _i=-1)
,,if(mes("Are you sure you want to delete the tag ''%s'' from the Tag List" "TagList" "YN?a" TagToDelete)!='Y') ret
,,SendMessage (hcb) CB_DELETESTRING _i 0;;deletes selected item from taglist in CB
,,;;but still need to update the file where the taglist is stored:
,,_i=CB_GetCount(hcb);; gets the total number of tags in CB taglist
,,ARRAY(str) NewTagArray;;creates new array
,,NewTagArray.create(_i);;with _i number of items
,,for i 0 _i;; for each item
,,,str tag
,,,CB_GetItemText(hcb i tag);;puts the item text in 'tag' string
,,,NewTagArray[i]=tag;; and puts this new tag string into the new tag array
,,str NewTagList= NewTagArray;; converts the array into a string collection
,,NewTagList.setfile("$my qm$\TagList.txt" 0);;replaces prior TagList with NewTagList (since no -1 flag, it replaces instead of appends)
,case 7;; Clear TagList
,,if(mes("Are you sure you want to delete the entire TagList?" "TagList" "YNC!")!='Y') ret
,,SendMessage hcb CB_RESETCONTENT 0 0;;clears CB
,,del "$my qm$\TagList.txt";;deletes TagList.txt which will be recreated fresh when dialog is re-run or if New Tag is added even in this Dialog instance
,case IDOK
,case IDCANCEL
ret 1