Mercurial Hosting > junotu
changeset 122:ad6ad9f695bb default tip
TabEdit: Started on card options pop-up menu
author | Fox |
---|---|
date | Sat, 25 Nov 2023 16:40:05 +0100 |
parents | cc1df2f32f2b |
children | |
files | src/junotu/TabEdit.java |
diffstat | 1 files changed, 55 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/TabEdit.java Sat Nov 25 15:18:53 2023 +0100 +++ b/src/junotu/TabEdit.java Sat Nov 25 16:40:05 2023 +0100 @@ -30,6 +30,7 @@ import javax.swing.JScrollBar; import javax.swing.JPopupMenu; import javax.swing.JMenuItem; +import javax.swing.JCheckBoxMenuItem; import junotu.Main; import junotu.Database; @@ -84,9 +85,14 @@ private JButton back; private JButton delete; + private JButton options; private JButton editAsBoard; private JButton save; + private JPopupMenu cardMenu; + private JMenuItem cardMenu_hidden; + private JMenuItem cardMenu_board; + private JPopupMenu tagMenu; private JMenuItem tagMenu_OpenUri; private JMenuItem tagMenu_CopyValue; @@ -107,6 +113,7 @@ Box bottom = Box.createHorizontalBox(); back = new JButton(); /* Text set in 'updateStatus()'. */ delete = new JButton("Delete"); + options = new JButton("Options"); editAsBoard = new JButton("As board"); save = new JButton("Save"); @@ -114,6 +121,11 @@ tagMenu_OpenUri = tagMenu.add("Open as URI"); tagMenu_CopyValue = tagMenu.add("Copy value"); + cardMenu = new JPopupMenu("Options"); + cardMenu_hidden = new JCheckBoxMenuItem("Hidden card"); + cardMenu.add(cardMenu_hidden); + cardMenu_board = cardMenu.add(""); + tags.setLayout( new FlowLayout() ); title.setFont( new Font( "Monospaced", Font.PLAIN, 32 ) ); @@ -139,6 +151,7 @@ bottom.add( back ); bottom.add( Box.createHorizontalGlue() ); bottom.add( delete ); + bottom.add( options ); bottom.add( editAsBoard ); bottom.add( save ); @@ -146,10 +159,18 @@ back.addActionListener(this); delete.addActionListener(this); + options.addActionListener(this); editAsBoard.addActionListener(this); save.addActionListener(this); addTag.addActionListener(this); + MenuElement cardMenuElements[] = cardMenu.getSubElements(); + for( int i = 0; i < cardMenuElements.length; i++ ) { + if( cardMenuElements[i] instanceof JMenuItem ) { + ((JMenuItem)cardMenuElements[i]).addActionListener(this); + } + } + MenuElement tagMenuElements[] = tagMenu.getSubElements(); for( int i = 0; i < tagMenuElements.length; i++ ) { if( tagMenuElements[i] instanceof JMenuItem ) { @@ -202,9 +223,12 @@ title.setToolTipText("Card title."); back.setToolTipText("Go back without saving. Can also use [ESC]."); delete.setToolTipText("Delete the card. There is no confirmation, nor going back."); + options.setToolTipText("Various card options"); editAsBoard.setToolTipText("Edit this card as board."); save.setToolTipText("Save and go back. Shift-click to save without exiting. Can also use [CTRL]+[S]."); + cardMenu_hidden.setToolTipText("Exclude the card from search results."); + addTag.setToolTipText("Add new tag."); tagMenu_OpenUri.setToolTipText("Open tag's value as URI; most commonly a file path ('file://') or URL ('http://')."); @@ -232,7 +256,10 @@ card = new Card(); dirty = true; updateStatus(); + updateOptions(); delete.setVisible(false); + cardMenu_board.setText("Attach board"); + cardMenu_board.setToolTipText("Attach a column board to this card."); updateTags(); } @@ -245,6 +272,7 @@ content.setText( card.contentGet() ); dirty = false; updateStatus(); + updateOptions(); delete.setVisible(true); updateTags(); /* TODO: Is this needed? */ @@ -322,6 +350,23 @@ } + private void updateOptions() + { + editAsBoard.setVisible( card.tagHas(Card.TAG_BOARD) ); + cardMenu_board.setText( + card.tagHas(Card.TAG_BOARD) ? "Remove board" : "Attach board" + ); + cardMenu_board.setToolTipText( + card.tagHas(Card.TAG_BOARD) ? + "Delete this card's attached column board, potentially deleting all contained cards." + : "Attach a column board to this card." + ); + /* Card visibility can't be toggled for now. */ + cardMenu_hidden.setEnabled(false); + /* Board removal isn't done for now. */ + cardMenu_board.setEnabled( !card.tagHas(Card.TAG_BOARD) ); + } + private void updateTags() { tags.removeAll(); @@ -598,7 +643,7 @@ private boolean possiblyShowTagContextMenu( MouseEvent e ) { - if( e.isPopupTrigger() ) { + if( e.isPopupTrigger() && e.getSource() instanceof TagWidget ) { TagWidget tagWidget = (TagWidget)e.getSource(); tagMenu_OpenUri.setEnabled( tagWidget.value instanceof String ); tagMenu_CopyValue.setEnabled( tagWidget.value != null ); @@ -633,11 +678,20 @@ buttonClickedEditAsBoard(); } else if( source == delete ) { buttonClickedDelete(); + } else if( source == options ) { + cardMenu.show( options, 0, 0 ); } else if( source == save ) { boolean noSwitch = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; buttonClickedSave( noSwitch ); } else if( source == addTag ) { tagAdd(); + } else if( source == cardMenu_board ) { + if( !card.tagHas(Card.TAG_BOARD) ) { + buttonClickedEditAsBoard(); + } else { + /* TODO: Remove the board from the card. */ + System.out.print("Tried to remove a column board from a card. This can't be done presently.\n"); + } } else if( source instanceof TagWidget ) { tagEdit( (TagWidget)source ); } else if( source == tagMenu_OpenUri ) {