home *** CD-ROM | disk | FTP | other *** search
/ Star Trek Starfleet Academy Mini Omnipedia / MINI_OMNI.ISO / pc / omni_v2.dxr / 00421_ImportParent.ls < prev    next >
Encoding:
Text File  |  1996-04-15  |  13.0 KB  |  455 lines

  1. property iAttribListCast, iAttribList, iFirstDumpCast, iLastDumpCast, iFolderPath, iTopicAddList, iTopicDeleteList, iKeyScriptHolder, iNameChangeType, iLastTopicName, iFieldWindow, iSkipSave
  2. global oFile, oIndexMediator, gTopicNameField, oTextScroller, gScrollIncrK, oImportSlider, gDirectOrFolderK, gAddField, gDeleteField, oVidCD
  3.  
  4. on birth me
  5.   set iKeyScriptHolder to EMPTY
  6.   set iFieldWindow to 234
  7.   set iAttribListCast to the number of cast "ATTRIB_A_TOPICS"
  8.   set iAttribList to value(the text of cast iAttribListCast)
  9.   set iFirstDumpCast to 3900
  10.   set iLastDumpCast to 3998
  11.   set iFolderPath to the pathName & "USERARTS" & mGetFileDelimiter(oFile)
  12.   set oImportSlider to birth(script "SliderManagerTall", 0, 1, "mImportScroll(oTextScroller,mShowVal(oImportSlider))", 21, 146, 150, 20, 144, 335, 0, 0)
  13.   set gTopicNameField to the number of cast "TopicFileName"
  14.   set iNameChangeType to #none
  15.   sort(iAttribList)
  16.   return me
  17. end
  18.  
  19. on mStripChars me, pText, psearchitem
  20.   set vFound to 1
  21.   repeat while vFound
  22.     set vFound to offset(psearchitem, pText)
  23.     if vFound then
  24.       delete char vFound of pText
  25.     end if
  26.   end repeat
  27. end
  28.  
  29. on mReport me, pWhat
  30.   put pWhat into field "article_status"
  31. end
  32.  
  33. on mFormatText me, pText
  34.   mStripChars(me, pText, "~")
  35.   put "‚Ä¢" before pText
  36.   set vTitle to line 1 of pText
  37.   set vWordsinTitle to the number of words in vTitle
  38.   delete line 1 of pText
  39.   set vMarkerList to [:]
  40.   set vTextLen to the number of words in pText
  41.   set vWordNum to 1
  42.   set vFound to 0
  43.   repeat while vWordNum <= vTextLen
  44.     if word vWordNum of pText starts "@" then
  45.       set vStart to vWordNum
  46.       set vDone to 0
  47.       put EMPTY into char 1 of word vWordNum of pText
  48.       repeat while not vDone
  49.         if word vWordNum of pText contains "@" then
  50.           if the last char in word vWordNum of pText = "@" then
  51.             put EMPTY into char length(word vWordNum of pText) of word vWordNum of pText
  52.             set vend to vWordNum
  53.             set vDone to 1
  54.           else
  55.             put " " into char offset("@", word vWordNum of pText) of word vWordNum of pText
  56.             set vTextLen to vTextLen + 1
  57.             set vend to vWordNum
  58.             set vDone to 1
  59.           end if
  60.           next repeat
  61.         end if
  62.         set vWordNum to vWordNum + 1
  63.       end repeat
  64.       addProp(vMarkerList, vStart + vWordsinTitle, list(vend - vStart + 1, #b))
  65.       next repeat
  66.     end if
  67.     set vWordNum to vWordNum + 1
  68.   end repeat
  69.   set vMarkerList to string(vMarkerList)
  70.   delete char 1 of vMarkerList
  71.   delete char length(vMarkerList) of vMarkerList
  72.   mStripChars(me, pText, "@")
  73.   put "~" & vMarkerList & "@1" & vTitle & "@2" before line 1 of pText
  74.   put RETURN & RETURN after pText
  75.   return pText
  76. end
  77.  
  78. on mFindCastSpace me, pTextSize
  79.   set vFound to 0
  80.   set vCastLoc to iFirstDumpCast - 1
  81.   repeat while (vFound = 0) and (vCastLoc <= iLastDumpCast)
  82.     set vCastLoc to vCastLoc + 1
  83.     set vFound to the castType of cast vCastLoc = #empty
  84.   end repeat
  85.   if vFound then
  86.     return vCastLoc
  87.   else
  88.     return 0
  89.   end if
  90. end
  91.  
  92. on mStoreText me, pText
  93.   set vCastLoc to mFindCastSpace(me, the number of chars in pText)
  94.   set vItem to 0
  95.   if vCastLoc = 0 then
  96.     alert("You have filled the available space for custom articles.")
  97.   else
  98.     put pText into field vCastLoc
  99.     set vNumItems to the number of items in field vCastLoc
  100.   end if
  101.   return vCastLoc
  102. end
  103.  
  104. on mProcessNewText me, pText
  105.   set pText to mFormatText(me, pText)
  106.   set vOldDelim to the itemDelimiter
  107.   set the itemDelimiter to "@"
  108.   set vTitle to item 2 of pText
  109.   set the itemDelimiter to vOldDelim
  110.   set vCompletionCode to 0
  111.   if (length(vTitle) <= 40) and (length(vTitle) > 0) then
  112.     set vOldDelim to the itemDelimiter
  113.     set the itemDelimiter to "@"
  114.     set vTitle to item 2 of pText
  115.     delete char 1 of vTitle
  116.     set the itemDelimiter to vOldDelim
  117.     set vNewLoc to mStoreText(me, pText)
  118.     if not voidp(getaProp(iAttribList, vTitle)) then
  119.       set vCompletionCode to 4
  120.       set iNameChangeType to #replace
  121.       erase(cast vNewLoc)
  122.     else
  123.       if vNewLoc > 0 then
  124.         addProp(iAttribList, vTitle, [0, 0, [0], -1, 0, 0, 0, 1, vNewLoc, 2])
  125.         set vCompletionCode to 1
  126.         set iNameChangeType to #none
  127.         set the text of cast vNewLoc to mMakeCurlies(me, vNewLoc)
  128.       else
  129.         set vCompletionCode to 3
  130.         set iNameChangeType to #none
  131.         erase(cast vNewLoc)
  132.       end if
  133.     end if
  134.   else
  135.     set vCompletionCode to 2
  136.     set iNameChangeType to #append
  137.   end if
  138.   set iLastTopicName to char 1 to 40 of vTitle
  139.   return vCompletionCode
  140. end
  141.  
  142. on mGetUserAddList me
  143.   set iTopicAddList to [:]
  144.   set vLInes to the number of lines in field gAddField
  145.   repeat with x = 1 to vLInes
  146.     if the textStyle of line x of field gAddField = "Bold" then
  147.       if line x of field gAddField <> EMPTY then
  148.         addProp(iTopicAddList, line x of field gAddField, x)
  149.       end if
  150.     end if
  151.   end repeat
  152. end
  153.  
  154. on mGetUserDeleteList me
  155.   set iTopicDeleteList to [:]
  156.   set vLInes to the number of lines in field gDeleteField
  157.   repeat with x = 1 to vLInes
  158.     if the textStyle of line x of field gDeleteField = "Bold" then
  159.       if line x of field gDeleteField <> EMPTY then
  160.         addProp(iTopicDeleteList, line x of field gDeleteField, x)
  161.         next repeat
  162.       end if
  163.     end if
  164.   end repeat
  165. end
  166.  
  167. on mPrepToGetUserAdds me
  168.   set iAttribList to value(the text of cast iAttribListCast)
  169.   sort(iAttribList)
  170.   mGetUserAddList(me)
  171. end
  172.  
  173. on mStartUserImport me
  174.   mGetUserAddList(me)
  175.   if count(iTopicAddList) > 0 then
  176.     mPrepToGetUserAdds(me)
  177.     mUnPuppetSlider(oImportSlider)
  178.     go("addLoop")
  179.   end if
  180. end
  181.  
  182. on mFinishUserImport me
  183.   put string(iAttribList) into field iAttribListCast
  184.   mUpdateTopicIndex(oIndexMediator)
  185.   if not iSkipSave then
  186.     if mRunningFromHD(oVidCD) then
  187.       mReport(me, "Now Saving. Takes about one minute. Please wait.")
  188.       saveMovie()
  189.     end if
  190.   end if
  191.   set iSkipSave to 0
  192.   mReport(me, "Available files from" && gDirectOrFolderK && "USERARTS")
  193.   go("TopicAdd")
  194.   mCheckImportScroll(me, gAddField)
  195. end
  196.  
  197. on mStartUserDelete me
  198.   global gIndexSND
  199.   mGetUserDeleteList(me)
  200.   if count(iTopicDeleteList) then
  201.     mReport(me, "Deleting files one moment please...")
  202.     mUnPuppetSlider(oImportSlider)
  203.     go("DeleteLoop")
  204.     mDeleteEntryList(me)
  205.     go("TopicDelete")
  206.     mCheckImportScroll(me, gDeleteField)
  207.     if mRunningFromHD(oVidCD) then
  208.       mReport(me, "Now Saving. Takes about one minute. Please wait.")
  209.       saveMovie()
  210.     else
  211.     end if
  212.   end if
  213.   hearit(gIndexSND)
  214.   mReport(me, "Delete complete.")
  215. end
  216.  
  217. on mUserAddLoop me, pX
  218.   if count(iTopicAddList) > 0 then
  219.     mGetNextFile(me)
  220.     go(the frame)
  221.     if voidp(pX) then
  222.       mReport("Adding Files, one moment please...")
  223.     end if
  224.   else
  225.     mFinishUserImport(me)
  226.   end if
  227. end
  228.  
  229. on mGetNextFile me
  230.   set vFileName to getPropAt(iTopicAddList, 1)
  231.   set vNewText to mGetFile(oFile, iFolderPath & vFileName)
  232.   if iNameChangeType = #replace then
  233.     put the text of field gTopicNameField into line 1 of vNewText
  234.     if char 1 of vNewText = "‚Ä¢" then
  235.       delete char 1 of vNewText
  236.     end if
  237.   else
  238.     if iNameChangeType = #append then
  239.       put the text of field gTopicNameField & RETURN before vNewText
  240.       if char 1 of vNewText = "‚Ä¢" then
  241.         delete char 1 of vNewText
  242.       end if
  243.     end if
  244.   end if
  245.   set vImportResult to mProcessNewText(me, vNewText)
  246.   if vImportResult = 1 then
  247.     set vLine to getAt(iTopicAddList, 1)
  248.     if the number of lines in field gAddField = 1 then
  249.       put "." into line 1 of field gAddField
  250.     else
  251.       delete line vLine of field gAddField
  252.     end if
  253.     set iTopicAddList to iTopicAddList - 1
  254.     deleteAt(iTopicAddList, 1)
  255.   else
  256.     if vImportResult = 2 then
  257.       mGoToBadName(me)
  258.       set vLastName to iLastTopicName
  259.       if vLastName starts "‚Ä¢" then
  260.         delete char 1 of vLastName
  261.       end if
  262.       put vLastName into field gTopicNameField
  263.     else
  264.       if vImportResult = 3 then
  265.         alert("This file is full.  There is no more storage available for custom articles.")
  266.         set iTopicAddList to [:]
  267.         set the textStyle of field gAddField to "Plain"
  268.       else
  269.         set vLastName to iLastTopicName
  270.         if vLastName starts "‚Ä¢" then
  271.           delete char 1 of vLastName
  272.         end if
  273.         put vLastName into field gTopicNameField
  274.         go("same")
  275.       end if
  276.     end if
  277.   end if
  278. end
  279.  
  280. on mSkipNewEntry me
  281.   set iSkipSave to 1
  282.   set vLine to getAt(iTopicAddList, 1)
  283.   set the textStyle of line vLine of field gAddField to "plain"
  284.   deleteAt(iTopicAddList, 1)
  285.   go("SKIPLoop")
  286. end
  287.  
  288. on mReplaceSameName me
  289.   mDeleteSingleEntry(me, iLastTopicName)
  290.   go("AddLoop")
  291. end
  292.  
  293. on mReNameNewTopic me
  294.   mGetNewName(me)
  295. end
  296.  
  297. on mGoToBadName me
  298.   go("Bad")
  299. end
  300.  
  301. on mGetNewName me
  302.   go("New")
  303.   puppetSprite(30, 1)
  304.   set the editableText of sprite 30 to 1
  305.   set vLastName to iLastTopicName
  306.   if vLastName starts "‚Ä¢" then
  307.     delete char 1 of vLastName
  308.   end if
  309.   put vLastName into field gTopicNameField
  310.   set the selStart to 0
  311.   set the selEnd to 41
  312.   mStoreKeyDown(me)
  313.   set the keyDownScript to "hTopicKeys"
  314. end
  315.  
  316. on mCancelNewName me
  317.   puppetSprite(30, 0)
  318.   set the editableText of sprite 30 to 0
  319.   set vLineNum to getAt(iTopicAddList, 1)
  320.   set the textStyle of line vLineNum of field gAddField to "Plain"
  321.   deleteAt(iTopicAddList, 1)
  322.   mRestoreKeydown(me)
  323.   go("AddLoop")
  324. end
  325.  
  326. on mStoreKeyDown me
  327.   if the keyDownScript <> "hTopicKeys" then
  328.     set iKeyScriptHolder to the keyDownScript
  329.   end if
  330. end
  331.  
  332. on mRestoreKeydown me
  333.   set the keyDownScript to "iKeyScriptHolder"
  334. end
  335.  
  336. on mEnterNewName me
  337.   set the editableText of sprite 30 to 0
  338.   puppetSprite(30, 0)
  339.   put line 1 of field gTopicNameField into field gTopicNameField
  340.   mGetNextFile(me)
  341.   go("AddLoop")
  342.   mRestoreKeydown(me)
  343. end
  344.  
  345. on mDeleteSingleEntry me, pLineNum
  346.   if not stringp(pLineNum) then
  347.     set vEntryName to line pLineNum of field gDeleteField
  348.   else
  349.     set vEntryName to pLineNum
  350.   end if
  351.   set iAttribList to value(the text of cast iAttribListCast)
  352.   set x to findPos(iAttribList, vEntryName)
  353.   if not voidp(x) then
  354.     set vListData to getAt(iAttribList, x)
  355.     set vcastNum to getAt(vListData, 9)
  356.     erase(cast vcastNum)
  357.     deleteAt(iAttribList, x)
  358.     put string(iAttribList) into field iAttribListCast
  359.   end if
  360.   if not stringp(pLineNum) then
  361.     if the number of lines in field gDeleteField = 1 then
  362.       put "." into line pLineNum of field gDeleteField
  363.     else
  364.       delete line pLineNum of field gDeleteField
  365.     end if
  366.   end if
  367.   mUpdateTopicIndex(oIndexMediator)
  368.   mCheckImportScroll(me, gDeleteField)
  369. end
  370.  
  371. on mDeleteEntryList me
  372.   set iAttribList to value(the text of cast iAttribListCast)
  373.   repeat while count(iTopicDeleteList) > 0
  374.     set vEntryName to getPropAt(iTopicDeleteList, 1)
  375.     set x to findPos(iAttribList, vEntryName)
  376.     if not voidp(x) then
  377.       set vListData to getAt(iAttribList, x)
  378.       set vcastNum to getAt(vListData, 9)
  379.       erase(cast vcastNum)
  380.       deleteAt(iAttribList, x)
  381.     end if
  382.     set vLineToKill to getAt(iTopicDeleteList, 1)
  383.     if the number of lines in field gDeleteField = 1 then
  384.       put "." into line vLineToKill of field gDeleteField
  385.     else
  386.       delete line vLineToKill of field gDeleteField
  387.     end if
  388.     set iTopicDeleteList to iTopicDeleteList - 1
  389.     deleteAt(iTopicDeleteList, 1)
  390.   end repeat
  391.   put string(iAttribList) into field iAttribListCast
  392.   mUpdateTopicIndex(oIndexMediator)
  393.   mCheckImportScroll(me, gDeleteField)
  394. end
  395.  
  396. on mCheckImportScroll me, pTextField
  397.   if the height of cast pTextField > iFieldWindow then
  398.     repeat with x = 20 to 23
  399.       set the visible of sprite x to 1
  400.     end repeat
  401.     set vNewHeight to (the height of cast the castNum of sprite 4 - iFieldWindow) / gScrollIncrK
  402.     mReDefineSlider(oImportSlider, 0, vNewHeight, 0)
  403.     mNudgeSlider(oImportSlider, 0)
  404.   else
  405.     repeat with x = 20 to 23
  406.       set the visible of sprite x to 0
  407.     end repeat
  408.   end if
  409.   updateStage()
  410. end
  411.  
  412. on mMakeCurlies me, pFieldNum
  413.   global gBeginCurlyQ, gEndCurlyQ
  414.   set vEps to ["TOS", "TNG", "DS9", "VGR"]
  415.   set vChar1 to 1
  416.   set vtext to field pFieldNum
  417.   set vLastChar to length(vtext)
  418.   set vNewText to EMPTY
  419.   set vTextChunk to vtext
  420.   mReport(me, "Interpreting the article text...")
  421.   repeat with vEpName in vEps
  422.     set vPtr to offset(vEpName, vTextChunk)
  423.     repeat while vPtr > 0
  424.       if (vPtr - 54) <= 0 then
  425.         set vStart to 1
  426.       else
  427.         set vStart to vPtr - 54
  428.       end if
  429.       repeat with x = vPtr - 1 down to vStart
  430.         if char x of vTextChunk = QUOTE then
  431.           put gEndCurlyQ into char x of vTextChunk
  432.           repeat with y = x - 1 down to vStart
  433.             if char y of vTextChunk = QUOTE then
  434.               put gBeginCurlyQ into char y of vTextChunk
  435.               exit repeat
  436.             end if
  437.           end repeat
  438.           set x to vStart + 1
  439.           next repeat
  440.         end if
  441.       end repeat
  442.       set vNewText to vNewText & char vChar1 to vPtr + 2 of vTextChunk
  443.       set vChar1 to vPtr + 3
  444.       set vTextChunk to char vChar1 to length(vTextChunk) of vTextChunk
  445.       set vPtr to offset(vEpName, vTextChunk)
  446.       if vPtr = 0 then
  447.         set vTextChunk to vNewText & vTextChunk
  448.         set vNewText to EMPTY
  449.         set vChar1 to 1
  450.       end if
  451.     end repeat
  452.   end repeat
  453.   return vTextChunk
  454. end
  455.