home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / DEMO / RIM22 / MACROS / BUFFER.RM < prev    next >
Text File  |  1994-01-11  |  4KB  |  143 lines

  1. /*
  2. ** Macro module: buffer.rm - Misc. routines
  3. **
  4. ** Copyright (C) 1993 Brian L. Smith
  5. ** Copyright (C) 1993 RimStar Technology, Inc.
  6. ** All rights reserved internationally.
  7. ** Unlicensed use is a violation of applicable laws.
  8. **
  9. ** This source code is provided to licensed users of RimStar's products
  10. ** for the purpose of allowing the user to customize and/or enhance RimStar's
  11. ** products. The source code remains the property of the copyright holders
  12. ** with all rights reserved internationally.
  13. ** Any modifications to the source code are considered derivative works and
  14. ** all rights thereto are reserved to the copyright holders except
  15. ** that the purchaser may use the derivitive work in the same manner
  16. ** as permitted by the license governing the unmodified product.
  17. ** Distribution in any manner of any part of the original source code,
  18. ** whether in source or object form, is expressly prohibited without the
  19. ** express written permission of the copyright holders.
  20. **
  21. */
  22.  
  23. #include "macro.h"
  24.  
  25.  
  26. char *reloadMsg = "This file is already loaded and has been modified. "
  27.                         "Modifications will be lost if you answer YES. Reload file?";
  28.  
  29. /*
  30. **    EditFile - this macro is called by the DlgOpenFile primitive for each file
  31. **        selected to be edited, therefore it is required if you use DlgOpenFile.
  32. **    You may modify it of course.
  33. */
  34. SHORT
  35. EditFile(char *pathname, ULONG flags) {
  36.     SHORT        rc, reply;
  37.     HBUFFER    hb;
  38.  
  39.     if ( !(pathname = complete_path(pathname)) )
  40.         return 1;
  41.  
  42.     if ( (hb = BufFindBuffer(pathname, 0)) && BufQueryModified(hb) ) {
  43.         reply = PopupMsgBox( reloadMsg,
  44.                                     pathname,
  45.                                     MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2 | MB_APPLMODAL);
  46.         if ( reply != MBID_YES )
  47.             return 1;
  48.         rc = BufLoadFile(hb, pathname, flags);
  49.         free(pathname);
  50.         return rc;
  51.     }
  52.     rc = BufEditFile(pathname, flags);
  53.     free(pathname);
  54.     return rc;
  55. }  /* end EditFile() */
  56.  
  57.  
  58. SHORT
  59. ReloadBuffer(void) {
  60.     SHORT        reply;
  61.     char        *pathname;
  62.     HBUFFER    hbCurrent;
  63.  
  64.     hbCurrent = BufQueryCurrentBuffer();
  65.     pathname = BufQueryFilename();
  66.     if ( BufQueryModified() ) {
  67.         reply = PopupMsgBox( reloadMsg,
  68.                                     pathname,
  69.                                     MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2 | MB_APPLMODAL);
  70.         if ( reply != MBID_YES )
  71.             return 1;
  72.     }
  73.     return BufLoadFile(hbCurrent, pathname);
  74. } /* end ReloadBuffer() */
  75.  
  76.  
  77. SHORT
  78. SaveBuffer(void) {
  79.     if ( MarkQuerySelType() )
  80.         return BufWriteSel();
  81.     if ( !BufQueryModified() )    {
  82.         PopupMsg("File has not been modified. Save request ignored.", BufQueryFilename());
  83.         return -1;
  84.     }
  85.     return BufWrite();
  86. } /* end SaveBuffer() */
  87.  
  88.  
  89. void
  90. ReadOnlyBuffer(USHORT event, PVOID pData) {
  91.     char        *pathname;
  92.     SHORT        reply;
  93.  
  94.     pathname = BufQueryFilename();
  95.     reply = PopupMsgBox("Buffer is read only. Allow modifications?",
  96.                             pathname,
  97.                             MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2 | MB_APPLMODAL);
  98.     if ( reply == MBID_YES ) {
  99.         BufSetFlags(BUFFER_READ_ONLY, 0L);
  100.         return 0;
  101.     }
  102.     return 1;
  103. } /* end ReadOnlyBuffer() */
  104.  
  105.  
  106. void
  107. CopyToScrap(void) {
  108.     if ( !MarkQuerySelType() )        /* If no current selection */
  109.         MarkBeginSel(SELECT_LINE);    /* Mark current line */
  110.     BufCopyToScrap(0);
  111.     MarkRemoveSel();
  112. } /* CopyToScrap() */
  113.  
  114.  
  115. void
  116. CutToScrap(void) {
  117.     if ( !MarkQuerySelType() )        /* If no current selection */
  118.         MarkBeginSel(SELECT_LINE);    /* Mark current line */
  119.     BufCutToScrap(0);
  120. } /* end CutToScrap() */
  121.  
  122.  
  123. void
  124. CopyAppendToScrap(void) {
  125.     if ( !MarkQuerySelType() )        /* If no current selection */
  126.         MarkBeginSel(SELECT_LINE);    /* Mark current line */
  127.     BufCopyToScrap(1);
  128.     MarkRemoveSel();
  129. } /* CopyToScrap() */
  130.  
  131.  
  132. void
  133. CutAppendToScrap(void) {
  134.     if ( !MarkQuerySelType() )        /* If no current selection */
  135.         MarkBeginSel(SELECT_LINE);    /* Mark current line */
  136.     BufCutToScrap(1);
  137. } /* end CutToScrap() */
  138.  
  139.  
  140. /*
  141. ** End macro: buffer.rm
  142. */
  143.