Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] minimal tab seperation support #313

Open
Freymaurer opened this issue Feb 15, 2024 · 3 comments
Open

[Feature Request] minimal tab seperation support #313

Freymaurer opened this issue Feb 15, 2024 · 3 comments

Comments

@Freymaurer
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
While developing Swate the need for clipboard support arose. I decided to parse the cells to tab seperated strings, due to:

  • Excel support. Pasting tab separated strings into Excels makes automatic cell splits.
  • The existing CompositeCell.GetContent() function returns all fields as string array and build a good basis for this function

Describe the solution you'd like

⚠️ Function names are off, there must be ebtter options.

    let internal tryFromContent' (content: string []) =
        match content with
        | [|freetext|] -> CompositeCell.createFreeText freetext |> Ok
        | [|name; tsr; tan|] -> CompositeCell.createTermFromString(name, tsr, tan) |> Ok
        | [|value; name; tsr; tan|] -> CompositeCell.createUnitizedFromString(value, name, tsr, tan) |> Ok
        | anyElse -> sprintf "Unable to convert \"%A\" to CompositeCell." anyElse |> Error

    type CompositeCell with
        
        static member tryFromContent (content: string []) =
            match tryFromContent' content with
            | Ok r -> Some r
            | Error _ -> None

        static member fromContent (content: string []) =
            match tryFromContent' content with
            | Ok r -> r
            | Error msg -> raise (exn msg) 

        member this.ToTabStr() = this.GetContent() |> String.concat "\t"

        static member fromTabStr (str:string) = 
            let content = str.Split('\t', enum<System.StringSplitOptions>3)
            CompositeCell.fromContent content

        static member ToTabTxt (cells: CompositeCell []) =
            cells 
            |> Array.map (fun c -> c.ToTabStr())
            |> String.concat (System.Environment.NewLine)

        static member fromTabTxt (tabTxt: string) =
            let lines = tabTxt.Split(System.Environment.NewLine, enum<System.StringSplitOptions>3)
            let cells = lines |> Array.map (fun line -> CompositeCell.fromTabStr line)
            cells 
@HLWeil
Copy link
Member

HLWeil commented Feb 15, 2024

I don't quite understand the requested feature from the text 😅

@Freymaurer
Copy link
Collaborator Author

Create tab separated text from composite cells 😅 . Like one line per cell.

@Freymaurer
Copy link
Collaborator Author

🐛 found a bug for cells without tsr tan, in which tabs were trimmed away. so change to:

static member fromTabTxt (tabTxt: string) =
    let lines = tabTxt.Split(System.Environment.NewLine, System.StringSplitOptions.None)
    let cells = lines |> Array.map (fun line -> CompositeCell.fromTabStr line)
    cells 

@Freymaurer Freymaurer added this to the Release ARCtrl 2.0 milestone Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants