Skip to content

Commit 64a5cc4

Browse files
committed
fix for issue #3
1 parent dfbf4ac commit 64a5cc4

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/kate_with_ai/kate_with_ai.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ kate_with_ai_view::kate_with_ai_view(kate_with_ai * plugin, KTextEditor::MainWin
5151
plugin_{plugin},
5252
main_window_(main_window)
5353
{
54+
openai_process_action = new QAction(tr("Process with OpenAI"), this);
55+
connect(openai_process_action, &QAction::triggered, this, &kate_with_ai_view::on_process_with_ai);
56+
5457
// Connect to the signal that notifies about the current view change
5558
connect(main_window_, &KTextEditor::MainWindow::viewChanged, this, &kate_with_ai_view::on_view_changed);
5659

@@ -75,13 +78,11 @@ void kate_with_ai_view::on_context_menu_about_to_show(KTextEditor::View *, QMenu
7578
if(!menu) [[unlikely]]
7679
return;
7780

78-
info("Context menu registered for AI");
79-
// Add your custom action to the menu
80-
QAction * myAction = new QAction(tr("Process with OpenAI"), this);
81-
connect(myAction, &QAction::triggered, this, &kate_with_ai_view::on_process_with_ai);
82-
83-
// Append your action to the context menu
84-
menu->addAction(myAction);
81+
if(!menu->actions().contains(openai_process_action))
82+
{
83+
info("Context menu registered for AI");
84+
menu->addAction(openai_process_action);
85+
}
8586
}
8687

8788
void kate_with_ai_view::on_process_with_ai()

src/kate_with_ai/kate_with_ai.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ private slots:
5050

5151
kate_with_ai * plugin_;
5252
KTextEditor::MainWindow * main_window_;
53+
QAction * openai_process_action{};
5354
};

0 commit comments

Comments
 (0)