Skip to content

Commit

Permalink
Disable copy paste when either 3mf reader or writer is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
casperlamboo committed Aug 8, 2023
1 parent f8b3fb3 commit c393d91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 7 additions & 1 deletion cura/CuraActions.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ def cut(self) -> None:
@pyqtSlot()
def copy(self) -> None:
mesh_writer = cura.CuraApplication.CuraApplication.getInstance().getMeshFileHandler().getWriter("3MFWriter")
if not mesh_writer:
Logger.log("e", "No 3MF writer found, unable to copy.")
return

# Get the selected nodes
selected_objects = Selection.getAllSelectedObjects()
Expand All @@ -204,11 +207,14 @@ def copy(self) -> None:
@pyqtSlot()
def paste(self) -> None:
application = cura.CuraApplication.CuraApplication.getInstance()
mesh_reader = application.getMeshFileHandler().getReaderForFile(".3mf")
if not mesh_reader:
Logger.log("e", "No 3MF reader found, unable to paste.")
return

# Parse the scene from the clipboard
scene_string = QApplication.clipboard().text()

mesh_reader = application.getMeshFileHandler().getReaderForFile(".3mf")
nodes = mesh_reader.stringToSceneNodes(scene_string)

# Find all fixed nodes, these are the nodes that should be avoided when arranging
Expand Down
13 changes: 9 additions & 4 deletions resources/qml/Actions.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pragma Singleton
import QtQuick 2.10
import QtQuick.Controls 2.4
import UM 1.1 as UM
import Cura 1.0 as Cura
import Cura 1.5 as Cura

Item
{
Expand Down Expand Up @@ -75,6 +75,11 @@ Item
property alias copy: copyAction
property alias cut: cutAction

readonly property bool copy_paste_enabled: {
const all_enabled_packages = CuraApplication.getPackageManager().allEnabledPackages;
return all_enabled_packages.includes("3MFReader") && all_enabled_packages.includes("3MFWriter");
}

UM.I18nCatalog{id: catalog; name: "cura"}


Expand Down Expand Up @@ -318,7 +323,7 @@ Item
id: copyAction
text: catalog.i18nc("@action:inmenu menubar:edit", "Copy to clipboard")
onTriggered: CuraActions.copy()
enabled: UM.Controller.toolsEnabled && UM.Selection.hasSelection
enabled: UM.Controller.toolsEnabled && UM.Selection.hasSelection && copy_paste_enabled
shortcut: StandardKey.Copy
}

Expand All @@ -327,7 +332,7 @@ Item
id: pasteAction
text: catalog.i18nc("@action:inmenu menubar:edit", "Paste from clipboard")
onTriggered: CuraActions.paste()
enabled: UM.Controller.toolsEnabled
enabled: UM.Controller.toolsEnabled && copy_paste_enabled
shortcut: StandardKey.Paste
}

Expand All @@ -336,7 +341,7 @@ Item
id: cutAction
text: catalog.i18nc("@action:inmenu menubar:edit", "Cut")
onTriggered: CuraActions.cut()
enabled: UM.Controller.toolsEnabled && UM.Selection.hasSelection
enabled: UM.Controller.toolsEnabled && UM.Selection.hasSelection && copy_paste_enabled
shortcut: StandardKey.Cut
}

Expand Down

0 comments on commit c393d91

Please sign in to comment.