2021-04-02 10:24:46 -04:00
|
|
|
/*
|
2025-02-06 21:47:26 -04:00
|
|
|
* Copyright (C) 2020-2025 Savoir-faire Linux Inc.
|
2021-04-02 10:24:46 -04:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2021-09-08 10:31:38 -04:00
|
|
|
import QtQuick
|
2024-04-15 13:58:17 -04:00
|
|
|
import net.jami.Adapters 1.1
|
2021-08-23 13:24:08 -04:00
|
|
|
import net.jami.Constants 1.1
|
2025-05-12 10:46:10 -04:00
|
|
|
import net.jami.Enums 1.1
|
|
|
|
|
import net.jami.Models 1.1
|
2021-05-31 14:04:38 -04:00
|
|
|
import "contextmenu"
|
2024-04-15 13:58:17 -04:00
|
|
|
import "../mainview"
|
|
|
|
|
import "../mainview/components"
|
2021-04-02 10:24:46 -04:00
|
|
|
|
2021-05-31 14:04:38 -04:00
|
|
|
ContextMenuAutoLoader {
|
2021-04-02 10:24:46 -04:00
|
|
|
id: root
|
|
|
|
|
|
2021-05-31 14:04:38 -04:00
|
|
|
// lineEdit (TextEdit) selection will be lost when menu is opened
|
|
|
|
|
property var lineEditObj
|
|
|
|
|
property var selectionStart
|
|
|
|
|
property var selectionEnd
|
2021-07-06 15:16:08 -04:00
|
|
|
property bool customizePaste: false
|
2021-06-03 15:33:24 -04:00
|
|
|
property bool selectOnly: false
|
2025-05-12 10:46:10 -04:00
|
|
|
property bool spellCheckEnabled: false
|
2024-04-15 13:58:17 -04:00
|
|
|
property var suggestionList
|
|
|
|
|
property var menuItemsLength
|
|
|
|
|
property var language
|
2021-05-31 14:04:38 -04:00
|
|
|
|
2021-07-06 15:16:08 -04:00
|
|
|
signal contextMenuRequirePaste
|
2025-05-12 10:46:10 -04:00
|
|
|
|
2024-04-15 13:58:17 -04:00
|
|
|
SpellLanguageContextMenu {
|
|
|
|
|
id: spellLanguageContextMenu
|
2025-05-12 10:46:10 -04:00
|
|
|
active: spellCheckEnabled
|
2024-04-15 13:58:17 -04:00
|
|
|
}
|
2021-07-06 15:16:08 -04:00
|
|
|
|
2021-05-31 14:04:38 -04:00
|
|
|
property list<GeneralMenuItem> menuItems: [
|
|
|
|
|
GeneralMenuItem {
|
2025-03-14 16:57:20 -05:00
|
|
|
id: cut
|
2021-05-31 14:04:38 -04:00
|
|
|
|
2023-10-24 16:35:37 -04:00
|
|
|
canTrigger: true
|
2025-03-14 16:57:20 -05:00
|
|
|
isActif: lineEditObj.selectedText.length && !selectOnly
|
|
|
|
|
itemName: JamiStrings.cut
|
2023-10-18 13:01:22 -04:00
|
|
|
hasIcon: false
|
2025-05-12 10:46:10 -04:00
|
|
|
onClicked: lineEditObj.cut()
|
2021-05-31 14:04:38 -04:00
|
|
|
},
|
|
|
|
|
GeneralMenuItem {
|
2025-03-14 16:57:20 -05:00
|
|
|
id: copy
|
2021-04-02 10:24:46 -04:00
|
|
|
|
2023-10-24 16:35:37 -04:00
|
|
|
canTrigger: true
|
2025-03-14 16:57:20 -05:00
|
|
|
isActif: lineEditObj.selectedText.length
|
|
|
|
|
itemName: JamiStrings.copy
|
2023-10-18 13:01:22 -04:00
|
|
|
hasIcon: false
|
2025-05-12 10:46:10 -04:00
|
|
|
onClicked: lineEditObj.copy()
|
2021-05-31 14:04:38 -04:00
|
|
|
},
|
|
|
|
|
GeneralMenuItem {
|
|
|
|
|
id: paste
|
|
|
|
|
|
2021-06-03 15:33:24 -04:00
|
|
|
canTrigger: !selectOnly
|
2021-05-31 14:04:38 -04:00
|
|
|
itemName: JamiStrings.paste
|
2023-10-18 13:01:22 -04:00
|
|
|
hasIcon: false
|
2021-05-31 14:04:38 -04:00
|
|
|
onClicked: {
|
2021-07-06 15:16:08 -04:00
|
|
|
if (customizePaste)
|
2023-04-13 16:18:26 -04:00
|
|
|
root.contextMenuRequirePaste();
|
2021-07-06 15:16:08 -04:00
|
|
|
else
|
2023-04-13 16:18:26 -04:00
|
|
|
lineEditObj.paste();
|
2021-05-31 14:04:38 -04:00
|
|
|
}
|
2024-04-15 13:58:17 -04:00
|
|
|
},
|
|
|
|
|
GeneralMenuItem {
|
2025-05-12 10:46:10 -04:00
|
|
|
id: textLanguage
|
|
|
|
|
canTrigger: spellCheckEnabled && SpellCheckAdapter.installedDictionaryCount > 0
|
|
|
|
|
itemName: JamiStrings.textLanguage
|
2024-04-15 13:58:17 -04:00
|
|
|
hasIcon: false
|
|
|
|
|
onClicked: {
|
|
|
|
|
spellLanguageContextMenu.openMenu();
|
|
|
|
|
}
|
2025-05-12 10:46:10 -04:00
|
|
|
},
|
|
|
|
|
GeneralMenuItem {
|
|
|
|
|
id: manageLanguages
|
|
|
|
|
itemName: JamiStrings.manageDictionaries
|
|
|
|
|
canTrigger: spellCheckEnabled
|
|
|
|
|
hasIcon: false
|
|
|
|
|
onClicked: {
|
|
|
|
|
viewCoordinator.presentDialog(appWindow, "commoncomponents/ManageDictionariesDialog.qml");
|
|
|
|
|
}
|
2021-05-31 14:04:38 -04:00
|
|
|
}
|
|
|
|
|
]
|
2021-04-02 10:24:46 -04:00
|
|
|
|
2024-04-15 13:58:17 -04:00
|
|
|
ListView {
|
|
|
|
|
model: ListModel {
|
2025-05-12 10:46:10 -04:00
|
|
|
id: suggestionListModel
|
2024-04-15 13:58:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Instantiator {
|
2025-05-12 10:46:10 -04:00
|
|
|
model: suggestionListModel
|
2024-04-15 13:58:17 -04:00
|
|
|
delegate: GeneralMenuItem {
|
|
|
|
|
id: suggestion
|
|
|
|
|
|
|
|
|
|
canTrigger: true
|
|
|
|
|
isActif: true
|
|
|
|
|
itemName: model.name
|
2025-05-12 10:46:10 -04:00
|
|
|
bold: true
|
2024-04-15 13:58:17 -04:00
|
|
|
hasIcon: false
|
|
|
|
|
onClicked: {
|
|
|
|
|
replaceWord(model.name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onObjectAdded: {
|
|
|
|
|
menuItems.push(object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onObjectRemoved: {
|
|
|
|
|
menuItems.splice(menuItemsLength, suggestionList.length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeItems() {
|
2025-05-12 10:46:10 -04:00
|
|
|
suggestionListModel.clear();
|
2024-04-15 13:58:17 -04:00
|
|
|
suggestionList.length = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addMenuItem(wordList) {
|
|
|
|
|
menuItemsLength = menuItems.length; // Keep initial number of items for easier removal
|
|
|
|
|
suggestionList = wordList;
|
|
|
|
|
for (var i = 0; i < suggestionList.length; ++i) {
|
2025-05-12 10:46:10 -04:00
|
|
|
suggestionListModel.append({
|
2024-04-15 13:58:17 -04:00
|
|
|
"name": suggestionList[i]
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function replaceWord(word) {
|
|
|
|
|
lineEditObj.remove(selectionStart, selectionEnd);
|
|
|
|
|
lineEditObj.insert(lineEditObj.cursorPosition, word);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 14:04:38 -04:00
|
|
|
function openMenuAt(mouseEvent) {
|
2021-06-03 15:33:24 -04:00
|
|
|
if (lineEditObj.selectedText.length === 0 && selectOnly)
|
2023-04-13 16:18:26 -04:00
|
|
|
return;
|
|
|
|
|
x = mouseEvent.x;
|
|
|
|
|
y = mouseEvent.y;
|
|
|
|
|
selectionStart = lineEditObj.selectionStart;
|
|
|
|
|
selectionEnd = lineEditObj.selectionEnd;
|
|
|
|
|
root.openMenu();
|
|
|
|
|
lineEditObj.select(selectionStart, selectionEnd);
|
2021-04-02 10:24:46 -04:00
|
|
|
}
|
|
|
|
|
|
2021-05-31 14:04:38 -04:00
|
|
|
Connections {
|
|
|
|
|
target: root.item
|
|
|
|
|
enabled: root.status === Loader.Ready
|
|
|
|
|
function onOpened() {
|
2023-04-13 16:18:26 -04:00
|
|
|
lineEditObj.select(selectionStart, selectionEnd);
|
2021-05-31 14:04:38 -04:00
|
|
|
}
|
2024-04-15 13:58:17 -04:00
|
|
|
function onClosed() {
|
2025-05-12 10:46:10 -04:00
|
|
|
if (!suggestionList || suggestionList.length === 0) {
|
2024-04-15 13:58:17 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
removeItems();
|
|
|
|
|
}
|
2021-04-02 10:24:46 -04:00
|
|
|
}
|
2021-05-31 14:04:38 -04:00
|
|
|
|
|
|
|
|
Component.onCompleted: menuItemsToLoad = menuItems
|
2021-04-02 10:24:46 -04:00
|
|
|
}
|