1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Bug 333134 - Add options to configure doxygen behavior

Reworked UI code to its natural contract.
Switched java 8 to compact the code
Encapsulated scope inside the DoxygenPreferences

Change-Id: I534b8d4f7c2d6e7674b132a10ef3514e61f2c1ed
Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
Alexander Fedorov 2020-01-14 21:24:53 +03:00 committed by Marco Stornelli
parent 4909e9632f
commit 830bf8074c
8 changed files with 182 additions and 174 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2015 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2020 Wind River Systems, Inc. and others.
* *
* This program and the accompanying materials * This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0 * are made available under the terms of the Eclipse Public License 2.0
@ -12,11 +12,12 @@
* Anton Leherbauer (Wind River Systems) - initial API and implementation * Anton Leherbauer (Wind River Systems) - initial API and implementation
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.text.doctools.doxygen; package org.eclipse.cdt.ui.tests.text.doctools.doxygen;
import java.util.HashMap; import java.util.HashMap;
import java.util.Optional;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
@ -64,15 +65,13 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
super.setUp(); super.setUp();
fOptions = CCorePlugin.getOptions(); fOptions = CCorePlugin.getOptions();
fCProject = CProjectHelper.createCCProject("test" + System.currentTimeMillis(), null); fCProject = CProjectHelper.createCCProject("test" + System.currentTimeMillis(), null);
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty()); DoxygenPreferences pref = new DoxygenPreferences();
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG); pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF, pref.putBoolean(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF,
DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF); DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS, pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS, DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS);
DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS); pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS, DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS, pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS,
DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS,
DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS); DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS);
} }
@ -695,8 +694,8 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
// */ // */
//void foo() {} //void foo() {}
public void testAutoDocCommentBrief() throws CoreException { public void testAutoDocCommentBrief() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty()); DoxygenPreferences pref = new DoxygenPreferences();
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true); pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
assertAutoEditBehaviour(); assertAutoEditBehaviour();
} }
@ -708,9 +707,9 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
// */ // */
//void foo() {} //void foo() {}
public void testAutoDocCommentBriefNoNewLine() throws CoreException { public void testAutoDocCommentBriefNoNewLine() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty()); DoxygenPreferences pref = new DoxygenPreferences();
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true); pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF, false); pref.putBoolean(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF, false);
assertAutoEditBehaviour(); assertAutoEditBehaviour();
} }
@ -722,8 +721,8 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
// */ // */
//void foo() {} //void foo() {}
public void testAutoDocCommentStructured() throws CoreException { public void testAutoDocCommentStructured() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty()); DoxygenPreferences pref = new DoxygenPreferences();
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS, true); pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS, true);
assertAutoEditBehaviour(); assertAutoEditBehaviour();
} }
@ -736,9 +735,9 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
// */ // */
//void foo() {} //void foo() {}
public void testAutoDocCommentNoJavadoc() throws CoreException { public void testAutoDocCommentNoJavadoc() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty()); DoxygenPreferences pref = new DoxygenPreferences();
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true); pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS, false); pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS, false);
assertAutoEditBehaviour(); assertAutoEditBehaviour();
} }
@ -753,9 +752,9 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
// */ // */
//void foo() {} //void foo() {}
public void testAutoDocCommentPrePostTags() throws CoreException { public void testAutoDocCommentPrePostTags() throws CoreException {
DoxygenPreferences pref = new DoxygenPreferences(Optional.empty()); DoxygenPreferences pref = new DoxygenPreferences();
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true); pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, true);
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS, true); pref.putBoolean(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS, true);
assertAutoEditBehaviour(); assertAutoEditBehaviour();
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2014 IBM Corporation and others. * Copyright (c) 2005, 2020 IBM Corporation and others.
* *
* This program and the accompanying materials * This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0 * are made available under the terms of the Eclipse Public License 2.0
@ -14,6 +14,8 @@
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.preferences; package org.eclipse.cdt.internal.ui.preferences;
@ -30,6 +32,7 @@ import org.eclipse.cdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey
import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl; import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl;
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference; import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager; import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
import org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.dialogs.DocCommentOwnerComposite; import org.eclipse.cdt.ui.dialogs.DocCommentOwnerComposite;
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner; import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
@ -85,11 +88,13 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
private DocCommentOwnerComposite fDocCommentOwnerComposite; private DocCommentOwnerComposite fDocCommentOwnerComposite;
// TODO(sprigogin): Remove once compatibility with Platform 4.4 is no longer required. // TODO(sprigogin): Remove once compatibility with Platform 4.4 is no longer required.
private final boolean formattingScopeForEmptySelectionSupported; private final boolean formattingScopeForEmptySelectionSupported;
private final DoxygenPreferences doxygenPreferences;
public CEditorPreferencePage() { public CEditorPreferencePage() {
super(); super();
Bundle jfaceText = Platform.getBundle("org.eclipse.jface.text"); //$NON-NLS-1$ Bundle jfaceText = Platform.getBundle("org.eclipse.jface.text"); //$NON-NLS-1$
formattingScopeForEmptySelectionSupported = jfaceText.getVersion().compareTo(new Version(3, 10, 0)) >= 0; formattingScopeForEmptySelectionSupported = jfaceText.getVersion().compareTo(new Version(3, 10, 0)) >= 0;
doxygenPreferences = new DoxygenPreferences();
} }
@Override @Override
@ -363,14 +368,14 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
fAppearanceColorList.select(0); fAppearanceColorList.select(0);
handleAppearanceColorListSelection(); handleAppearanceColorListSelection();
}); });
fDocCommentOwnerComposite.loadValues(); fDocCommentOwnerComposite.initialize(doxygenPreferences);
} }
@Override @Override
public boolean performOk() { public boolean performOk() {
DocCommentOwnerManager.getInstance() DocCommentOwnerManager.getInstance()
.setWorkspaceCommentOwner(fDocCommentOwnerComposite.getSelectedDocCommentOwner()); .setWorkspaceCommentOwner(fDocCommentOwnerComposite.getSelectedDocCommentOwner());
fDocCommentOwnerComposite.performOk(); fDocCommentOwnerComposite.apply(doxygenPreferences);
return super.performOk(); return super.performOk();
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2020 Marco Stornelli * Copyright (c) 2020 Marco Stornelli and others
* *
* This program and the accompanying materials * This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0 * are made available under the terms of the Eclipse Public License 2.0
@ -10,101 +10,136 @@
* *
* Contributors: * Contributors:
* Marco Stornelli - Initial implementation * Marco Stornelli - Initial implementation
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.text.doctools; package org.eclipse.cdt.internal.ui.text.doctools;
import java.util.Optional;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.service.prefs.Preferences; import org.osgi.service.prefs.Preferences;
public class DoxygenPreferences { /**
* Encapsulates access to the Doxygen-related preferences according to the current scope
* @since 6.7
*
*/
public final class DoxygenPreferences {
/** /**
* Use always brief tag in auto-generation of doxygen comment * Use always brief tag in auto-generation of doxygen comment
* @since 6.7 * @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/ */
public static final String DOXYGEN_USE_BRIEF_TAG = "doxygen_use_brief_tag"; //$NON-NLS-1$ public static final String DOXYGEN_USE_BRIEF_TAG = "doxygen_use_brief_tag"; //$NON-NLS-1$
/** /**
* Use always structured commands in auto-generation of doxygen comment * Use always structured commands in auto-generation of doxygen comment
* @since 6.7 * @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/ */
public static final String DOXYGEN_USE_STRUCTURAL_COMMANDS = "doxygen_use_structural_commands"; //$NON-NLS-1$ public static final String DOXYGEN_USE_STRUCTURAL_COMMANDS = "doxygen_use_structural_commands"; //$NON-NLS-1$
/** /**
* Use always javadoc tag style in auto-generation of doxygen comment * Use always javadoc tag style in auto-generation of doxygen comment
* @since 6.7 * @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/ */
public static final String DOXYGEN_USE_JAVADOC_TAGS = "doxygen_use_javadoc_tags"; //$NON-NLS-1$ public static final String DOXYGEN_USE_JAVADOC_TAGS = "doxygen_use_javadoc_tags"; //$NON-NLS-1$
/** /**
* Use always a new line after brief tag in auto-generation of doxygen comment * Use always a new line after brief tag in auto-generation of doxygen comment
* @since 6.7 * @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/ */
public static final String DOXYGEN_NEW_LINE_AFTER_BRIEF = "doxygen_new_line_after_brief"; //$NON-NLS-1$ public static final String DOXYGEN_NEW_LINE_AFTER_BRIEF = "doxygen_new_line_after_brief"; //$NON-NLS-1$
/** /**
* Use always a pre tag in auto-generation of doxygen comment * Use always a pre tag in auto-generation of doxygen comment
* @since 6.7 * @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/ */
public static final String DOXYGEN_USE_PRE_POST_TAGS = "doxygen_use_pre_tag"; //$NON-NLS-1$ public static final String DOXYGEN_USE_PRE_POST_TAGS = "doxygen_use_pre_tag"; //$NON-NLS-1$
/** /**
* Default use always brief tag in auto-generation of doxygen comment * Default use always brief tag in auto-generation of doxygen comment
* @since 6.7 * @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/ */
public static final boolean DEF_DOXYGEN_USE_BRIEF_TAG = false; public static final boolean DEF_DOXYGEN_USE_BRIEF_TAG = false;
/** /**
* Default use always structured commands in auto-generation of doxygen comment * Default use always structured commands in auto-generation of doxygen comment
* @since 6.7 * @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/ */
public static final boolean DEF_DOXYGEN_USE_STRUCTURED_COMMANDS = false; public static final boolean DEF_DOXYGEN_USE_STRUCTURED_COMMANDS = false;
/** /**
* Default use always javadoc tag style in auto-generation of doxygen comment * Default use always javadoc tag style in auto-generation of doxygen comment
* @since 6.7 * @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/ */
public static final boolean DEF_DOXYGEN_USE_JAVADOC_TAGS = true; public static final boolean DEF_DOXYGEN_USE_JAVADOC_TAGS = true;
/** /**
* Default use always a new line after brief tag in auto-generation of doxygen comment * Default use always a new line after brief tag in auto-generation of doxygen comment
* @since 6.7 * @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/ */
public static final boolean DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF = true; public static final boolean DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF = true;
/** /**
* Default use always a pre tag in auto-generation of doxygen comment * Default use always a pre tag in auto-generation of doxygen comment
* @since 6.7 * @since 6.7
* @noreference This field is not intended to be referenced by clients.
*/ */
public static final boolean DEF_DOXYGEN_USE_PRE_POST_TAGS = false; public static final boolean DEF_DOXYGEN_USE_PRE_POST_TAGS = false;
private static final String QUALIFIER = CCorePlugin.PLUGIN_ID; private final Preferences preferences;
private static final String WORKSPACE_DOXYGEN_NODE = "doxygen"; //$NON-NLS-1$
private Optional<IProject> project; public DoxygenPreferences() {
this(InstanceScope.INSTANCE);
}
public DoxygenPreferences(Optional<IProject> project) { public DoxygenPreferences(IProject project) {
this.project = project; this(new ProjectScope(project));
}
public DoxygenPreferences(IScopeContext scope) {
this.preferences = scope.getNode(getNodeQualifier()).node(getNodePath());
}
private String getNodeQualifier() {
return CCorePlugin.PLUGIN_ID;
}
private String getNodePath() {
return "doxygen"; //$NON-NLS-1$
} }
/** /**
* Get boolean preferences * Get boolean preference value
* @param key A preference key * @param key A preference key
* @param defaultValue A default value * @param defaultValue A default value
* @return The preference value * @return The preference value
*
* @since 6.7
*/ */
public boolean getBooleanPref(String key, boolean defaultValue) { public boolean getBoolean(String key, boolean defaultValue) {
Preferences prefs = project.isPresent() return preferences.getBoolean(key, defaultValue);
? new ProjectScope(project.get()).getNode(QUALIFIER).node(WORKSPACE_DOXYGEN_NODE)
: InstanceScope.INSTANCE.getNode(QUALIFIER).node(WORKSPACE_DOXYGEN_NODE);
return prefs.getBoolean(key, defaultValue);
} }
/** /**
* Put boolean preferences * Put boolean preference value
* @param key A preference key * @param key A preference key
* @param defaultValue A default value * @param defaultValue A default value
*
* @since 6.7
*/ */
public void putBooleanPref(String key, boolean value) { public void putBoolean(String key, boolean value) {
Preferences prefs = project.isPresent() preferences.putBoolean(key, value);
? new ProjectScope(project.get()).getNode(QUALIFIER).node(WORKSPACE_DOXYGEN_NODE)
: InstanceScope.INSTANCE.getNode(QUALIFIER).node(WORKSPACE_DOXYGEN_NODE);
prefs.putBoolean(key, value);
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2009 Symbian Software Systems and others. * Copyright (c) 2008, 2020 Symbian Software Systems and others.
* *
* This program and the accompanying materials * This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0 * are made available under the terms of the Eclipse Public License 2.0
@ -10,10 +10,13 @@
* *
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.dialogs; package org.eclipse.cdt.ui.dialogs;
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager; import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
import org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences;
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner; import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -87,12 +90,14 @@ public class DocCommentOwnerBlock extends AbstractCOptionPage {
String dsc = DialogsMessages.DocCommentOwnerBlock_SelectDocToolDescription; String dsc = DialogsMessages.DocCommentOwnerBlock_SelectDocToolDescription;
String msg = DialogsMessages.DocCommentOwnerBlock_DocToolLabel; String msg = DialogsMessages.DocCommentOwnerBlock_DocToolLabel;
IDocCommentOwner prjOwner = DocCommentOwnerManager.getInstance().getCommentOwner(getProject()); IProject project = getProject();
IDocCommentOwner prjOwner = DocCommentOwnerManager.getInstance().getCommentOwner(project);
fDocComboComposite = new DocCommentOwnerComposite(pane, prjOwner, dsc, msg); fDocComboComposite = new DocCommentOwnerComposite(pane, prjOwner, dsc, msg);
fDocComboComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create()); fDocComboComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
fCheckbox.setSelection(fManager.projectDefinesOwnership(getProject())); fCheckbox.setSelection(fManager.projectDefinesOwnership(project));
fDocComboComposite.loadValues(getProject()); DoxygenPreferences preferences = new DoxygenPreferences(project);
fDocComboComposite.initialize(preferences);
handleCheckBox(); handleCheckBox();
} }
@ -105,7 +110,8 @@ public class DocCommentOwnerBlock extends AbstractCOptionPage {
IDocCommentOwner newOwner = fDocComboComposite.getSelectedDocCommentOwner(); IDocCommentOwner newOwner = fDocComboComposite.getSelectedDocCommentOwner();
fManager.setCommentOwner(project, newOwner, true); fManager.setCommentOwner(project, newOwner, true);
} }
fDocComboComposite.performOk(project); DoxygenPreferences preferences = new DoxygenPreferences(project);
fDocComboComposite.apply(preferences);
} }
public IProject getProject() { public IProject getProject() {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2009 Symbian Software Systems and others. * Copyright (c) 2008, 2020 Symbian Software Systems and others.
* *
* This program and the accompanying materials * This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0 * are made available under the terms of the Eclipse Public License 2.0
@ -10,6 +10,8 @@
* *
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.dialogs; package org.eclipse.cdt.ui.dialogs;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2009 Symbian Software Systems and others. * Copyright (c) 2008, 2020 Symbian Software Systems and others.
* *
* This program and the accompanying materials * This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0 * are made available under the terms of the Eclipse Public License 2.0
@ -10,19 +10,31 @@
* *
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.dialogs; package org.eclipse.cdt.ui.dialogs;
import java.util.Optional; import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS;
import static org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS;
import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager; import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
import org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences; import org.eclipse.cdt.internal.ui.text.doctools.DoxygenPreferences;
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner; import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
@ -37,33 +49,18 @@ import org.eclipse.swt.widgets.Label;
* @noextend This class is not intended to be subclassed by clients. * @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients. * @noinstantiate This class is not intended to be instantiated by clients.
*/ */
public class DocCommentOwnerComposite extends Composite implements SelectionListener { public class DocCommentOwnerComposite extends Composite {
protected DocCommentOwnerCombo fDocCombo; protected DocCommentOwnerCombo fDocCombo;
protected Label desc, comboLabel; protected Label desc, comboLabel;
protected Group group; protected Group group;
/**
* @since 6.7 private final Map<String, Button> buttons;
*/ private final Map<String, Boolean> defaults;
protected Button useBriefTag;
/**
* @since 6.7
*/
protected Button useStructuralCommands;
/**
* @since 6.7
*/
protected Button useJavadocStyle;
/**
* @since 6.7
*/
protected Button newLineAfterBrief;
/**
* @since 6.7
*/
protected Button usePrePostTag;
public DocCommentOwnerComposite(Composite parent, IDocCommentOwner initialOwner, String description, String label) { public DocCommentOwnerComposite(Composite parent, IDocCommentOwner initialOwner, String description, String label) {
super(parent, SWT.NONE); super(parent, SWT.NONE);
buttons = new LinkedHashMap<>();
defaults = new LinkedHashMap<>();
GridLayout gl = new GridLayout(); GridLayout gl = new GridLayout();
gl.marginHeight = gl.marginWidth = 0; gl.marginHeight = gl.marginWidth = 0;
setLayout(gl); setLayout(gl);
@ -85,21 +82,28 @@ public class DocCommentOwnerComposite extends Composite implements SelectionList
}; };
gd = GridDataFactory.fillDefaults().grab(true, false).create(); gd = GridDataFactory.fillDefaults().grab(true, false).create();
fDocCombo.setLayoutData(gd); fDocCombo.setLayoutData(gd);
fDocCombo.addSelectionListener(this); fDocCombo.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> recheckButtons()));
useBriefTag = addCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseBriefTagTitle); createCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseBriefTagTitle, DOXYGEN_USE_BRIEF_TAG,
useStructuralCommands = addCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseStructuralCommandsTitle); DEF_DOXYGEN_USE_BRIEF_TAG);
useJavadocStyle = addCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseTagJavadocStyleTitle); createCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseStructuralCommandsTitle,
newLineAfterBrief = addCheckBox(group, DialogsMessages.DocCommentOwnerComposite_NewLineAfterBriefTitle); DOXYGEN_USE_STRUCTURAL_COMMANDS, DEF_DOXYGEN_USE_STRUCTURED_COMMANDS);
usePrePostTag = addCheckBox(group, DialogsMessages.DocCommentOwnerComposite_AddPrePostTagsTitle); createCheckBox(group, DialogsMessages.DocCommentOwnerComposite_UseTagJavadocStyleTitle,
DOXYGEN_USE_JAVADOC_TAGS, DEF_DOXYGEN_USE_JAVADOC_TAGS);
createCheckBox(group, DialogsMessages.DocCommentOwnerComposite_NewLineAfterBriefTitle,
DOXYGEN_NEW_LINE_AFTER_BRIEF, DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF);
createCheckBox(group, DialogsMessages.DocCommentOwnerComposite_AddPrePostTagsTitle, DOXYGEN_USE_PRE_POST_TAGS,
DEF_DOXYGEN_USE_PRE_POST_TAGS);
} }
private Button addCheckBox(Composite parent, String label) { private Button createCheckBox(Composite parent, String label, String key, boolean value) {
Button checkBox = new Button(parent, SWT.CHECK); Button checkBox = new Button(parent, SWT.CHECK);
checkBox.setText(label); checkBox.setText(label);
GridData gd = new GridData(GridData.FILL_HORIZONTAL); GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalIndent = 0; gd.horizontalIndent = 0;
gd.horizontalSpan = 2; gd.horizontalSpan = 2;
checkBox.setLayoutData(gd); checkBox.setLayoutData(gd);
buttons.put(key, checkBox);
defaults.put(key, value);
return checkBox; return checkBox;
} }
@ -107,51 +111,34 @@ public class DocCommentOwnerComposite extends Composite implements SelectionList
return fDocCombo.getSelectedDocCommentOwner(); return fDocCombo.getSelectedDocCommentOwner();
} }
private void initialize(Button button, DoxygenPreferences pref, String key, boolean defaultValue) { /**
button.setSelection(pref.getBooleanPref(key, defaultValue)); * Initializes widget values from the given preference instance
*
* @param preferences the preferences to initialize from
*
* @since 6.7
*
* @noreference This method is not intended to be referenced by clients.
*/
public void initialize(DoxygenPreferences preferences) {
buttons.entrySet().stream().forEach(e -> initialize(e.getValue(), preferences, e.getKey()));
}
void initialize(Button button, DoxygenPreferences pref, String key) {
button.setSelection(pref.getBoolean(key, defaults.get(key)));
} }
/** /**
* Apply widget values to the given preference instance
*
* @param preferences the preferences to apply to
*
* @since 6.7 * @since 6.7
*
* @noreference This method is not intended to be referenced by clients.
*/ */
public void loadValues(IProject project) { public void apply(DoxygenPreferences preferences) {
DoxygenPreferences pref = new DoxygenPreferences(Optional.ofNullable(project)); buttons.entrySet().stream().forEach(e -> preferences.putBoolean(e.getKey(), e.getValue().getSelection()));
initialize(newLineAfterBrief, pref, DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF,
DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF);
initialize(useBriefTag, pref, DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG,
DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG);
initialize(useJavadocStyle, pref, DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS);
initialize(usePrePostTag, pref, DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS);
initialize(useStructuralCommands, pref, DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS,
DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS);
}
/**
* @since 6.7
*/
public void loadValues() {
loadValues(null);
}
/**
* @since 6.7
*/
public void performOk(IProject project) {
DoxygenPreferences pref = new DoxygenPreferences(Optional.ofNullable(project));
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF, newLineAfterBrief.getSelection());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, useBriefTag.getSelection());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS, useJavadocStyle.getSelection());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS, usePrePostTag.getSelection());
pref.putBooleanPref(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS, useStructuralCommands.getSelection());
}
/**
* @since 6.7
*/
public void performOk() {
performOk(null);
} }
@Override @Override
@ -160,45 +147,13 @@ public class DocCommentOwnerComposite extends Composite implements SelectionList
comboLabel.setEnabled(enabled); comboLabel.setEnabled(enabled);
fDocCombo.setEnabled(enabled); fDocCombo.setEnabled(enabled);
group.setEnabled(enabled); group.setEnabled(enabled);
if (fDocCombo.isEnabled() && DocCommentOwnerManager.DOXYGEN_CDT_DOC_ONWER_ID recheckButtons();
.equals(fDocCombo.getSelectedDocCommentOwner().getID())) {
useBriefTag.setEnabled(true);
useStructuralCommands.setEnabled(true);
useJavadocStyle.setEnabled(true);
newLineAfterBrief.setEnabled(true);
usePrePostTag.setEnabled(true);
} else {
useBriefTag.setEnabled(false);
useStructuralCommands.setEnabled(false);
useJavadocStyle.setEnabled(false);
newLineAfterBrief.setEnabled(false);
usePrePostTag.setEnabled(false);
}
} }
@Override void recheckButtons() {
public void widgetSelected(SelectionEvent e) { boolean doxygenEnabled = fDocCombo.isEnabled() && DocCommentOwnerManager.DOXYGEN_CDT_DOC_ONWER_ID
if (DocCommentOwnerManager.DOXYGEN_CDT_DOC_ONWER_ID.equals(fDocCombo.getSelectedDocCommentOwner().getID())) { .equals(fDocCombo.getSelectedDocCommentOwner().getID());
useBriefTag.setEnabled(true); buttons.values().forEach(b -> b.setEnabled(doxygenEnabled));
useStructuralCommands.setEnabled(true);
useJavadocStyle.setEnabled(true);
newLineAfterBrief.setEnabled(true);
usePrePostTag.setEnabled(true);
} else {
useBriefTag.setEnabled(false);
useStructuralCommands.setEnabled(false);
useJavadocStyle.setEnabled(false);
newLineAfterBrief.setEnabled(false);
usePrePostTag.setEnabled(false);
}
} }
@Override
public void widgetDefaultSelected(SelectionEvent e) {
useBriefTag.setEnabled(false);
useStructuralCommands.setEnabled(false);
useJavadocStyle.setEnabled(false);
newLineAfterBrief.setEnabled(false);
usePrePostTag.setEnabled(false);
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2015 Symbian Software Systems and others. * Copyright (c) 2008, 2020 Symbian Software Systems and others.
* *
* This program and the accompanying materials * This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0 * are made available under the terms of the Eclipse Public License 2.0
@ -11,6 +11,8 @@
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.text.doctools; package org.eclipse.cdt.ui.text.doctools;
@ -93,8 +95,9 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
* @since 6.7 * @since 6.7
*/ */
protected Optional<IProject> getProject() { protected Optional<IProject> getProject() {
if (fProject != null) if (fProject != null) {
return Optional.of(fProject.getProject()); return Optional.of(fProject.getProject());
}
return Optional.empty(); return Optional.empty();
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2010 Symbian Software Systems and others. * Copyright (c) 2008, 2020 Symbian Software Systems and others.
* *
* This program and the accompanying materials * This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0 * are made available under the terms of the Eclipse Public License 2.0
@ -11,6 +11,8 @@
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
* Marco Stornelli <marco.stornelli@gmail.com> - Bug 333134
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 333134
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.text.doctools.doxygen; package org.eclipse.cdt.ui.text.doctools.doxygen;
@ -99,16 +101,17 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
private void refreshPreferences() { private void refreshPreferences() {
Optional<IProject> project = getProject(); Optional<IProject> project = getProject();
DoxygenPreferences pref = new DoxygenPreferences(project); DoxygenPreferences pref = project.isPresent() ? new DoxygenPreferences(project.get())
newLineAfterBrief = pref.getBooleanPref(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF, : new DoxygenPreferences();
newLineAfterBrief = pref.getBoolean(DoxygenPreferences.DOXYGEN_NEW_LINE_AFTER_BRIEF,
DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF); DoxygenPreferences.DEF_DOXYGEN_NEW_LINE_AFTER_BRIEF);
useBriefTag = pref.getBooleanPref(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG, useBriefTag = pref.getBoolean(DoxygenPreferences.DOXYGEN_USE_BRIEF_TAG,
DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG); DoxygenPreferences.DEF_DOXYGEN_USE_BRIEF_TAG);
useJavadocStyle = pref.getBooleanPref(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS, useJavadocStyle = pref.getBoolean(DoxygenPreferences.DOXYGEN_USE_JAVADOC_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS); DoxygenPreferences.DEF_DOXYGEN_USE_JAVADOC_TAGS);
usePrePostTag = pref.getBooleanPref(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS, usePrePostTag = pref.getBoolean(DoxygenPreferences.DOXYGEN_USE_PRE_POST_TAGS,
DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS); DoxygenPreferences.DEF_DOXYGEN_USE_PRE_POST_TAGS);
useStructuralCommands = pref.getBooleanPref(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS, useStructuralCommands = pref.getBoolean(DoxygenPreferences.DOXYGEN_USE_STRUCTURAL_COMMANDS,
DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS); DoxygenPreferences.DEF_DOXYGEN_USE_STRUCTURED_COMMANDS);
} }