From 01b3b8a0e0bf962b52de98e5c335434a94a21244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 18 Oct 2017 16:01:48 +0200 Subject: [PATCH] Make first slicing profile the default We also reflect that in the Cura profile import dialog by checking and disabling modification of the corresponding checkbox if no profiles are yet available. --- src/octoprint/plugins/cura/static/js/cura.js | 6 +++++- .../snippets/settings/cura/profileImporter.jinja2 | 8 ++++---- src/octoprint/slicing/__init__.py | 10 ++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/octoprint/plugins/cura/static/js/cura.js b/src/octoprint/plugins/cura/static/js/cura.js index 87f9d5f6..78b30bfd 100644 --- a/src/octoprint/plugins/cura/static/js/cura.js +++ b/src/octoprint/plugins/cura/static/js/cura.js @@ -24,6 +24,7 @@ $(function() { self.profileDescription = ko.observable(); self.profileAllowOverwrite = ko.observable(true); self.profileMakeDefault = ko.observable(false); + self.profileFirst = ko.observable(false); // make sure to update form data if any of the metadata changes self.profileName.subscribe(function() { self.copyProfileMetadata(); }); @@ -134,7 +135,10 @@ $(function() { self.profileDisplayName(undefined); self.profileDescription(undefined); self.profileAllowOverwrite(true); - self.profileMakeDefault(false); + + var firstProfile = self.profiles.items().length === 0; + self.profileMakeDefault(firstProfile); + self.profileFirst(firstProfile); }; self.uploadElement.fileupload({ diff --git a/src/octoprint/plugins/cura/templates/snippets/settings/cura/profileImporter.jinja2 b/src/octoprint/plugins/cura/templates/snippets/settings/cura/profileImporter.jinja2 index 71ff1465..c2aee166 100644 --- a/src/octoprint/plugins/cura/templates/snippets/settings/cura/profileImporter.jinja2 +++ b/src/octoprint/plugins/cura/templates/snippets/settings/cura/profileImporter.jinja2 @@ -37,15 +37,15 @@
-
-
diff --git a/src/octoprint/slicing/__init__.py b/src/octoprint/slicing/__init__.py index a1546c0a..27ca5849 100644 --- a/src/octoprint/slicing/__init__.py +++ b/src/octoprint/slicing/__init__.py @@ -377,6 +377,10 @@ class SlicingManager(object): If it's a :class:`dict`, a new :class:`SlicingProfile` instance will be created with the supplied meta data and the profile data as the :attr:`~SlicingProfile.data` attribute. + + .. note:: + + If the profile is the first profile to be saved for the slicer, it will automatically be marked as default. Arguments: slicer (str): Identifier of the slicer for which to save the ``profile``. @@ -414,6 +418,8 @@ class SlicingManager(object): if description is not None: profile.description = description + first_profile = len(self.all_profiles(slicer, require_configured=False)) == 0 + path = self.get_profile_path(slicer, name) is_overwrite = os.path.exists(path) @@ -426,6 +432,10 @@ class SlicingManager(object): profile=name) event = octoprint.events.Events.SLICING_PROFILE_MODIFIED if is_overwrite else octoprint.events.Events.SLICING_PROFILE_ADDED octoprint.events.eventManager().fire(event, payload) + + if first_profile: + # enforce the first profile we add for this slicer is set as default + self.set_default_profile(slicer, name) return profile