Skip to content

Bug 799538 - Clipboard pastes to wrong field in... #2095

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

Open
wants to merge 3 commits into
base: stable
Choose a base branch
from

Conversation

Oscar65
Copy link
Contributor

@Oscar65 Oscar65 commented May 28, 2025

Fixed Cut, Copy and Paste when focus is not in GnucashSheet.

Fixed Cut, Copy and Paste when focus is not in GnucashSheet.
if (strcmp(name, "GnucashSheet") != 0) {
gtk_editable_cut_clipboard( GTK_EDITABLE(widget));

return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENTER at the start of the function is followed by LEAVE when you leave the function so you need to add some thing like LEAVE("Not cut from GnucashSheet"); above the return. Also the opening brace is on the wrong line and the indent should be 4 spaces.
This applies to all three functions.

@Bob-IT
Copy link
Contributor

Bob-IT commented May 28, 2025

I had a look at this bug and got side tracked so have tested your fix. It is an improvement but there was one thing I found when testing as follows...
Highlight some text on scheduled editor sheet and ctrl+c
Navigate to title with cursor at end and ctrl+v
Now select all the title and ctrl+c
Try pasting it back to same cell on sheet, it ends up in the title.

This is when I ran out of time so did not identify the reason.

Added LEAVE before return.
@Oscar65
Copy link
Contributor Author

Oscar65 commented May 29, 2025

I can repeat the bug, but I think it's a different one. When you click on the same field as above in the scheduled editor sheet after going to title, the title doesn't lose focus. You need to press TAB or double-click the scheduled editor sheet field for the title to lose focus.

@jralls
Copy link
Member

jralls commented May 29, 2025

When you click on the same field as above in the scheduled editor sheet after going to title, the title doesn't lose focus.

Right. This is directly observable: The I-beam cursor remains in the title field. Interestingly clicking in a different field in the register does move the focus.

@Oscar65
Copy link
Contributor Author

Oscar65 commented May 30, 2025

After investigating, I found that the scheduled editor sheet loses focus, but not the box indicating that it is being edited.

If it doesn't have focus and you click on the box editing, it doesn't gain focus, but if you click on the same field, but in the small space outside the box editing, it does gain focus.

The problem I'm having is that I don't know how to get the sheet variable to gain focus every time the "Template Transaction" tab is clicked or run gnucash_sheet_deactivate_cursor_cell(reg->sheet);.

If I run gtk_widget_grab_focus(GTK_WIDGET(sxed->embed_window)); or gtk_widget_grab_focus(GTK_WIDGET(sxed->nameEntry)); every time the "Template Transaction" tab is clicked, it does nothing. The "Duplicate" button always has focus. But to test if it works, I run gtk_widget_set_margin_top (GTK_WIDGET(sxed->embed_window), 500); and it does.

If you press the TAB key when entering the "Template Transaction" tab
when the focus is on the "Duplicate" button, then the field with the box editing gains focus.

Any ideas on how to fix this bug?

@Bob-IT
Copy link
Contributor

Bob-IT commented May 30, 2025

I dug through my saved working on patches and came across one that was looking into the gnucash-item-edit.c line 892

// Make sure the Entry can not have focus and no frame
gtk_widget_set_can_focus (GTK_WIDGET(item_edit->editor), FALSE);

Changing this to TRUE seems to sort of fix this but I can not remember why it was set that way.
May be a pointer.

@jralls
Copy link
Member

jralls commented May 30, 2025

@Bob-IT That line is from 1ed4f3d. In the commit message you wrote

Most of the call backs and procedures rely on the sheet being the one in focus so prevent the entry being in focus. In doing this there is no text cursor so add a draw function to draw one after the entry drawn. Also remove the frame from the entry.

So is the paste supposed to go to the sheet and the sheet figures out what frame to put it into?

@Bob-IT
Copy link
Contributor

Bob-IT commented May 31, 2025

I think the focus can be fixed by adding this to the end of the existing button_press_cb in gnucash-item-edit.c at line 860 before the return FALSE;

if (!gtk_widget_has_focus (GTK_WIDGET(sheet)))
    gtk_widget_grab_focus (GTK_WIDGET(sheet));

When the title entry is focused at the top of the dialog, the sheet focus out event is triggered which then triggers a focus out event for the item_edit. Possibly as that can not have focus, it upsets the events. When you click back in the same cell, there is no sheet in focus event so this change makes sure there is.

Now when the ledger loses focus, turns off editing controls.
And when the ledger regains focus, turns on editing controls.

Now, when the user clicks on the "Scheduled Transactions" tab,
the focus goes to the last edited cell.
@jralls
Copy link
Member

jralls commented Jun 9, 2025

LGTM. @Bob-IT ?

@Bob-IT
Copy link
Contributor

Bob-IT commented Jun 10, 2025

To start with you do not need the gnucash-sheet.c changes, with them the transfer cell popup does not work, probably all popups.
The source file changes in dialog-sx-editor.c need a bit off realignment.

I am not sure why there is a need for the IdleType structure, why not just do...


static gboolean
focus_idle_callback (gpointer user_data)
{
    GNCLedgerDisplay *ledger_display = (GNCLedgerDisplay *)user_data;

    if (ledger_display)
        gnc_ledger_display_refresh (ledger_display);

    return FALSE;
}

static void
on_notebook_switch_page (GtkNotebook *notebook, GtkWidget *page,
                         guint page_num, gpointer user_data)
{
    GtkWidget *current_page = gtk_notebook_get_nth_page (notebook, page_num);
    if (current_page && page_num == 2)
    {
        GncSxEditorDialog *sxed = (GncSxEditorDialog *)user_data;

        // Wait until Gtk is idle to refresh the display.
        g_idle_add (focus_idle_callback, sxed->ledger);
    }
}

@Oscar65
Copy link
Contributor Author

Oscar65 commented Jun 10, 2025

@Bob-IT Do you mean Action / Transfer...? On my PC it works. Could you be more specific about why does not work?

Sorry, I forgot to delete IdleType. I used before because I needed to pass two parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants