home *** CD-ROM | disk | FTP | other *** search
Wrap
/* $VER: CutNPaste.dopus5 3.4 (28.08.99) Written by Keith Halstead <cutnpaste@halsteadk.freeserve.co.uk> * Locale support by Michael Skibsted Sørensen <MSS@kob.dk> * * For full history and acknowledgements see accompanying documentation * */ parse arg portname function source dest arguments address value portname options results if ~show('l','rexxsupport.library') then call addlib('rexxsupport.library',0,-30,0) if ~show(l,'locale.library') then call addlib('locale.library',0,-30) if show(l,'locale.library') then catalog = opencatalog('CutNPaste.catalog','english',0) /* ****** USER CONFIGURATION SECTION ****** */ /* Edit these filetype ID's to suit your own filetypes (you may use wildcards, eg 'LHA#?') */ lhatype = 'LHA' lzxtype = 'LZX' ziptype = 'ZIP' /* Edit these commands to suit yourself (if you really don't like the defaults) - By default they will automatically add non-existant files and update older files, but not replace newer files. To add non-existant files only - change "u" to "a" for lzx and lha, change zipcmd to 'zip -r'. Do not remove "-r" for any of them - the defaults and rest of the script will handle (empty) directories (and their contents) perfectly. Don't change them unless you really want to!! */ lzxcmd = 'lzx -r -e u' lhacmd = 'lha -r -e u' zipcmd = 'zip -ru' /* Some miscellaneous things to alter the behaviour of Cut'n'Paste */ ramdisktype = 'RAMDISK' /* allows 'clear' command to be added to ram disk icon menu */ copyicons = 'yes' /* 'yes' if you want to always cut/copy associated icons from RMB cut/copy/add, 'notnamemode' if you want to do this in icon (action) mode listers only, anything else if you never want to copy the icon */ addcheck = 'quiet' /* 'yes' - checks that items aren't already in clipboard when adding, 'quiet' - no warning requesters - these are a bit slower than 'no' */ enablepastelinks = 'yes' /* 'yes' will enable all "paste as links" menu items, anything else will disable them (for if you never use links) */ secondviewreq = 'yes' /* 'yes' allows a second view requester to pop up after you view the clipboard contents in the DOpus text reader; anything else to disable the second requester */ /* ****** DO NOT EDIT BELOW THIS LINE ****** */ dopus version dopver = substr(result,3,1) /* "dopver" contains "8" for Mag II and "6" for Mag I */ /* MAIN PROGRAM LOOP STARTS */ select when function = 'init' then do cnptypes = 'type drawer type tool type project type trash' 'dopus command "Clip-Cut" program "CutNPaste" ext 'locale(2,"Cut")' private' cnptypes 'dopus command "Clip-MCut" program "CutNPaste" ext 'locale(2,"Cut")' desc "Cut''n''Paste: "'locale(2,"Cut")'' type lister 'dopus command "Clip-Copy" program "CutNPaste" ext 'locale(1,"Copy")' private' cnptypes 'dopus command "Clip-MCopy" program "CutNPaste" ext 'locale(1,"Copy")' desc "Cut''n''Paste: "'locale(1,"Copy")'' type lister call addpastecmds call cnpclear end /* CUT OR COPY SINGLE ITEMS (with RMB) */ when (function = 'Clip-Cut') | (function = 'Clip-Copy') then call clipsingle /* CUT OR COPY MULTIPLE ITEMS (from lister pop-up menus or buttons) */ when (function = 'Clip-MCut') | (function = 'Clip-MCopy') then call clipmulti /* ADD SINGLE ITEMS (with RMB) */ when (function = 'Clip-Add') then call addsingle /* ADD MULTIPLE ITEMS (from lister pop-up menus or buttons) */ when function = 'Clip-MAdd' then call addmulti /* PASTE (AS/LINKS) */ when (function = 'Clip-MPaste') | (function = 'Clip-MPasteAs') | (function = 'Clip-MPasteLinks') then do lister query source path pastepath = '"'result'"' call pastefunc lister set source busy off end /* PASTE INTO (AS/LINKS) */ when (function = 'Clip-MPasteInto') | (function = 'Clip-MPasteIntoAs') | (function = 'Clip-MPasteLinksInto') then do pastepath = strip(arguments,L) call pastefunc lister set source busy off end /* PASTE INTO ARCHIVES */ when (function='Clip-LhaPaste')|(function='Clip-LzxPaste')|(function='Clip-ZipPaste') then call arcpaste /* CLEAR */ when function = 'Clip-Clear' then call cnpclear /* VIEW CLIPBOARD CONTENTS */ when function = 'Clip-View' then call viewfunc /* ABOUT */ otherwise do if getclip('numselobj') = 1 then objtext = locale(33,"item") else objtext = locale(34,"items") dopus request """Opus Cut'n'Paste "||locale(17,'Version')||' 3.4'||'0a'x||, "- - - - - - - - - - - - - - - - -"""||'0a'x||, locale(18,'Written by')||""" Keith Halstead, 1999"||'0a'x||, locale(19,'E-mail:')||" cutnpaste@halsteadk.freeserve.co.uk"||'0a'x||, "http://www.halsteadk.freeserve.co.uk/cutnpaste/"""||'0a0a'x||, locale(16,'Using built-in English')||'0a0a'x||, locale(13,"Cut'n'Paste clipboard contents")||''': '||, getclip('numselobj')||' '''||objtext, compress(locale(32,'Help...|OK'),'"') if rc=1 then address command "run >NIL: multiview DOpus5:Help/CutNPaste.guide" end end exit /* LOCALE FUNCTION */ locale: parse arg msgno,msgstring if catalog ~= 0 then msgstring = getcatalogstr(catalog,msgno,msgstring) do i = 3 to arg() parse var msgstring before '%s' after msgstring = before||arg(i)||after end return '"'msgstring'"' /* INVALID CLIPBOARD FUNCTION */ invalid: lister request source locale(7,"Cut'n'Paste clipboard was invalid! It has been cleared.") call cnpclear return /* CLEAR CLIPBOARD FUNCTION */ cnpclear: setclip('numselobj',0) if exists('T:clipcnp')=1 then command 'Delete T:clipcnp quiet' call rempastecmds setclip('cnpcmd',0) return /* REMOVE PASTE/VIEW COMMANDS */ rempastecmds: if dopver>=8 then do dopus command "Clip-Add" remove dopus command "Clip-MAdd" remove dopus command "Clip-MPasteInto" remove dopus command "Clip-MPasteIntoAs" remove dopus command "Clip-MPaste" remove dopus command "Clip-MPasteAs" remove if enablepastelinks='yes' then do dopus command "Clip-MPasteLinks" remove dopus command "Clip-MPasteLinksInto" remove end dopus command "Clip-LhaPaste" remove dopus command "Clip-LzxPaste" remove dopus command "Clip-ZipPaste" remove dopus command "Clip-View" remove dopus command "Clip-Clear" remove end return /* ADD PASTE/VIEW COMMANDS */ addpastecmds: call rempastecmds if dopver>=8 then dopus command "Clip-About" remove if (function = 'init') | (dopver>=8) then do cnptypes = 'type drawer type tool type project type trash' 'dopus command "Clip-Add" program "CutNPaste" ext 'locale(40,"Add To Clipboard")' private' cnptypes 'dopus command "Clip-MAdd" program "CutNPaste" ext 'locale(40,"Add To Clipboard")' desc "Cut''n''Paste: "'locale(40,"Add to Clipboard")'' type lister 'dopus command "Clip-MPasteInto" program "CutNPaste" ext 'locale(5,"Paste Into")' private' type disk type drawer 'dopus command "Clip-MPasteIntoAs" program "CutNPaste" ext 'locale(6,"Paste Into As...")' private' type disk type drawer 'dopus command "Clip-MPaste" program "CutNPaste" ext 'locale(3,"Paste")' desc "Cut''n''Paste: "'locale(3,"Paste")'' type lister 'dopus command "Clip-MPasteAs" program "CutNPaste" ext 'locale(4,"Paste As...")' desc "Cut''n''Paste: "'locale(4,"Paste As...")'' type lister if enablepastelinks='yes' then do if getclip('numselobj')=1 then do /* only if one item in clipboard */ 'dopus command "Clip-MPasteLinks" program "CutNPaste" ext 'locale(37,"Paste As Link")' private' type lister 'dopus command "Clip-MPasteLinksInto" program "CutNPaste" ext 'locale(38,"Paste Into As Link")' private' type disk type drawer end else do /* for several or zero items - ie for function = "init" for Opus 5.66 */ 'dopus command "Clip-MPasteLinks" program "CutNPaste" ext 'locale(35,"Paste As Links")' desc "Cut''n''Paste: "'locale(35,"Paste As Links")'' type lister 'dopus command "Clip-MPasteLinksInto" program "CutNPaste" ext 'locale(36,"Paste Into As Links")' private' type disk type drawer end end 'dopus command "Clip-LhaPaste" program "CutNPaste" ext 'locale(47,"Paste Into Archive")' private' type lhatype 'dopus command "Clip-LzxPaste" program "CutNPaste" ext 'locale(47,"Paste Into Archive")' private' type lzxtype 'dopus command "Clip-ZipPaste" program "CutNPaste" ext 'locale(47,"Paste Into Archive")' private' type ziptype 'dopus command "Clip-View" program "CutNPaste" ext 'locale(9,"View/Alter Clipboard Properties...")' desc 'locale(9,"View Clipboard Contents...")'' type lister 'dopus command "Clip-Clear" program "CutNPaste" ext 'locale(10,"Clear Clipboard Contents")' desc 'locale(10,"Clear Clipboard Contents")'' type ramdisktype type lister 'dopus command "Clip-About" program "CutNPaste" ext 'locale(12,"About Opus Cut'n'Paste...")' desc 'locale(12,"About Opus Cut'n'Paste...")'' type lister end return /* VIEW CLIPBOARD CONTENTS FUNCTION */ viewfunc: numobj = getclip('numselobj') if numobj>0 & exists('T:clipcnp')=0 then call cnpclear if numobj>0 & exists('T:clipcnp')=1 then do if numobj>1 then do if getclip('cnpcmd')=1 then righttext = locale(45,"items cut to the Cut'n'Paste clipboard.") else if getclip('cnpcmd')=2 then righttext = locale(46,"items copied to the Cut'n'Paste clipboard.") else do call invalid return end lister request source locale(20,'There are')||''' 'numobj' '''||righttext||'0a'x||, locale(22,'What would you like to do with them?'), compress(locale(24,'View...|Paste here|Toggle cut/copy|Clear clipboard|Nothing'),'"') action = rc if action=1 then do command wait read 't:clipcnp' if secondviewreq = 'yes' then do lister request source locale(22,'What would you like to do with them?'), compress(locale(25,'Paste into current lister|Toggle cut/copy|Clear clipboard|Nothing'),'"') action = rc end else action = 0 /* if second requester not displayed, pretend "Nothing" was pressed */ end else action=action-1 /* now paste=1, toggle=2, clear=3 regardless of previous statements */ end /* routine for when number of objects is 1 */ else if open('cnpfile','T:clipcnp','r') then do if getclip('cnpcmd')=2 then cmd = compress(locale(1,'Copy'),'"') else cmd = compress(locale(2,'Cut'),'"') srcfile = '"'readln('cnpfile')'"' call close('cnpfile') if length(srcfile)>3 then do if length(srcfile) > 72 then sourcefile=left(srcfile,60)||' ...'||'0a'x||'... '||substr(srcfile,61) else sourcefile=srcfile lister request source locale(11,'Clipboard contents')||'": '||'0a'x||, cmd' "'sourcefile||'0a'x||, locale(23,'What would you like to do with it?'), compress(locale(26,'Paste here|Toggle cut/copy|Clear clipboard|Nothing'),'"') action = rc end else do call invalid return end end else do call invalid return end /* execute one action depending on which button was pressed */ if action = 1 then do lister query source path pastepath = '"'result'"' call pastefunc end else if action = 2 then do setclip('cnpcmd',getclip('cnpcmd')-1) if getclip('cnpcmd')=0 then do setclip('cnpcmd',2) newactiontext = locale(44,'Clipboard contents will now be copied') end else newactiontext = locale(43,'Clipboard contents will now be cut') lister request source newactiontext end else if action = 3 then call cnpclear end else lister request source locale(21,"View")||""": """||locale(8,"Cut'n'Paste clipboard is empty") return /* PASTE (INTO) (AS/LINKS) FUNCTION */ pastefunc: if getclip('numselobj')>0 then do if open('cnpfile','T:clipcnp','r') then do if (function = 'Clip-MPasteLinksInto') | (function = 'Clip-MPasteLinks') then do dopcmd = 'makelink' /* same whether cut or copied */ action = compress(locale(42,'Pasting link to'),'"') end else if getclip('cnpcmd')=1 then do /* if not pasting links and items were cut */ clear = 1 /* will clear clipboard after paste finishes - see later */ dopcmd = 'move' action = compress(locale(30,'Moving'),'"') end else if getclip('cnpcmd')=2 then do /* if not pasting links and items were copied */ dopcmd = 'copy' action = compress(locale(29,'Copying'),'"') end else do call invalid return end if (function = 'Clip-MPasteAs') | (function = 'Clip-MPasteIntoAs') then do dopcmd = dopcmd||'as' end numobj = getclip('numselobj') lister set source newprogress name file info bar abort progressfail=rc /* progressfail is 1 if progress requester isn't created */ lister set source newprogress title compress(locale(28,"Cut'n'Paste progress..."),'"') lister set source newprogress info compress(locale(31,'into') "'"pastepath"'",'"') lister set source busy on /* loops for each item */ do i=1 for numobj lister query source abort if (result = 1) & (progressfail = 0) then leave i /* if abort pressed AND progress requester created successfully */ lister set source newprogress bar numobj i lister set source newprogress file numobj i srcfile = readln('cnpfile') lister set source newprogress name action "'"substr(srcfile,max(lastpos(":",srcfile),lastpos("/",srcfile))+1)"'" srcfile = '"'srcfile'"' command wait dopcmd 'name=' srcfile 'to=' pastepath /* this line does it all - remove "wait" for speed but there are problems! */ end lister set source busy off if (function = 'Clip-MPaste') | (function = 'Clip-MPasteAs') then lister refresh source call close('cnpfile') if clear = 1 then call cnpclear /* if action was cut+paste then clear clipboard */ end else do call cnpclear lister request source locale(3,"Paste")'": "'locale(8,"Cut'n'Paste clipboard is empty") end end else lister request source locale(3,"Paste")'": "'locale(8,"Cut'n'Paste clipboard is empty") return /* FUNCTION TO PASTE CLIPBOARD CONTENTS INTO ARCHIVES */ arcpaste: if getclip('numselobj')>0 then do if open('cnpfile','T:clipcnp','r') then do numobj = getclip('numselobj') arcname = substr(arguments,max(lastpos(":",arguments),lastpos("/",arguments))+1) arcname = left(arcname,length(arcname)-1) if (function = 'Clip-LzxPaste') then arccmd = lzxcmd else if (function = 'Clip-LhaPaste') then arccmd = lhacmd else if (function = 'Clip-ZipPaste') then arccmd = zipcmd else return /* should be impossible */ lister set source newprogress name file info bar abort progressfail=rc /* checks if progress indicator appears - doesn't for desktop items */ lister set source newprogress title compress(locale(28,"Cut'n'Paste progress..."),'"') lister set source newprogress info compress(locale(49,'to') "'"arcname"'",'"') lister set source busy on /* loops for each item */ do loopcount=1 for numobj lister query source abort if (result = 1) & (progressfail = 0) then leave loopcount /* if abort pressed AND indicator was created */ lister set source newprogress bar numobj loopcount lister set source newprogress file numobj loopcount srcfile = readln('cnpfile') /* complete path and name */ breakpos = max(lastpos(":",srcfile),lastpos("/",srcfile)) /* finds position of last : or / */ srcname = substr(srcfile,breakpos+1) /* name of current file or dir */ srcdir = left(srcfile,breakpos) /* name of path to current file or dir */ lister set source newprogress name compress(locale(48,'Adding'),'"') "'"srcname"'" srctype = left(statef(srcfile),1) if (srctype = 'D') & (arccmd=zipcmd) then srcname = '"'srcname'"' '"'srcname'/#?"' else if srctype = 'D' then srcname = '"'srcname'/#?"' else srcname = '"'srcname'"' olddir = pragma(D,srcdir) address command arccmd arguments srcname pragma(D,olddir) end lister set source busy off lister refresh source call close('cnpfile') end else do call cnpclear lister request source locale(3,"Paste")'": "'locale(8,"Cut'n'Paste clipboard is empty") end end else lister request source locale(3,"Paste")'": "'locale(8,"Cut'n'Paste clipboard is empty") return /* CUT OR COPY SINGLE ITEM (WITH ICON) */ clipsingle: if open('cnpfile','T:clipcnp','w,') then do selfile=compress(strip(arguments,L),'"') /* fix for lone icons cut/copied in icon mode */ if exists(selfile)=0 & exists(selfile||'.info')=1 then selfile = selfile||'.info' writeln('cnpfile',selfile) if function = 'Clip-Cut' then setclip('cnpcmd',1) else setclip('cnpcmd',2) setclip('numselobj',1) if exists(selfile||'.info')=1 then do /* test for existence of icon */ lister query source mode if (copyicons = 'yes') | ((copyicons = 'notnamemode') & (left(result,4) = 'icon')) then do writeln('cnpfile',selfile||'.info') setclip('numselobj',2) end end call close('cnpfile') call addpastecmds end return /* FUNCTION TO WRITE CLIPBOARD FILE CONTAINING MULTIPLE ITEMS */ clipmulti: lister query source numselentries numsel = result if numsel~=0 then do if open('cnpfile','T:clipcnp','w,') then do if function = 'Clip-MCut' then setclip('cnpcmd',1) else setclip('cnpcmd',2) setclip('numselobj',numsel) lister query source path srcpath = result do i=1 for numsel lister query source firstsel selobj = compress(result,'"') call writeln('cnpfile',srcpath || selobj) lister select source '"'selobj'"' off end lister refresh source full call close('cnpfile') call addpastecmds end end else if function = 'Clip-MCut' then lister request source locale(14,'Please select something to cut!') else lister request source locale(15,'Please select something to copy!') return /* ADD SINGLE ITEM (WITH ICON) */ addsingle: if open('cnpfile','T:clipcnp','a')=1 & getclip('numselobj')>0 then do if (addcheck = 'yes')|(addcheck = 'quiet') then call readclip selfile=compress(strip(arguments,L),'"') /* fix for lone icons cut/copied in icon mode */ if exists(selfile)=0 & exists(selfile||'.info')=1 then selfile = selfile||'.info' present = 0 if (addcheck = 'yes')|(addcheck = 'quiet') then call checkitem(selfile,oldnumobj) if present = 0 then do writeln('cnpfile',selfile) setclip('numselobj',getclip('numselobj')+1) end else present = 0 /* ensures present = 0 for next check */ if exists(selfile||'.info')=1 then do /* test for existence of icon */ lister query source mode if (copyicons = 'yes') | ((copyicons = 'notnamemode') & (left(result,4) = 'icon')) then do if (addcheck = 'yes')|(addcheck = 'quiet') then call checkitem(selfile||'.info',oldnumobj) if present = 0 then do writeln('cnpfile',selfile||'.info') setclip('numselobj',getclip('numselobj')+1) end end end call close('cnpfile') call addpastecmds end else do dopus request locale(39,"Add")""": """locale(8,"Cut'n'Paste clipboard is empty") call cnpclear end return /* FUNCTION TO ADD MULTIPLE ITEMS TO CLIPBOARD */ addmulti: if open('cnpfile','T:clipcnp','a,')=1 & getclip('numselobj')>0 then do lister query source numselentries numsel = result if numsel~=0 then do lister set source busy on lister query source path srcpath = result if (addcheck = 'yes')|(addcheck = 'quiet') then do call readclip duplicates = 0 lister set source newprogress file name info bar abort lister set source newprogress title compress(locale(28,"Cut'n'Paste progress..."),'"') lister set source newprogress info compress(locale(51,'Number of duplicated items: '),'"') duplicates end do lcount=1 for numsel lister query source firstsel selobj = compress(result,'"') present = 0 if (addcheck = 'yes')|(addcheck = 'quiet') then do lister query source abort if result = 1 then leave lcount lister set source newprogress name compress(locale(48,'Adding'),'"') "'"selobj"'" lister set source newprogress bar numsel lcount lister set source newprogress file numsel lcount call checkitem(srcpath||selobj,oldnumobj) end if present = 0 then do call writeln('cnpfile',srcpath || selobj) call setclip('numselobj',getclip('numselobj')+1) end else do duplicates = duplicates+1 lister set source newprogress info compress(locale(51,'Number of duplicated items:'),'"') duplicates end lister select source '"'selobj'"' off end lister refresh source full call close('cnpfile') call addpastecmds lister set source busy off end else lister request source locale(41,'Please select something to add!') end else do lister request source locale(39,"Add")'": "'locale(8,"Cut'n'Paste clipboard is empty") call cnpclear end return /* FUNCTION TO READ CURRENT CONTENTS OF CLIPBOARD TO STEM VARIABLE (assumes cnpfile already open) */ readclip: seek('cnpfile',0,BEGIN) /* returns read/write pointer to start of cnpfile */ oldnumobj = getclip('numselobj') do i=1 for oldnumobj oldclipitem.i = readln('cnpfile') end return /* FUNCTION TO CHECK FOR AN ITEM IN THE oldclipitem.x STEM VARIABLE */ checkitem: parse arg checkfile,numobj present = 0 do i=1 for numobj if checkfile = oldclipitem.i then do if addcheck = 'yes' then dopus request '"'''checkfile''''||'0a'x||, compress(locale(50,"already present in the clipboard!"),'"')'"' present = 1 leave i end end return