GTK-Chess icon indicating copy to clipboard operation
GTK-Chess copied to clipboard

Add PGN copy/paste/save/open feature

Open pddshk opened this issue 1 year ago • 2 comments

Add functions and connect them to appropriate widgets on the UI that would perform following logic:

Copy/paste features

  1. PGN copy function
    • Generate PGN string from the current position
    • Send generated PGN string to clipboard
  2. PGN paste function
    • Read clipboard content into string
    • Verifiy that it is a valid PGN string (use separate function for it)
    • If string is valid PGN, then paste position onto the board which means
      • Clear current state_tree
      • Initialize state_tree with game obtained from PGN
    • Else show error message

Open/Save features

Open and save functions should use Gtk.FileChooserDialog to let user select file.

PGN save feature logic should be implemented as follows

  1. Generate PGN string from the current position
  2. If there's currently opened file
    • Write PGN to the currently opened file
  3. Else request file name via FileChooserDialog and save PGN into given file

PGN open feature logic should be implemented as follows:

  1. Click on "Open PGN" button should
  2. Event handler connected to open signal then should
    • Verify file existence and readability
    • Read file contents into string
    • Verify it is a valid PGN string
    • If string is valid PGN, then paste position onto the board which means
      • Clear current state_tree
      • Initialize state_tree with game obtained from PGN
    • Else show error message

pddshk avatar Jun 06 '23 15:06 pddshk