The final 100 yards using Bob Finnerty's suggestion - (Hey! Finnerty. Glad to 
see still working with 4D!)



1. Here is the code (non-pseudo) that you place in your project as a Project 
Method: here called SortMethod. Paste this text in and save it.


  // PROJECT METHOD: SortMethod
  // ----------------------------------------------------
  // CREATED: 05/31/17, 17:40:22 Robert Livingston
  // DESCRIPTION: Alphabetically sorts the lines of a method when used in a 
Macro
  // Call SortMethod from the Macro dropdown in the Method Editor

C_TEXT ($inputText)
C_TEXT ($sortedText)

C_LONGINT ($FULL_METHOD_TEXT)
$FULL_METHOD_TEXT:=1
GET MACRO PARAMETER ($FULL_METHOD_TEXT;$inputText)

  // take the input text and turn it into a Text array
ARRAY TEXT ($axLineCode;0)
C_LONGINT ($positionDelimiter)
C_TEXT ($element)

Repeat

  $positionDelimiter:=Position (Char (Carriage return);$inputText)

  If ($positionDelimiter=0)

    If ($inputText#"")  // don't gratuitously add a blank line to the array at 
the end
      APPEND TO ARRAY ($axLineCode;$inputText)
    End if

  Else

    $element:=Substring ($inputText;1; ($positionDelimiter-1))
    $inputText:=Substring ($inputText;$positionDelimiter+1)

    If ($element#"")  // filter out blank lines
      APPEND TO ARRAY ($axLineCode;$element)
    End if

  End if

Until ($positionDelimiter=0)

SORT ARRAY ($axLineCode)

C_LONGINT ($nElement;$totElement)
$totElement:=Size of array ($axLineCode)

If ($totElement>0)

  $sortedText:=$axLineCode{1}

  For ($nElement;2;$totElement)
    $sortedText:=$sortedText+Char (Carriage return)+$axLineCode{$nElement}
  End for

Else

  $sortedText:="ALERT("+Char (Double quote)+"Method passed has no content"+Char 
(Double quote)+")"

End if

SET MACRO PARAMETER ($FULL_METHOD_TEXT;$sortedText)



2. Here is the Macro that you have in your Macro v2 folder (you can just add 
these lines to any existing Macros.xml that you may have.


<macro name="SortMethod" version="2">
    <text>
        <method>SortMethod</method>
    </text>
</macro>


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*    *    *    *    *    *    *    *    *    *    *    

To use: 

– Be in the method that you wish to sort. 

– Call the Macro -- SortMethod -- from the macro dropdown list that is part of 
the method editor.

– Boom, the method is sorted.


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*    *    *    *    *    *    *    *    *    *    *    

It can be a little disconcerting if you accidentally apply this Macro to some 
random method. It will instantly turn into an alphabetized mess. Fortunately, 
the Undo Command will restore its original state.



> On May 30, 2017, at 8:39 AM, Bob Finnerty via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> Hi Chip,
> 
> Here's the pseudocode:
> 
> Create a 4d method mySortMethod
> GET MACRO PARAMETER highlighted text
> Parse returned text to text array with substring using CR as delimiter
> Sort array
> Rebuild method text from array: For(1;$element;size of array())+CR
> SET MACRO PARAMETER highlighted text
> 
> Then in your macros.xml v2 file:
> 
> <macro
>        name="Sort method lines"
>        in_toolbar="true"
>        in_menu="true"
>        type_ahead="false"
>        version="2"
>> 
>        <text><method>mySortMethod</method></text>
> </macro>
> 
> HTH
> 
> -- 
> Bob Finnerty
> Exodus Software
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **********************************************************************
> 
> On Tue, May 30, 2017 at 8:04 AM, Chip Scheide via 4D_Tech <
> 4d_tech@lists.4d.com> wrote:
> 
>> Anyone have a macro (or anything else)
>> which will sort method editor text?
>> 
>> I have a method which I am using to keep track of other methods I have
>> worked on.
>> I would like to sort this list. Currently I am copy/pasting in excel
>> and sorting and copy/pasting back
> 
> 

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to