home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / p2demo21.exe / PEL / GUI.PEL < prev    next >
Text File  |  1995-03-17  |  13KB  |  491 lines

  1. # $Header:   P:\source\wmacros\gui.pev   1.83   17 Mar 1995 11:59:06   WALKER  $
  2.  
  3. ##############################################################################
  4. #
  5. #       Compuware Corporation
  6. #         31440 Northwestern Highway
  7. #           Farmington Hills, Michigan 48334-2564
  8. #
  9. #   This source code listing contains information that is
  10. #   proprietary to Compuware Corporation and may not be copied
  11. #   duplicated, translated, transmitted, stored, retrieved
  12. #   or in any manner or by any method conveyed or disclosed
  13. #   to a third party or parties without express written
  14. #   permission from Compuware Corporation.
  15. #
  16. #  
  17. ##############################################################################
  18.  
  19.  
  20. #### $Workfile:   gui.pel  $: gui functions
  21.  
  22. ## $Tabs:4 7$
  23.  
  24. # Not used right now, but will be when and if we decide to disable buttons
  25. #local function check_ext()
  26. #{
  27. #   local ext    = tolower(path_ext( buffer_filename ));
  28. #   return  (  (file_extensions["c"]          ~ ext) \
  29. #         || (file_extensions["basic"]      ~ ext) \
  30. #         || (file_extensions["pascal"]     ~ ext) \
  31. #         || (file_extensions["dbase"]      ~ ext) \
  32. #         || (file_extensions["clipper87"]  ~ ext) \
  33. #         || (file_extensions["clipper50"]  ~ ext) \
  34. #         || (file_extensions["force"]      ~ ext) )
  35. #}
  36.  
  37.  
  38. function gui_undo( index )
  39. {
  40.    local status = !!undo_index()
  41.  
  42.    if ( argcount() )
  43.       status = undo( index )
  44.    else
  45.       status = undo()
  46. }
  47.  
  48. function gui_redo( index )
  49. {
  50.    local status
  51.  
  52.    if ( argcount() )
  53.       status = redo( index )
  54.    else
  55.       status = redo()
  56. }
  57.  
  58. #------------- Basic text commands support ---------------------------------#
  59. function gui_backspace()
  60. {
  61.    if (( current_column > 1 ) \
  62.    || and( buffer_flags, BUFFER_WP_ENABLED ))
  63.    {
  64.       backspace()
  65.    }
  66. }
  67.  
  68.  
  69. #------------- Playback/record and Macros functions unique to gui ----------#
  70.  
  71.  
  72. #------------- Miscellaneous functions unique to gui -----------------------#
  73.  
  74. global function gui_invoke_function()
  75. {
  76.    local mac
  77.  
  78. # UNCOMMENT next 3 lines when common command works and delete last line
  79. #   mac = ltrim( command_dialog() )
  80. #   if (mac) 
  81. #      invoke_function(mac)
  82.  
  83.    invoke_function()
  84. }
  85.  
  86. # new_edit_file()
  87. #
  88. # Whenever a new edit file is created, the extension is stripped from
  89. # the file name and a function with that extension (preceded by "_")
  90. # is invoked. If the function does not exist, "default()" is called.
  91. #
  92. #global function new_edit_file()
  93. #{
  94. #   local   ext = path_ext( buffer_filename );
  95. #   local   lev = message_level;
  96. #   local   def_name = "default"
  97. #   local   id
  98. #
  99. #   message_level = 3;
  100. #
  101. #   if (ext)
  102. #   {
  103. #      if (substr( ext, 1, 1 ) == "." )
  104. #      {
  105. #         ext = "_" substr( ext, 2 );
  106. #         id = function_id( ext );
  107. #         if ( id )
  108. #         {
  109. #            message_level = lev;
  110. #            execute_function( ext );
  111. #            return;
  112. #         }
  113. #      }
  114. #   }
  115. #
  116. #   id = function_id( def_name );
  117. #   message_level = lev;
  118. #   if ( id )
  119. #      execute_function( def_name );
  120. #}
  121.  
  122. # read the print settings the first time print is selected
  123. local read_print_settings = 1
  124.  
  125. global function gui_print()
  126. {
  127.    if (read_print_settings)
  128.    {
  129.       read_print_settings = 0
  130.       read_config_section("$PRINT_SETTINGS$")      
  131.    }
  132.    print_dialog()
  133. }
  134.  
  135. global function save_print_settings()
  136. {
  137.    local data_array
  138.    local index = 0
  139.  
  140.    # if read_print_settings is 1 then we haven't read the config
  141.    # information in so don't try to write it just return.
  142.    if (read_print_settings == 1)
  143.       return data_array;
  144.  
  145.    data_array[ index++ ] = sprintf( "print_split=%d\n",          print_split )
  146.    data_array[ index++ ] = sprintf( "print_word_wrap=%d\n",      print_word_wrap )
  147.    data_array[ index++ ] = sprintf( "print_indent=%d\n",         print_indent )
  148.    data_array[ index++ ] = sprintf( "print_program_indent=%d\n", print_program_indent )
  149.    data_array[ index++ ] = sprintf( "print_columns=%d\n",        print_columns )
  150.    data_array[ index++ ] = sprintf( "print_orientation=%d\n",    print_orientation )
  151.  
  152.    data_array[ index++ ] = sprintf( "headers_enabled=%d\n",      headers_enabled)
  153.    data_array[ index++ ] = sprintf( "footers_enabled=%d\n",      footers_enabled)
  154.  
  155.    data_array[ index++ ] = sprintf( "header=\"%s\"\n", quote_string(header))
  156.    data_array[ index++ ] = sprintf( "footer=\"%s\"\n", quote_string(footer))
  157.  
  158.    if ( length(print_font_name) )
  159.    {
  160.       store_print_font("print", "Fonts")
  161.       data_array[ index++ ] = sprintf("load_print_font \"print\" \"Fonts\"\n")
  162.    }
  163.  
  164.    if ( length(header_font_name) )
  165.    {
  166.       store_header_font("header", "Fonts")
  167.       data_array[ index++ ] = sprintf("load_header_font \"header\" \"Fonts\"\n")
  168.    }
  169.  
  170.    if ( length(footer_font_name) )
  171.    {
  172.       store_footer_font("footer", "Fonts")
  173.       data_array[ index++ ] = sprintf("load_footer_font \"footer\" \"Fonts\"\n")
  174.    }
  175.  
  176.    data_array[ index++ ] = sprintf( "\n" )
  177.    return data_array
  178. }
  179.  
  180.  
  181. global function gui_print_select()
  182. {
  183.    print_select_dialog()
  184. }
  185.  
  186. global function gui_new(dontCallCreate)
  187. {
  188.    local this_buffer = current_buffer
  189.    local newBuffer;
  190.  
  191.    next_buffer( this_buffer )
  192.    newBuffer = new_buffer_name();
  193.  
  194.    if(newBuffer && !dontCallCreate)
  195.    {
  196.       create_buf_and_win(newBuffer);
  197.       buffer_flags = or(buffer_flags, BUFFER_SCRATCH);
  198.    }
  199.  
  200.    return newBuffer;
  201. }
  202.  
  203. local lastPath = "*.*"
  204.  
  205. local ENABLE_LOCK_FILE            = 0x10000000
  206. local ENABLE_COPY_FILE_TO_VM      = 0x01000000
  207. local ENABLE_OPEN_FILE_IN_WINDOW  = 0x00100000
  208. local ENABLE_READ_ONLY            = 0x00010000
  209. local ALL_ENABLED                 =  ENABLE_COPY_FILE_TO_VM      +
  210.                                      ENABLE_LOCK_FILE            +
  211.                                      ENABLE_OPEN_FILE_IN_WINDOW  +
  212.                                      ENABLE_READ_ONLY
  213.  
  214. local COPY_FILE_TO_VM_CHECKED     = 0x00001000
  215. local LOCK_FILE_CHECKED           = 0x00000100
  216. local OPEN_FILE_IN_WINDOW_CHECKED = 0x00000010
  217. local READ_ONLY_CHECKED           = 0x00000001
  218.  
  219. global function gui_open( infileToOpen )
  220. {
  221.    local InitialPath
  222.    local listOfFiles
  223.    local arrayOfFiles
  224.    local fileToOpen
  225.    local ret
  226.    local i
  227.    local flags
  228.    local buffer_ro
  229.    local lock_buf
  230.    local copy
  231.    local wf
  232.    local editfile_list
  233.    local old_create_new_bufwin = create_new_bufwin
  234.    
  235.    #  if infileToOpen is specified use it otherwise use 
  236.    #  use the last path that was used.
  237.    InitialPath = (infileToOpen) ? infileToOpen : lastPath
  238.    
  239.    flags = ALL_ENABLED
  240.    
  241.    if ( !mdi_mode )
  242.       flags = and(flags, not(ENABLE_OPEN_FILE_IN_WINDOW) )
  243.  
  244.    if ( create_new_bufwin )
  245.       flags = or(flags, OPEN_FILE_IN_WINDOW_CHECKED);
  246.  
  247.    editfile_list = get_history_list("EDITFILE")
  248.  
  249.    listOfFiles = open_dialog( InitialPath, "Open", flags, "open", editfile_list )
  250.    
  251.    if ( listOfFiles )
  252.    {
  253.       # parse out the files and flags.  Flags are always the first
  254.       # element in the list. 
  255.  
  256.       split(listOfFiles, arrayOfFiles, ";")
  257.  
  258.       # the flags are the first items in the array
  259.       if ( and( arrayOfFiles[1], OPEN_FILE_IN_WINDOW_CHECKED) )
  260.          create_new_bufwin = 1
  261.       else
  262.          create_new_bufwin = 0
  263.  
  264.       if ( and( arrayOfFiles[1], READ_ONLY_CHECKED ) )
  265.          buffer_ro = 1             
  266.       else
  267.          buffer_ro = 0
  268.  
  269.       if ( and( arrayOfFiles[1], LOCK_FILE_CHECKED ) )
  270.          lock_buf = TRUE
  271.       else
  272.          lock_buf = FALSE
  273.  
  274.       if ( and( arrayOfFiles[1], COPY_FILE_TO_VM_CHECKED ) )
  275.          copy = TRUE
  276.       else
  277.          copy = FALSE
  278.  
  279.       for(i in arrayOfFiles)
  280.       {
  281.  
  282.          if ( i != 1 )
  283.          {
  284.             fileToOpen = arrayOfFiles[i]
  285.             add_prompt_history("EDITFILE", fileToOpen)
  286.             create_buf_and_win(fileToOpen)
  287.  
  288.             if ( buffer_ro )
  289.                buffer_flags = or( buffer_flags, BUFFER_READ_ONLY )
  290.  
  291.             if ( lock_buf )
  292.                lock_buffer()
  293.  
  294.             if ( copy )
  295.                copy_buffer_internally()
  296.  
  297.             # parse the drive:directory from the filename and store in
  298.             # last path.
  299.             #
  300.             lastPath = path_path(fileToOpen) "*.*"
  301.          }
  302.       }
  303.       #  restore the old state of create_new_bufwin only if it was not toggled off;
  304.       if(!old_create_new_bufwin || create_new_bufwin)
  305.          create_new_bufwin = old_create_new_bufwin
  306.  
  307. #      if ( current_window == 0 )
  308. #      {
  309. #         if ( mdi_mode )
  310. #         {
  311. #            wf = and(WINDOW_STANDARD_MDI, not(WINDOW_ZOOM))
  312. #            wf = or(wf, WINDOW_EXPANDED)
  313. #            current_window = create_window( 0, 0, 100, 100, wf)
  314. #         }
  315. #         else
  316. #            current_window = create_window( 0, 0, 100, 100, WINDOW_STANDARD_SDI )
  317. #      
  318. #         attach_window_buffer( current_window, current_buffer )
  319. #      }
  320.  
  321.       # display current filename
  322.       #
  323.       display_filename()
  324.       return TRUE
  325.    }
  326.    else
  327.       return FALSE
  328. }
  329.  
  330. function gui_save()
  331. {
  332.    if ( is_scratch_file(current_buffer) )
  333.       return gui_saveas()
  334.  
  335.    write_buffer_key()
  336. }
  337.  
  338. global function edit_another(infileToOpen)
  339. {
  340.    local InitialPath
  341.    local fileToOpen
  342.    local arr
  343.    local ret
  344.  
  345.    #  if infileToOpen is specified use it otherwise use 
  346.    #  use the last path that was used.
  347.    InitialPath = (infileToOpen) ? infileToOpen : lastPath
  348.  
  349.    fileToOpen = open_dialog( InitialPath, "Edit Another File", 0, "open_dialog" )
  350.    split(fileToOpen, arr, ";")
  351.  
  352.    if ( arr[2] )  {
  353.       ret = spawn( ARGV[0], arr[2] )
  354.       if (ret != 0) {
  355.          error("Could not execute: " ARGV[0] " " arr[2])
  356.       }
  357.  
  358.       # parse the drive:directory from the filename and store in
  359.       # last path.
  360.       lastPath = path_path(arr[2]) "*.*"
  361.    }
  362. }
  363.  
  364. global function gui_insert_file( infileToOpen )
  365. {
  366.    local InitialPath
  367.    local fileToOpen
  368.    local arr
  369.  
  370.    #  if infileToOpen is specified use it otherwise use 
  371.    #  use the last path that was used.
  372.    #
  373.    InitialPath = (infileToOpen) ? infileToOpen : lastPath
  374.  
  375.    fileToOpen = open_dialog( InitialPath, "Insert File", 0, "insert" )
  376.  
  377.    # parse out the open flags
  378.    split(fileToOpen, arr, ";")
  379.  
  380.    if ( arr[2] ) {
  381.       read_file_key(arr[2])
  382.  
  383.       # parse the drive:directory from the filename and store in
  384.       # last path.
  385.       lastPath = path_path(arr[2]) "*.*"
  386.    }
  387.    return arr[2];
  388. }
  389.  
  390. # gui_saveas returns 0 if file was not written, 1 if it was
  391. global function gui_saveas( infileToWrite )
  392. {
  393.    local fileToWrite
  394.    local old_bfname
  395.    local old_bname
  396.    local ret = 0
  397.    local overwrite = TRUE
  398.    local prompt_str
  399.    local fname
  400.    local start_buf
  401.  
  402.    fileToWrite = saveas_dialog( (infileToWrite) ? infileToWrite : buffer_filename, 
  403.                                  "saveas")
  404.    
  405.    if ( filemode(fileToWrite) != -1 )
  406.       prompt_str = fileToWrite " exists"
  407.  
  408.    start_buf = current_buffer
  409.    fname = path_fname(fileToWrite)
  410.    while ( (current_buffer = next_buffer("", 1, 1)) != start_buf )
  411.    {
  412.       if ( buildpath(fileToWrite) == buildpath(buffer_filename) )
  413.       {
  414.          if ( prompt_str )
  415.             prompt_str = prompt_str " and is in a buffer"
  416.          else
  417.             prompt_str = fileToWrite " is in a buffer"
  418.  
  419.          current_buffer = start_buf
  420.          break
  421.       }
  422.    }
  423.  
  424.    if ( prompt_str )
  425.       overwrite = tolower(confirm( prompt_str ". Overwrite? ", "yYnN" )) == "y"
  426.  
  427.    if ( fileToWrite && overwrite )  
  428.     {
  429.       ret = write_buffer_as(fileToWrite)
  430.         if ( ret )
  431.         {
  432.            new_edit_file()
  433.            syntax_new_buffer()
  434.         }
  435.     }
  436.  
  437.    return ret
  438. }      
  439.  
  440. global function gui_saveall()
  441. {
  442.    if ( !write_all_buffers() ) 
  443.       {
  444.       error("Unable to write buffers")
  445.       return
  446.       }
  447.    message("All buffers saved.")
  448. }
  449.  
  450. function gui_write_block()
  451. {
  452.    local   fileToWrite
  453.    local   status
  454.  
  455.    if( selection_type() == NO_SELECTION )
  456.    {
  457.       warning("Cannot write block.  Nothing selected.")
  458.    }
  459.    else
  460.    {
  461.       fileToWrite = prompt( "Write block as: ", "", "write_buffer_as_dialog" )
  462.       if (fileToWrite)
  463.       {
  464.          backup_file( fileToWrite );
  465.          if (write_marked_block( fileToWrite ))
  466.             message("Write successful.")
  467.       }
  468.    }
  469. }
  470.  
  471. global function gui_delete_buffer()
  472. {
  473.    delete_buffer_key("", 1);
  474. }
  475.  
  476. function gui_delete_to_scrap()
  477. {
  478.    delete_to_scrap()
  479. }
  480.  
  481. global function gui_nyi()                                       #PUBLIC #VOID
  482. {
  483.    warning( " Not yet implemented" )
  484. }
  485.  
  486. # unimplemented functions
  487. global function init_menu_colors() { gui_nyi();}
  488. global function pvcs_get_group() { gui_nyi();}
  489.  
  490.