home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / FREDV19A.LHA / FrexxEd / fpl / SoftEdit.FPL < prev    next >
Encoding:
Text File  |  1994-05-31  |  10.2 KB  |  341 lines

  1. //*******************************************************************
  2. //  This program adds a X-window/Mac/Windows style editing with mouse
  3. //  marking and Cut/Copy/Paste in a slightly different way. Read
  4. //  SoftEdit.FPL.README for more information.
  5. //*******************************************************************
  6.  
  7. export int SE_MouseMark(int mode)
  8. {
  9.    SetInfo(-1, "softedit_cursor_marking", 0);
  10.    BlockMark(mode);
  11.    PlaceCursor(ReadInfo("mouse_x"), ReadInfo("mouse_y"));
  12. }
  13.  
  14. export int SE_MouseMarkWord()
  15. {
  16.    string str;
  17.    int x, y;
  18.    int v = Visible(0);
  19.  
  20.    BlockMark(0);
  21.    PlaceCursor(ReadInfo("mouse_x"), ReadInfo("mouse_y"));
  22.    str = GetLine();
  23.    SetInfo(-1, "softedit_cursor_marking", 1);
  24.    CursorRightWord();
  25.    CursorLeftWord();
  26.    x = ReadInfo("byte_position");
  27.  
  28.    while (Isword(str[x++]))
  29.       y++;
  30.  
  31.    BlockMark(1);
  32.    CursorRight(y);
  33.    SetInfo(-1, "softedit_cursor_marking", 0);
  34.    Visible(v);
  35. }
  36.  
  37. export int SE_BlockHook()
  38. {
  39.    if (!ReadInfo("softedit_cursor_marking"))
  40.    {
  41.       BlockMark(0);
  42.       return (0);
  43.    }
  44.    return(0);
  45. }
  46.  
  47. export int SE_OutputHook()
  48. {
  49.    BlockDelete();
  50.    return (0);
  51. }
  52.  
  53. export void SE_Paste(void)
  54. {
  55.    int x = Visible(0);
  56.    BlockDelete();
  57.    BlockPaste(-1);
  58.    Visible(x);
  59. }
  60.  
  61. export void SE_BlockMarkKey(void)
  62. {
  63.    BlockMark();
  64.    SetInfo(-1, "softedit_cursor_marking", ReadInfo("block_exist"));
  65. }
  66.  
  67. export void SE_BlockCopyKey(void)
  68. {
  69.    BlockCopy();
  70.    SetInfo(-1, "softedit_cursor_marking", ReadInfo("block_exist"));
  71. }
  72.  
  73. export void SE_BlockCutKey(void)
  74. {
  75.    BlockCut();
  76.    SetInfo(-1, "softedit_cursor_marking", ReadInfo("block_exist"));
  77. }
  78.  
  79. void ReplaceMenuItems(void)
  80. {
  81.    string slask, name;
  82.  
  83.    if (MenuRead(&slask, &name, &slask, &slask, 2, 9, 0) >= 0)
  84.    {
  85.       MenuDelete(2, 9, 0);
  86.       MenuAdd("item", name, "SE_Paste();", "Amiga i", 2, 9, 0);
  87.       MenuBuild();
  88.    }
  89. }
  90.  
  91. void SoftEditAssignKeys(void)
  92. {
  93.    if(stristr(ReadInfo("softedit_dragbutton"), "Mouse") >= 0)
  94.    {
  95.       AssignKey("SE_MouseMark(0);", ReadInfo("softedit_dragbutton"));
  96.       AssignKey("SE_MouseMark(1);", ReadInfo("softedit_dragbutton") + "Drag");
  97.       AssignKey("BlockMark(2);", ReadInfo("softedit_dragbutton") + "Up", "block_exist");
  98.    }
  99.  
  100.    if(stristr(ReadInfo("softedit_cutbutton"), "Mouse") >= 0)
  101.    {
  102.       AssignKey("BlockCut();", ReadInfo("softedit_cutbutton"));
  103.    }
  104.  
  105.    if(stristr(ReadInfo("softedit_copybutton"), "Mouse") >= 0)
  106.    {
  107.       AssignKey("BlockCopy();", ReadInfo("softedit_copybutton"));
  108.    }
  109.  
  110.    if(stristr(ReadInfo("softedit_pastebutton"), "Mouse") >= 0)
  111.    {
  112.       AssignKey("SE_Paste();", ReadInfo("softedit_pastebutton"));
  113.       // If we have assigned with singleclick then
  114.       // we assign the same function to double and triple as well
  115.       if((stristr(ReadInfo("softedit_pastebutton"), "Double") < 0) &&
  116.            (stristr(ReadInfo("softedit_pastebutton"), "Triple") < 0))
  117.       {
  118.      AssignKey("SE_Paste();", ReadInfo("softedit_pastebutton") + "Double");
  119.      AssignKey("SE_Paste();", ReadInfo("softedit_pastebutton") + "Triple");
  120.       }
  121.    }
  122.  
  123.    if(stristr(ReadInfo("softedit_wordmarkbutton"), "Mouse") >= 0)
  124.    {
  125.       AssignKey("SE_MouseMarkWord();", ReadInfo("softedit_wordmarkbutton"));
  126.    }
  127.  
  128.    if(stristr(ReadInfo("softedit_extendmarkbutton"), "Mouse") >= 0)
  129.    {
  130.       AssignKey("SE_MouseMark(1);", ReadInfo("softedit_extendmarkbutton"));
  131.    }
  132. }
  133.  
  134. export void SoftEditSettings(void)
  135. {
  136.    int persist = ReadInfo("softedit_persistent_blocks");
  137.    int dragkey, dragqual;
  138.    int cutkey, cutqual, cutclicks;
  139.    int copykey, copyqual, copyclicks;
  140.    int pastekey, pastequal, pasteclicks;
  141.    int wordmarkkey, wordmarkqual, wordmarkclicks;
  142.    int extendmarkkey, extendmarkqual, extendmarkclicks;
  143.    int x;
  144.    string dragbutton = ReadInfo("softedit_dragbutton");
  145.    string cutbutton = ReadInfo("softedit_cutbutton");
  146.    string copybutton = ReadInfo("softedit_copybutton");
  147.    string pastebutton = ReadInfo("softedit_pastebutton");
  148.    string wordmarkbutton = ReadInfo("softedit_wordmarkbutton");
  149.    string extendmarkbutton = ReadInfo("softedit_extendmarkbutton");
  150.  
  151.    string quals[5] = {"", "Shift", "Ctrl", "Amiga", "Alt"};
  152.    string keys[4] = {"", "MouseLeft", "MouseMiddle", "MouseRight"};
  153.    string clicks[3] = {"", "Double", "Triple"};
  154.  
  155.    DeleteKey(dragbutton);
  156.    DeleteKey(dragbutton + "Drag");
  157.    DeleteKey(dragbutton + "Up");
  158.    DeleteKey(cutbutton);
  159.    DeleteKey(copybutton);
  160.    DeleteKey(pastebutton);
  161.    DeleteKey(wordmarkbutton);
  162.    DeleteKey(extendmarkbutton);
  163.  
  164.    // Remove all assigns to double and triple click as well
  165.    if((stristr(pastebutton, "Double") < 0) && (stristr(pastebutton, "Triple") < 0))
  166.    {
  167.       DeleteKey(pastebutton + "Double");
  168.       DeleteKey(pastebutton + "Triple");
  169.    }
  170.  
  171.    for(x = 1;x < 5;x++)
  172.    {
  173.       if(stristr(dragbutton, quals[x]) >= 0)
  174.       {
  175.      dragqual = x;
  176.       }
  177.       if(stristr(cutbutton, quals[x]) >= 0)
  178.       {
  179.      cutqual = x;
  180.       }
  181.       if(stristr(copybutton, quals[x]) >= 0)
  182.       {
  183.      copyqual = x;
  184.       }
  185.       if(stristr(pastebutton, quals[x]) >= 0)
  186.       {
  187.      pastequal = x;
  188.       }
  189.       if(stristr(wordmarkbutton, quals[x]) >= 0)
  190.       {
  191.      wordmarkqual = x;
  192.       }
  193.       if(stristr(extendmarkbutton, quals[x]) >= 0)
  194.       {
  195.      extendmarkqual = x;
  196.       }
  197.    }
  198.  
  199.    for(x = 1;x < 4;x++)
  200.    {
  201.       if(stristr(dragbutton, keys[x]) >= 0)
  202.       {
  203.      dragkey = x;
  204.       }
  205.       if(stristr(cutbutton, keys[x]) >= 0)
  206.       {
  207.      cutkey = x;
  208.       }
  209.       if(stristr(copybutton, keys[x]) >= 0)
  210.       {
  211.      copykey = x;
  212.       }
  213.       if(stristr(pastebutton, keys[x]) >= 0)
  214.       {
  215.      pastekey = x;
  216.       }
  217.       if(stristr(wordmarkbutton, keys[x]) >= 0)
  218.       {
  219.      wordmarkkey = x;
  220.       }
  221.       if(stristr(extendmarkbutton, keys[x]) >= 0)
  222.       {
  223.      extendmarkkey = x;
  224.       }
  225.    }
  226.  
  227.    for(x = 1;x < 3;x++)
  228.    {
  229.       if(stristr(cutbutton, clicks[x]) >= 0)
  230.       {
  231.      cutclicks = x;
  232.       }
  233.       if(stristr(copybutton, clicks[x]) >= 0)
  234.       {
  235.      copyclicks = x;
  236.       }
  237.       if(stristr(pastebutton, clicks[x]) >= 0)
  238.       {
  239.      pasteclicks = x;
  240.       }
  241.       if(stristr(wordmarkbutton, clicks[x]) >= 0)
  242.       {
  243.      wordmarkclicks = x;
  244.       }
  245.       if(stristr(extendmarkbutton, clicks[x]) >= 0)
  246.       {
  247.      extendmarkclicks = x;
  248.       }
  249.    }
  250.  
  251.    RequestWindow("SoftEdit Settings", 15,
  252.            "Persistent blocks", "b", &persist,
  253.            "Drag qualifier", "c", &dragqual,
  254.         "None|Shift|Ctrl|Amiga|Alt",
  255.            "Drag button", "c", &dragkey,
  256.         "None|MouseLeft|MouseMiddle|MouseRight",
  257.            "Cut qualifier", "c", &cutqual,
  258.         "None|Shift|Ctrl|Amiga|Alt",
  259.            "Cut button", "c", &cutkey,
  260.         "None|MouseLeft|MouseMiddle|MouseRight",
  261.            "Cut clicks", "c", &cutclicks,
  262.         "Single|Double|Triple",
  263.            "Copy qualifier", "c", ©qual,
  264.         "None|Shift|Ctrl|Amiga|Alt",
  265.            "Copy button", "c", ©key,
  266.         "None|MouseLeft|MouseMiddle|MouseRight",
  267.            "Copy clicks", "c", ©clicks,
  268.         "Single|Double|Triple",
  269.            "Paste qualifier", "c", &pastequal,
  270.         "None|Shift|Ctrl|Amiga|Alt",
  271.            "Paste button", "c", &pastekey,
  272.         "None|MouseLeft|MouseMiddle|MouseRight",
  273.            "Paste clicks", "c", &pasteclicks,
  274.         "Single|Double|Triple",
  275.            "Word mark qualifier", "c", &wordmarkqual,
  276.         "None|Shift|Ctrl|Amiga|Alt",
  277.            "Word mark button", "c", &wordmarkkey,
  278.         "None|MouseLeft|MouseMiddle|MouseRight",
  279.            "Word mark clicks", "c", &wordmarkclicks,
  280.         "Single|Double|Triple",
  281.            "Extend mark qualifier", "c", &extendmarkqual,
  282.         "None|Shift|Ctrl|Amiga|Alt",
  283.            "Extend mark button", "c", &extendmarkkey,
  284.         "None|MouseLeft|MouseMiddle|MouseRight",
  285.            "Extend mark clicks", "c", &extendmarkclicks,
  286.         "Single|Double|Triple");
  287.  
  288.    SetInfo(-1, "softedit_persistent_blocks", persist);
  289.    SetInfo(-1, "softedit_dragbutton", quals[dragqual] + " " + keys[dragkey]);
  290.    SetInfo(-1, "softedit_cutbutton", quals[cutqual] + " " + keys[cutkey] + clicks[cutclicks]);
  291.    SetInfo(-1, "softedit_copybutton", quals[copyqual] + " " + keys[copykey] + clicks[copyclicks]);
  292.    SetInfo(-1, "softedit_pastebutton", quals[pastequal] + " " + keys[pastekey] + clicks[pasteclicks]);
  293.    SetInfo(-1, "softedit_extendmarkbutton", quals[extendmarkqual] + " " + keys[extendmarkkey] + clicks[extendmarkclicks]);
  294.    SetInfo(-1, "softedit_wordmarkbutton", quals[wordmarkqual] + " " + keys[wordmarkkey] + clicks[wordmarkclicks]);
  295.  
  296.    SoftEditAssignKeys();
  297. }
  298.  
  299. // Clicking clears the marked block
  300. AssignKey("BlockMark(0);
  301.        PlaceCursor(ReadInfo(\"mouse_x\"), ReadInfo(\"mouse_y\"));", "MouseLeft");
  302.  
  303. // Output clears the marked block
  304. Hook("Output", "SE_OutputHook();", "block_exist&!softedit_persistent_blocks");
  305.  
  306. // Cursor movements removes the block marking
  307. Hook("CursorUp", "SE_BlockHook();", "block_exist&!softedit_persistent_blocks");
  308. Hook("CursorDown", "SE_BlockHook();", "block_exist&!softedit_persistent_blocks");
  309. Hook("CursorLeft", "SE_BlockHook();", "block_exist&!softedit_persistent_blocks");
  310. Hook("CursorRight", "SE_BlockHook();", "block_exist&!softedit_persistent_blocks");
  311. Hook("CursorLeftWord", "SE_BlockHook();", "block_exist&!softedit_persistent_blocks");
  312. Hook("CursorRightWord", "SE_BlockHook();", "block_exist&!softedit_persistent_blocks");
  313. Hook("PageUp", "SE_BlockHook();", "block_exist&!softedit_persistent_blocks");
  314. Hook("PageDown", "SE_BlockHook();", "block_exist&!softedit_persistent_blocks");
  315. Hook("Backspace", "SE_OutputHook(); return(1);", "block_exist&!softedit_persistent_blocks");
  316. Hook("Delete", "SE_OutputHook(); return(1);", "block_exist&!softedit_persistent_blocks");
  317.  
  318. // This hack makes it possible for us to mark with Amiga b as usual
  319. ConstructInfo("softedit_cursor_marking", "", "", "LBH", "", 0, 1);
  320. SetInfo(-2, "softedit_cursor_marking", 0);
  321.  
  322. AssignKey("SE_BlockMarkKey();", "Amiga b");
  323. AssignKey("SE_BlockCopyKey();", "Amiga c");
  324. AssignKey("SE_BlockCutKey();", "Amiga x");
  325.  
  326. // Replace the "Insert" choice in the menu
  327. ReplaceMenuItems();
  328.  
  329. ConstructInfo("softedit_persistent_blocks", "", "", "HBW", "", 0, 1, 0);
  330. ConstructInfo("softedit_dragbutton", "", "", "HSW", "", 0, 0, "MouseLeft");
  331. ConstructInfo("softedit_cutbutton", "", "", "HSW", "", 0, 0, "Shift MouseRight");
  332. ConstructInfo("softedit_copybutton", "", "", "HSW", "", 0, 0, "MouseRight");
  333. ConstructInfo("softedit_pastebutton", "", "", "HSW", "", 0, 0, "MouseMiddle");
  334. ConstructInfo("softedit_wordmarkbutton", "", "", "HSW", "", 0, 0, "MouseLeftDouble");
  335. ConstructInfo("softedit_extendmarkbutton", "", "", "HSW", "", 0, 0, "Shift MouseLeft");
  336.  
  337. SoftEditAssignKeys();
  338.  
  339. MenuAdd("S", "Softedit...", "SoftEditSettings();", "", 6, 6, -1);
  340. MenuBuild();
  341.