From c30fd07d50123210af376871a3198042a078ee41 Mon Sep 17 00:00:00 2001 From: jsurfer Date: Thu, 2 Sep 2004 18:14:39 +0000 Subject: [PATCH] intial source from ttp://www.sf.net/projects/wdte --- .../net.sourceforge.phpeclipse.css.core/.classpath | 7 + .../net.sourceforge.phpeclipse.css.core/.cvsignore | 3 + .../net.sourceforge.phpeclipse.css.core/.project | 29 + .../build.properties | 12 + .../plugin.properties | 22 + .../net.sourceforge.phpeclipse.css.core/plugin.xml | 44 + .../schema/profiles.exsd | 120 +++ .../sourceforge/phpeclipse/css/core/CssCore.java | 136 +++ .../css/core/internal/CssCoreMessages.java | 102 +++ .../css/core/internal/CssCoreMessages.properties | 46 + .../css/core/internal/CssCorePreferences.java | 49 + .../css/core/internal/model/AbstractRule.java | 137 +++ .../phpeclipse/css/core/internal/model/AtRule.java | 83 ++ .../css/core/internal/model/Declaration.java | 124 +++ .../css/core/internal/model/PropertyInfo.java | 102 +++ .../css/core/internal/model/StyleRule.java | 73 ++ .../css/core/internal/model/StyleSheet.java | 161 ++++ .../internal/parser/AbstractProblemReporter.java | 130 +++ .../css/core/internal/parser/DefaultCssParser.java | 474 ++++++++++ .../core/internal/parser/DefaultCssScanner.java | 318 +++++++ .../css/core/internal/parser/DefaultProblem.java | 107 +++ .../css/core/internal/parser/MutableRegion.java | 125 +++ .../core/internal/profiles/ProfileDescriptor.java | 100 +++ .../css/core/internal/profiles/ProfileManager.java | 236 +++++ .../css/core/internal/text/CssCodeReader.java | 396 +++++++++ .../css/core/internal/text/CssTextUtils.java | 128 +++ .../phpeclipse/css/core/model/IAtRule.java | 28 + .../phpeclipse/css/core/model/IDeclaration.java | 55 ++ .../phpeclipse/css/core/model/IPropertyInfo.java | 29 + .../phpeclipse/css/core/model/IRule.java | 53 ++ .../phpeclipse/css/core/model/IStyleRule.java | 25 + .../phpeclipse/css/core/model/IStyleSheet.java | 49 + .../phpeclipse/css/core/parser/ICssParser.java | 91 ++ .../phpeclipse/css/core/parser/ICssScanner.java | 58 ++ .../phpeclipse/css/core/parser/ICssTokens.java | 43 + .../phpeclipse/css/core/parser/IProblem.java | 80 ++ .../css/core/parser/IProblemCollector.java | 28 + .../css/core/parser/IProblemReporter.java | 28 + .../css/core/parser/LexicalErrorException.java | 39 + .../css/core/parser/SyntaxErrorException.java | 101 +++ .../css/core/profiles/AbstractProfile.java | 126 +++ .../phpeclipse/css/core/profiles/Css1Profile.java | 129 +++ .../phpeclipse/css/core/profiles/Css2Profile.java | 139 +++ .../phpeclipse/css/core/profiles/IProfile.java | 38 + .../css/core/profiles/IProfileDescriptor.java | 52 ++ .../css/core/profiles/IProfileManager.java | 53 ++ .../net.sourceforge.phpeclipse.css.ui/.classpath | 7 + .../net.sourceforge.phpeclipse.css.ui/.cvsignore | 3 + archive/net.sourceforge.phpeclipse.css.ui/.project | 42 + .../build.properties | 15 + .../icons/at_rule_obj.gif | Bin 0 -> 215 bytes .../icons/class_obj.gif | Bin 0 -> 161 bytes .../icons/full/ovr16/error_co.gif | Bin 0 -> 84 bytes .../icons/full/ovr16/warning_co.gif | Bin 0 -> 116 bytes .../icons/important_obj.gif | Bin 0 -> 74 bytes .../icons/int_obj.gif | Bin 0 -> 122 bytes .../icons/property_obj.gif | Bin 0 -> 92 bytes .../icons/pseudo_class_obj.gif | Bin 0 -> 104 bytes .../icons/shorthand_obj.gif | Bin 0 -> 107 bytes .../icons/style_rule_obj.gif | Bin 0 -> 91 bytes .../icons/style_sheet_obj.gif | Bin 0 -> 140 bytes .../plugin.properties | 38 + .../net.sourceforge.phpeclipse.css.ui/plugin.xml | 245 ++++++ .../net/sourceforge/phpeclipse/css/ui/CssUI.java | 229 +++++ .../css/ui/internal/CssDocumentProvider.java | 115 +++ .../ui/internal/CssDocumentSetupParticipant.java | 37 + .../phpeclipse/css/ui/internal/CssUIMessages.java | 102 +++ .../css/ui/internal/CssUIMessages.properties | 123 +++ .../css/ui/internal/CssUIPreferences.java | 225 +++++ .../css/ui/internal/ICssUIHelpContextIds.java | 35 + .../css/ui/internal/compare/CssMergeViewer.java | 177 ++++ .../ui/internal/compare/CssMergeViewerCreator.java | 34 + .../css/ui/internal/compare/CssNode.java | 134 +++ .../ui/internal/compare/CssStructureCreator.java | 235 +++++ .../css/ui/internal/editor/CommentAction.java | 164 ++++ .../css/ui/internal/editor/CssEditor.java | 367 ++++++++ .../editor/CssEditorActionContributor.java | 118 +++ .../internal/editor/ICssEditorActionConstants.java | 42 + .../editor/ICssEditorActionDefinitionIds.java | 36 + .../editor/ShowSelectedElementOnlyAction.java | 150 ++++ .../css/ui/internal/editor/UncommentAction.java | 181 ++++ .../outline/CssOutlineContentProvider.java | 95 ++ .../outline/CssOutlineDoubleClickListener.java | 95 ++ .../internal/outline/CssOutlineLabelProvider.java | 99 +++ .../css/ui/internal/outline/CssOutlinePage.java | 321 +++++++ .../css/ui/internal/outline/link_editor.gif | Bin 0 -> 116 bytes .../css/ui/internal/outline/sort_alpha.gif | Bin 0 -> 224 bytes .../preferences/AbstractConfigurationBlock.java | 193 ++++ .../CssEditorAnnotationsConfigurationBlock.java | 226 +++++ .../CssEditorAppearanceConfigurationBlock.java | 193 ++++ .../CssEditorContentAssistConfigurationBlock.java | 200 +++++ .../preferences/CssEditorPreferencePage.java | 231 +++++ .../CssEditorSyntaxConfigurationBlock.java | 255 ++++++ .../CssEditorTypingConfigurationBlock.java | 63 ++ .../ui/internal/preferences/CssPreferencePage.java | 177 ++++ .../preferences/OverlayPreferenceStore.java | 597 +++++++++++++ .../ui/internal/preferences/SyntaxPreviewer.java | 227 +++++ .../css/ui/internal/preferences/preview.css | 5 + .../properties/CssPropertiesAdapterFactory.java | 60 ++ .../ui/internal/properties/CssPropertyPage.java | 197 +++++ .../internal/properties/CssRulePropertySource.java | 172 ++++ .../css/ui/internal/text/AbstractCssScanner.java | 271 ++++++ .../css/ui/internal/text/AnnotationAdapter.java | 39 + .../css/ui/internal/text/CssAnnotationHover.java | 113 +++ .../css/ui/internal/text/CssAutoEditStrategy.java | 277 ++++++ .../css/ui/internal/text/CssCodeScanner.java | 352 ++++++++ .../css/ui/internal/text/CssColorManager.java | 148 ++++ .../css/ui/internal/text/CssCommentScanner.java | 44 + .../internal/text/CssContentAssistProcessor.java | 408 +++++++++ .../ui/internal/text/CssDoubleClickStrategy.java | 116 +++ .../css/ui/internal/text/CssPairMatcher.java | 135 +++ .../css/ui/internal/text/CssPartitionScanner.java | 65 ++ .../css/ui/internal/text/CssReconcileStep.java | 221 +++++ .../ui/internal/text/CssReconcilingStrategy.java | 178 ++++ .../text/CssSourceViewerConfiguration.java | 369 ++++++++ .../css/ui/internal/text/CssStringScanner.java | 44 + .../css/ui/internal/text/CssTextHover.java | 69 ++ .../css/ui/internal/text/CssWordFinder.java | 62 ++ .../ui/internal/text/IReconcilingParticipant.java | 26 + .../phpeclipse/css/ui/text/CssTextTools.java | 300 +++++++ .../phpeclipse/css/ui/text/IColorManager.java | 52 ++ .../net.sourceforge.phpeclipse.html.ui/.classpath | 7 + .../net.sourceforge.phpeclipse.html.ui/.cvsignore | 1 + .../net.sourceforge.phpeclipse.html.ui/.project | 31 + .../build.properties | 4 + .../icons/full/obj16/html.png | Bin 0 -> 256 bytes .../net.sourceforge.phpeclipse.html.ui/plugin.xml | 58 ++ .../net/sourceforge/phpeclipse/html/ui/HTMLUI.java | 45 + .../html/ui/internal/HTMLUIMessages.java | 102 +++ .../html/ui/internal/HTMLUIMessages.properties | 12 + .../ui/internal/editor/HTMLDocumentProvider.java | 23 + .../editor/HTMLDocumentSetupParticipant.java | 23 + .../html/ui/internal/editor/HTMLEditor.java | 114 +++ .../ui/internal/editor/HTMLEditorMessages.java | 45 + .../internal/editor/HTMLEditorMessages.properties | 10 + .../html/ui/internal/preview/HTMLPreviewPage.java | 96 ++ .../ui/internal/text/HTMLCompletionProcessor.java | 35 + .../html/ui/internal/text/HTMLConfiguration.java | 53 ++ .../net.sourceforge.phpeclipse.js.core/.classpath | 7 + .../net.sourceforge.phpeclipse.js.core/.cvsignore | 1 + .../net.sourceforge.phpeclipse.js.core/.project | 28 + .../build.properties | 15 + .../plugin.properties | 15 + .../net.sourceforge.phpeclipse.js.core/plugin.xml | 26 + .../phpeclipse/js/core/JSCorePlugin.java | 131 +++ .../phpeclipse/js/core/model/JSClassElement.java | 80 ++ .../js/core/model/JSClassMethodElement.java | 42 + .../js/core/model/JSClassVariableElement.java | 47 + .../phpeclipse/js/core/model/JSElement.java | 222 +++++ .../js/core/model/JSElementCategories.java | 36 + .../phpeclipse/js/core/model/JSElementList.java | 205 +++++ .../js/core/model/JSFunctionElement.java | 72 ++ .../js/core/model/JSGlobalVariableElement.java | 47 + .../js/core/model/JSInstanceMethodElement.java | 41 + .../js/core/model/JSInstanceVariableElement.java | 47 + .../phpeclipse/js/core/parser/JSParser.java | 926 ++++++++++++++++++++ .../js/core/parser/JSPartitionScanner.java | 108 +++ .../js/core/parser/JSReferenceDetector.java | 34 + .../phpeclipse/js/core/parser/JSScanner.java | 62 ++ .../phpeclipse/js/core/parser/JSStringScanner.java | 77 ++ .../js/core/parser/JSSyntaxModelFactory.java | 157 ++++ .../phpeclipse/js/core/parser/JSSyntaxScanner.java | 86 ++ .../js/core/parser/JSWhitespaceDetector.java | 52 ++ .../phpeclipse/js/core/parser/JSWordDetector.java | 54 ++ .../core/parser/NonRuleBasedDamagerRepairer.java | 175 ++++ .../js/core/parser/PredicateWordRule.java | 107 +++ net.sourceforge.phpeclipse.core/.classpath | 7 + net.sourceforge.phpeclipse.core/.cvsignore | 1 + net.sourceforge.phpeclipse.core/.project | 28 + net.sourceforge.phpeclipse.core/build.properties | 4 + net.sourceforge.phpeclipse.core/plugin.xml | 21 + .../net/sourceforge/phpeclipse/core/WebCore.java | 60 ++ .../phpeclipse/core/model/ISourceModel.java | 46 + .../phpeclipse/core/model/ISourceReference.java | 45 + .../phpeclipse/core/model/SourceReference.java | 119 +++ 175 files changed, 17947 insertions(+), 0 deletions(-) create mode 100644 archive/net.sourceforge.phpeclipse.css.core/.classpath create mode 100644 archive/net.sourceforge.phpeclipse.css.core/.cvsignore create mode 100644 archive/net.sourceforge.phpeclipse.css.core/.project create mode 100644 archive/net.sourceforge.phpeclipse.css.core/build.properties create mode 100644 archive/net.sourceforge.phpeclipse.css.core/plugin.properties create mode 100644 archive/net.sourceforge.phpeclipse.css.core/plugin.xml create mode 100644 archive/net.sourceforge.phpeclipse.css.core/schema/profiles.exsd create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/CssCore.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/CssCoreMessages.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/CssCoreMessages.properties create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/CssCorePreferences.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/model/AbstractRule.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/model/AtRule.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/model/Declaration.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/model/PropertyInfo.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/model/StyleRule.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/model/StyleSheet.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/parser/AbstractProblemReporter.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/parser/DefaultCssParser.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/parser/DefaultCssScanner.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/parser/DefaultProblem.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/parser/MutableRegion.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/profiles/ProfileDescriptor.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/profiles/ProfileManager.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/text/CssCodeReader.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/text/CssTextUtils.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/model/IAtRule.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/model/IDeclaration.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/model/IPropertyInfo.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/model/IRule.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/model/IStyleRule.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/model/IStyleSheet.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/parser/ICssParser.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/parser/ICssScanner.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/parser/ICssTokens.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/parser/IProblem.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/parser/IProblemCollector.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/parser/IProblemReporter.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/parser/LexicalErrorException.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/parser/SyntaxErrorException.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/profiles/AbstractProfile.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/profiles/Css1Profile.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/profiles/Css2Profile.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/profiles/IProfile.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/profiles/IProfileDescriptor.java create mode 100644 archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/profiles/IProfileManager.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/.classpath create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/.cvsignore create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/.project create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/build.properties create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/icons/at_rule_obj.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/icons/class_obj.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/icons/full/ovr16/error_co.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/icons/full/ovr16/warning_co.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/icons/important_obj.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/icons/int_obj.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/icons/property_obj.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/icons/pseudo_class_obj.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/icons/shorthand_obj.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/icons/style_rule_obj.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/icons/style_sheet_obj.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/plugin.properties create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/plugin.xml create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/CssUI.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssDocumentProvider.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssDocumentSetupParticipant.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIMessages.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIMessages.properties create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIPreferences.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/ICssUIHelpContextIds.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssMergeViewer.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssMergeViewerCreator.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssNode.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssStructureCreator.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CommentAction.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CssEditor.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CssEditorActionContributor.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ICssEditorActionConstants.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ICssEditorActionDefinitionIds.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ShowSelectedElementOnlyAction.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/UncommentAction.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineContentProvider.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineDoubleClickListener.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineLabelProvider.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlinePage.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/link_editor.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/sort_alpha.gif create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/AbstractConfigurationBlock.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorAnnotationsConfigurationBlock.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorAppearanceConfigurationBlock.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorContentAssistConfigurationBlock.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorPreferencePage.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorSyntaxConfigurationBlock.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorTypingConfigurationBlock.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssPreferencePage.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/OverlayPreferenceStore.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/SyntaxPreviewer.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/preview.css create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssPropertiesAdapterFactory.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssPropertyPage.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssRulePropertySource.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/AbstractCssScanner.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/AnnotationAdapter.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssAnnotationHover.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssAutoEditStrategy.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssCodeScanner.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssColorManager.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssCommentScanner.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssContentAssistProcessor.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssDoubleClickStrategy.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssPairMatcher.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssPartitionScanner.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssReconcileStep.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssReconcilingStrategy.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssSourceViewerConfiguration.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssStringScanner.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssTextHover.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssWordFinder.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/IReconcilingParticipant.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/text/CssTextTools.java create mode 100644 archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/text/IColorManager.java create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/.classpath create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/.cvsignore create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/.project create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/build.properties create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/icons/full/obj16/html.png create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/plugin.xml create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/HTMLUI.java create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/HTMLUIMessages.java create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/HTMLUIMessages.properties create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLDocumentProvider.java create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLDocumentSetupParticipant.java create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditor.java create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditorMessages.java create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditorMessages.properties create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/preview/HTMLPreviewPage.java create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/text/HTMLCompletionProcessor.java create mode 100644 archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/text/HTMLConfiguration.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/.classpath create mode 100644 archive/net.sourceforge.phpeclipse.js.core/.cvsignore create mode 100644 archive/net.sourceforge.phpeclipse.js.core/.project create mode 100644 archive/net.sourceforge.phpeclipse.js.core/build.properties create mode 100644 archive/net.sourceforge.phpeclipse.js.core/plugin.properties create mode 100644 archive/net.sourceforge.phpeclipse.js.core/plugin.xml create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/JSCorePlugin.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassElement.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassMethodElement.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassVariableElement.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElement.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElementCategories.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElementList.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSFunctionElement.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSGlobalVariableElement.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSInstanceMethodElement.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSInstanceVariableElement.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSParser.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSPartitionScanner.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSReferenceDetector.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSScanner.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSStringScanner.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSSyntaxModelFactory.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSSyntaxScanner.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSWhitespaceDetector.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSWordDetector.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/NonRuleBasedDamagerRepairer.java create mode 100644 archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/PredicateWordRule.java create mode 100644 net.sourceforge.phpeclipse.core/.classpath create mode 100644 net.sourceforge.phpeclipse.core/.cvsignore create mode 100644 net.sourceforge.phpeclipse.core/.project create mode 100644 net.sourceforge.phpeclipse.core/build.properties create mode 100644 net.sourceforge.phpeclipse.core/plugin.xml create mode 100644 net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/WebCore.java create mode 100644 net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/ISourceModel.java create mode 100644 net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/ISourceReference.java create mode 100644 net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/SourceReference.java diff --git a/archive/net.sourceforge.phpeclipse.css.core/.classpath b/archive/net.sourceforge.phpeclipse.css.core/.classpath new file mode 100644 index 0000000..751c8f2 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.css.core/.cvsignore b/archive/net.sourceforge.phpeclipse.css.core/.cvsignore new file mode 100644 index 0000000..67b544a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.core/.cvsignore @@ -0,0 +1,3 @@ +bin +build +dist diff --git a/archive/net.sourceforge.phpeclipse.css.core/.project b/archive/net.sourceforge.phpeclipse.css.core/.project new file mode 100644 index 0000000..2f37b2f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.core/.project @@ -0,0 +1,29 @@ + + + net.sourceforge.phpeclipse.css.core + + + net.sf.wdte.core + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/archive/net.sourceforge.phpeclipse.css.core/build.properties b/archive/net.sourceforge.phpeclipse.css.core/build.properties new file mode 100644 index 0000000..3dcad1e --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.core/build.properties @@ -0,0 +1,12 @@ +source.csscore.jar = src/ +bin.includes = plugin.xml,\ + *.jar,\ + csscore.jar,\ + plugin.properties +src.includes = .project,\ + .classpath,\ + build.properties,\ + plugin.properties,\ + plugin.xml,\ + schema/,\ + src/ diff --git a/archive/net.sourceforge.phpeclipse.css.core/plugin.properties b/archive/net.sourceforge.phpeclipse.css.core/plugin.properties new file mode 100644 index 0000000..b13b3db --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.core/plugin.properties @@ -0,0 +1,22 @@ +# +# Copyright (c) 2003-2004 Christopher Lenz and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Common Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/cpl-v10.html +# +# Contributors: +# Christopher Lenz - initial english resources +# +# $Id: plugin.properties,v 1.1 2004-09-02 18:07:13 jsurfer Exp $ +# + +pluginName = Web Development Tools CSS Core +providerName= WDTE Project + +css1Profile.name = CSS Level 1 +css1Profile.description = \ + Profile correspondong to the CSS 1.0 specification +css2Profile.name = CSS Level 2 +css2Profile.description =\ + Profile correspondong to the CSS 2.0 specification diff --git a/archive/net.sourceforge.phpeclipse.css.core/plugin.xml b/archive/net.sourceforge.phpeclipse.css.core/plugin.xml new file mode 100644 index 0000000..87a6460 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.core/plugin.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.css.core/schema/profiles.exsd b/archive/net.sourceforge.phpeclipse.css.core/schema/profiles.exsd new file mode 100644 index 0000000..ed3b206 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.core/schema/profiles.exsd @@ -0,0 +1,120 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + + + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/CssCore.java b/archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/CssCore.java new file mode 100644 index 0000000..7daa73d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/CssCore.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssCore.java,v 1.1 2004-09-02 18:07:13 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.core; + +import net.sourceforge.phpeclipse.css.core.internal.CssCorePreferences; +import net.sourceforge.phpeclipse.css.core.internal.profiles.ProfileManager; +import net.sourceforge.phpeclipse.css.core.profiles.IProfileManager; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; + +/** + * The main plugin class to be used in the desktop. + */ +public class CssCore extends Plugin { + + // Class Variables --------------------------------------------------------- + + /** The shared instance. */ + private static CssCore plugin; + + // Instance Variables ------------------------------------------------------ + + /** + * The profile manager. + */ + private IProfileManager profileManager; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + */ + public CssCore() { + plugin = this; + } + + // Public Methods ---------------------------------------------------------- + + /** + * Returns the shared instance. + */ + public static CssCore getDefault() { + return plugin; + } + + /** + * Returns the plugin ID. + * + * @return the plugin ID + */ + public static String getPluginId() { + return getDefault().getBundle().getSymbolicName(); + } + + /** + * Returns the object that manages the CSS profiles. + * + * @return the profile manager + */ + public synchronized IProfileManager getProfileManager() { + if (profileManager == null) { + profileManager = new ProfileManager(getPluginPreferences()); + } + return profileManager; + } + + /** + * Writes a status message and the associated exception stack trace (if + * provided) to the error log. + * + * @param status the status to log + */ + public static void log(IStatus status) { + getDefault().getLog().log(status); + if (status.getException() != null) { + status.getException().printStackTrace(System.err); + } + } + + /** + * Writes the specified error message and exception stack trace to the error + * log. + * + * @param message the error message + * @param e the exception that caused the error, or null to omit + * the stack trace in the log + */ + public static void log(String message, Throwable e) { + IStatus status = new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, + message, e); + log(status); + } + + /** + * Writes the specified error message to the error log. + * + * @param message the error message + */ + public static void log(String message) { + IStatus status = new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, + message, null); + log(status); + } + + /** + * Writes the stack trace of the given exception to the error log. + * + * @param e the exception that caused the error + */ + public static void log(Throwable e) { + log(e.getMessage(), e); + } + + // Plugin Implementation --------------------------------------------------- + + /* + * @see Plugin#initializeDefaultPluginPreferences() + */ + protected void initializeDefaultPluginPreferences() { + CssCorePreferences.initializeDefaultValues(getPluginPreferences()); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/CssCoreMessages.java b/archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/CssCoreMessages.java new file mode 100644 index 0000000..fde7d55 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/CssCoreMessages.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssCoreMessages.java,v 1.1 2004-09-02 18:07:12 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.core.internal; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * Utility class that provides easy access to externalized strings. + */ +public final class CssCoreMessages { + + // Constants --------------------------------------------------------------- + + /** + * Qualified name of the resource bundle containing the localized messages. + */ + private static final String RESOURCE_BUNDLE = + "net.sourceforge.phpeclipse.css.core.internal.CssCoreMessages"; //$NON-NLS-1$ + + // Class Variables --------------------------------------------------------- + + /** + * The resource bundle. + */ + private static ResourceBundle resourceBundle = + ResourceBundle.getBundle(RESOURCE_BUNDLE); + + // Constructors ------------------------------------------------------------ + + /** + * Hidden constructor. + */ + private CssCoreMessages() { + // Hidden + } + + // Public Methods ---------------------------------------------------------- + + /** + * Returns the resource bundle. + * + * @return the resource bundle + */ + public static ResourceBundle getResourceBundle() { + return resourceBundle; + } + + /** + * Returns the message identified by the specified key. + * + * @param key the message key + * @return the localized message, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key) { + try { + return resourceBundle.getString(key); + } catch (MissingResourceException e) { + return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$ + } + } + + /** + * Returns the message identified by the specified key, replacing a single + * parameter with the provided value. + * + * @param key the message key + * @param arg the parameter value + * @return the formatted string, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key, String arg) { + return getString(key, new String[] { arg }); + } + + /** + * Returns the message identified by the specified key, replacing all + * parameters with the provided values. + * + * @param key the message key + * @param args the parameter values + * @return the formatted string, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key, String[] args) { + return MessageFormat.format(getString(key), args); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/CssCoreMessages.properties b/archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/CssCoreMessages.properties new file mode 100644 index 0000000..f545808 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/CssCoreMessages.properties @@ -0,0 +1,46 @@ +# +# Copyright (c) 2004 Christopher Lenz and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Common Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/cpl-v10.html +# +# Contributors: +# Christopher Lenz - initial API and implementation +# +# $Id: CssCoreMessages.properties,v 1.1 2004-09-02 18:07:12 jsurfer Exp $ +# + +# Problem Messages ------------------------------------------------------------- + +CssParser.problem.emptyDeclarationValue = Empty declaration value +CssParser.problem.expectedDeclaration = Expected declaration +CssParser.problem.expectedProperty = Expected property +CssParser.problem.expectedSelectorOrAtKeyword = Expected selector or at-keyword +CssParser.problem.expectedToken = Expected token {0} +CssParser.problem.illegalPositionForCDC = '-->' may only appear at the beginning of the style sheet +CssParser.problem.illegalPositionForCDO = ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/CssUI.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/CssUI.java new file mode 100644 index 0000000..46d5617 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/CssUI.java @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssUI.java,v 1.1 2004-09-02 18:11:51 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui; + +import java.net.URL; + +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; +import net.sourceforge.phpeclipse.css.ui.internal.properties.CssPropertiesAdapterFactory; +import net.sourceforge.phpeclipse.css.ui.text.CssTextTools; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.ui.editors.text.TextEditorPreferenceConstants; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class. + */ +public final class CssUI extends AbstractUIPlugin { + + // Constants --------------------------------------------------------------- + + public static final String ICON_STYLE_SHEET = + "style_sheet_obj.gif"; //$NON-NLS-1$ + public static final String ICON_AT_RULE = + "at_rule_obj.gif"; //$NON-NLS-1$ + public static final String ICON_STYLE_RULE = + "style_rule_obj.gif"; //$NON-NLS-1$ + public static final String ICON_PROPERTY = + "property_obj.gif"; //$NON-NLS-1$ + public static final String ICON_SHORTHAND = + "shorthand_obj.gif"; //$NON-NLS-1$ + public static final String ICON_PSEUDO_CLASS = + "pseudo_class_obj.gif"; //$NON-NLS-1$ + public static final String ICON_IMPORTANT = + "important_obj.gif"; //$NON-NLS-1$ + public static final String ICON_OVERLAY_ERROR = + "full/ovr16/error_co.gif"; //$NON-NLS-1$ + public static final String ICON_OVERLAY_WARNING = + "full/ovr16/warning_co.gif"; //$NON-NLS-1$ + + // Class Variables --------------------------------------------------------- + + /** + * Singleton instance of the plugin. + */ + private static CssUI plugin; + + // Instance Variables ------------------------------------------------------ + + /** + * The text tools collection. + */ + private CssTextTools textTools; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param descriptor the plugin descriptor. + */ + public CssUI() { + plugin = this; + } + + // Static Methods ---------------------------------------------------------- + + /** + * Returns the singleton instance of the plugin. + * + * @return the plugin instance + */ + public static CssUI getDefault() { + return plugin; + } + + /** + * Returns the plugin ID. + * + * @return the plugin ID + */ + public static String getPluginId() { + return getDefault().getBundle().getSymbolicName(); + } + + // Public Methods ---------------------------------------------------------- + + /** + * Returns the CSS text tools that are used primarily for partitioning and + * syntax highlighting of CSS source. + * + * @return the CSS text tools + */ + public synchronized CssTextTools getTextTools() { + if (textTools == null) { + textTools = new CssTextTools(getPreferenceStore()); + } + return textTools; + } + + /** + * Returns an image descriptor for the image corresponding to the specified + * key (which is the name of the image file). + * + * @param key The key of the image + * @return The descriptor for the requested image, or null if + * the image could not be found + */ + public ImageDescriptor getImageDescriptor(String key) { + try { + URL url = getBundle().getEntry("/icons/" + key); //$NON-NLS-1$ + return ImageDescriptor.createFromURL(url); + } catch (IllegalStateException e) { + return null; + } + } + + /** + * Writes a status message and the associated exception stack trace (if + * provided) to the error log. + * + * @param status the status to log + */ + public static void log(IStatus status) { + getDefault().getLog().log(status); + if (status.getException() != null) { + status.getException().printStackTrace(System.err); + } + } + + /** + * Writes the specified error message and exception stack trace to the error + * log. + * + * @param message the error message + * @param e the exception that caused the error, or null to omit + * the stack trace in the log + */ + public static void log(String message, Throwable e) { + IStatus status = new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, + message, e); + log(status); + } + + /** + * Writes the specified error message to the error log. + * + * @param message the error message + */ + public static void log(String message) { + IStatus status = new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, + message, null); + log(status); + } + + /** + * Writes the stack trace of the given exception to the error log. + * + * @param e the exception that caused the error + */ + public static void log(Throwable e) { + log(e.getMessage(), e); + } + + // AbstractUIPlugin Implementation ----------------------------------------- + + /* + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + CssPropertiesAdapterFactory.register(Platform.getAdapterManager()); + } + + /* + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + try { + if (textTools != null) { + textTools.dispose(); + textTools = null; + } + } finally { + super.stop(context); + } + } + + /* + * @see AbstractUIPlugin#initializeDefaultPreferences(IPreferenceStore) + */ + protected void initializeDefaultPreferences(IPreferenceStore store) { + TextEditorPreferenceConstants.initializeDefaultValues(store); + CssUIPreferences.initializeDefaultValues(store); + } + + /* + * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry) + */ + protected void initializeImageRegistry(ImageRegistry reg) { + reg.put(ICON_AT_RULE, getImageDescriptor(ICON_AT_RULE)); + reg.put(ICON_STYLE_RULE, getImageDescriptor(ICON_STYLE_RULE)); + reg.put(ICON_STYLE_SHEET, getImageDescriptor(ICON_STYLE_SHEET)); + reg.put(ICON_PROPERTY, getImageDescriptor(ICON_PROPERTY)); + reg.put(ICON_SHORTHAND, getImageDescriptor(ICON_SHORTHAND)); + reg.put(ICON_PSEUDO_CLASS, getImageDescriptor(ICON_PSEUDO_CLASS)); + reg.put(ICON_IMPORTANT, getImageDescriptor(ICON_IMPORTANT)); + reg.put(ICON_OVERLAY_ERROR, getImageDescriptor(ICON_OVERLAY_ERROR)); + reg.put(ICON_OVERLAY_WARNING, getImageDescriptor(ICON_OVERLAY_WARNING)); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssDocumentProvider.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssDocumentProvider.java new file mode 100644 index 0000000..d43169f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssDocumentProvider.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssDocumentProvider.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal; + +import net.sourceforge.phpeclipse.css.core.internal.model.StyleSheet; +import net.sourceforge.phpeclipse.css.core.model.IStyleSheet; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentListener; +import org.eclipse.ui.editors.text.TextFileDocumentProvider; + +/** + * Document provider for CSS files. + * + * TODO This class currently doubles as a model manager which will need to be + * moved into core at some point, and would make this class pretty much + * useless + */ +public class CssDocumentProvider extends TextFileDocumentProvider { + + // Inner Classes ----------------------------------------------------------- + + private class StyleSheetInfo extends FileInfo { + private IStyleSheet styleSheet; + } + + // TestFileDocumentProvider Implementation --------------------------------- + + /* + * @see TextFileDocumentProvider#createEmptyFileInfo() + */ + protected FileInfo createEmptyFileInfo() { + return new StyleSheetInfo(); + } + + /* + * @see TextFileDocumentProvider#createFileInfo(Object) + */ + protected FileInfo createFileInfo(Object element) throws CoreException { + FileInfo fileInfo = super.createFileInfo(element); + if (!(fileInfo instanceof StyleSheetInfo)) { + return null; + } + + IDocument document = fileInfo.fTextFileBuffer.getDocument(); + IStyleSheet styleSheet = createStyleSheet(document); + if (styleSheet instanceof IDocumentListener) { + document.addDocumentListener((IDocumentListener) styleSheet); + } + StyleSheetInfo styleSheetInfo = (StyleSheetInfo) fileInfo; + styleSheetInfo.styleSheet = styleSheet; + + return styleSheetInfo; + } + + /* + * @see TextFileDocumentProvider#disposeFileInfo(Object, TextFileDocumentProvider.FileInfo) + */ + protected void disposeFileInfo(Object element, FileInfo info) { + if (info instanceof StyleSheetInfo) { + IDocument document = getDocument(element); + // TODO Check whether this is really necessary, as the document is + // always null here + if (document != null) { + IStyleSheet styleSheet = ((StyleSheetInfo) info).styleSheet; + if (styleSheet instanceof IDocumentListener) { + document.removeDocumentListener((IDocumentListener) + styleSheet); + } + } + } + super.disposeFileInfo(element, info); + } + + // Public Methods ---------------------------------------------------------- + + /** + * Creates the parsed style sheet object corresponding to the specified + * document. + * + * @param document the document to parse + * @return the parsed style sheet + */ + public IStyleSheet createStyleSheet(IDocument document) { + return new StyleSheet(document); + } + + /** + * Returns the style sheet associated with the specified element. + * + * @param element the element + * @return the style sheet associated with the element + */ + public IStyleSheet getStyleSheet(Object element) { + FileInfo info = getFileInfo(element); + if (info instanceof StyleSheetInfo) { + StyleSheetInfo styleSheetInfo = (StyleSheetInfo) info; + return styleSheetInfo.styleSheet; + } + return null; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssDocumentSetupParticipant.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssDocumentSetupParticipant.java new file mode 100644 index 0000000..a0aae6d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssDocumentSetupParticipant.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial implementation + * + * $Id: CssDocumentSetupParticipant.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal; + +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.text.CssTextTools; + +import org.eclipse.core.filebuffers.IDocumentSetupParticipant; +import org.eclipse.jface.text.IDocument; + +/** + * Document setup participant that sets up the CSS specific partitioning. + */ +public class CssDocumentSetupParticipant implements IDocumentSetupParticipant { + + /* + * @see IDocumentSetupParticipant#setup(IDocument) + */ + public void setup(IDocument document) { + if (document != null) { + CssTextTools tools = CssUI.getDefault().getTextTools(); + tools.setupDocument(document); + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIMessages.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIMessages.java new file mode 100644 index 0000000..206b604 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIMessages.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssUIMessages.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * Utility class that provides easy access to externalized strings. + */ +public final class CssUIMessages { + + // Constants --------------------------------------------------------------- + + /** + * Qualified name of the resource bundle containing the localized messages. + */ + private static final String RESOURCE_BUNDLE = + "net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages"; //$NON-NLS-1$ + + // Class Variables --------------------------------------------------------- + + /** + * The resource bundle. + */ + private static ResourceBundle fgResourceBundle = + ResourceBundle.getBundle(RESOURCE_BUNDLE); + + // Constructors ------------------------------------------------------------ + + /** + * Hidden constructor. + */ + private CssUIMessages() { + // Hidden + } + + // Public Methods ---------------------------------------------------------- + + /** + * Returns the resource bundle. + * + * @return the resource bundle + */ + public static ResourceBundle getResourceBundle() { + return fgResourceBundle; + } + + /** + * Returns the message identified by the specified key. + * + * @param key the message key + * @return the localized message, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$ + } + } + + /** + * Returns the message identified by the specified key, replacing a single + * parameter with the provided value. + * + * @param key the message key + * @param arg the parameter value + * @return the formatted string, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key, String arg) { + return getString(key, new String[] { arg }); + } + + /** + * Returns the message identified by the specified key, replacing all + * parameters with the provided values. + * + * @param key the message key + * @param args the parameter values + * @return the formatted string, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key, String[] args) { + return MessageFormat.format(getString(key), args); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIMessages.properties b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIMessages.properties new file mode 100644 index 0000000..85c692f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIMessages.properties @@ -0,0 +1,123 @@ +# +# Copyright (c) 2003-2004 Christopher Lenz and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Common Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/cpl-v10.html +# +# Contributors: +# Christopher Lenz - initial english resources +# +# $Id: CssUIMessages.properties,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ +# + +# Outline Page ----------------------------------------------------------------- + +CssOutlinePage.sort.image = sort_alpha.gif +CssOutlinePage.sort.label = Sort +CssOutlinePage.sort.tooltip = Sort rules alpabetically +CssOutlinePage.sort.description = Sort rules alpabetically +CssOutlinePage.linkWithEditor.image = link_editor.gif +CssOutlinePage.linkWithEditor.label = Link with editor +CssOutlinePage.linkWithEditor.tooltip = Link with editor +CssOutlinePage.linkWithEditor.description = Link with editor + +# Editor ----------------------------------------------------------------------- + +CssEditor.comment.label = Comment +CssEditor.comment.tooltip = Comment Selected Code +CssEditor.comment.description = Comment Selected Code +CssEditor.uncomment.label = Uncomment +CssEditor.uncomment.tooltip = Uncomment Selected Code +CssEditor.uncomment.description = Uncomment Selected Code +CssEditor.contentAssist.label = Content Assist@Ctrl+Space +CssEditor.contentAssist.tooltip = Content Assist +CssEditor.contentAssist.description = Content Assist +CssEditor.showSelectedElementOnly.label = Show Source of Selected Rule Only +CssEditor.showSelectedElementOnly.tooltip = Show Source of Selected Rule Only +CssEditor.showSelectedElementOnly.description = Show Source of Selected Rule Only + +# Compare ---------------------------------------------------------------------- + +CssMergeViewer.title = CSS Source Compare +CssStructureViewer.title = CSS Structure Compare +CssStructureViewer.styleSheet = Stylesheet + +# Preference Pages ------------------------------------------------------------- + +CssPreferencePage.description = CSS settings: +CssPreferencePage.profile = CSS profile: + +CssEditorPreferencePage.description = CSS editor settings: +CssEditorPreferencePage.empty_input = Empty input +CssEditorPreferencePage.invalid_input = ''{0}'' is not a valid input. + +CssEditorPreferencePage.appearance = Appeara&nce +CssEditorPreferencePage.appearance.displayedTabWidth = Displayed &tab width: +CssEditorPreferencePage.appearance.printMarginColumn = Print margin col&umn: +CssEditorPreferencePage.appearance.showOverviewRuler = Show overview &ruler +CssEditorPreferencePage.appearance.showLineNumbers = Show lin&e numbers +CssEditorPreferencePage.appearance.highlightMatchingBrackets = Highlight &matching brackets +CssEditorPreferencePage.appearance.highlightCurrentLine =Hi&ghlight current line +CssEditorPreferencePage.appearance.showPrintMargin = Sho&w print margin +CssEditorPreferencePage.appearance.color = C&olor: +CssEditorPreferencePage.appearance.colorOptions = Appearance co&lor options: +CssEditorPreferencePage.appearance.lineNumberForegroundColor = Line number foreground +CssEditorPreferencePage.appearance.matchingBracketsHighlightColor = Matching brackets highlight +CssEditorPreferencePage.appearance.currentLineHighlighColor = Current line highlight +CssEditorPreferencePage.appearance.printMarginColor = Print margin + +CssEditorPreferencePage.annotations = Annotation&s +CssEditorPreferencePage.annotations.analyzeWhileTyping = Analyze annotations &while typing +CssEditorPreferencePage.annotations.presentationOptions = Annotation &presentation: +CssEditorPreferencePage.annotations.bookmarks = Bookmarks +CssEditorPreferencePage.annotations.searchResults = Search Results +CssEditorPreferencePage.annotations.errors = Errors +CssEditorPreferencePage.annotations.warnings = Warnings +CssEditorPreferencePage.annotations.infos = Infos +CssEditorPreferencePage.annotations.tasks = Tasks +CssEditorPreferencePage.annotations.others = Others +CssEditorPreferencePage.annotations.showInText = Show in &text +CssEditorPreferencePage.annotations.showInOverviewRuler = Show in overview &ruler +CssEditorPreferencePage.annotations.color = C&olor: + +CssEditorPreferencePage.syntax = Synta&x +CssEditorPreferencePage.syntax.backgroundColor = Background color +CssEditorPreferencePage.syntax.backgroundColorSystemDefault = System default +CssEditorPreferencePage.syntax.backgroundColorCustom = Custom: +CssEditorPreferencePage.syntax.foregroundColor = Foreground: +CssEditorPreferencePage.syntax.commentColor = Comments +CssEditorPreferencePage.syntax.propertyNameColor = Property names +CssEditorPreferencePage.syntax.atKeywordColor = At-keywords +CssEditorPreferencePage.syntax.pseudoClassColor = Pseudo classes and elements +CssEditorPreferencePage.syntax.stringColor = Strings +CssEditorPreferencePage.syntax.defaultColor = Others +CssEditorPreferencePage.syntax.color = C&olor +CssEditorPreferencePage.syntax.bold = &Bold + +CssEditorPreferencePage.contentAssist = &Content Assist +CssEditorPreferencePage.contentAssist.insertSingleProposalsAutomatically = Insert single &proposals automatically +CssEditorPreferencePage.contentAssist.presentProposalsInAlphabeticalOrder = Present proposals in &alphabetical order +CssEditorPreferencePage.contentAssist.enableAutoActivation = &Enable auto activation +CssEditorPreferencePage.contentAssist.autoActivationDelay = Auto activation dela&y: +CssEditorPreferencePage.contentAssist.autoActivationTriggers = Auto activation &triggers: +CssEditorPreferencePage.contentAssist.colorOptions = Content assist colo&r options: +CssEditorPreferencePage.contentAssist.color = C&olor: +CssEditorPreferencePage.contentAssist.backgroundForCompletionProposals = Completion proposal background +CssEditorPreferencePage.contentAssist.foregroundForCompletionProposals = Completion proposal foreground + +CssEditorPreferencePage.typing = T&yping +CssEditorPreferencePage.typing.insertSpaceForTabs = Ins&ert space for tabs +CssEditorPreferencePage.typing.closeStrings = Close strin&gs +CssEditorPreferencePage.typing.closeBracketsAndParens = Close &brackets and parenthesis +CssEditorPreferencePage.typing.closeBraces = Cl&ose braces + +TextStyleFieldsEditor.color = C&olor +TextStyleFieldsEditor.bold = &Bold + +# Property Pages --------------------------------------------------------------- + +CssPropertyPage.useWorkspaceSettings = Use &workspace settings +CssPropertyPage.useProjectSettings = Use project or &workspace settings +CssPropertyPage.useCustomSettings = Use c&ustom settings +CssPropertyPage.profile = CSS profile: diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIPreferences.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIPreferences.java new file mode 100644 index 0000000..70cf898 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/CssUIPreferences.java @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssUIPreferences.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; +import org.eclipse.ui.texteditor.AbstractTextEditor; + +/** + * + */ +public final class CssUIPreferences { + + // Constants --------------------------------------------------------------- + + // Inherited constants + + public static final String EDITOR_CURRENT_LINE = + AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE; + + public static final String EDITOR_CURRENT_LINE_COLOR = + AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR; + + public static final String EDITOR_TAB_WIDTH = + AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH; + + public static final String EDITOR_LINE_NUMBER_RULER = + AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER; + + public static final String EDITOR_LINE_NUMBER_RULER_COLOR = + AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR; + + public static final String EDITOR_PRINT_MARGIN = + AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN; + + public static final String EDITOR_PRINT_MARGIN_COLOR = + AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR; + + public static final String EDITOR_PRINT_MARGIN_COLUMN = + AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN; + + public static final String EDITOR_OVERVIEW_RULER = + AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER; + + public static final String EDITOR_BACKGROUND_DEFAULT_COLOR = + AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT; + + public static final String EDITOR_BACKGROUND_COLOR = + AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND; + + public static final String EDITOR_FOREGROUND_COLOR = + AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND; + + public static final String EDITOR_FOREGROUND_DEFAULT_COLOR = + AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT; + + // Custom constants + + public static final String EDITOR_MATCHING_BRACKETS = + "matchingBrackets"; //$NON-NLS-1$ + + public static final String EDITOR_MATCHING_BRACKETS_COLOR = + "matchingBracketsColor"; //$NON-NLS-1$ + + public static final String EDITOR_COMMENT_COLOR = + "commentColor"; //$NON-NLS-1$ + + public static final String EDITOR_COMMENT_BOLD = + "commentBold"; //$NON-NLS-1$ + + public static final String EDITOR_PROPERTY_COLOR = + "propertyColor"; //$NON-NLS-1$ + + public static final String EDITOR_PROPERTY_BOLD = + "propertyBold"; //$NON-NLS-1$ + + public static final String EDITOR_AT_KEYWORD_COLOR = + "atKeywordColor"; //$NON-NLS-1$ + + public static final String EDITOR_AT_KEYWORD_BOLD = + "atKeywordBold"; //$NON-NLS-1$ + + public static final String EDITOR_PSEUDO_CLASS_COLOR = + "pseudoClassColor"; //$NON-NLS-1$ + + public static final String EDITOR_PSEUDO_CLASS_BOLD = + "pseudoClassBold"; //$NON-NLS-1$ + + public static final String EDITOR_STRING_COLOR = + "stringColor"; //$NON-NLS-1$ + + public static final String EDITOR_STRING_BOLD = + "stringBold"; //$NON-NLS-1$ + + public static final String EDITOR_DEFAULT_COLOR = + "defaultColor"; //$NON-NLS-1$ + + public static final String EDITOR_DEFAULT_BOLD = + "defaultBold"; //$NON-NLS-1$ + + public static final String EDITOR_SPACES_FOR_TABS = + "spacesForTabs"; //$NON-NLS-1$ + + public static final String EDITOR_CLOSE_STRINGS = + "closeStrings"; //$NON-NLS-1$ + + public static final String EDITOR_CLOSE_BRACKETS_AND_PARENS = + "closeBracketsAndParens"; //$NON-NLS-1$ + + public static final String EDITOR_CLOSE_BRACES = + "closeBraces"; //$NON-NLS-1$ + + public static final String EDITOR_SHOW_SELECTED_ELEMENT_ONLY = + "showSelectedElementOnly"; //$NON-NLS-1$ + + public static final String OUTLINE_LINK_WITH_EDITOR = + "linkOutlineWithEditor"; //$NON-NLS-1$ + + public static final String OUTLINE_SORT_LEXICALLY = + "sortOutlineLexically"; //$NON-NLS-1$ + + public static final String CONTENTASSIST_AUTOACTIVATION = + "contentAssistAutoActivation"; //$NON-NLS-1$ + + public static final String CONTENTASSIST_AUTOACTIVATION_DELAY = + "contentAssistAutoActivationDelay"; //$NON-NLS-1$ + + public static final String CONTENTASSIST_AUTOACTIVATION_TRIGGERS = + "contentAssistAutoActivationTriggers"; //$NON-NLS-1$ + + public static final String CONTENTASSIST_AUTOINSERT = + "contentAssistAutoInsert"; //$NON-NLS-1$ + + public static final String CONTENTASSIST_ORDER_PROPOSALS = + "contentAssistOrderProposals"; //$NON-NLS-1$ + + public static final String CONTENTASSIST_PROPOSALS_BACKGROUND = + "contentAssistProposalsBackground"; //$NON-NLS-1$ + + public static final String CONTENTASSIST_PROPOSALS_FOREGROUND = + "contentAssistProposalsForeground"; //$NON-NLS-1$ + + // Constructors ------------------------------------------------------------ + + /** + * Hidden constructor. + */ + private CssUIPreferences() { + // Hidden + } + + // Public Methods ---------------------------------------------------------- + + /** + * Initializes the preference store with the default values. + * + * @param store The preference store to initialize + */ + public static final void initializeDefaultValues(IPreferenceStore store) { + + // Appearance + store.setDefault(EDITOR_TAB_WIDTH, 4); + store.setDefault(EDITOR_MATCHING_BRACKETS, true); + PreferenceConverter.setDefault(store, EDITOR_MATCHING_BRACKETS_COLOR, + new RGB(192, 192, 192)); + + // Syntax + store.setDefault(EDITOR_FOREGROUND_DEFAULT_COLOR, true); + store.setDefault(EDITOR_BACKGROUND_DEFAULT_COLOR, true); + PreferenceConverter.setDefault(store, EDITOR_COMMENT_COLOR, + new RGB(63, 127, 95)); + store.setDefault(EDITOR_COMMENT_BOLD, false); + PreferenceConverter.setDefault(store, EDITOR_PROPERTY_COLOR, + new RGB(127, 0, 85)); + store.setDefault(EDITOR_PROPERTY_BOLD, true); + PreferenceConverter.setDefault(store, EDITOR_AT_KEYWORD_COLOR, + new RGB(127, 0, 85)); + store.setDefault(EDITOR_AT_KEYWORD_BOLD, true); + PreferenceConverter.setDefault(store, EDITOR_PSEUDO_CLASS_COLOR, + new RGB(0, 0, 0)); + store.setDefault(EDITOR_PSEUDO_CLASS_BOLD, false); + PreferenceConverter.setDefault(store, EDITOR_STRING_COLOR, + new RGB(42, 0, 255)); + store.setDefault(EDITOR_STRING_BOLD, false); + PreferenceConverter.setDefault(store, EDITOR_DEFAULT_COLOR, + new RGB(0, 0, 0)); + store.setDefault(EDITOR_DEFAULT_BOLD, false); + + // Content assist + store.setDefault(CONTENTASSIST_AUTOINSERT, false); + store.setDefault(CONTENTASSIST_ORDER_PROPOSALS, false); + store.setDefault(CONTENTASSIST_AUTOACTIVATION, true); + store.setDefault(CONTENTASSIST_AUTOACTIVATION_DELAY, 500); + store.setDefault(CONTENTASSIST_AUTOACTIVATION_TRIGGERS, + "-@:"); //$NON-NLS-1$ + PreferenceConverter.setDefault(store, + CONTENTASSIST_PROPOSALS_BACKGROUND, new RGB(254, 241, 233)); + PreferenceConverter.setDefault(store, + CONTENTASSIST_PROPOSALS_FOREGROUND, new RGB(0, 0, 0)); + + // Typing + store.setDefault(EDITOR_TAB_WIDTH, 4); + store.setDefault(EDITOR_SPACES_FOR_TABS, false); + store.setDefault(EDITOR_CLOSE_STRINGS, true); + store.setDefault(EDITOR_CLOSE_BRACKETS_AND_PARENS, true); + store.setDefault(EDITOR_CLOSE_BRACES, true); + + // Outline + store.setDefault(OUTLINE_SORT_LEXICALLY, false); + store.setDefault(OUTLINE_LINK_WITH_EDITOR, false); + } +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/ICssUIHelpContextIds.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/ICssUIHelpContextIds.java new file mode 100644 index 0000000..693a1a2 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/ICssUIHelpContextIds.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: ICssUIHelpContextIds.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal; + +import net.sourceforge.phpeclipse.css.ui.CssUI; + +/** + * Symbolic constants for the help context IDs. + */ +public interface ICssUIHelpContextIds { + + /** + * The string with which all other defined ids are prefixed to construct + * help context ids. + */ + String PREFIX = CssUI.getPluginId() + "."; //$NON-NLS-1$ + + /** + * Help context ID for the CSS editor. + * Value: "net.sourceforge.phpeclipse.css.ui.editor_context". + */ + String EDITOR = PREFIX + "css_editor_context"; //$NON-NLS-1$ + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssMergeViewer.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssMergeViewer.java new file mode 100644 index 0000000..ba08f3c --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssMergeViewer.java @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssMergeViewer.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.compare; + +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; +import net.sourceforge.phpeclipse.css.ui.internal.text.CssSourceViewerConfiguration; +import net.sourceforge.phpeclipse.css.ui.text.CssTextTools; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.contentmergeviewer.TextMergeViewer; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.text.TextViewer; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Composite; + +/** + * Merge viewer for CSS files. + */ +public class CssMergeViewer extends TextMergeViewer { + + // Constants --------------------------------------------------------------- + + /** + * Alias for the preference constant EDITOR_BACKGROUND_COLOR. + */ + private static final String PREFERENCE_BACKGROUND_COLOR = + CssUIPreferences.EDITOR_BACKGROUND_COLOR; + + /** + * Alias for the preference constant + * EDITOR_BACKGROUND_DEFAULT_COLOR. + */ + private static final String PREFERENCE_BACKGROUND_DEFAULT_COLOR = + CssUIPreferences.EDITOR_BACKGROUND_DEFAULT_COLOR; + + // Instance Variables ------------------------------------------------------ + + /** + * The preference store. + */ + private IPreferenceStore preferenceStore; + + /** + * The listener for changes to the preference store. + */ + private IPropertyChangeListener propertyChangeListener; + + /** + * The CSS text tools. + */ + private CssTextTools textTools; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param parent the parent control + * @param style SWT style bits for top level composite of this viewer + * @param configuration the configuration object + */ + public CssMergeViewer(Composite parent, int style, + CompareConfiguration configuration) { + super(parent, style, configuration); + } + + // TextMergeViewer Implementation ------------------------------------------ + + /* + * @see TextMergeViewer#configureTextViewer() + */ + protected void configureTextViewer(TextViewer textViewer) { + + CssUI plugin = CssUI.getDefault(); + + this.preferenceStore = plugin.getPreferenceStore(); + if (preferenceStore != null) { + propertyChangeListener = new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + handlePreferenceStoreChanged(event); + } + }; + preferenceStore.addPropertyChangeListener(propertyChangeListener); + } + + textTools = plugin.getTextTools(); + if (textViewer instanceof SourceViewer) { + SourceViewer sourceViewer = (SourceViewer) textViewer; + sourceViewer.configure(new CssSourceViewerConfiguration( + textTools, preferenceStore)); + } + + updateBackgroundColor(); + } + + /* + * @see TextMergeViewer#getDocumentPartitioner() + */ + protected IDocumentPartitioner getDocumentPartitioner() { + return textTools.createDocumentPartitioner(); + } + + /* + * @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#getTitle() + */ + public String getTitle() { + return CssUIMessages.getString( + "CssMergeViewer.title"); //$NON-NLS-1$ + } + + /* + * @see org.eclipse.jface.viewers.ContentViewer#handleDispose(org.eclipse.swt.events.DisposeEvent) + */ + protected void handleDispose(DisposeEvent event) { + if (propertyChangeListener != null) { + if (preferenceStore != null) { + preferenceStore.removePropertyChangeListener( + propertyChangeListener); + } + propertyChangeListener = null; + } + super.handleDispose(event); + } + + // Private Methods --------------------------------------------------------- + + /** + * Called when the preference store notifies us about a change. + * + * @param event the change event + */ + protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { + String p = event.getProperty(); + if (PREFERENCE_BACKGROUND_COLOR.equals(p) + || PREFERENCE_BACKGROUND_DEFAULT_COLOR.equals(p)) { + updateBackgroundColor(); + } else if (textTools.affectsPresentation(event)) { + invalidateTextPresentation(); + } + } + + /** + * Updates the background color of the merge viewer to the value set in the + * preferences. + */ + private void updateBackgroundColor() { + boolean defaultBackgroundColor = preferenceStore.getBoolean( + PREFERENCE_BACKGROUND_DEFAULT_COLOR); + if (defaultBackgroundColor) { + setBackgroundColor(null); + } else { + RGB backgroundColor = PreferenceConverter.getColor( + preferenceStore, CssUIPreferences.EDITOR_BACKGROUND_COLOR); + setBackgroundColor(backgroundColor); + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssMergeViewerCreator.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssMergeViewerCreator.java new file mode 100644 index 0000000..d35786a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssMergeViewerCreator.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssMergeViewerCreator.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.compare; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.IViewerCreator; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; + +/** + * Factory for creating a CSS merge viewer. + */ +public class CssMergeViewerCreator implements IViewerCreator { + + /* + * @see IViewerCreator#createViewer(Composite, CompareConfiguration) + */ + public Viewer createViewer(Composite parent, CompareConfiguration config) { + return new CssMergeViewer(parent, SWT.NULL, config); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssNode.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssNode.java new file mode 100644 index 0000000..5786149 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssNode.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssNode.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.compare; + +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; + +import org.eclipse.compare.ITypedElement; +import org.eclipse.compare.structuremergeviewer.DocumentRangeNode; +import org.eclipse.jface.text.IDocument; +import org.eclipse.swt.graphics.Image; + +/** + * + */ +public class CssNode extends DocumentRangeNode implements ITypedElement { + + // Constants --------------------------------------------------------------- + + /** + * Type code for the top-level style sheet. + */ + public static final int STYLE_SHEET = 0; + + /** + * Type code for at rules. + */ + public static final int AT_RULE = 1; + + /** + * Type code for style rules. + */ + public static final int STYLE_RULE = 2; + + /** + * Type code for declarations (property-value assignment). + */ + public static final int DECLARATION = 3; + + // Instance Variables ------------------------------------------------------ + + /** + * The display name of the node. + */ + private String name; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor for the top-level style sheet node. + * + * @param document The document + */ + public CssNode(IDocument document) { + super(STYLE_SHEET, "root", document, 0, //$NON-NLS-1$ + document.getLength()); + } + + /** + * Constructor. + * + * @param parent + * @param typeCode + * @param id + * @param name + * @param start + * @param length + */ + public CssNode(CssNode parent, int typeCode, String id, String name, + int start, int length) { + super(typeCode, parent.getId() + Integer.toString(typeCode) + id, + parent.getDocument(), start, length); + this.name = name; + } + + /** + * @see org.eclipse.compare.ITypedElement#getName() + */ + public String getName() { + if (getTypeCode() == STYLE_SHEET) { + return CssUIMessages.getString( + "CssStructureViewer.styleSheet"); //$NON-NLS-1$ + } + return name; + } + + /** + * @see org.eclipse.compare.ITypedElement#getImage() + */ + public Image getImage() { + String key = null; + switch (getTypeCode()) { + case STYLE_SHEET: { + key = CssUI.ICON_STYLE_SHEET; + break; + } + case AT_RULE: { + key = CssUI.ICON_AT_RULE; + break; + } + case STYLE_RULE: { + key = CssUI.ICON_STYLE_RULE; + break; + } + case DECLARATION: { + key = CssUI.ICON_PROPERTY; + break; + } + default: { + // we'll just return null + } + } + return CssUI.getDefault().getImageRegistry().get(key); + } + + /** + * @see org.eclipse.compare.ITypedElement#getType() + */ + public String getType() { + return "css"; //$NON-NLS-1$ + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssStructureCreator.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssStructureCreator.java new file mode 100644 index 0000000..c9dcd14 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/compare/CssStructureCreator.java @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssStructureCreator.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.compare; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; + +import net.sourceforge.phpeclipse.core.model.ISourceReference; +import net.sourceforge.phpeclipse.css.core.internal.parser.DefaultCssParser; +import net.sourceforge.phpeclipse.css.core.internal.text.CssTextUtils; +import net.sourceforge.phpeclipse.css.core.model.IAtRule; +import net.sourceforge.phpeclipse.css.core.model.IDeclaration; +import net.sourceforge.phpeclipse.css.core.model.IRule; +import net.sourceforge.phpeclipse.css.core.model.IStyleRule; +import net.sourceforge.phpeclipse.css.core.parser.ICssParser; +import net.sourceforge.phpeclipse.css.core.parser.LexicalErrorException; +import net.sourceforge.phpeclipse.css.core.parser.SyntaxErrorException; +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; +import net.sourceforge.phpeclipse.css.ui.text.CssTextTools; + +import org.eclipse.compare.IStreamContentAccessor; +import org.eclipse.compare.internal.DocumentManager; +import org.eclipse.compare.structuremergeviewer.IStructureComparator; +import org.eclipse.compare.structuremergeviewer.IStructureCreator; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; + +/** + * TODO Check why the root node is not being displayed + */ +public class CssStructureCreator implements IStructureCreator { + + // IStructureCreator Implementation ---------------------------------------- + + /* + * @see IStructureCreator#getName() + */ + public String getName() { + return CssUIMessages.getString( + "CssStructureViewer.title"); //$NON-NLS-1$ + } + + /* + * @see IStructureCreator#getStructure(Object) + */ + public IStructureComparator getStructure(final Object input) { + IDocument doc = DocumentManager.get(input); + if (doc == null) { + if (input instanceof IStreamContentAccessor) { + doc = createDocument((IStreamContentAccessor) input); + } + } + if (doc != null) { + CssNode node = new CssNode(doc); + ICssParser parser = new DefaultCssParser(); + parser.setSource(doc); + try { + IRule[] rules = parser.parseRules(null); + for (int i = 0; i < rules.length; i++) { + node.addChild(createNode(node, rules[i], new HashMap())); + } + } catch (LexicalErrorException e) { + // just return null + } catch (SyntaxErrorException e) { + // just return null + } + return node; + } + return null; + } + + /* + * @see IStructureCreator#locate(Object, Object) + */ + public IStructureComparator locate(Object path, Object input) { + // TODO Find out what locate() is about and implement the functionality + return null; + } + + /* + * @see IStructureCreator#getContents(Object, boolean) + */ + public String getContents(Object node, boolean ignoreWhitespace) { + if (node instanceof CssNode) { + CssNode cssNode = (CssNode) node; + int ch; + InputStream in = null; + try { + StringBuffer buf = new StringBuffer(); + in = cssNode.getContents(); + while ((ch = in.read()) != -1) { + if (!ignoreWhitespace + || !CssTextUtils.isCssWhitespace((char) ch)) { + buf.append((char) ch); + } + } + return buf.toString(); + } catch (IOException e) { + // just return an empty string + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e1) { + // ignore + } + } + } + } + return ""; //$NON-NLS-1$ + } + + /* + * @see IStructureCreator#save(IStructureComparator, Object) + */ + public void save(IStructureComparator node, Object input) { + // TODO Find out what save() is about and implement the functionality + } + + // Private Methods --------------------------------------------------------- + + private IDocument createDocument(IStreamContentAccessor content) { + IDocument document = null; + InputStreamReader in = null; + try { + in = new InputStreamReader(content.getContents()); + StringBuffer buf = new StringBuffer(); + int ch; + while ((ch = in.read()) != -1) { + buf.append((char) ch); + } + document = new Document(buf.toString()); + DocumentManager.put(content, document); + CssTextTools tools = CssUI.getDefault().getTextTools(); + tools.setupDocument(document); + } catch (CoreException e) { + CssUI.log(e); + } catch (IOException e) { + CssUI.log(e); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + // ignore + } + } + } + return document; + } + + private CssNode createNode(CssNode parent, IRule rule, Map names) { + int typeCode = -1; + String name = ""; //$NON-NLS-1$ + if (rule instanceof IAtRule) { + IAtRule atRule = (IAtRule) rule; + typeCode = CssNode.AT_RULE; + ISourceReference atKeyword = atRule.getName(); + if (atKeyword != null) { + name = atKeyword.getSource(); + } + } else if (rule instanceof IStyleRule) { + IStyleRule styleRule = (IStyleRule) rule; + typeCode = CssNode.STYLE_RULE; + ISourceReference selector = styleRule.getSelector(); + if (selector != null) { + name = selector.getSource(); + } + } + String id = name; + if (names.containsKey(name)) { + Integer count = (Integer) names.get(name); + id += count.toString(); + names.put(name, new Integer(count.intValue() + 1)); + } else { + names.put(name, new Integer(0)); + } + IRegion region = rule.getSourceRegion(); + CssNode node = new CssNode(parent, typeCode, id, name, + region.getOffset(), region.getLength()); + IRule[] children = rule.getChildren(); + if (children.length > 0) { + Map ruleNames = new HashMap(); + for (int i = 0; i < children.length; i++) { + node.addChild(createNode(node, children[i], ruleNames)); + } + } + IDeclaration[] properties = rule.getDeclarations(); + if (properties.length > 0) { + Map propertyNames = new HashMap(); + for (int i = 0; i < properties.length; i++) { + node.addChild(createNode(node, properties[i], propertyNames)); + } + } + return node; + } + + private CssNode createNode(CssNode parent, IDeclaration declaration, + Map names) { + String name = ""; //$NON-NLS-1$ + ISourceReference property = declaration.getProperty(); + if (property != null) { + name = property.getSource(); + } + String id = name; + if (names.containsKey(name)) { + Integer count = (Integer) names.get(name); + id += count.toString(); + names.put(name, new Integer(count.intValue() + 1)); + } else { + names.put(name, new Integer(0)); + } + IRegion region = declaration.getSourceRegion(); + return new CssNode(parent, CssNode.DECLARATION, id, name, + region.getOffset(), region.getLength()); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CommentAction.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CommentAction.java new file mode 100644 index 0000000..b92b1ee --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CommentAction.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CommentAction.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.editor; + +import java.util.ResourceBundle; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRewriteTarget; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorExtension2; +import org.eclipse.ui.texteditor.TextEditorAction; + +/** + * (Heavily inspired by the AddBlockComment class in JDT-UI) + */ +public class CommentAction extends TextEditorAction { + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param bundle the resource bundle + * @param prefix a prefix to be prepended to the various resource keys + * (described in ResourceAction constructor), or + * null if none + * @param editor the text editor + */ + public CommentAction(ResourceBundle bundle, String prefix, + ITextEditor editor) { + super(bundle, prefix, editor); + } + + // TextEditorAction Implementation ----------------------------------------- + + /** + * @see org.eclipse.jface.action.Action#run() + */ + public void run() { + if (!isEnabled()) { + return; + } + ITextEditor editor = getTextEditor(); + if ((editor == null) || !ensureEditable(editor)) { + return; + } + ITextSelection selection = getCurrentSelection(); + if (!validSelection(selection)) { + return; + } + IDocumentProvider docProvider = editor.getDocumentProvider(); + IEditorInput input = editor.getEditorInput(); + if (docProvider == null || input == null) { + return; + } + IDocument document = docProvider.getDocument(input); + if (document == null) { + return; + } + IRewriteTarget target = (IRewriteTarget) + editor.getAdapter(IRewriteTarget.class); + if (target != null) { + target.beginCompoundChange(); + } + try { + int offset = selection.getOffset(); + String start = "/*"; //$NON-NLS-1$ + document.replace(offset, 0, start); + document.replace(offset + selection.getLength() + start.length(), 0, + "*/"); //$NON-NLS-1$ + } catch (BadLocationException e) { + // ignore + } finally { + if (target != null) { + target.endCompoundChange(); + } + } + } + + /** + * @see org.eclipse.ui.texteditor.TextEditorAction#update() + */ + public void update() { + super.update(); + if (isEnabled()) { + if (!validSelection(getCurrentSelection())) { + setEnabled(false); + } + } + } + + // Private Methods --------------------------------------------------------- + + /** + * Ensures that the editor is modifyable. If the editor is an instance of + * ITextEditorExtension2, its + * validateEditorInputState method is called, otherwise, the + * result of isEditable is returned. + * + * @param editor the editor to be checked + * @return true if the editor is editable, false + * otherwise + */ + private boolean ensureEditable(ITextEditor editor) { + if (editor instanceof ITextEditorExtension2) { + ITextEditorExtension2 extension = (ITextEditorExtension2) editor; + return extension.validateEditorInputState(); + } + return editor.isEditable(); + } + + /** + * Returns the editor's selection, or null if no selection can + * be obtained or the editor is null. + * + * @return the selection of the action's editor, or null + */ + private ITextSelection getCurrentSelection() { + ITextEditor editor = getTextEditor(); + if (editor != null) { + ISelectionProvider provider = editor.getSelectionProvider(); + if (provider != null) { + ISelection selection = provider.getSelection(); + if (selection instanceof ITextSelection) { + return (ITextSelection) selection; + } + } + } + return null; + } + + /** + * Checks whether selection is valid, i.e. neither + * null or empty. + * + * @param selection the selection to check + * @return true if the selection is valid, false + * otherwise + */ + private boolean validSelection(ITextSelection selection) { + if (selection != null) { + return (!selection.isEmpty() && (selection.getLength() > 0)); + } + return false; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CssEditor.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CssEditor.java new file mode 100644 index 0000000..41b8129 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CssEditor.java @@ -0,0 +1,367 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssEditor.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.editor; + +import net.sourceforge.phpeclipse.core.model.ISourceReference; +import net.sourceforge.phpeclipse.css.core.model.IAtRule; +import net.sourceforge.phpeclipse.css.core.model.IRule; +import net.sourceforge.phpeclipse.css.core.model.IStyleRule; +import net.sourceforge.phpeclipse.css.core.model.IStyleSheet; +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.internal.CssDocumentProvider; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; +import net.sourceforge.phpeclipse.css.ui.internal.ICssUIHelpContextIds; +import net.sourceforge.phpeclipse.css.ui.internal.outline.CssOutlinePage; +import net.sourceforge.phpeclipse.css.ui.internal.text.CssPairMatcher; +import net.sourceforge.phpeclipse.css.ui.internal.text.CssSourceViewerConfiguration; +import net.sourceforge.phpeclipse.css.ui.internal.text.IReconcilingParticipant; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.editors.text.TextEditor; +import org.eclipse.ui.texteditor.ContentAssistAction; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; +import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; +import org.eclipse.ui.views.contentoutline.IContentOutlinePage; + +/** + * Implementation of a CSS editor based on the text editor infrastructure + * provided by the platform. + * + * TODO Reacting to every caret move seems rather expensive. Ideally, we'd + * collect the caret position changes and react after a specific delay. + */ +public class CssEditor extends TextEditor implements IReconcilingParticipant { + + // Inner Classes ----------------------------------------------------------- + + /** + * Listens to changes to the selection in the outline page, and changes the + * selection and highlight range in the editor accordingly. + */ + private class OutlineSelectionChangedListener + implements ISelectionChangedListener { + + /* + * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent) + */ + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = + (IStructuredSelection) event.getSelection(); + if (selection.isEmpty()) { + resetHighlightRange(); + } else { + ISourceReference element = + (ISourceReference) selection.getFirstElement(); + highlightElement(element, true); + + IRegion selectedRegion = null; + if (element instanceof IAtRule) { + IAtRule atRule = (IAtRule) element; + selectedRegion = atRule.getValue().getSourceRegion(); + } else if (element instanceof IStyleRule) { + IStyleRule styleRule = (IStyleRule) element; + selectedRegion = styleRule.getSelector().getSourceRegion(); + } + + if (selectedRegion != null) { + selectAndReveal(selectedRegion.getOffset(), + selectedRegion.getLength()); + } + } + } + } + + // Constants --------------------------------------------------------------- + + /** + * Alias for the preference constant OUTLINE_LINK_WITH_EDITOR. + */ + private static final String LINK_WITH_OUTLINE = + CssUIPreferences.OUTLINE_LINK_WITH_EDITOR; + + // Instance Variables ------------------------------------------------------ + + /** + * The associated outline page. + */ + CssOutlinePage outlinePage; + + /** + * Listens to changes in the outline page's selection to update the editor + * selection and highlight range. + */ + private ISelectionChangedListener outlineSelectionChangedListener; + + // Constructors ------------------------------------------------------------ + + /** + * Default constructor. + */ + public CssEditor() { + setSourceViewerConfiguration( + new CssSourceViewerConfiguration( + CssUI.getDefault().getTextTools(), + getPreferenceStore(), this)); + } + + // AbstractTextEditor Implementation --------------------------------------- + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent) + */ + protected boolean affectsTextPresentation(PropertyChangeEvent event) { + String p = event.getProperty(); + if (CssUIPreferences.EDITOR_DEFAULT_COLOR.equals(p) || + CssUIPreferences.EDITOR_DEFAULT_BOLD.equals(p) || + CssUIPreferences.EDITOR_COMMENT_COLOR.equals(p) || + CssUIPreferences.EDITOR_COMMENT_BOLD.equals(p) || + CssUIPreferences.EDITOR_STRING_COLOR.equals(p) || + CssUIPreferences.EDITOR_STRING_BOLD.equals(p) || + CssUIPreferences.EDITOR_PROPERTY_COLOR.equals(p) || + CssUIPreferences.EDITOR_PROPERTY_BOLD.equals(p) || + CssUIPreferences.EDITOR_AT_KEYWORD_COLOR.equals(p) || + CssUIPreferences.EDITOR_AT_KEYWORD_BOLD.equals(p) || + CssUIPreferences.EDITOR_PSEUDO_CLASS_COLOR.equals(p) || + CssUIPreferences.EDITOR_PSEUDO_CLASS_BOLD.equals(p) + ) { + return true; + } + + return super.affectsTextPresentation(event); + } + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions() + */ + protected void createActions() { + super.createActions(); + + IAction action; + + action = new ContentAssistAction( + CssUIMessages.getResourceBundle(), + "CssEditor.contentAssist.", this); //$NON-NLS-1$ + action.setActionDefinitionId( + ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + setAction(ICssEditorActionConstants.CONTENT_ASSIST, action); + + action = new CommentAction( + CssUIMessages.getResourceBundle(), + "CssEditor.comment.", this); //$NON-NLS-1$ + action.setActionDefinitionId(ICssEditorActionDefinitionIds.COMMENT); + setAction(ICssEditorActionConstants.COMMENT, action); + markAsStateDependentAction(ICssEditorActionConstants.COMMENT, true); + markAsSelectionDependentAction(ICssEditorActionConstants.COMMENT, true); + + action = new UncommentAction( + CssUIMessages.getResourceBundle(), + "CssEditor.uncomment.", this); //$NON-NLS-1$ + action.setActionDefinitionId(ICssEditorActionDefinitionIds.UNCOMMENT); + setAction(ICssEditorActionConstants.UNCOMMENT, action); + markAsStateDependentAction(ICssEditorActionConstants.UNCOMMENT, true); + markAsSelectionDependentAction(ICssEditorActionConstants.UNCOMMENT, + true); + } + + /* + * @see org.eclipse.ui.texteditor.ExtendedTextEditor#configureSourceViewerDecorationSupport(SourceViewerDecorationSupport) + */ + protected void configureSourceViewerDecorationSupport( + SourceViewerDecorationSupport support + ) { + super.configureSourceViewerDecorationSupport(support); + + support.setCharacterPairMatcher(new CssPairMatcher()); + support.setMatchingCharacterPainterPreferenceKeys( + CssUIPreferences.EDITOR_MATCHING_BRACKETS, + CssUIPreferences.EDITOR_MATCHING_BRACKETS_COLOR); + support.setSymbolicFontName(getFontPropertyPreferenceKey()); + } + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#getAdapter(Class) + */ + public Object getAdapter(Class adapter) { + if (IContentOutlinePage.class.equals(adapter)) { + if (outlinePage == null) { + outlinePage = new CssOutlinePage(this); + outlineSelectionChangedListener = + new OutlineSelectionChangedListener(); + outlinePage.addSelectionChangedListener( + outlineSelectionChangedListener); + } + + return outlinePage; + } + + return super.getAdapter(adapter); + } + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#handleCursorPositionChanged() + */ + protected void handleCursorPositionChanged() { + super.handleCursorPositionChanged(); + + highlightElement(computeHighlightRangeSourceReference(), false); + synchronizeOutlinePageSelection(); + } + + /* + * @see org.eclipse.ui.texteditor.ExtendedTextEditor#initializeEditor() + */ + protected void initializeEditor() { + super.initializeEditor(); + + setHelpContextId(ICssUIHelpContextIds.EDITOR); + setPreferenceStore(CssUI.getDefault().getPreferenceStore()); + configureInsertMode(SMART_INSERT, true); + setInsertMode(SMART_INSERT); + } + + // IReconcilingParticipant Implementation ---------------------------------- + + /* + * @see IReconcilingParticipant#reconciled() + */ + public void reconciled() { + Shell shell = getSite().getShell(); + if ((shell != null) && !shell.isDisposed()) { + shell.getDisplay().asyncExec(new Runnable() { + public void run() { + if (outlinePage != null) { + outlinePage.update(); + } + synchronizeOutlinePageSelection(); + } + }); + } + } + + // Public Methods ---------------------------------------------------------- + + /** + * Computes and returns the source reference that includes the caret and + * serves as provider for the outline page selection and the editor range + * indication. + * + * @return the computed source reference + */ + public ISourceReference computeHighlightRangeSourceReference() { + ISourceViewer sourceViewer = getSourceViewer(); + if (sourceViewer == null) { + return null; + } + + StyledText styledText = sourceViewer.getTextWidget(); + if ((styledText == null) || styledText.isDisposed()) { + return null; + } + + int offset = sourceViewer.getVisibleRegion().getOffset(); + int caret = offset + styledText.getCaretOffset(); + + return getRuleAt(caret); + } + + /** + * Informs the editor that its outliner has been closed. + * + * TODO There must be a more elegant way to get notified when the outline + * page was closed. Otherwise move this method into an interface + */ + public void outlinePageClosed() { + if (outlinePage != null) { + outlinePage.removeSelectionChangedListener( + outlineSelectionChangedListener); + outlinePage = null; + resetHighlightRange(); + } + } + + /** + * Synchronizes the outliner selection with the given element position in + * the editor. + * + * @param element the java element to select + */ + public void synchronizeOutlinePage(ISourceReference element) { + if (outlinePage != null) { + outlinePage.removeSelectionChangedListener( + outlineSelectionChangedListener); + outlinePage.select(element); + outlinePage.addSelectionChangedListener( + outlineSelectionChangedListener); + } + } + + /** + * Synchronizes the outliner selection with the currently highlighted source + * reference. + */ + public void synchronizeOutlinePage() { + ISourceReference element = computeHighlightRangeSourceReference(); + synchronizeOutlinePage(element); + } + + // Private Methods --------------------------------------------------------- + + private IRule getRuleAt(int offset) { + IStyleSheet styleSheet = getStyleSheet(); + if (styleSheet == null) { + return null; + } + + return styleSheet.getRuleAt(offset); + } + + private IStyleSheet getStyleSheet() { + if (getDocumentProvider() instanceof CssDocumentProvider) { + CssDocumentProvider p = (CssDocumentProvider) getDocumentProvider(); + return p.getStyleSheet(getEditorInput()); + } + + return null; + } + + void highlightElement(ISourceReference element, boolean moveCursor) { + if (element != null) { + IRegion highlightRegion = element.getSourceRegion(); + setHighlightRange(highlightRegion.getOffset(), + highlightRegion.getLength(), moveCursor); + } else { + resetHighlightRange(); + } + } + + void synchronizeOutlinePageSelection() { + IPreferenceStore store = getPreferenceStore(); + if (store != null) { + boolean linkWithEditor = store.getBoolean(LINK_WITH_OUTLINE); + if (linkWithEditor) { + synchronizeOutlinePage(computeHighlightRangeSourceReference()); + } + } + } +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CssEditorActionContributor.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CssEditorActionContributor.java new file mode 100644 index 0000000..5107b71 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/CssEditorActionContributor.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssEditorActionContributor.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.editor; + +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.texteditor.BasicTextEditorActionContributor; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; +import org.eclipse.ui.texteditor.RetargetTextEditorAction; + +/** + * + */ +public class CssEditorActionContributor + extends BasicTextEditorActionContributor { + + // Instance Variables ------------------------------------------------------ + + private RetargetTextEditorAction contentAssistAction = + new RetargetTextEditorAction(CssUIMessages.getResourceBundle(), + "CssEditor.contentAssistProposal."); //$NON-NLS-1$ + + private ShowSelectedElementOnlyAction showSelectedElementOnlyAction = + new ShowSelectedElementOnlyAction(); //$NON-NLS-1$ + + // IEditorActionBarContributor Implementation ------------------------------ + + /** + * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(IMenuManager) + */ + public void contributeToMenu(IMenuManager menu) { + super.contributeToMenu(menu); + IMenuManager editMenu = menu.findMenuUsingPath( + IWorkbenchActionConstants.M_EDIT); + if (editMenu != null) { + editMenu.add(new Separator()); + editMenu.add(this.contentAssistAction); + } + } + + /** + * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(IToolBarManager) + */ + public void contributeToToolBar(IToolBarManager toolBarManager) { + super.contributeToToolBar(toolBarManager); + if (toolBarManager != null) { + toolBarManager.add(new Separator()); + } + } + + /** + * @see org.eclipse.ui.IEditorActionBarContributor#dispose() + */ + public void dispose() { + doSetActiveEditor(null); + super.dispose(); + } + + /** + * @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(IEditorPart) + */ + public void setActiveEditor(IEditorPart part) { + super.setActiveEditor(part); + doSetActiveEditor(part); + } + + // Private Methods --------------------------------------------------------- + + private void doSetActiveEditor(IEditorPart part) { + ITextEditor editor = null; + if (part instanceof ITextEditor) { + editor = (ITextEditor) part; + } + + contentAssistAction.setAction( + getAction(editor, ICssEditorActionConstants.CONTENT_ASSIST)); + + showSelectedElementOnlyAction.setEditor(editor); + showSelectedElementOnlyAction.update(); + + IActionBars bars = getActionBars(); + bars.setGlobalActionHandler( + ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, + showSelectedElementOnlyAction); + bars.setGlobalActionHandler( + ICssEditorActionDefinitionIds.COMMENT, + getAction(editor, ICssEditorActionConstants.COMMENT)); + bars.setGlobalActionHandler( + ICssEditorActionDefinitionIds.UNCOMMENT, + getAction(editor, ICssEditorActionConstants.UNCOMMENT)); + bars.setGlobalActionHandler( + ITextEditorActionDefinitionIds.SHIFT_LEFT, + getAction(editor, ITextEditorActionConstants.SHIFT_LEFT)); + bars.setGlobalActionHandler( + ITextEditorActionDefinitionIds.SHIFT_RIGHT, + getAction(editor, ITextEditorActionConstants.SHIFT_RIGHT)); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ICssEditorActionConstants.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ICssEditorActionConstants.java new file mode 100644 index 0000000..9c231f4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ICssEditorActionConstants.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: ICssEditorActionConstants.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.editor; + +import org.eclipse.ui.texteditor.ITextEditorActionConstants; + +/** + * + */ +public interface ICssEditorActionConstants + extends ITextEditorActionConstants { + + /** + * Edit menu: name of the standard global action "Content Assist" + * (value "ContentAssist"). + */ + String CONTENT_ASSIST = "ContentAssist"; //$NON-NLS-1$ + + /** + * Source menu: name of standard global action "Comment" + * (value "Comment"). + */ + String COMMENT = "Comment"; //$NON-NLS-1$ + + /** + * Source menu: name of standard global action "Uncomment" + * (value "Uncomment"). + */ + String UNCOMMENT = "Uncomment"; //$NON-NLS-1$ + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ICssEditorActionDefinitionIds.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ICssEditorActionDefinitionIds.java new file mode 100644 index 0000000..da4ad4a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ICssEditorActionDefinitionIds.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: ICssEditorActionDefinitionIds.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.editor; + +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; + +/** + * Action definition IDs used by the CSS editor. + */ +public interface ICssEditorActionDefinitionIds + extends ITextEditorActionDefinitionIds { + + /** + * Action definition ID of the "Source > Comment" action + * (value "net.sourceforge.phpeclipse.css.ui.commentAction"). + */ + String COMMENT = "net.sourceforge.phpeclipse.css.ui.commentAction"; //$NON-NLS-1$ + + /** + * Action definition ID of the "Source > Uncomment" action + * (value "net.sourceforge.phpeclipse.css.ui.uncommentAction"). + */ + String UNCOMMENT = "net.sourceforge.phpeclipse.css.ui.uncommentAction"; //$NON-NLS-1$ + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ShowSelectedElementOnlyAction.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ShowSelectedElementOnlyAction.java new file mode 100644 index 0000000..ab1e80f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/ShowSelectedElementOnlyAction.java @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: ShowSelectedElementOnlyAction.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.editor; + +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.TextEditorAction; + +/** + * A toolbar action which toggles the presentation model of the connected text + * editor. The editor shows either the highlight range only or always the whole + * document. + * + *

+ * This class is an implementation for the retargetable action + * TOGGLE_SHOW_SELECTED_ELEMENT_ONLY provided by the platform. + *

+ * + * @see org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds#TOGGLE_SHOW_SELECTED_ELEMENT_ONLY + */ +public class ShowSelectedElementOnlyAction extends TextEditorAction + implements IPropertyChangeListener { + + // Instance Variables ------------------------------------------------------ + + private IPreferenceStore store; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + */ + public ShowSelectedElementOnlyAction() { + super(CssUIMessages.getResourceBundle(), + "CssEditor.showSelectedElementOnly.", null); //$NON-NLS-1$ + store = CssUI.getDefault().getPreferenceStore(); + update(); + } + + // TextEditor Implementation ----------------------------------------------- + + /* + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + ITextEditor editor = getTextEditor(); + if (editor != null) { + IRegion highlightRange = editor.getHighlightRange(); + editor.resetHighlightRange(); + boolean show = !editor.showsHighlightRangeOnly(); + setChecked(show); + editor.showHighlightRangeOnly(show); + if (highlightRange != null) { + editor.setHighlightRange(highlightRange.getOffset(), + highlightRange.getLength(), true); + } + store.removePropertyChangeListener(this); + store.setValue( + CssUIPreferences.EDITOR_SHOW_SELECTED_ELEMENT_ONLY, show); + store.addPropertyChangeListener(this); + } + } + + /* + * @see TextEditorAction#setEditor(ITextEditor) + */ + public void setEditor(ITextEditor editor) { + super.setEditor(editor); + if (editor != null) { + if (store == null) { + store = CssUI.getDefault().getPreferenceStore(); + store.addPropertyChangeListener(this); + } + synchronizeWithPreference(editor); + } else if (store != null) { + store.removePropertyChangeListener(this); + store = null; + } + update(); + } + + /* + * @see org.eclipse.ui.texteditor.IUpdate#update() + */ + public void update() { + ITextEditor editor = getTextEditor(); + if (editor != null) { + setChecked(getTextEditor().showsHighlightRangeOnly()); + setEnabled(true); + } else { + setEnabled(false); + } + } + + // IPropertyChangeListener Implementation ---------------------------------- + + /* + * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent event) { + String p = event.getProperty(); + if (CssUIPreferences.EDITOR_SHOW_SELECTED_ELEMENT_ONLY.equals(p)) { + synchronizeWithPreference(getTextEditor()); + } + } + + // Private Methods --------------------------------------------------------- + + /** + * Synchronizes the appearance of the editor with what the preference store + * contains. + * + * @param editor the editor to synchronize + */ + private void synchronizeWithPreference(ITextEditor editor) { + if (editor != null) { + boolean show = this.store.getBoolean( + CssUIPreferences.EDITOR_SHOW_SELECTED_ELEMENT_ONLY); + setChecked(show); + if (show != editor.showsHighlightRangeOnly()) { + IRegion highlightRange = editor.getHighlightRange(); + editor.resetHighlightRange(); + editor.showHighlightRangeOnly(show); + if (highlightRange != null) { + editor.setHighlightRange(highlightRange.getOffset(), + highlightRange.getLength(), true); + } + } + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/UncommentAction.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/UncommentAction.java new file mode 100644 index 0000000..010d4dc --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/editor/UncommentAction.java @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: UncommentAction.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.editor; + +import java.util.ResourceBundle; + +import net.sourceforge.phpeclipse.css.ui.internal.text.CssPartitionScanner; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRewriteTarget; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorExtension2; +import org.eclipse.ui.texteditor.TextEditorAction; + +/** + * (Heavily inspired by the RemoveBlockComment class in JDT-UI) + */ +public class UncommentAction extends TextEditorAction { + + // Constructors ------------------------------------------------------------ + + /** + * Creates a new instance. + * + * @param bundle the resource bundle + * @param prefix a prefix to be prepended to the various resource keys + * (described in ResourceAction constructor), or + * null if none + * @param editor the text editor + */ + public UncommentAction(ResourceBundle bundle, String prefix, + ITextEditor editor) { + super(bundle, prefix, editor); + } + + // TextEditorAction Implementation ----------------------------------------- + + /** + * @see org.eclipse.jface.action.Action#run() + */ + public void run() { + if (!isEnabled()) { + return; + } + ITextEditor editor = getTextEditor(); + if ((editor == null) || !ensureEditable(editor)) { + return; + } + ITextSelection selection = getCurrentSelection(); + if (!isValidSelection(selection)) { + return; + } + IDocumentProvider docProvider = editor.getDocumentProvider(); + IEditorInput input = editor.getEditorInput(); + if (docProvider == null || input == null) { + return; + } + IDocument document = docProvider.getDocument(input); + if (document == null) { + return; + } + IRewriteTarget target = (IRewriteTarget) + editor.getAdapter(IRewriteTarget.class); + if (target != null) { + target.beginCompoundChange(); + } + try { + ITypedRegion region = getBlockCommentRegion(document, selection); + if (region != null) { + int offset = region.getOffset(); + document.replace(offset, 2, ""); //$NON-NLS-1$ + document.replace(offset + region.getLength() - 4, 2, + ""); //$NON-NLS-1$ + } + } catch (BadLocationException e) { + // ignore + } finally { + if (target != null) { + target.endCompoundChange(); + } + } + } + + // Private Methods --------------------------------------------------------- + + /** + * Ensures that the editor is modifyable. If the editor is an instance of + * ITextEditorExtension2, its + * validateEditorInputState method is called, otherwise, the + * result of isEditable is returned. + * + * @param editor the editor to be checked + * @return true if the editor is editable, false + * otherwise + */ + private boolean ensureEditable(ITextEditor editor) { + if (editor instanceof ITextEditorExtension2) { + ITextEditorExtension2 extension = (ITextEditorExtension2) editor; + return extension.validateEditorInputState(); + } + return editor.isEditable(); + } + + /** + * Returns the block comment typed region enclosing the position at the end + * of selection or null if there is no block + * comment at this position. + * + * @param selection the caret position (the end of the selection is taken as + * the position) + * @return the block comment region at the selection's end, or + * null + */ + private ITypedRegion getBlockCommentRegion(IDocument document, + ITextSelection selection) { + try { + ITypedRegion region = document.getPartition( + selection.getOffset() + selection.getLength()); + if (CssPartitionScanner.CSS_COMMENT.equals(region.getType())) { + return region; + } + } catch (BadLocationException e) { + // ignore + } + return null; + } + + /** + * Returns the editor's selection, or null if no selection can + * be obtained or the editor is null. + * + * @return the selection of the action's editor, or null + */ + private ITextSelection getCurrentSelection() { + ITextEditor editor = getTextEditor(); + if (editor != null) { + ISelectionProvider provider = editor.getSelectionProvider(); + if (provider != null) { + ISelection selection = provider.getSelection(); + if (selection instanceof ITextSelection) { + return (ITextSelection) selection; + } + } + } + return null; + } + + /** + * Checks whether given selection is valid, i.e. neither null + * or empty. + * + * @param selection the selection to check + * @return true if the selection is valid, false + * otherwise + */ + private boolean isValidSelection(ITextSelection selection) { + if (selection != null) { + return (!selection.isEmpty() && (selection.getLength() > 0)); + } + return false; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineContentProvider.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineContentProvider.java new file mode 100644 index 0000000..1bd8b24 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineContentProvider.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssOutlineContentProvider.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.outline; + +import net.sourceforge.phpeclipse.css.core.model.IRule; +import net.sourceforge.phpeclipse.css.core.model.IStyleSheet; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * Content provider for the CSS outline page. + */ +public class CssOutlineContentProvider implements ITreeContentProvider { + + // Instance Variables ------------------------------------------------------ + + /** + * The parsed style sheet. + */ + private IStyleSheet styleSheet; + + // ITreeContentProvider Implementation ------------------------------------- + + /* + * ITreeContentProvider#getChildren(Object) + */ + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof IRule) { + return ((IRule) parentElement).getChildren(); + } + return new Object[0]; + } + + /* + * @see ITreeContentProvider#getParent(Object) + */ + public Object getParent(Object element) { + if (element instanceof IRule) { + return ((IRule) element).getParent(); + } + return null; + } + + /* + * @see ITreeContentProvider#hasChildren(Object) + */ + public boolean hasChildren(Object element) { + return getChildren(element).length > 0; + } + + /* + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object) + */ + public Object[] getElements(Object inputElement) { + if (styleSheet != null) { + return styleSheet.getRules(); + } + return new Object[0]; + } + + /* + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + styleSheet = null; + } + + /* + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(Viewer, Object, Object) + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (oldInput != newInput) { + if (oldInput instanceof IStyleSheet) { + styleSheet = null; + } + if (newInput instanceof IStyleSheet) { + IStyleSheet newStyleSheet = (IStyleSheet) newInput; + styleSheet = newStyleSheet; + } + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineDoubleClickListener.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineDoubleClickListener.java new file mode 100644 index 0000000..3a599e5 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineDoubleClickListener.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssOutlineDoubleClickListener.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.outline; + +import net.sourceforge.phpeclipse.css.core.model.IStyleRule; +import net.sourceforge.phpeclipse.css.ui.CssUI; + +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.views.contentoutline.ContentOutlinePage; + +/** + * A double click listener that is intended to be attached to an outline page + * displaying CSS elements. If a style rule is double clicked, it will attempt + * to show the standard properties view. + */ +public class CssOutlineDoubleClickListener implements IDoubleClickListener { + + // Instance Variables ------------------------------------------------------ + + /** + * The associated content outline page. + */ + private ContentOutlinePage outlinePage; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param outlinePage the associated outline page + */ + public CssOutlineDoubleClickListener(ContentOutlinePage outlinePage) { + this.outlinePage = outlinePage; + } + + // IDoubleClickListener Implementation ------------------------------------- + + /* + * @see IDoubleClickListener#doubleClick(DoubleClickEvent) + */ + public void doubleClick(DoubleClickEvent event) { + Object selectedElement = getSelectedElement(event.getSelection()); + if (selectedElement instanceof IStyleRule) { + showPropertiesView(); + } + } + + // Private Methods --------------------------------------------------------- + + /** + * Shows the properties view in the current workbench window. + */ + private void showPropertiesView() { + IWorkbenchPage workbenchPage = outlinePage.getSite().getPage(); + try { + workbenchPage.showView(IPageLayout.ID_PROP_SHEET); + } catch (PartInitException e) { + CssUI.log( + "Could not show properties view", e); //$NON-NLS-1$ + } + } + + /** + * Finds the element that is selected. As this is a double click listener, + * only a single element can be selected at once. + * + * @param selection the selection + * @return the selected element + */ + private Object getSelectedElement(ISelection selection) { + Object element = null; + if (selection instanceof IStructuredSelection) { + element = ((IStructuredSelection) selection).getFirstElement(); + } + return element; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineLabelProvider.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineLabelProvider.java new file mode 100644 index 0000000..a66c266 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlineLabelProvider.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssOutlineLabelProvider.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.outline; + +import net.sourceforge.phpeclipse.core.model.ISourceReference; +import net.sourceforge.phpeclipse.css.core.model.IAtRule; +import net.sourceforge.phpeclipse.css.core.model.IStyleRule; +import net.sourceforge.phpeclipse.css.ui.CssUI; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +/** + * Label provider for the CSS outline page. + */ +public class CssOutlineLabelProvider extends LabelProvider { + + // LabelProvider Implementation -------------------------------------------- + + /** + * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) + */ + public Image getImage(Object element) { + if (element instanceof IStyleRule) { + return CssUI.getDefault().getImageRegistry().get( + CssUI.ICON_STYLE_RULE); + } else if (element instanceof IAtRule) { + return CssUI.getDefault().getImageRegistry().get( + CssUI.ICON_AT_RULE); + } + return null; + } + + /** + * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) + */ + public String getText(Object element) { + StringBuffer text = new StringBuffer(); + if (element instanceof IStyleRule) { + IStyleRule rule = (IStyleRule) element; + ISourceReference selector = rule.getSelector(); + if (selector != null) { + text.append(selector.getSource()); + } + } else if (element instanceof IAtRule) { + IAtRule rule = (IAtRule) element; + ISourceReference name = rule.getName(); + ISourceReference value = rule.getValue(); + if (name != null) { + text.append(name.getSource()); + if (value != null) { + text.append(' '); + } + } + if (value != null) { + text.append(value.getSource()); + } + } + return normalizeWhitespace(text.toString()); + } + + // Private Methods --------------------------------------------------------- + + /** + * Replaces all whitespace characters by regular spaces, and trims excessive + * whitespace down to at most one whitespace between non-whitespace + * characters. + * + * @param text The text to normalize + * @return The normalized text + */ + public String normalizeWhitespace(String text) { + StringBuffer buf = new StringBuffer(); + boolean previousWasWhitespace = false; + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); + if ((c == 9) || (c == 10) || (c == 13)) { // Tab + c = ' '; + } + if ((c != ' ') || !previousWasWhitespace) { + buf.append(c); + } + previousWasWhitespace = (c == ' '); + } + return buf.toString(); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlinePage.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlinePage.java new file mode 100644 index 0000000..7db8459 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/CssOutlinePage.java @@ -0,0 +1,321 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssOutlinePage.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.outline; + +import java.util.List; + +import net.sourceforge.phpeclipse.core.model.ISourceReference; +import net.sourceforge.phpeclipse.css.core.model.IAtRule; +import net.sourceforge.phpeclipse.css.core.model.IStyleSheet; +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.internal.CssDocumentProvider; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; +import net.sourceforge.phpeclipse.css.ui.internal.editor.CssEditor; +import net.sourceforge.phpeclipse.css.ui.internal.editor.ShowSelectedElementOnlyAction; +import net.sourceforge.phpeclipse.ui.views.outline.ProblemsLabelDecorator; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.viewers.DecoratingLabelProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.part.IPageSite; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; +import org.eclipse.ui.texteditor.ResourceAction; +import org.eclipse.ui.views.contentoutline.ContentOutlinePage; + +/** + * Implements the outline page associated with the CSS editor. + */ +public class CssOutlinePage extends ContentOutlinePage { + + // Inner Classes ----------------------------------------------------------- + + /** + * Action that activates or deactivates the lexical sorting of elements in + * the outline tree viewer. + */ + private class ToggleLexicalSortingAction extends ResourceAction { + + // Constants ----------------------------------------------------------- + + private static final int CATEGORY_AT_RULE = 0; + private static final int CATEGORY_STYLE_RULE = 1; + + // Instance Variables -------------------------------------------------- + + /** + * The viewer sorter. At-rules are displayed before style rules, + * otherwise the default lexical sorting applies. + */ + private final ViewerSorter sorter = new ViewerSorter() { + public int category(Object element) { + if (element instanceof IAtRule) { + return CATEGORY_AT_RULE; + } else { + return CATEGORY_STYLE_RULE; + } + } + }; + + // Constructors -------------------------------------------------------- + + /** + * Constructor. + */ + public ToggleLexicalSortingAction() { + super(CssUIMessages.getResourceBundle(), + "CssOutlinePage.sort."); //$NON-NLS-1$ + CssUI plugin = CssUI.getDefault(); + boolean checked = plugin.getPreferenceStore().getBoolean( + CssUIPreferences.OUTLINE_SORT_LEXICALLY); //$NON-NLS-1$ + valueChanged(checked, false); + } + + // Action Implementation ----------------------------------------------- + + /* + * @see org.eclipse.jface.action.Action#run() + */ + public void run() { + valueChanged(isChecked(), true); + } + + // Private Methods ----------------------------------------------------- + + /** + * Updates the sorting of the outline. + * + * @param checked Whether lexical sorting is enabled + * @param store Whether the new state should be written back as a + * preference + */ + private void valueChanged(final boolean checked, boolean store) { + setChecked(checked); + BusyIndicator.showWhile(getTreeViewer().getControl().getDisplay(), + new Runnable() { + public void run() { + getTreeViewer().setSorter(checked ? sorter : null); + } + }); + if (store) { + CssUI plugin = CssUI.getDefault(); + plugin.getPreferenceStore().setValue( + CssUIPreferences.OUTLINE_SORT_LEXICALLY, checked); + } + } + + } + + /** + * This action toggles whether this Java Outline page links its selection + * to the active editor. + */ + private class ToggleLinkingAction extends ResourceAction { + + /** + * Constructs a new action. + */ + public ToggleLinkingAction() { + super(CssUIMessages.getResourceBundle(), + "CssOutlinePage.linkWithEditor."); //$NON-NLS-1$ + CssUI plugin = CssUI.getDefault(); + boolean checked = plugin.getPreferenceStore().getBoolean( + CssUIPreferences.OUTLINE_LINK_WITH_EDITOR); //$NON-NLS-1$ + valueChanged(checked, false); + } + + /* + * @see org.eclipse.jface.action.Action#run() + */ + public void run() { + valueChanged(isChecked(), true); + } + + // Private Methods ----------------------------------------------------- + + /** + * Updates the sorting of the outline. + * + * @param checked Whether lexical sorting is enabled + * @param store Whether the new state should be written back as a + * preference + */ + private void valueChanged(final boolean checked, boolean store) { + setChecked(checked); + BusyIndicator.showWhile(getTreeViewer().getControl().getDisplay(), + new Runnable() { + public void run() { + editor.synchronizeOutlinePage(); + } + }); + if (store) { + CssUI plugin = CssUI.getDefault(); + plugin.getPreferenceStore().setValue( + CssUIPreferences.OUTLINE_LINK_WITH_EDITOR, checked); + } + } + + } + + // Instance Variables ------------------------------------------------------ + + /** + * The associated editor. + */ + private CssEditor editor; + + /** + * Toolbar action for showing only the selected element in the editor. + */ + private ShowSelectedElementOnlyAction showSelectedElementOnlyAction = + new ShowSelectedElementOnlyAction(); //$NON-NLS-1$ + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param editor The associated text editor + */ + public CssOutlinePage(CssEditor editor) { + this.editor = editor; + } + + // ContentOutlinePage Implementation --------------------------------------- + + /* + * @see org.eclipse.ui.part.IPage#createControl(Composite) + */ + public void createControl(Composite parent) { + super.createControl(parent); + TreeViewer viewer = getTreeViewer(); + viewer.addDoubleClickListener(new CssOutlineDoubleClickListener(this)); + viewer.setContentProvider(new CssOutlineContentProvider()); + viewer.setLabelProvider(new DecoratingLabelProvider( + new CssOutlineLabelProvider(), + new ProblemsLabelDecorator(editor))); + viewer.setInput(getStyleSheet()); + } + + /* + * @see org.eclipse.ui.part.IPage#dispose() + */ + public void dispose() { + if (editor != null) { + editor.outlinePageClosed(); + editor = null; + } + super.dispose(); + } + + /* + * @see org.eclipse.ui.part.IPageBookViewPage#init(org.eclipse.ui.part.IPageSite) + */ + public void init(IPageSite pageSite) { + super.init(pageSite); + IActionBars bars = pageSite.getActionBars(); + bars.setGlobalActionHandler( + ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, + showSelectedElementOnlyAction); + showSelectedElementOnlyAction.setEditor(editor); + showSelectedElementOnlyAction.update(); + } + + /* + * @see org.eclipse.ui.part.Page#makeContributions(IMenuManager, IToolBarManager, IStatusLineManager) + */ + public void makeContributions(IMenuManager menuManager, + IToolBarManager toolBarManager, IStatusLineManager statusLineManager) { + if (toolBarManager != null) { + toolBarManager.add(new ToggleLexicalSortingAction()); + toolBarManager.add(new ToggleLinkingAction()); + } + super.makeContributions(menuManager, toolBarManager, statusLineManager); + } + + // Public Methods ---------------------------------------------------------- + + /** + * Selects a specific element in the outline page. + * + * @param element the element to select + */ + public void select(ISourceReference element) { + TreeViewer viewer = getTreeViewer(); + if (viewer != null) { + ISelection selection = viewer.getSelection(); + if (selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = + (IStructuredSelection) selection; + List elements = structuredSelection.toList(); + if (!elements.contains(element)) { + if (element == null) { + selection = StructuredSelection.EMPTY; + } else { + selection = new StructuredSelection(element); + } + viewer.setSelection(selection, true); + } + } + } + } + + /** + * Updates the outline page. + */ + public void update() { + IStyleSheet styleSheet = getStyleSheet(); + if (styleSheet != null) { + TreeViewer viewer = getTreeViewer(); + if (viewer != null) { + Control control = viewer.getControl(); + if ((control != null) && !control.isDisposed()) { + control.setRedraw(false); + viewer.setInput(styleSheet); + viewer.expandAll(); + control.setRedraw(true); + } + } + } + } + + // Private Methods --------------------------------------------------------- + + /** + * Returns the parsed model of the style sheet that is loaded into the + * associated editor. + * + * @return the parsed style sheet + */ + private IStyleSheet getStyleSheet() { + IDocumentProvider provider = editor.getDocumentProvider(); + if (provider instanceof CssDocumentProvider) { + CssDocumentProvider cssProvider = (CssDocumentProvider) provider; + return cssProvider.getStyleSheet(editor.getEditorInput()); + } + return null; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/link_editor.gif b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/link_editor.gif new file mode 100644 index 0000000000000000000000000000000000000000..f865f3a39b9c1c39203c6563f28d99f354e14a2a GIT binary patch literal 116 zcmZ?wbhEHb6krfwSj50kUvK~a|NQ^=?eEXGua5_^|1*Gr;!hSv1_o9J9S{$smVwza zVi(UJehUuA86}a5)^SG^dQ{w7nHH{+7Z#e?w6ajKaqHDAIfWRJ_)L=q*Dx)|jms(w NXCF(SGKqn~8USjICBpy! literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/sort_alpha.gif b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/outline/sort_alpha.gif new file mode 100644 index 0000000000000000000000000000000000000000..6d772441d0dbf077f40c69416a5bf27d2901b966 GIT binary patch literal 224 zcmZ?wbhEHb6krfwIKsd%Kfa!sfoZ;deZ74>BO|lD{d{}-c>DPM_VxSi=kKqdKY#xI z{S1r@`{&QUzaIpE0t^fc|Ns97lEeVTpDc_F3_=V#AjKd%8CYW%sPv^|dYvlN=>93t zzr(BeCyQaFf}XH`=iPInol8Yb=B@3p@(?@xlz(B6$dtwGpH)nG_a$_ixeJ-7^f5Z@ mQJs7Fb%&#z;X&649dbdtyw6qEs4_4s@iN6IB_t>^SOWlBJVIUo literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/AbstractConfigurationBlock.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/AbstractConfigurationBlock.java new file mode 100644 index 0000000..ec72daf --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/AbstractConfigurationBlock.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: AbstractConfigurationBlock.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.preferences; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.FontMetrics; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +/** + * + */ +abstract class AbstractConfigurationBlock { + + // Instance Variables ------------------------------------------------------ + + private IPreferenceStore fPreferenceStore; + + private Map fCheckBoxes = new HashMap(); + private SelectionListener fCheckBoxListener = new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + Button button = (Button) e.widget; + getPreferenceStore().setValue((String) fCheckBoxes.get(button), + button.getSelection()); + } + }; + + private Map fTextFields = new HashMap(); + private ModifyListener fTextFieldListener = new ModifyListener() { + public void modifyText(ModifyEvent e) { + Text text = (Text) e.widget; + getPreferenceStore().setValue((String) fTextFields.get(text), + text.getText()); + } + }; + + private List fNumberFields = new ArrayList(); + private ModifyListener fNumberFieldListener = new ModifyListener() { + public void modifyText(ModifyEvent e) { + //numberFieldChanged((Text) e.widget); + } + }; + + private Map fLabels = new HashMap(); + + // Constructors ------------------------------------------------------------ + + public AbstractConfigurationBlock(IPreferenceStore store) { + this.fPreferenceStore = store; + } + + // Public Methods ---------------------------------------------------------- + + public void initializeFields() { + for (Iterator i = fCheckBoxes.keySet().iterator(); i.hasNext(); ) { + Button button = (Button) i.next(); + String key = (String) fCheckBoxes.get(button); + button.setSelection(getPreferenceStore().getBoolean(key)); + } + for (Iterator i = fTextFields.keySet().iterator(); i.hasNext(); ) { + Text text = (Text) i.next(); + String key = (String) fTextFields.get(text); + text.setText(getPreferenceStore().getString(key)); + } + } + + // Protected Methods ------------------------------------------------------- + + protected final Button addBooleanField(Composite parent, String label, + String key, int indentation) { + + Button checkBox = new Button(parent, SWT.CHECK); + checkBox.setText(label); + + GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + gd.horizontalIndent = indentation; + gd.horizontalSpan = 2; + checkBox.setLayoutData(gd); + checkBox.addSelectionListener(fCheckBoxListener); + + fCheckBoxes.put(checkBox, key); + + return checkBox; + } + + protected final Control addIntegerField(Composite composite, String label, + String key, int textLimit, int indentation) { + + Text textControl = + addStringField(composite, label, textLimit, indentation); + fTextFields.put(textControl, key); + fNumberFields.add(textControl); + textControl.addModifyListener(fNumberFieldListener); + + return textControl; + } + + protected final Control addTextField(Composite composite, String label, + String key, int textLimit, int indentation) { + + Text textControl = + addStringField(composite, label, textLimit, indentation); + fTextFields.put(textControl, key); + textControl.addModifyListener(fTextFieldListener); + + return textControl; + } + + protected final int convertHeightInCharsToPixels(Control control, + int chars) { + GC gc = new GC(control); + gc.setFont(control.getFont()); + FontMetrics fontMetrics = gc.getFontMetrics(); + gc.dispose(); + if (fontMetrics == null) { + return 0; + } + return Dialog.convertHeightInCharsToPixels(fontMetrics, chars); + } + + protected final int convertWidthInCharsToPixels(Control control, + int chars) { + GC gc = new GC(control); + gc.setFont(control.getFont()); + FontMetrics fontMetrics = gc.getFontMetrics(); + gc.dispose(); + if (fontMetrics == null) { + return 0; + } + return Dialog.convertWidthInCharsToPixels(fontMetrics, chars); + } + + protected final Control getLabel(Control field) { + return (Control) fLabels.get(field); + } + + protected final IPreferenceStore getPreferenceStore() { + return fPreferenceStore; + } + + // Private Methods --------------------------------------------------------- + + private Text addStringField(Composite composite, String label, + int textLimit, int indentation) { + + Label labelControl = new Label(composite, SWT.NONE); + labelControl.setText(label); + GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + gd.horizontalIndent = indentation; + labelControl.setLayoutData(gd); + + Text textControl = new Text(composite, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + gd.widthHint = convertWidthInCharsToPixels(textControl, textLimit + 1); + textControl.setLayoutData(gd); + textControl.setTextLimit(textLimit); + + fLabels.put(textControl, labelControl); + + return textControl; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorAnnotationsConfigurationBlock.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorAnnotationsConfigurationBlock.java new file mode 100644 index 0000000..37e7e6a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorAnnotationsConfigurationBlock.java @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssEditorAnnotationsConfigurationBlock.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.preferences; + +import java.util.ArrayList; +import java.util.Iterator; + +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; + +import org.eclipse.jface.preference.ColorSelector; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.ui.texteditor.AnnotationPreference; +import org.eclipse.ui.texteditor.MarkerAnnotationPreferences; + +/** + * + */ +final class CssEditorAnnotationsConfigurationBlock + extends AbstractConfigurationBlock { + + // Instance Variables ------------------------------------------------------ + + private List fColorList; + private String[][] fColorListModel; + private ColorSelector fColorSelector; + private Button fShowInTextCheckBox; + private Button fShowInOverviewRulerCheckBox; + + // Constructors ------------------------------------------------------------ + + public CssEditorAnnotationsConfigurationBlock(IPreferenceStore store) { + super(store); + MarkerAnnotationPreferences preferences = + new MarkerAnnotationPreferences(); + fColorListModel = createAnnotationTypeListModel(preferences); + } + + // Public Methods ---------------------------------------------------------- + + public Control createControl(Composite parent) { + + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + composite.setLayout(layout); + + Label label = new Label(composite, SWT.LEFT); + label.setText(getString("presentationOptions")); //$NON-NLS-1$ + GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gridData.horizontalSpan = 2; + label.setLayoutData(gridData); + + Composite editorComposite = new Composite(composite, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginWidth = 0; + editorComposite.setLayout(layout); + gridData = new GridData( + GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); + gridData.horizontalSpan = 2; + editorComposite.setLayoutData(gridData); + + fColorList = new List(editorComposite, + SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); + gridData = new GridData( + GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL); + gridData.heightHint = convertHeightInCharsToPixels(composite, 8); + fColorList.setLayoutData(gridData); + fColorList.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { } + public void widgetSelected(SelectionEvent e) { + handleAnnotationColorListSelection(); + } + }); + + Composite optionsComposite = new Composite(editorComposite, SWT.NONE); + layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 2; + optionsComposite.setLayout(layout); + optionsComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + fShowInTextCheckBox = new Button(optionsComposite, SWT.CHECK); + fShowInTextCheckBox.setText(getString( + "showInText")); //$NON-NLS-1$ + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalAlignment = GridData.BEGINNING; + gridData.horizontalSpan = 2; + fShowInTextCheckBox.setLayoutData(gridData); + fShowInTextCheckBox.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { } + public void widgetSelected(SelectionEvent e) { + int i = fColorList.getSelectionIndex(); + String key = fColorListModel[i][2]; + getPreferenceStore().setValue(key, + fShowInTextCheckBox.getSelection()); + } + }); + + fShowInOverviewRulerCheckBox = new Button(optionsComposite, SWT.CHECK); + fShowInOverviewRulerCheckBox.setText(getString( + "showInOverviewRuler")); //$NON-NLS-1$ + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalAlignment = GridData.BEGINNING; + gridData.horizontalSpan = 2; + fShowInOverviewRulerCheckBox.setLayoutData(gridData); + fShowInOverviewRulerCheckBox.addSelectionListener( + new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { } + public void widgetSelected(SelectionEvent e) { + int i = fColorList.getSelectionIndex(); + String key = fColorListModel[i][3]; + getPreferenceStore().setValue(key, + fShowInOverviewRulerCheckBox.getSelection()); + } + }); + + label = new Label(optionsComposite, SWT.LEFT); + label.setText(getString("color")); //$NON-NLS-1$ + gridData = new GridData(); + gridData.horizontalAlignment = GridData.BEGINNING; + label.setLayoutData(gridData); + + fColorSelector = new ColorSelector(optionsComposite); + Button foregroundColorButton = fColorSelector.getButton(); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalAlignment = GridData.BEGINNING; + foregroundColorButton.setLayoutData(gridData); + foregroundColorButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { } + public void widgetSelected(SelectionEvent e) { + int i = fColorList.getSelectionIndex(); + String key = fColorListModel[i][1]; + PreferenceConverter.setValue(getPreferenceStore(), key, + fColorSelector.getColorValue()); + } + }); + + initialize(); + + return composite; + } + + // Event Handlers ---------------------------------------------------------- + + void handleAnnotationColorListSelection() { + int i = fColorList.getSelectionIndex(); + String key = fColorListModel[i][1]; + RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key); + fColorSelector.setColorValue(rgb); + key = fColorListModel[i][2]; + fShowInTextCheckBox.setSelection(getPreferenceStore().getBoolean(key)); + key = fColorListModel[i][3]; + fShowInOverviewRulerCheckBox.setSelection( + getPreferenceStore().getBoolean(key)); + } + + // Private Methods --------------------------------------------------------- + + private String[][] createAnnotationTypeListModel( + MarkerAnnotationPreferences preferences) { + + ArrayList listModelItems = new ArrayList(); + Iterator i = preferences.getAnnotationPreferences().iterator(); + while (i.hasNext()) { + AnnotationPreference info = (AnnotationPreference) i.next(); + listModelItems.add(new String[] { + info.getPreferenceLabel(), + info.getColorPreferenceKey(), + info.getTextPreferenceKey(), + info.getOverviewRulerPreferenceKey() + }); + } + + String[][] listModel = new String[listModelItems.size()][]; + listModelItems.toArray(listModel); + return listModel; + } + + private static String getString(String key) { + return CssUIMessages.getString( + "CssEditorPreferencePage.annotations." + key); //$NON-NLS-1$ + } + + private void initialize() { + for (int i = 0; i < fColorListModel.length; i++) { + fColorList.add(fColorListModel[i][0]); + } + fColorList.getDisplay().asyncExec(new Runnable() { + public void run() { + if ((fColorList != null) + && !fColorList.isDisposed()) { + fColorList.select(0); + handleAnnotationColorListSelection(); + } + } + }); + initializeFields(); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorAppearanceConfigurationBlock.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorAppearanceConfigurationBlock.java new file mode 100644 index 0000000..c1fcbf0 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorAppearanceConfigurationBlock.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssEditorAppearanceConfigurationBlock.java,v 1.1 2004-09-02 18:11:51 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.preferences; + +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; + +import org.eclipse.jface.preference.ColorSelector; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; + +/** + * + */ +final class CssEditorAppearanceConfigurationBlock + extends AbstractConfigurationBlock { + + // Instance Variables ------------------------------------------------------ + + private List fColorList; + private final String[][] fColorListModel = new String[][] { + { getString("lineNumberForegroundColor"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_LINE_NUMBER_RULER_COLOR }, + { getString("matchingBracketsHighlightColor"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_MATCHING_BRACKETS_COLOR }, + { getString("currentLineHighlighColor"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_CURRENT_LINE_COLOR }, + { getString("printMarginColor"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_PRINT_MARGIN_COLOR }, + }; + private ColorSelector fColorSelector; + + // Constructors ------------------------------------------------------------ + + public CssEditorAppearanceConfigurationBlock(IPreferenceStore store) { + super(store); + } + + // Public Methods ---------------------------------------------------------- + + public Control createControl(Composite parent) { + + Composite control = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + control.setLayout(layout); + + addTextField(control, getString("displayedTabWidth"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_TAB_WIDTH, 3, 0); + addTextField(control, getString("printMarginColumn"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_PRINT_MARGIN_COLUMN, 3, + 0); + addBooleanField(control, getString("showOverviewRuler"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_OVERVIEW_RULER, 0); + addBooleanField(control, getString("showLineNumbers"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_LINE_NUMBER_RULER, 0); + addBooleanField(control, + getString("highlightMatchingBrackets"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_MATCHING_BRACKETS, 0); + addBooleanField(control, + getString("highlightCurrentLine"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_CURRENT_LINE, 0); + addBooleanField(control, getString("showPrintMargin"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_PRINT_MARGIN, 0); + + Label label = new Label(control, SWT.LEFT); + GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gridData.horizontalSpan = 2; + gridData.heightHint = convertHeightInCharsToPixels(control, 1) / 2; + label.setLayoutData(gridData); + + label = new Label(control, SWT.LEFT); + label.setText(getString("colorOptions")); //$NON-NLS-1$ + gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gridData.horizontalSpan = 2; + label.setLayoutData(gridData); + + Composite editorComposite = new Composite(control, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginWidth = 0; + editorComposite.setLayout(layout); + gridData = new GridData( + GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); + gridData.horizontalSpan = 2; + editorComposite.setLayoutData(gridData); + + fColorList = new List(editorComposite, + SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); + gridData = new GridData( + GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL); + gridData.heightHint = convertHeightInCharsToPixels(control, 8); + fColorList.setLayoutData(gridData); + fColorList.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + // do nothing + } + public void widgetSelected(SelectionEvent e) { + handleColorListSelection(); + } + }); + + Composite stylesComposite = new Composite(editorComposite, SWT.NONE); + layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 2; + stylesComposite.setLayout(layout); + stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + label = new Label(stylesComposite, SWT.LEFT); + label.setText(getString("color")); //$NON-NLS-1$ + gridData = new GridData(); + gridData.horizontalAlignment = GridData.BEGINNING; + label.setLayoutData(gridData); + + fColorSelector = new ColorSelector(stylesComposite); + Button foregroundColorButton = fColorSelector.getButton(); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalAlignment = GridData.BEGINNING; + foregroundColorButton.setLayoutData(gridData); + foregroundColorButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + // do nothing + } + public void widgetSelected(SelectionEvent e) { + int i = fColorList.getSelectionIndex(); + String key = fColorListModel[i][1]; + PreferenceConverter.setValue(getPreferenceStore(), key, + fColorSelector.getColorValue()); + } + }); + + initialize(); + + return control; + } + + // Event Handlers ---------------------------------------------------------- + + void handleColorListSelection() { + int i = fColorList.getSelectionIndex(); + String key = fColorListModel[i][1]; + RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key); + fColorSelector.setColorValue(rgb); + } + + // Private Methods --------------------------------------------------------- + + private static String getString(String key) { + return CssUIMessages.getString( + "CssEditorPreferencePage.appearance." + key); //$NON-NLS-1$ + } + + private void initialize() { + for (int i = 0; i < fColorListModel.length; i++) { + fColorList.add(fColorListModel[i][0]); + } + fColorList.getDisplay().asyncExec(new Runnable() { + public void run() { + if ((fColorList != null) + && !fColorList.isDisposed()) { + fColorList.select(0); + handleColorListSelection(); + } + } + }); + initializeFields(); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorContentAssistConfigurationBlock.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorContentAssistConfigurationBlock.java new file mode 100644 index 0000000..34f2381 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorContentAssistConfigurationBlock.java @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssEditorContentAssistConfigurationBlock.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.preferences; + +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; + +import org.eclipse.jface.preference.ColorSelector; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; + +/** + * Configuration block for setting the preferences related to content assist. + */ +final class CssEditorContentAssistConfigurationBlock + extends AbstractConfigurationBlock { + + // Instance Variables ------------------------------------------------------ + + private List fColorList; + private final String[][] fColorListModel = new String[][] { + { getString("backgroundForCompletionProposals"), //$NON-NLS-1$ + CssUIPreferences.CONTENTASSIST_PROPOSALS_BACKGROUND }, + { getString("foregroundForCompletionProposals"), //$NON-NLS-1$ + CssUIPreferences.CONTENTASSIST_PROPOSALS_FOREGROUND }, + }; + private ColorSelector fColorSelector; + private Control fAutoActivationDelayField; + private Control fAutoActivationTriggersField; + + // Constructors ------------------------------------------------------------ + + public CssEditorContentAssistConfigurationBlock(IPreferenceStore store) { + super(store); + } + + // Public Methods ---------------------------------------------------------- + + public Control createControl(Composite parent) { + + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + composite.setLayout(layout); + + //addCompletionRadioButtons(contentAssistComposite); + + addBooleanField(composite, + getString("insertSingleProposalsAutomatically"), //$NON-NLS-1$ + CssUIPreferences.CONTENTASSIST_AUTOINSERT, 0); + addBooleanField(composite, + getString("presentProposalsInAlphabeticalOrder"), //$NON-NLS-1$ + CssUIPreferences.CONTENTASSIST_ORDER_PROPOSALS, 0); + addBooleanField(composite, + getString("enableAutoActivation"), //$NON-NLS-1$ + CssUIPreferences.CONTENTASSIST_AUTOACTIVATION, + 0).addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateAutoactivationControls(); + } + }); + fAutoActivationDelayField = addIntegerField(composite, + getString("autoActivationDelay"), //$NON-NLS-1$ + CssUIPreferences.CONTENTASSIST_AUTOACTIVATION_DELAY, 4, 0); + fAutoActivationTriggersField = addTextField(composite, + getString("autoActivationTriggers"), //$NON-NLS-1$ + CssUIPreferences.CONTENTASSIST_AUTOACTIVATION_TRIGGERS, 4, 0); + + Label label = new Label(composite, SWT.LEFT); + label.setText(getString("colorOptions")); //$NON-NLS-1$ + GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gridData.horizontalSpan = 2; + label.setLayoutData(gridData); + + Composite editorComposite = new Composite(composite, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginWidth = 0; + editorComposite.setLayout(layout); + gridData = new GridData( + GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); + gridData.horizontalSpan = 2; + editorComposite.setLayoutData(gridData); + + fColorList = new List(editorComposite, + SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); + gridData = new GridData( + GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL); + gridData.heightHint = convertHeightInCharsToPixels(composite, 8); + fColorList.setLayoutData(gridData); + fColorList.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + // do nothing + } + public void widgetSelected(SelectionEvent e) { + handleColorListSelection(); + } + }); + + Composite stylesComposite = new Composite(editorComposite, SWT.NONE); + layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 2; + stylesComposite.setLayout(layout); + stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + label = new Label(stylesComposite, SWT.LEFT); + label.setText(getString("color")); //$NON-NLS-1$ + gridData = new GridData(); + gridData.horizontalAlignment = GridData.BEGINNING; + label.setLayoutData(gridData); + + fColorSelector = new ColorSelector(stylesComposite); + Button colorButton = fColorSelector.getButton(); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalAlignment = GridData.BEGINNING; + colorButton.setLayoutData(gridData); + colorButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + // do nothing + } + public void widgetSelected(SelectionEvent e) { + int i = fColorList.getSelectionIndex(); + String key = fColorListModel[i][1]; + PreferenceConverter.setValue(getPreferenceStore(), key, + fColorSelector.getColorValue()); + } + }); + + initialize(); + + return composite; + } + + // Event Handlers ---------------------------------------------------------- + + void handleColorListSelection() { + int i = fColorList.getSelectionIndex(); + String key = fColorListModel[i][1]; + RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key); + fColorSelector.setColorValue(rgb); + } + + // Private Methods --------------------------------------------------------- + + private static String getString(String key) { + return CssUIMessages.getString( + "CssEditorPreferencePage.contentAssist." + key); //$NON-NLS-1$ + } + + private void initialize() { + for (int i = 0; i < fColorListModel.length; i++) { + fColorList.add(fColorListModel[i][0]); + } + fColorList.getDisplay().asyncExec(new Runnable() { + public void run() { + if ((fColorList != null) + && !fColorList.isDisposed()) { + fColorList.select(0); + handleColorListSelection(); + } + } + }); + initializeFields(); + } + + private void updateAutoactivationControls() { + boolean enabled = getPreferenceStore().getBoolean( + CssUIPreferences.CONTENTASSIST_AUTOACTIVATION); + fAutoActivationDelayField.setEnabled(enabled); + getLabel(fAutoActivationDelayField).setEnabled(enabled); + fAutoActivationTriggersField.setEnabled(enabled); + getLabel(fAutoActivationTriggersField).setEnabled(enabled); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorPreferencePage.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorPreferencePage.java new file mode 100644 index 0000000..8b5ae6d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorPreferencePage.java @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssEditorPreferencePage.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.preferences; + +import java.util.Iterator; + +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.texteditor.AnnotationPreference; +import org.eclipse.ui.texteditor.MarkerAnnotationPreferences; + +/** + * Implements the CSS editor preference page. + */ +public class CssEditorPreferencePage extends PreferencePage + implements IWorkbenchPreferencePage { + + // Instance Variables ------------------------------------------------------ + + private OverlayPreferenceStore overlayStore; + + private CssEditorAppearanceConfigurationBlock appearanceBlock; + private CssEditorSyntaxConfigurationBlock syntaxBlock; + private CssEditorContentAssistConfigurationBlock contentAssistBlock; + private CssEditorAnnotationsConfigurationBlock annotationsBlock; + private CssEditorTypingConfigurationBlock typingBlock; + + // PreferencePage Implementation ------------------------------------------- + + /** + * @see PreferencePage#createContents(Composite) + */ + protected Control createContents(Composite parent) { + + TabFolder folder = new TabFolder(parent, SWT.NONE); + TabItem item; + + item = new TabItem(folder, SWT.NONE); + item.setText(getString("appearance")); //$NON-NLS-1$ + item.setControl(createAppearancePage(folder)); + + item = new TabItem(folder, SWT.NONE); + item.setText(getString("syntax")); //$NON-NLS-1$ + item.setControl(createSyntaxPage(folder)); + + item = new TabItem(folder, SWT.NONE); + item.setText(getString("contentAssist")); //$NON-NLS-1$ + item.setControl(createCodeAssistPage(folder)); + + item = new TabItem(folder, SWT.NONE); + item.setText(getString("annotations")); //$NON-NLS-1$ + item.setControl(createAnnotationsPage(folder)); + + item = new TabItem(folder, SWT.NONE); + item.setText(getString("typing")); //$NON-NLS-1$ + item.setControl(createTypingPage(folder)); + + return folder; + } + + /** + * @see PreferencePage#dispose() + */ + public void dispose() { + if (overlayStore != null) { + overlayStore.stopListening(); + overlayStore = null; + } + super.dispose(); + } + + /** + * @see PreferencePage#performOk() + */ + public boolean performOk() { + overlayStore.propagate(); + CssUI.getDefault().savePluginPreferences(); + return true; + } + + /** + * @see PreferencePage#performDefaults() + */ + protected void performDefaults() { + overlayStore.loadDefaults(); + super.performDefaults(); + } + + // IWorkbenchPreferencePage Implementation --------------------------------- + + /** + * @see IWorkbenchPreferencePage#init(IWorkbench) + */ + public void init(IWorkbench workbench) { + setDescription(getString("description")); //$NON-NLS-1$ + setPreferenceStore(CssUI.getDefault().getPreferenceStore()); + + MarkerAnnotationPreferences preferences = + new MarkerAnnotationPreferences(); + overlayStore = createOverlayStore(preferences); + overlayStore.load(); + overlayStore.startListening(); + } + + // Private Methods --------------------------------------------------------- + + private OverlayPreferenceStore createOverlayStore( + MarkerAnnotationPreferences preferences) { + + OverlayPreferenceStore store = + new OverlayPreferenceStore(getPreferenceStore()); + + Iterator e = preferences.getAnnotationPreferences().iterator(); + while (e.hasNext()) { + AnnotationPreference info = (AnnotationPreference) e.next(); + store.addStringKey(info.getColorPreferenceKey()); + store.addBooleanKey(info.getTextPreferenceKey()); + store.addBooleanKey(info.getOverviewRulerPreferenceKey()); + } + + // Appearance + store.addIntKey(CssUIPreferences.EDITOR_TAB_WIDTH); + store.addBooleanKey(CssUIPreferences.EDITOR_CURRENT_LINE); + store.addStringKey(CssUIPreferences.EDITOR_CURRENT_LINE_COLOR); + store.addBooleanKey(CssUIPreferences.EDITOR_MATCHING_BRACKETS); + store.addStringKey(CssUIPreferences.EDITOR_MATCHING_BRACKETS_COLOR); + store.addBooleanKey(CssUIPreferences.EDITOR_PRINT_MARGIN); + store.addStringKey(CssUIPreferences.EDITOR_PRINT_MARGIN_COLOR); + store.addIntKey(CssUIPreferences.EDITOR_PRINT_MARGIN_COLUMN); + store.addBooleanKey(CssUIPreferences.EDITOR_OVERVIEW_RULER); + store.addStringKey(CssUIPreferences.EDITOR_LINE_NUMBER_RULER_COLOR); + store.addBooleanKey(CssUIPreferences.EDITOR_LINE_NUMBER_RULER); + + // Syntax coloring + store.addStringKey(CssUIPreferences.EDITOR_FOREGROUND_COLOR); + store.addBooleanKey( + CssUIPreferences.EDITOR_FOREGROUND_DEFAULT_COLOR); + store.addStringKey(CssUIPreferences.EDITOR_BACKGROUND_COLOR); + store.addBooleanKey( + CssUIPreferences.EDITOR_BACKGROUND_DEFAULT_COLOR); + store.addStringKey(CssUIPreferences.EDITOR_COMMENT_COLOR); + store.addBooleanKey(CssUIPreferences.EDITOR_COMMENT_BOLD); + store.addStringKey(CssUIPreferences.EDITOR_STRING_COLOR); + store.addBooleanKey(CssUIPreferences.EDITOR_STRING_BOLD); + store.addStringKey(CssUIPreferences.EDITOR_PROPERTY_COLOR); + store.addBooleanKey(CssUIPreferences.EDITOR_PROPERTY_BOLD); + store.addStringKey(CssUIPreferences.EDITOR_AT_KEYWORD_COLOR); + store.addBooleanKey(CssUIPreferences.EDITOR_AT_KEYWORD_BOLD); + store.addStringKey(CssUIPreferences.EDITOR_PSEUDO_CLASS_COLOR); + store.addBooleanKey(CssUIPreferences.EDITOR_PSEUDO_CLASS_BOLD); + store.addStringKey(CssUIPreferences.EDITOR_DEFAULT_COLOR); + store.addBooleanKey(CssUIPreferences.EDITOR_DEFAULT_BOLD); + + // Content assist + store.addBooleanKey(CssUIPreferences.CONTENTASSIST_AUTOINSERT); + store.addBooleanKey(CssUIPreferences.CONTENTASSIST_ORDER_PROPOSALS); + store.addBooleanKey(CssUIPreferences.CONTENTASSIST_AUTOACTIVATION); + store.addIntKey( + CssUIPreferences.CONTENTASSIST_AUTOACTIVATION_DELAY); + store.addStringKey( + CssUIPreferences.CONTENTASSIST_AUTOACTIVATION_TRIGGERS); + store.addStringKey( + CssUIPreferences.CONTENTASSIST_PROPOSALS_BACKGROUND); + store.addStringKey( + CssUIPreferences.CONTENTASSIST_PROPOSALS_FOREGROUND); + + // Typing + store.addBooleanKey(CssUIPreferences.EDITOR_SPACES_FOR_TABS); + store.addBooleanKey(CssUIPreferences.EDITOR_CLOSE_STRINGS); + store.addBooleanKey( + CssUIPreferences.EDITOR_CLOSE_BRACKETS_AND_PARENS); + store.addBooleanKey(CssUIPreferences.EDITOR_CLOSE_BRACES); + + return store; + } + + private Control createAppearancePage(Composite parent) { + appearanceBlock = + new CssEditorAppearanceConfigurationBlock(overlayStore); + return appearanceBlock.createControl(parent); + } + + private Control createSyntaxPage(Composite parent) { + syntaxBlock = new CssEditorSyntaxConfigurationBlock(overlayStore); + return syntaxBlock.createControl(parent); + } + + private Control createCodeAssistPage(Composite parent) { + contentAssistBlock = + new CssEditorContentAssistConfigurationBlock(overlayStore); + return contentAssistBlock.createControl(parent); + } + + private Control createAnnotationsPage(Composite parent) { + annotationsBlock = + new CssEditorAnnotationsConfigurationBlock(overlayStore); + return annotationsBlock.createControl(parent); + } + + private Control createTypingPage(Composite parent) { + typingBlock = new CssEditorTypingConfigurationBlock(overlayStore); + return typingBlock.createControl(parent); + } + + private static String getString(String key) { + return CssUIMessages.getString( + "CssEditorPreferencePage." + key); //$NON-NLS-1$ + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorSyntaxConfigurationBlock.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorSyntaxConfigurationBlock.java new file mode 100644 index 0000000..fb1e101 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorSyntaxConfigurationBlock.java @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssEditorSyntaxConfigurationBlock.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.preferences; + +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; + +import org.eclipse.jface.preference.ColorSelector; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; + +/** + * + */ +final class CssEditorSyntaxConfigurationBlock + extends AbstractConfigurationBlock { + + // Instance Variables ------------------------------------------------------ + + private Button fBackgroundDefaultRadioButton; + private Button fBackgroundCustomRadioButton; + private ColorSelector fBackgroundColorSelector; + private List fColorList; + private final String[][] fColorListModel = new String[][] { + { getString("commentColor"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_COMMENT_COLOR, + CssUIPreferences.EDITOR_COMMENT_BOLD }, + { getString("stringColor"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_STRING_COLOR, + CssUIPreferences.EDITOR_STRING_BOLD }, + { getString("propertyNameColor"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_PROPERTY_COLOR, + CssUIPreferences.EDITOR_PROPERTY_BOLD }, + { getString("atKeywordColor"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_AT_KEYWORD_COLOR, + CssUIPreferences.EDITOR_AT_KEYWORD_BOLD }, + { getString("pseudoClassColor"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_PSEUDO_CLASS_COLOR, + CssUIPreferences.EDITOR_PSEUDO_CLASS_BOLD }, + { getString("defaultColor"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_DEFAULT_COLOR, + CssUIPreferences.EDITOR_DEFAULT_BOLD }, + }; + private ColorSelector fColorSelector; + private Button fBoldCheckbox; + + // Constructors ------------------------------------------------------------ + + public CssEditorSyntaxConfigurationBlock(IPreferenceStore store) { + super(store); + } + + // Public Methods ---------------------------------------------------------- + + public Control createControl(Composite parent) { + + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout()); + + Group backgroundComposite = new Group(composite, SWT.SHADOW_ETCHED_IN); + backgroundComposite.setLayout(new RowLayout()); + backgroundComposite.setText(getString("backgroundColor")); //$NON-NLS-1$ + SelectionListener backgroundSelectionListener = + new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + boolean custom = + fBackgroundCustomRadioButton.getSelection(); + fBackgroundColorSelector.setEnabled(custom); + getPreferenceStore().setValue( + CssUIPreferences.EDITOR_BACKGROUND_DEFAULT_COLOR, + !custom); + } + public void widgetDefaultSelected(SelectionEvent e) { } + }; + fBackgroundDefaultRadioButton = new Button(backgroundComposite, + SWT.RADIO | SWT.LEFT); + fBackgroundDefaultRadioButton.setText(getString( + "backgroundColorSystemDefault")); //$NON-NLS-1$ + fBackgroundDefaultRadioButton.addSelectionListener( + backgroundSelectionListener); + fBackgroundCustomRadioButton = new Button(backgroundComposite, + SWT.RADIO | SWT.LEFT); + fBackgroundCustomRadioButton.setText(getString( + "backgroundColorCustom")); //$NON-NLS-1$ + fBackgroundCustomRadioButton.addSelectionListener( + backgroundSelectionListener); + + fBackgroundColorSelector = new ColorSelector(backgroundComposite); + Button backgroundColorButton = fBackgroundColorSelector.getButton(); + backgroundColorButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { } + public void widgetSelected(SelectionEvent e) { + PreferenceConverter.setValue(getPreferenceStore(), + CssUIPreferences.EDITOR_BACKGROUND_COLOR, + fBackgroundColorSelector.getColorValue()); + } + }); + + Label label = new Label(composite, SWT.LEFT); + label.setText(getString("foregroundColor")); //$NON-NLS-1$ + label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Composite editorComposite = new Composite(composite, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginWidth = 0; + editorComposite.setLayout(layout); + GridData gridData = new GridData(GridData.FILL_BOTH); + editorComposite.setLayoutData(gridData); + + fColorList = new List(editorComposite, + SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); + gridData = new GridData(GridData.FILL_BOTH); + gridData.heightHint = convertHeightInCharsToPixels(composite, 5); + fColorList.setLayoutData(gridData); + fColorList.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + handleSyntaxColorListSelection(); + } + }); + + Composite stylesComposite = new Composite(editorComposite, SWT.NONE); + layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 2; + stylesComposite.setLayout(layout); + stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + label = new Label(stylesComposite, SWT.LEFT); + label.setText(getString("color")); //$NON-NLS-1$ + gridData = new GridData(); + gridData.horizontalAlignment = GridData.BEGINNING; + label.setLayoutData(gridData); + + fColorSelector = new ColorSelector(stylesComposite); + Button foregroundColorButton = fColorSelector.getButton(); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalAlignment = GridData.BEGINNING; + foregroundColorButton.setLayoutData(gridData); + foregroundColorButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { } + public void widgetSelected(SelectionEvent e) { + int i = fColorList.getSelectionIndex(); + String key = fColorListModel[i][1]; + PreferenceConverter.setValue(getPreferenceStore(), key, + fColorSelector.getColorValue()); + } + }); + + fBoldCheckbox = new Button(stylesComposite, SWT.CHECK); + fBoldCheckbox.setText(getString("bold")); //$NON-NLS-1$ + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalAlignment = GridData.BEGINNING; + gridData.horizontalSpan = 2; + fBoldCheckbox.setLayoutData(gridData); + fBoldCheckbox.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { } + public void widgetSelected(SelectionEvent e) { + int i = fColorList.getSelectionIndex(); + String key = fColorListModel[i][2]; + getPreferenceStore().setValue(key, + fBoldCheckbox.getSelection()); + } + }); + + Control previewer = + new SyntaxPreviewer(composite, getPreferenceStore()).getControl(); + gridData = new GridData(GridData.FILL_BOTH); + gridData.widthHint = convertWidthInCharsToPixels(composite, 20); + gridData.heightHint = convertHeightInCharsToPixels(composite, 5); + previewer.setLayoutData(gridData); + + initialize(); + + return composite; + } + + /** + * @see AbstractConfigurationBlock#initializeFields() + */ + public void initializeFields() { + super.initializeFields(); + RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), + CssUIPreferences.EDITOR_BACKGROUND_COLOR); + fBackgroundColorSelector.setColorValue(rgb); + boolean defaultBackgroud = getPreferenceStore().getBoolean( + CssUIPreferences.EDITOR_BACKGROUND_DEFAULT_COLOR); + fBackgroundDefaultRadioButton.setSelection(defaultBackgroud); + fBackgroundCustomRadioButton.setSelection(!defaultBackgroud); + fBackgroundColorSelector.setEnabled(!defaultBackgroud); + } + + // Event Handlers ---------------------------------------------------------- + + void handleSyntaxColorListSelection() { + int i = fColorList.getSelectionIndex(); + String key = fColorListModel[i][1]; + RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key); + fColorSelector.setColorValue(rgb); + key = fColorListModel[i][2]; + fBoldCheckbox.setSelection(getPreferenceStore().getBoolean(key)); + } + + // Private Methods --------------------------------------------------------- + + private static String getString(String key) { + return CssUIMessages.getString( + "CssEditorPreferencePage.syntax." + key); //$NON-NLS-1$ + } + + private void initialize() { + for (int i = 0; i < fColorListModel.length; i++) { + fColorList.add(fColorListModel[i][0]); + } + fColorList.getDisplay().asyncExec(new Runnable() { + public void run() { + if ((fColorList != null) + && !fColorList.isDisposed()) { + fColorList.select(0); + handleSyntaxColorListSelection(); + } + } + }); + initializeFields(); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorTypingConfigurationBlock.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorTypingConfigurationBlock.java new file mode 100644 index 0000000..e4a9cd4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssEditorTypingConfigurationBlock.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssEditorTypingConfigurationBlock.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.preferences; + +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * + */ +final class CssEditorTypingConfigurationBlock + extends AbstractConfigurationBlock { + + // Constructors ------------------------------------------------------------ + + public CssEditorTypingConfigurationBlock(IPreferenceStore store) { + super(store); + } + + // Public Methods ---------------------------------------------------------- + + public Control createControl(Composite parent) { + + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + composite.setLayout(layout); + + addBooleanField(composite, + getString("insertSpaceForTabs"), //$NON-NLS-1$ + CssUIPreferences.EDITOR_SPACES_FOR_TABS, 1); + initialize(); + + return composite; + } + + private static String getString(String key) { + return CssUIMessages.getString( + "CssEditorPreferencePage.typing." + key); //$NON-NLS-1$ + } + + private void initialize() { + initializeFields(); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssPreferencePage.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssPreferencePage.java new file mode 100644 index 0000000..41d92dc --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/CssPreferencePage.java @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssPreferencePage.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.preferences; + +import java.util.Arrays; +import java.util.Comparator; + +import net.sourceforge.phpeclipse.css.core.CssCore; +import net.sourceforge.phpeclipse.css.core.internal.CssCorePreferences; +import net.sourceforge.phpeclipse.css.core.profiles.IProfileDescriptor; +import net.sourceforge.phpeclipse.css.core.profiles.IProfileManager; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; + +import org.eclipse.core.runtime.Preferences; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * + */ +public class CssPreferencePage extends PreferencePage + implements IWorkbenchPreferencePage { + + // Instance Variables ------------------------------------------------------ + + /** + * The CSS core preferences. + */ + private Preferences preferences; + + /** + * The radio buttons used to select the default profile. + */ + private Button[] profileButtons; + + /** + * The ID of the currently selected CSS profile. + */ + private String selectedProfile; + + // Constructors ------------------------------------------------------------ + + /** + * Default constructor. + */ + public CssPreferencePage() { + super(getString("description")); //$NON-NLS-1$ + preferences = CssCore.getDefault().getPluginPreferences(); + } + + // PreferencePage Implementation ------------------------------------------- + + /* + * @see PreferencePage#createContents(Composite) + */ + protected Control createContents(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + composite.setLayout(layout); + + createProfileRadioGroup(composite); + + return composite; + } + + /* + * @see PreferencePage#performDefaults() + */ + protected void performDefaults() { + preferences.setToDefault(CssCorePreferences.PROFILE); + selectedProfile = preferences.getString(CssCorePreferences.PROFILE); + if (selectedProfile != null) { + for (int i = 0; i < profileButtons.length; i++) { + Button button = profileButtons[i]; + if (((String) button.getData()).equals(selectedProfile)) { + button.setSelection(true); + } else { + button.setSelection(false); + } + } + } + } + + /* + * @see PreferencePage#performOk() + */ + public boolean performOk() { + preferences.setValue(CssCorePreferences.PROFILE, selectedProfile); + return super.performOk(); + } + + // IWorkbenchPreferencePage Implementation --------------------------------- + + /** + * @see IWorkbenchPreferencePage#init(IWorkbench) + */ + public void init(IWorkbench workbench) { + selectedProfile = preferences.getString(CssCorePreferences.PROFILE); + } + + // Private Methods --------------------------------------------------------- + + /** + * Creates the radio button group for selecting the default CSS profile. + * + * @param composite the composite to add the group to + */ + private void createProfileRadioGroup(Composite composite) { + Group profileGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + profileGroup.setLayout(layout); + profileGroup.setText(getString("profile")); //$NON-NLS-1$ + + IProfileDescriptor[] profiles = getProfileDescriptors(); + profileButtons = new Button[profiles.length]; + for (int i = 0; i < profiles.length; i++) { + Button button = new Button(profileGroup, SWT.RADIO | SWT.LEFT); + button.setText(profiles[i].getName()); + button.setData(profiles[i].getId()); + if (profiles[i].getId().equals(selectedProfile)) { + button.setSelection(true); + } + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + selectedProfile = (String) event.widget.getData(); + } + }); + profileButtons[i] = button; + } + } + + /** + * Returns all available profile descriptors, alphabetically sorted by + * display name. + * + * @return the profile descriptors + */ + private IProfileDescriptor[] getProfileDescriptors() { + IProfileManager mgr = CssCore.getDefault().getProfileManager(); + IProfileDescriptor[] profiles = mgr.getProfileDescriptors(); + Arrays.sort(profiles, new Comparator() { + public int compare(Object o1, Object o2) { + return ((IProfileDescriptor) o1).getName().compareTo( + ((IProfileDescriptor) o2).getName()); + } + }); + return profiles; + } + + private static String getString(String key) { + return CssUIMessages.getString( + "CssPreferencePage." + key); //$NON-NLS-1$ + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/OverlayPreferenceStore.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/OverlayPreferenceStore.java new file mode 100644 index 0000000..e149eec --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/OverlayPreferenceStore.java @@ -0,0 +1,597 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: OverlayPreferenceStore.java,v 1.1 2004-09-02 18:11:51 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.preferences; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceStore; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; + +public class OverlayPreferenceStore implements IPreferenceStore { + + // Inner Classes ----------------------------------------------------------- + + /** + * Descriptor used to denote data types. + */ + public static final class Type { + protected Type() { + } + } + + /** + * Data structure for the overlay key. + */ + public static class OverlayKey { + + private Type fType; + private String fKey; + + public OverlayKey(Type type, String key) { + this.fType = type; + this.fKey = key; + } + } + + /** + * @see IPropertyChangeListener + */ + private class PropertyListener implements IPropertyChangeListener { + + /** + * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent event) { + OverlayKey key = findOverlayKey(event.getProperty()); + if (key != null) { + propagateProperty(fParent, key, fStore); + } + } + } + + // Constants --------------------------------------------------------------- + + /** + * Boolean property type. + */ + public static final Type BOOLEAN = new Type(); + + /** + * Double property type. + */ + public static final Type DOUBLE = new Type(); + + /** + * Floating point property type. + */ + public static final Type FLOAT = new Type(); + + /** + * Integer property type. + */ + public static final Type INT = new Type(); + + /** + * Long integer property type. + */ + public static final Type LONG = new Type(); + + /** + * String property type. + */ + public static final Type STRING = new Type(); + + // Instance Variables ------------------------------------------------------ + + /** + * The parent preference store. + */ + private IPreferenceStore fParent; + + /** + * The underlying preference store. + */ + private IPreferenceStore fStore; + + /** + * The keys of this store. + */ + private List fOverlayKeys = new ArrayList(); + + /** + * The property listener. + */ + private PropertyListener fPropertyListener; + + // Constructors ------------------------------------------------------------ + + /** + * Creates and returns a new overlay preference store. + * + * @param parent the parent preference store + */ + public OverlayPreferenceStore(IPreferenceStore parent) { + this.fParent = parent; + fStore = new PreferenceStore(); + } + + // Public Methods ---------------------------------------------------------- + + public void addKey(Type type, String key) { + this.fOverlayKeys.add(new OverlayKey(type, key)); + } + public void addBooleanKey(String key) { + addKey(BOOLEAN, key); + } + public void addDoubleKey(String key) { + addKey(DOUBLE, key); + } + public void addFloatKey(String key) { + addKey(FLOAT, key); + } + public void addIntKey(String key) { + addKey(INT, key); + } + public void addLongKey(String key) { + addKey(LONG, key); + } + public void addStringKey(String key) { + addKey(STRING, key); + } + + /** + * Propagates all overlay keys from this store to the parent store. + */ + public void propagate() { + for (Iterator i = fOverlayKeys.iterator(); i.hasNext(); ) { + propagateProperty(fStore, (OverlayKey) i.next(), fParent); + } + } + + /** + * Loads the values from the parent into this store. + */ + public void load() { + for (Iterator i = fOverlayKeys.iterator(); i.hasNext(); ) { + loadProperty(fParent, (OverlayKey) i.next(), fStore, true); + } + } + + /** + * Loads the default values. + */ + public void loadDefaults() { + for (Iterator i = fOverlayKeys.iterator(); i.hasNext(); ) { + setToDefault(((OverlayKey) i.next()).fKey); + } + } + + /** + * Starts to listen for changes. + */ + public void startListening() { + if (fPropertyListener == null) { + fPropertyListener = new PropertyListener(); + fParent.addPropertyChangeListener(fPropertyListener); + } + } + + /** + * Stops to listen for changes. + */ + public void stopListening() { + if (fPropertyListener != null) { + fParent.removePropertyChangeListener(fPropertyListener); + fPropertyListener = null; + } + } + + // IPreferenceStore Implementation ----------------------------------------- + + /** + * @see IPreferenceStore#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) + */ + public void addPropertyChangeListener(IPropertyChangeListener listener) { + fStore.addPropertyChangeListener(listener); + } + + /** + * @see IPreferenceStore#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) + */ + public void removePropertyChangeListener(IPropertyChangeListener listener) { + fStore.removePropertyChangeListener(listener); + } + + /** + * @see IPreferenceStore#firePropertyChangeEvent(java.lang.String, java.lang.Object, java.lang.Object) + */ + public void firePropertyChangeEvent(String name, Object oldValue, + Object newValue) { + fStore.firePropertyChangeEvent(name, oldValue, newValue); + } + + /** + * @see IPreferenceStore#contains(java.lang.String) + */ + public boolean contains(String name) { + return fStore.contains(name); + } + + /** + * @see IPreferenceStore#getBoolean(java.lang.String) + */ + public boolean getBoolean(String name) { + return fStore.getBoolean(name); + } + + /** + * @see IPreferenceStore#getDefaultBoolean(java.lang.String) + */ + public boolean getDefaultBoolean(String name) { + return fStore.getDefaultBoolean(name); + } + + /** + * @see IPreferenceStore#getDefaultDouble(java.lang.String) + */ + public double getDefaultDouble(String name) { + return fStore.getDefaultDouble(name); + } + + /** + * @see IPreferenceStore#getDefaultFloat(String) + */ + public float getDefaultFloat(String name) { + return fStore.getDefaultFloat(name); + } + + /** + * @see IPreferenceStore#getDefaultInt(String) + */ + public int getDefaultInt(String name) { + return fStore.getDefaultInt(name); + } + + /** + * @see IPreferenceStore#getDefaultLong(String) + */ + public long getDefaultLong(String name) { + return fStore.getDefaultLong(name); + } + + /** + * @see IPreferenceStore#getDefaultString(String) + */ + public String getDefaultString(String name) { + return fStore.getDefaultString(name); + } + + /** + * @see IPreferenceStore#getDouble(String) + */ + public double getDouble(String name) { + return fStore.getDouble(name); + } + + /** + * @see IPreferenceStore#getFloat(String) + */ + public float getFloat(String name) { + return fStore.getFloat(name); + } + + /** + * @see IPreferenceStore#getInt(String) + */ + public int getInt(String name) { + return fStore.getInt(name); + } + + /** + * @see IPreferenceStore#getLong(String) + */ + public long getLong(String name) { + return fStore.getLong(name); + } + + /** + * @see IPreferenceStore#getString(String) + */ + public String getString(String name) { + return fStore.getString(name); + } + + /** + * @see IPreferenceStore#isDefault(String) + */ + public boolean isDefault(String name) { + return fStore.isDefault(name); + } + + /** + * @see IPreferenceStore#needsSaving() + */ + public boolean needsSaving() { + return fStore.needsSaving(); + } + + /** + * @see IPreferenceStore#putValue(String, String) + */ + public void putValue(String name, String value) { + if (covers(name)) { + fStore.putValue(name, value); + } + } + + /** + * @see IPreferenceStore#setDefault(String, double) + */ + public void setDefault(String name, double value) { + if (covers(name)) { + fStore.setDefault(name, value); + } + } + + /** + * @see IPreferenceStore#setDefault(String, float) + */ + public void setDefault(String name, float value) { + if (covers(name)) { + fStore.setDefault(name, value); + } + } + + /** + * @see IPreferenceStore#setDefault(String, int) + */ + public void setDefault(String name, int value) { + if (covers(name)) { + fStore.setDefault(name, value); + } + } + + /** + * @see IPreferenceStore#setDefault(String, long) + */ + public void setDefault(String name, long value) { + if (covers(name)) { + fStore.setDefault(name, value); + } + } + + /** + * @see IPreferenceStore#setDefault(String, String) + */ + public void setDefault(String name, String value) { + if (covers(name)) { + fStore.setDefault(name, value); + } + } + + /** + * @see IPreferenceStore#setDefault(String, boolean) + */ + public void setDefault(String name, boolean value) { + if (covers(name)) { + fStore.setDefault(name, value); + } + } + + /** + * @see IPreferenceStore#setToDefault(String) + */ + public void setToDefault(String name) { + fStore.setToDefault(name); + } + + /** + * @see IPreferenceStore#setValue(String, double) + */ + public void setValue(String name, double value) { + if (covers(name)) { + fStore.setValue(name, value); + } + } + + /** + * @see IPreferenceStore#setValue(String, float) + */ + public void setValue(String name, float value) { + if (covers(name)) { + fStore.setValue(name, value); + } + } + + /** + * @see IPreferenceStore#setValue(String, int) + */ + public void setValue(String name, int value) { + if (covers(name)) { + fStore.setValue(name, value); + } + } + + /** + * @see IPreferenceStore#setValue(String, long) + */ + public void setValue(String name, long value) { + if (covers(name)) { + fStore.setValue(name, value); + } + } + + /** + * @see IPreferenceStore#setValue(String, String) + */ + public void setValue(String name, String value) { + if (covers(name)) { + fStore.setValue(name, value); + } + } + + /** + * @see IPreferenceStore#setValue(String, boolean) + */ + public void setValue(String name, boolean value) { + if (covers(name)) { + fStore.setValue(name, value); + } + } + + // Protected Methods ------------------------------------------------------- + + /** + * Tries to find and return the overlay key for the given preference key + * string. + * + * @param key the preference key string + * @return the overlay key or null if none can be found + */ + protected final OverlayKey findOverlayKey(String key) { + for (Iterator i = fOverlayKeys.iterator(); i.hasNext(); ) { + OverlayKey k = (OverlayKey) i.next(); + if (k.fKey.equals(key)) { + return k; + } + } + return null; + } + + /** + * Propagates the given overlay key from the orgin to the target preference + * store. + * + * @param origin the source preference store + * @param key the overlay key + * @param target the preference store to which the key is propagated + */ + protected final void propagateProperty(IPreferenceStore origin, + OverlayKey key, IPreferenceStore target) { + if (origin.isDefault(key.fKey)) { + if (!target.isDefault(key.fKey)) { + target.setToDefault(key.fKey); + } + return; + } + Type d = key.fType; + if (BOOLEAN == d) { + boolean originValue = origin.getBoolean(key.fKey); + boolean targetValue = target.getBoolean(key.fKey); + if (targetValue != originValue) { + target.setValue(key.fKey, originValue); + } + } else if (DOUBLE == d) { + double originValue = origin.getDouble(key.fKey); + double targetValue = target.getDouble(key.fKey); + if (targetValue != originValue) { + target.setValue(key.fKey, originValue); + } + } else if (FLOAT == d) { + float originValue = origin.getFloat(key.fKey); + float targetValue = target.getFloat(key.fKey); + if (targetValue != originValue) { + target.setValue(key.fKey, originValue); + } + } else if (INT == d) { + int originValue = origin.getInt(key.fKey); + int targetValue = target.getInt(key.fKey); + if (targetValue != originValue) { + target.setValue(key.fKey, originValue); + } + } else if (LONG == d) { + long originValue = origin.getLong(key.fKey); + long targetValue = target.getLong(key.fKey); + if (targetValue != originValue) { + target.setValue(key.fKey, originValue); + } + } else if (STRING == d) { + String originValue = origin.getString(key.fKey); + String targetValue = target.getString(key.fKey); + if ((targetValue != null) && (originValue != null) + && !targetValue.equals(originValue)) { + target.setValue(key.fKey, originValue); + } + } + } + + // Private Methods --------------------------------------------------------- + + /** + * Tells whether the given preference key string is + * covered by this overlay store. + * + * @param key the preference key string + * @return true if this overlay store covers the given key + */ + private boolean covers(String key) { + return (findOverlayKey(key) != null); + } + + /** + * Loads the given key from the orgin into the target. + * + * @param orgin the source preference store + * @param key the overlay key + * @param target the preference store to which the key is propagated + * @param forceInitialization if true the value in the target + * gets initialized before loading + */ + private void loadProperty(IPreferenceStore orgin, OverlayKey key, + IPreferenceStore target, boolean forceInitialization) { + Type d = key.fType; + if (BOOLEAN == d) { + if (forceInitialization) { + target.setValue(key.fKey, true); + } + target.setValue(key.fKey, orgin.getBoolean(key.fKey)); + target.setDefault(key.fKey, orgin.getDefaultBoolean(key.fKey)); + } else if (DOUBLE == d) { + if (forceInitialization) { + target.setValue(key.fKey, 1.0D); + } + target.setValue(key.fKey, orgin.getDouble(key.fKey)); + target.setDefault(key.fKey, orgin.getDefaultDouble(key.fKey)); + } else if (FLOAT == d) { + if (forceInitialization) { + target.setValue(key.fKey, 1.0F); + } + target.setValue(key.fKey, orgin.getFloat(key.fKey)); + target.setDefault(key.fKey, orgin.getDefaultFloat(key.fKey)); + } else if (INT == d) { + if (forceInitialization) { + target.setValue(key.fKey, 1); + } + target.setValue(key.fKey, orgin.getInt(key.fKey)); + target.setDefault(key.fKey, orgin.getDefaultInt(key.fKey)); + } else if (LONG == d) { + if (forceInitialization) { + target.setValue(key.fKey, 1L); + } + target.setValue(key.fKey, orgin.getLong(key.fKey)); + target.setDefault(key.fKey, orgin.getDefaultLong(key.fKey)); + } else if (STRING == d) { + if (forceInitialization) { + target.setValue(key.fKey, "1"); //$NON-NLS-1$ + } + target.setValue(key.fKey, orgin.getString(key.fKey)); + target.setDefault(key.fKey, orgin.getDefaultString(key.fKey)); + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/SyntaxPreviewer.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/SyntaxPreviewer.java new file mode 100644 index 0000000..f2e8a47 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/SyntaxPreviewer.java @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: SyntaxPreviewer.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.preferences; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; +import net.sourceforge.phpeclipse.css.ui.internal.text.CssSourceViewerConfiguration; +import net.sourceforge.phpeclipse.css.ui.text.CssTextTools; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +/** + * A previewer for the syntax styling preferences, used to give real time + * feedback on changes to the preferences. + */ +public class SyntaxPreviewer extends SourceViewer { + + // Constants --------------------------------------------------------------- + + /** + * Alias for the preference constant EDITOR_BACKGROUND_COLOR. + */ + private static final String BACKGROUND_COLOR = + CssUIPreferences.EDITOR_BACKGROUND_COLOR; + + /** + * Alias for the preference constant + * EDITOR_BACKGROUND_DEFAULT_COLOR. + */ + private static final String BACKGROUND_DEFAULT_COLOR = + CssUIPreferences.EDITOR_BACKGROUND_DEFAULT_COLOR; + + // Instance Variables ------------------------------------------------------ + + /** + * The preference store used for loading the style settings. + */ + private IPreferenceStore fStore; + + /** + * Listener that handles changes to the preference store. + */ + private IPropertyChangeListener fPropertyChangeListener = + new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + if (affectsPresentation(event)) { + updateColors(); + } + invalidateTextPresentation(); + } + }; + + private CssTextTools fTextTools; + + /** + * The cached background color of the previewer. + */ + private Color fBackgroundColor; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param parent The parent composite + * @param store The preference store to use for loading the style settings + */ + public SyntaxPreviewer(Composite parent, IPreferenceStore store) { + super(parent, null, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); + this.fStore = store; + this.fTextTools = new CssTextTools(this.fStore); + + configure(new CssSourceViewerConfiguration( + this.fTextTools, this.fStore)); + setEditable(false); + getTextWidget().setFont(JFaceResources.getTextFont()); + + IDocument document = new Document( + loadTextFromResource("preview.css")); //$NON-NLS-1$ + this.fTextTools.setupDocument(document); + setDocument(document); + + this.fStore.addPropertyChangeListener(this.fPropertyChangeListener); + } + + // SourceViewer Implementation --------------------------------------------- + + /** + * @see org.eclipse.jface.text.TextViewer#handleDispose() + */ + protected void handleDispose() { + if (this.fStore != null) { + if (this.fPropertyChangeListener != null) { + this.fStore.removePropertyChangeListener( + this.fPropertyChangeListener); + this.fPropertyChangeListener = null; + } + this.fStore = null; + } + if (this.fTextTools != null) { + this.fTextTools.dispose(); + this.fTextTools = null; + } + if ((this.fBackgroundColor != null) + && !this.fBackgroundColor.isDisposed()) { + this.fBackgroundColor.dispose(); + } + super.handleDispose(); + } + + // Private Methods --------------------------------------------------------- + + private boolean affectsPresentation(PropertyChangeEvent event) { + String p = event.getProperty(); + if (BACKGROUND_COLOR.equals(p) + || BACKGROUND_DEFAULT_COLOR.equals(p)) { + return true; + } + return false; + } + + /** + * Creates a color from the information stored in the given preference + * store. + * + * @param key The preference key under which the color is stored + * @param display The display + * @return The color found, or null if no corresponding + * preference is available + */ + private Color createColor(String key, Display display) { + Color color = null; + if (this.fStore.contains(key)) { + RGB rgb = null; + if (this.fStore.isDefault(key)) { + rgb = PreferenceConverter.getDefaultColor(this.fStore, key); + } else { + rgb = PreferenceConverter.getColor(this.fStore, key); + } + if (rgb != null) { + color = new Color(display, rgb); + } + } + return color; + } + + /** + * Loads and returns the text stored in the specified resource. + * + * @param name The resource name + * @return The text loaded from the resource, or an empty string if there + * was an error reading the resource contents + */ + private String loadTextFromResource(String name) { + String line; + String separator = System.getProperty("line.separator"); //$NON-NLS-1$ + StringBuffer buffer = new StringBuffer(512); + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader( + getClass().getResourceAsStream(name))); + while ((line = reader.readLine()) != null) { + buffer.append(line); + buffer.append(separator); + } + } catch (IOException io) { + CssUI.log(io); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + // ignore + } + } + } + return buffer.toString(); + } + + /** + * Updates the previewer colors. + */ + private void updateColors() { + if (this.fStore != null) { + StyledText styledText = getTextWidget(); + Color color = null; + if (!this.fStore.getBoolean(BACKGROUND_DEFAULT_COLOR)) { + color = createColor(BACKGROUND_COLOR, + styledText.getDisplay()); + } + styledText.setBackground(color); + if (this.fBackgroundColor != null) { + this.fBackgroundColor.dispose(); + } + this.fBackgroundColor = color; + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/preview.css b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/preview.css new file mode 100644 index 0000000..8242efc --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/preferences/preview.css @@ -0,0 +1,5 @@ +@import url("custom.css"); +a:link, a:visited { + /* Make links green, not underlined */ + color: #0F0; text-decoration: none +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssPropertiesAdapterFactory.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssPropertiesAdapterFactory.java new file mode 100644 index 0000000..3ab1c42 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssPropertiesAdapterFactory.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssPropertiesAdapterFactory.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.properties; + +import net.sourceforge.phpeclipse.css.core.model.IRule; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.ui.views.properties.IPropertySource; + +/** + * Factory for adapting model elements to property sources. + */ +public class CssPropertiesAdapterFactory implements IAdapterFactory { + + // Static Methods ---------------------------------------------------------- + + /** + * Creates and registers this adapter factory with the given manager. + * + * @param manager the adapter manager to register with + */ + public static void register(IAdapterManager manager) { + CssPropertiesAdapterFactory factory = new CssPropertiesAdapterFactory(); + manager.registerAdapters(factory, IRule.class); + } + + // IAdapterFactory Implementation ------------------------------------------ + + /* + * @see IAdapterFactory#getAdapter(Object, Class) + */ + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adapterType == IPropertySource.class) { + if (adaptableObject instanceof IRule) { + return new CssRulePropertySource((IRule) adaptableObject); + } + } + return null; + } + + /* + * @see IAdapterFactory#getAdapterList() + */ + public Class[] getAdapterList() { + return new Class[] { IPropertySource.class }; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssPropertyPage.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssPropertyPage.java new file mode 100644 index 0000000..024843d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssPropertyPage.java @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssPropertyPage.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.properties; + +import java.util.Arrays; +import java.util.Comparator; + +import net.sourceforge.phpeclipse.css.core.CssCore; +import net.sourceforge.phpeclipse.css.core.internal.CssCorePreferences; +import net.sourceforge.phpeclipse.css.core.internal.profiles.ProfileManager; +import net.sourceforge.phpeclipse.css.core.profiles.IProfileDescriptor; +import net.sourceforge.phpeclipse.css.core.profiles.IProfileManager; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Preferences; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.ui.dialogs.PropertyPage; + +/** + * Property page for CSS projects and files. + */ +public class CssPropertyPage extends PropertyPage { + + // Instance Variables ------------------------------------------------------ + + private IProfileManager profileManager; + + private boolean useCustomSettings; + private Group profileGroup; + private Button[] profileButtons; + private String selectedProfile; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + */ + public CssPropertyPage() { + profileManager = CssCore.getDefault().getProfileManager(); + } + + // PropertyPage Implementation --------------------------------------------- + + /** + * @see org.eclipse.jface.preference.PreferencePage#createContents(Composite) + */ + protected Control createContents(Composite parent) { + + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + composite.setLayout(layout); + + Object element = getElement(); + if (element instanceof IResource) { + IResource resource = (IResource) element; + try { + selectedProfile = resource.getPersistentProperty( + ProfileManager.PROFILE_PROPERTY); + } catch (CoreException e) { + // ignore + } + } + useCustomSettings = (selectedProfile != null); + if (selectedProfile == null) { + selectedProfile = getInheritedProfile(); + } + + Button useInheritedSettingsButton = + new Button(composite, SWT.RADIO | SWT.LEFT); + if (element instanceof IProject) { + useInheritedSettingsButton.setText( + getString("useWorkspaceSettings")); //$NON-NLS-1$ + } else if (element instanceof IResource) { + useInheritedSettingsButton.setText( + getString("useProjectSettings")); //$NON-NLS-1$ + } + useInheritedSettingsButton.setSelection(!useCustomSettings); + Button useCustomSettingsButton = + new Button(composite, SWT.RADIO | SWT.LEFT); + useCustomSettingsButton.setText( + getString("useCustomSettings")); //$NON-NLS-1$ + useCustomSettingsButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + useCustomSettings = + ((Button) event.widget).getSelection(); + updateProfileGroup(); + } + }); + useCustomSettingsButton.setSelection(useCustomSettings); + + profileGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); + layout = new GridLayout(); + layout.numColumns = 1; + profileGroup.setLayout(layout); + profileGroup.setText(getString("profile")); //$NON-NLS-1$ + + IProfileManager mgr = CssCore.getDefault().getProfileManager(); + IProfileDescriptor[] profiles = mgr.getProfileDescriptors(); + Arrays.sort(profiles, new Comparator() { + public int compare(Object o1, Object o2) { + return ((IProfileDescriptor) o1).getName().compareTo( + ((IProfileDescriptor) o2).getName()); + } + }); + + profileButtons = new Button[profiles.length]; + for (int i = 0; i < profiles.length; i++) { + Button button = new Button(profileGroup, SWT.RADIO | SWT.LEFT); + button.setText(profiles[i].getName()); + button.setData(profiles[i].getId()); + if (profiles[i].getId().equals(selectedProfile)) { + button.setSelection(true); + } + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + selectedProfile = (String) event.widget.getData(); + } + }); + profileButtons[i] = button; + } + updateProfileGroup(); + + return composite; + } + + /** + * @see org.eclipse.jface.preference.IPreferencePage#performOk() + */ + public boolean performOk() { + Object element = getElement(); + if (element instanceof IResource) { + IResource resource = (IResource) element; + if (useCustomSettings) { + profileManager.setProfile(resource, selectedProfile); + } else { + profileManager.setProfile(resource, null); + } + } + return true; + } + + // Private Methods --------------------------------------------------------- + + private String getInheritedProfile() { + Object element = getElement(); + String retVal = null; + if (element instanceof IResource) { + IProject project = ((IResource) element).getProject(); + try { + retVal = project.getPersistentProperty( + ProfileManager.PROFILE_PROPERTY); + } catch (CoreException e) { + // ignore + } + } + if (retVal == null) { + Preferences preferences = + CssCore.getDefault().getPluginPreferences(); + retVal = preferences.getString(CssCorePreferences.PROFILE); + } + return retVal; + } + + private String getString(String key) { + return CssUIMessages.getString("CssPropertyPage." + key); //$NON-NLS-1$ + } + + private void updateProfileGroup() { + profileGroup.setEnabled(useCustomSettings); + for (int i = 0; i < profileButtons.length; i++) { + profileButtons[i].setEnabled(useCustomSettings); + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssRulePropertySource.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssRulePropertySource.java new file mode 100644 index 0000000..873aa8e --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/properties/CssRulePropertySource.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssRulePropertySource.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.properties; + +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.phpeclipse.core.model.ISourceReference; +import net.sourceforge.phpeclipse.css.core.CssCore; +import net.sourceforge.phpeclipse.css.core.model.IDeclaration; +import net.sourceforge.phpeclipse.css.core.model.IPropertyInfo; +import net.sourceforge.phpeclipse.css.core.model.IRule; +import net.sourceforge.phpeclipse.css.core.profiles.IProfile; +import net.sourceforge.phpeclipse.css.core.profiles.IProfileManager; +import net.sourceforge.phpeclipse.css.ui.CssUI; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.views.properties.IPropertyDescriptor; +import org.eclipse.ui.views.properties.IPropertySource; +import org.eclipse.ui.views.properties.PropertyDescriptor; + +/** + * + */ +public class CssRulePropertySource implements IPropertySource { + + // Inner Classes ----------------------------------------------------------- + + /** + * Extended label provider that decorates the property values with specific + * icons when a priority is set. + */ + private static class DeclarationLabelProvider extends LabelProvider { + + /** + * The CSS declaration for which a label should be provided. + */ + private IDeclaration declaration; + + /** + * Constructor. + * + * @param declaration the declaration for which to provide a label + */ + public DeclarationLabelProvider(IDeclaration declaration) { + this.declaration = declaration; + } + + /* + * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object) + */ + public Image getImage(Object element) { + if (this.declaration.getPriority() != null) { + CssUI plugin = CssUI.getDefault(); + return plugin.getImageRegistry().get( + CssUI.ICON_IMPORTANT); + } + return null; + } + + /* + * @see org.eclipse.jface.viewers.ILabelProvider#getText(Object) + */ + public String getText(Object element) { + return this.declaration.getValue().getSource(); + } + + } + + // Instance Variables ------------------------------------------------------ + + /** + * The CSS rule for which properties should be provided. + */ + private IRule rule; + + /** + * Cached list of property descriptors (IPropertyDescriptor). + */ + private List descriptors; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param styleRule the style rule for which to provide properties + */ + public CssRulePropertySource(IRule styleRule) { + this.rule = styleRule; + } + + // IPropertySource Implementation ------------------------------------------ + + /** + * @see IPropertySource#getEditableValue() + */ + public Object getEditableValue() { + return null; + } + + /** + * @see IPropertySource#getPropertyDescriptors() + */ + public IPropertyDescriptor[] getPropertyDescriptors() { + if (this.descriptors == null) { + IProfileManager mgr = CssCore.getDefault().getProfileManager(); + IProfile profile = mgr.getProfile(null); + this.descriptors = new ArrayList(); + for (int i = 0; i < this.rule.getDeclarations().length; i++) { + IDeclaration declaration = this.rule.getDeclarations()[i]; + String property = declaration.getProperty().getSource(); + PropertyDescriptor descriptor = new PropertyDescriptor( + new Integer(i), property); + descriptor.setLabelProvider( + new DeclarationLabelProvider(declaration)); + IPropertyInfo info = profile.getPropertyInfo(property); + if (info != null) { + descriptor.setCategory(info.getCategory()); + } + this.descriptors.add(descriptor); + } + } + return (IPropertyDescriptor[]) this.descriptors.toArray( + new IPropertyDescriptor[this.descriptors.size()]); + } + + /** + * @see IPropertySource#getPropertyValue(Object) + */ + public Object getPropertyValue(Object id) { + int i = ((Integer) id).intValue(); + ISourceReference propertyValue = + this.rule.getDeclarations()[i].getValue(); + return propertyValue.getSource(); + } + + /** + * @see IPropertySource#isPropertySet(Object) + */ + public boolean isPropertySet(Object id) { + // read-only property + return false; + } + + /** + * @see IPropertySource#resetPropertyValue(Object) + */ + public void resetPropertyValue(Object id) { + // read-only property + } + + /** + * @see IPropertySource#setPropertyValue(Object, Object) + */ + public void setPropertyValue(Object id, Object value) { + // read-only property + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/AbstractCssScanner.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/AbstractCssScanner.java new file mode 100644 index 0000000..b5149db --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/AbstractCssScanner.java @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: AbstractCssScanner.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import net.sourceforge.phpeclipse.css.ui.text.IColorManager; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.resource.StringConverter; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.rules.BufferedRuleBasedScanner; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.RGB; + +/** + * + */ +public abstract class AbstractCssScanner extends BufferedRuleBasedScanner { + + // Inner Classes ----------------------------------------------------------- + + /** + * Internal data structure for associating the various style preferences + * of tokens with each other. + */ + private static final class StyleKeys { + + /** + * The preference key that determines the foreground color of the token. + */ + private String colorKey; + + /** + * The preference key that indicates whether the token is to be + * displayed in bold face. + */ + private String boldKey; + + /** + * Constructor. + * + * @param colorKey The color preference key + * @param boldKey The preference key determining whether the + * corresponding tokens should be rendered bold + */ + private StyleKeys(String colorKey, String boldKey) { + this.colorKey = colorKey; + this.boldKey = boldKey; + } + + /** + * @see Object#equals(Object) + */ + public boolean equals(Object o) { + if (!(o instanceof StyleKeys)) { + return false; + } + StyleKeys styleKeys = (StyleKeys) o; + if (((colorKey != null) && !colorKey.equals(styleKeys.colorKey)) + || (colorKey != styleKeys.colorKey)) { + return false; + } + if (((boldKey != null) && !boldKey.equals(styleKeys.boldKey)) + || (boldKey != styleKeys.boldKey)) { + return false; + } + return true; + } + + /** + * @see Object#hashCode() + */ + public int hashCode() { + int retVal = 17; + retVal = (retVal * 37) + + (colorKey != null ? colorKey.hashCode() : 0); + retVal = (retVal * 37) + + (boldKey != null ? boldKey.hashCode() : 0); + return retVal; + } + + } + + // Instance Variables ------------------------------------------------------ + + /** + * The preference store associated with the scanner. + */ + private IPreferenceStore store; + + /** + * Listener for preference store changes related to tokens. + */ + private IPropertyChangeListener propertyChangeListener = + new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + String property = event.getProperty(); + StyleKeys styleKeys = getStyleKeysContaining(property); + if (styleKeys != null) { + if (styleKeys.colorKey.equals(property)) { + Token token = (Token) tokens.get(styleKeys); + handleColorChange(token, event); + } else if (styleKeys.boldKey.equals(property)) { + Token token = (Token) tokens.get(styleKeys); + handleBoldChange(token, event); + } + } + } + }; + + /** + * The shared text colors. + */ + private IColorManager colorManager; + + /** + * A map containing the defined tokens keyed by the color preference key. + */ + private Map tokens = new HashMap(4); + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param store the preference store + * @param manager the color manager + */ + public AbstractCssScanner(IPreferenceStore store, IColorManager manager) { + store.addPropertyChangeListener(propertyChangeListener); + this.store = store; + this.colorManager = manager; + } + + // Public Methods ---------------------------------------------------------- + + /** + * Adapts the tokens managed by this scanner to changes made to the + * corresponding preferences. + * + * @param event the change event fired by the preference store + */ + public void adaptToPreferenceChange(PropertyChangeEvent event) { + String property = event.getProperty(); + StyleKeys styleKeys = getStyleKeysContaining(property); + if (styleKeys != null) { + if (styleKeys.colorKey.equals(property)) { + Token token = (Token) tokens.get(styleKeys); + handleColorChange(token, event); + } else if (styleKeys.boldKey.equals(property)) { + Token token = (Token) tokens.get(styleKeys); + handleBoldChange(token, event); + } + } + } + + /** + * Called to determine whether the change of a specific preference affects + * the presentation of the tokens managed by the scanner. + * + * @param event the preference change event + * @return true if the change affects the presentation of one + * of the tokens managed by the scanner, false + * otherwise + */ + public boolean affectsPresentation(PropertyChangeEvent event) { + String property = event.getProperty(); + return (getStyleKeysContaining(property) != null); + } + + // Protected Methods ------------------------------------------------------- + + /** + * Creates a token with the specified color and style as associated text + * attribute. The color and style are specified as preference keys. + * + * @param colorKey The preference key of the color + * @param boldKey The preference key of the boolean value that determines + * whether the text should be rendered bold, or null + * @return the created token + */ + protected final IToken createToken(String colorKey, String boldKey) { + RGB rgb = PreferenceConverter.getColor(store, colorKey); + colorManager.unbindColor(colorKey); + colorManager.bindColor(colorKey, rgb); + int style = SWT.NORMAL; + if ((boldKey != null) && store.getBoolean(boldKey)) { + style |= SWT.BOLD; + } + IToken token = new Token(new TextAttribute( + colorManager.getColor(colorKey), null, style)); + StyleKeys styleKeys = new StyleKeys(colorKey, boldKey); + tokens.put(styleKeys, token); + return token; + } + + // Private Methods --------------------------------------------------------- + + private StyleKeys getStyleKeysContaining(String key) { + for (Iterator i = tokens.keySet().iterator(); i.hasNext(); ) { + StyleKeys styleKeys = (StyleKeys) i.next(); + if (styleKeys.colorKey.equals(key) + || styleKeys.boldKey.equals(key)) { + return styleKeys; + } + } + return null; + } + + private void handleColorChange(Token token, PropertyChangeEvent event) { + RGB rgb = null; + Object value = event.getNewValue(); + if (value instanceof RGB) { + rgb = (RGB) value; + } else if (value instanceof String) { + rgb = StringConverter.asRGB((String) value); + } + if (rgb != null) { + String key = event.getProperty(); + colorManager.unbindColor(key); + colorManager.bindColor(key, rgb); + Object data = token.getData(); + if (data instanceof TextAttribute) { + TextAttribute oldAttr = (TextAttribute) data; + token.setData(new TextAttribute(colorManager.getColor(key), + oldAttr.getBackground(), oldAttr.getStyle())); + } + } + } + + private void handleBoldChange(Token token, PropertyChangeEvent event) { + boolean bold = false; + Object value = event.getNewValue(); + if (value instanceof Boolean) { + bold = ((Boolean) value).booleanValue(); + } else if (value instanceof String) { + StringConverter.asBoolean((String) value); + } + Object data = token.getData(); + if (data instanceof TextAttribute) { + TextAttribute oldAttr = (TextAttribute) data; + boolean wasBold = ((oldAttr.getStyle() & SWT.BOLD) != 0); + if (wasBold != bold) { + int newStyle = bold ? oldAttr.getStyle() | SWT.BOLD + : oldAttr.getStyle() ^ SWT.BOLD; + token.setData(new TextAttribute(oldAttr.getForeground(), + oldAttr.getBackground(), newStyle)); + } + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/AnnotationAdapter.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/AnnotationAdapter.java new file mode 100644 index 0000000..d743f29 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/AnnotationAdapter.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: AnnotationAdapter.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.reconciler.IReconcileResult; +import org.eclipse.jface.text.source.Annotation; + +/** + * Adapts a temporary or persistent annotation to a reconcile result. + */ +public abstract class AnnotationAdapter implements IReconcileResult { + + /** + * Creates and returns the annotation adapted by this adapter. + * + * @return an annotation (can be temporary or persistent) + */ + public abstract Annotation createAnnotation(); + + /** + * The position of the annotation adapted by this adapter. + * + * @return the position + */ + public abstract Position getPosition(); + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssAnnotationHover.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssAnnotationHover.java new file mode 100644 index 0000000..d2a68b2 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssAnnotationHover.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssAnnotationHover.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.IAnnotationHover; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.ISourceViewer; + + +/** + * Implements simple annotation hover to show the associated messages. + */ +public class CssAnnotationHover implements IAnnotationHover { + /* + * @see IVerticalRulerHover#getHoverInfo(ISourceViewer, int) + */ + public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) { + List annotations = getAnnotationsForLine(sourceViewer, lineNumber); + if (annotations != null) { + List messages = new ArrayList(); + + Iterator e = annotations.iterator(); + while (e.hasNext()) { + Annotation annotation = (Annotation) e.next(); + String message = annotation.getText(); + if (message != null) { + message = message.trim(); + if (message.length() > 0) { + messages.add(message); + } + } + } + + if (messages.size() == 1) { + return (String) messages.get(0); + } + + if (messages.size() > 1) { + return formatMessages(messages); + } + } + + return null; + } + + /** + * Formats multiple annotation messages for display. + */ + private String formatMessages(List messages) { + StringBuffer buffer = new StringBuffer(); + + Iterator e = messages.iterator(); + while (e.hasNext()) { + buffer.append("- "); //$NON-NLS-1$ + buffer.append(e.next()); + buffer.append('\n'); + } + + return buffer.toString(); + } + + /** + * Returns annotations for the ruler's line of activity. + */ + private List getAnnotationsForLine(ISourceViewer viewer, int line) { + IDocument document = viewer.getDocument(); + + IAnnotationModel model = viewer.getAnnotationModel(); + if (model == null) { + return null; + } + + List retVal = new ArrayList(); + + Iterator e = model.getAnnotationIterator(); + while (e.hasNext()) { + Annotation a = (Annotation) e.next(); + Position position = model.getPosition(a); + if (position != null) { + try { + int annotationLine = document + .getLineOfOffset(position.getOffset()); + if (annotationLine == line) { + retVal.add(a); + } + } catch (BadLocationException e1) { + // ignore + } + } + } + + return retVal; + } +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssAutoEditStrategy.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssAutoEditStrategy.java new file mode 100644 index 0000000..ee17d38 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssAutoEditStrategy.java @@ -0,0 +1,277 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssAutoEditStrategy.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import net.sourceforge.phpeclipse.css.core.internal.text.CssTextUtils; +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DefaultAutoIndentStrategy; +import org.eclipse.jface.text.DefaultLineTracker; +import org.eclipse.jface.text.DocumentCommand; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ILineTracker; +import org.eclipse.jface.text.IRegion; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.texteditor.ITextEditorExtension3; +import org.eclipse.ui.texteditor.ITextEditorExtension3.InsertMode; + +/** + * Implements various auto-editing aspects for editing CSS: + * + * All these only operate when 'Smart Insert' mode is enabled, and the closing + * of braces, brackets, parenthesis and strings can be disabled in the editor + * preferences. + */ +public class CssAutoEditStrategy extends DefaultAutoIndentStrategy { + + // Constants --------------------------------------------------------------- + + /** + * Alias for the preference constant EDITOR_SPACES_FOR_TABS. + */ + public static final String SPACES_FOR_TABS = + CssUIPreferences.EDITOR_SPACES_FOR_TABS; + + /** + * Alias for the preference constant EDITOR_TAB_WIDTH. + */ + public static final String TAB_WIDTH = + CssUIPreferences.EDITOR_TAB_WIDTH; + + // Instance Variables ------------------------------------------------------ + + /** + * The line tracker. + */ + private ILineTracker lineTracker; + + /** + * The preference store. + */ + private IPreferenceStore store; + + // Constructors ------------------------------------------------------------ + + /** + * Default constructor. + */ + public CssAutoEditStrategy() { + lineTracker = new DefaultLineTracker(); + store = CssUI.getDefault().getPreferenceStore(); + } + + // DefaultAutoIndentStrategy Implementation -------------------------------- + + /** + * @see org.eclipse.jface.text.IAutoEditStrategy#customizeDocumentCommand(IDocument, DocumentCommand) + */ + public void customizeDocumentCommand(IDocument d, DocumentCommand c) { + if (isSmartInsertMode()) { + if (isNewLine(d, c)) { + smartIndentAfterNewLine(d, c); + } else if (c.text != null) { + if (c.text.length() == 1) { + switch (c.text.charAt(0)) { + case '}': { + smartInsertClosingBrace(d, c); + break; + } + default: { + // do nothing + } + } + } + if (store.getBoolean(SPACES_FOR_TABS)) { + convertTabs(d, c); + } + } + } + } + + // Private Methods --------------------------------------------------------- + + private void convertTabs(IDocument d, DocumentCommand c) { + int index = c.text.indexOf('\t'); + if (index > -1) { + StringBuffer buffer = new StringBuffer(); + lineTracker.set(c.text); + int lines = lineTracker.getNumberOfLines(); + try { + for (int i = 0; i < lines; i++) { + int offset = lineTracker.getLineOffset(i); + int endOffset = offset + lineTracker.getLineLength(i); + String line = c.text.substring(offset, endOffset); + int position = 0; + if (i == 0) { + IRegion firstLine = + d.getLineInformationOfOffset(c.offset); + position = c.offset - firstLine.getOffset(); + } + int length = line.length(); + for (int j = 0; j < length; j++) { + char ch = line.charAt(j); + if (ch == '\t') { + int tabWidth = getTabWidth(); + int remainder = position % tabWidth; + remainder = tabWidth - remainder; + for (int k = 0; k < remainder; k++) { + buffer.append(' '); + } + position += remainder; + } else { + buffer.append(ch); + position++; + } + } + } + c.text = buffer.toString(); + } catch (BadLocationException e) { + // ignore + } + } + } + + private String getIndentOfLine(IDocument d, int line) + throws BadLocationException { + if (line > -1) { + int start = d.getLineOffset(line); + int end = start + d.getLineLength(line) - 1; + int whiteEnd = findEndOfWhiteSpace(d, start, end); + return d.get(start, whiteEnd - start); + } else { + return ""; //$NON-NLS-1$ + } + } + + private int getTabWidth() { + return store.getInt(TAB_WIDTH); + } + + private boolean isNewLine(IDocument d, DocumentCommand c) { + if ((c.length == 0) && (c.text != null)) { + String[] delimiters = d.getLegalLineDelimiters(); + for (int i = 0; i < delimiters.length; i++) { + if (c.text.equals(delimiters[i])) { + return true; + } + } + } + return false; + } + + private boolean isSmartInsertMode() { + IWorkbenchWindow window = + PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window != null) { + IWorkbenchPage page = window.getActivePage(); + if (page != null) { + IEditorPart part = page.getActiveEditor(); + if (part instanceof ITextEditorExtension3) { + InsertMode insertMode = + ((ITextEditorExtension3) part).getInsertMode(); + return (insertMode == ITextEditorExtension3.SMART_INSERT); + } + } + } + return false; + } + + private String createIndentation(int level) { + StringBuffer buf = new StringBuffer(); + if (store.getBoolean(SPACES_FOR_TABS)) { + int tabWidth = getTabWidth(); + for (int i = 0; i < level * tabWidth; i++) { + buf.append(' '); + } + } else { + for (int i = 0; i < level; i++) { + buf.append('\t'); + } + } + return buf.toString(); + } + + private void smartInsertClosingBrace(IDocument d, DocumentCommand c) { + int docLength = d.getLength(); + if ((c.offset == -1) || (docLength == 0)) { + return; + } + try { + int lineOffset = d.getLineInformationOfOffset(c.offset).getOffset(); + if (c.offset == findEndOfWhiteSpace(d, lineOffset, c.offset)) { + int openingBraceOffset = + CssTextUtils.findMatchingOpeningPeer(d, c.offset - 1, '}'); + if (openingBraceOffset >= 0) { + int openingBraceLine = + d.getLineOfOffset(openingBraceOffset); + StringBuffer buf = + new StringBuffer(getIndentOfLine(d, openingBraceLine)); + buf.append(c.text); + c.length += c.offset - lineOffset; + c.offset = lineOffset; + c.text = buf.toString(); + } + } + } catch (BadLocationException e) { + CssUI.log( + "Failed to smart indent after closing brace", e); //$NON-NLS-1$ + } + } + + private void smartIndentAfterNewLine(IDocument d, DocumentCommand c) { + try { + int docLength = d.getLength(); + if ((c.offset == -1) || (docLength == 0)) { + return; + } + StringBuffer buf = new StringBuffer(c.text); + if ((c.offset < docLength) && (d.getChar(c.offset - 1) == '}')) { + // indent with the same amount used before the block was opened + int openingBraceOffset = + CssTextUtils.findMatchingOpeningPeer(d, c.offset - 2, '}'); + if (openingBraceOffset >= 0) { + int openingBraceLine = + d.getLineOfOffset(openingBraceOffset); + buf.append(getIndentOfLine(d, openingBraceLine)); + } + } else if ((c.offset < docLength) + && (d.getChar(c.offset - 1) == '{')) { + int previousLine = d.getLineOfOffset(c.offset); + buf.append(getIndentOfLine(d, previousLine)); + buf.append(createIndentation(1)); + } else { + int previousLine = d.getLineOfOffset(c.offset); + buf.append(getIndentOfLine(d, previousLine)); + } + c.text = buf.toString(); + } catch (BadLocationException e) { + CssUI.log( + "Failed to smart indent after new line", e); //$NON-NLS-1$ + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssCodeScanner.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssCodeScanner.java new file mode 100644 index 0000000..62447eb --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssCodeScanner.java @@ -0,0 +1,352 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssCodeScanner.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import net.sourceforge.phpeclipse.css.core.internal.text.CssTextUtils; +import net.sourceforge.phpeclipse.css.core.profiles.IProfile; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; +import net.sourceforge.phpeclipse.css.ui.text.IColorManager; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.IWhitespaceDetector; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.rules.WhitespaceRule; + +/** + * Rule based scanner responsible for syntax highlighting CSS source. + */ +public class CssCodeScanner extends AbstractCssScanner { + + // Inner Classes ----------------------------------------------------------- + + /** + * Custom rule that detects the SGML/XML comment delimiters + * (<!-- and --> which are allowed at the + * beginning and the end of CSS content. + */ + private class CdoCdcRule implements IRule { + + /** + * The associated token. + */ + private IToken token; + + /** + * Constructor. + * + * @param token the associated token + */ + public CdoCdcRule(IToken token) { + this.token = token; + } + + /** + * @see IRule#evaluate(ICharacterScanner) + */ + public synchronized IToken evaluate(ICharacterScanner scanner) { + IToken retVal = Token.UNDEFINED; + int count = 1; + int c = scanner.read(); + if (c == '<') { + count++; + c = scanner.read(); + if (c == '!') { + count++; + c = scanner.read(); + if (c == '-') { + count++; + c = scanner.read(); + if (c == '-') { + return token; + } + } + } + } else if (c == '-') { + count++; + c = scanner.read(); + if (c == '-') { + count++; + c = scanner.read(); + if (c == '>') { + return token; + } + } + } + while (count-- > 0) { + scanner.unread(); + } + return retVal; + } + + } + + /** + * Custom rule that can detect an at-keyword such as @import. + */ + private class AtKeywordRule implements IRule { + + /** + * The associated token. + */ + private IToken token; + + /** + * Collection of known at-keywords. + */ + private Collection atKeywords; + + /** + * Constructor. + * + * @param token the associated token + */ + public AtKeywordRule(IToken token) { + this.token = token; + atKeywords = getProfile().getAtKeywords(); + } + + /** + * @see IRule#evaluate(ICharacterScanner) + */ + public synchronized IToken evaluate(ICharacterScanner scanner) { + IToken retVal = Token.UNDEFINED; + int count = 1; + int c = scanner.read(); + if (c == '@') { + c = scanner.read(); + if (CssTextUtils.isCssIdentifierStart((char) c)) { + resetBuffer(); + do { + appendToBuffer((char) c); + c = scanner.read(); + count++; + } while (CssTextUtils.isCssIdentifierPart((char) c)); + String candidate = getBufferContent().toLowerCase(); + if (atKeywords.contains(candidate)) { + return token; + } + } + } + while (count-- > 0) { + scanner.unread(); + } + return retVal; + } + + } + + /** + * Custom rule that can detect a known property. + */ + private class PropertyRule implements IRule { + + /** + * The associated token. + */ + private IToken token; + + /** + * Collection of known properties. + */ + private Collection properties; + + /** + * Constructor. + * + * @param token the associated token + */ + public PropertyRule(IToken token) { + this.token = token; + properties = getProfile().getProperties(); + } + + /** + * @see IRule#evaluate(ICharacterScanner) + */ + public synchronized IToken evaluate(ICharacterScanner scanner) { + IToken retVal = Token.UNDEFINED; + int count = 1; + int c = scanner.read(); + if (CssTextUtils.isCssIdentifierStart((char) c)) { + resetBuffer(); + do { + appendToBuffer((char) c); + c = scanner.read(); + count++; + } while (CssTextUtils.isCssIdentifierPart((char) c)); + String candidate = getBufferContent().toLowerCase(); + if (properties.contains(candidate)) { + while (CssTextUtils.isCssWhitespace((char) c)) { + c = scanner.read(); + count++; + } + if (c == ':') { + scanner.unread(); + return token; + } + } + } + while (count-- > 0) { + scanner.unread(); + } + return retVal; + } + + } + + /** + * Custom rule that can detect a pseudo-class in a selector. + */ + private class PseudoClassRule implements IRule { + + /** + * The associated token. + */ + private IToken token; + + /** + * Collection of known pseudo-classes. + */ + private Collection pseudoClasses; + + /** + * Constructor. + * + * @param token the associated token + */ + public PseudoClassRule(IToken token) { + this.token = token; + pseudoClasses = getProfile().getPseudoClassNames(); + } + + /** + * @see IRule#evaluate(ICharacterScanner) + */ + public synchronized IToken evaluate(ICharacterScanner scanner) { + IToken retVal = Token.UNDEFINED; + int count = 1; + int c = scanner.read(); + if (c == ':') { + c = scanner.read(); + if (CssTextUtils.isCssIdentifierStart((char) c)) { + resetBuffer(); + do { + appendToBuffer((char) c); + c = scanner.read(); + count++; + } while (CssTextUtils.isCssIdentifierPart((char) c)); + String candidate = getBufferContent().toLowerCase(); + if (pseudoClasses.contains(candidate)) { + return token; + } + } + } + while (count-- > 0) { + scanner.unread(); + } + return retVal; + } + + } + + /** + * Detects CSS white space. + */ + private static class WhitespaceDetector implements IWhitespaceDetector { + + /** + * @see IWhitespaceDetector#isWhitespace(char) + */ + public boolean isWhitespace(char c) { + return CssTextUtils.isCssWhitespace(c); + } + + } + + // Instance Variables ------------------------------------------------------ + + /** + * The current CSS profile. + */ + private IProfile profile; + + /** + * Shared buffer used by the word detectors. + */ + private StringBuffer buffer = new StringBuffer(); + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param store The preference store + * @param manager The color manager + * @param profile The CSS profile to use + */ + public CssCodeScanner(IPreferenceStore store, IColorManager manager, + IProfile profile) { + super(store, manager); + this.profile = profile; + + List rules = new ArrayList(); + + rules.add(new WhitespaceRule(new WhitespaceDetector())); + + rules.add(new CdoCdcRule(createToken( + CssUIPreferences.EDITOR_COMMENT_COLOR, + CssUIPreferences.EDITOR_COMMENT_BOLD))); + rules.add(new AtKeywordRule(createToken( + CssUIPreferences.EDITOR_AT_KEYWORD_COLOR, + CssUIPreferences.EDITOR_AT_KEYWORD_BOLD))); + rules.add(new PropertyRule(createToken( + CssUIPreferences.EDITOR_PROPERTY_COLOR, + CssUIPreferences.EDITOR_PROPERTY_BOLD))); + rules.add(new PseudoClassRule(createToken( + CssUIPreferences.EDITOR_PSEUDO_CLASS_COLOR, + CssUIPreferences.EDITOR_PSEUDO_CLASS_BOLD))); + + setRules((IRule[]) rules.toArray(new IRule[rules.size()])); + + setDefaultReturnToken(createToken( + CssUIPreferences.EDITOR_DEFAULT_COLOR, + CssUIPreferences.EDITOR_DEFAULT_BOLD)); + } + + // Private Methods --------------------------------------------------------- + + private IProfile getProfile() { + return profile; + } + + private void appendToBuffer(char c) { + buffer.append(c); + } + + private String getBufferContent() { + return buffer.toString(); + } + + private void resetBuffer() { + buffer.setLength(0); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssColorManager.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssColorManager.java new file mode 100644 index 0000000..396fc26 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssColorManager.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssColorManager.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import net.sourceforge.phpeclipse.css.ui.text.IColorManager; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + +/** + * CSS color manager. + */ +public class CssColorManager implements IColorManager { + + // Instance Variables ------------------------------------------------------ + + private Map keyTable = new HashMap(10); + + private Map displayTable = new HashMap(2); + + /** + * Flag which tells if the colors are automatically disposed when the + * current display gets disposed. + */ + private boolean autoDisposeOnDisplayDispose; + + // Constructors ------------------------------------------------------------ + + /** + * Creates a new CSS color manager which automatically disposes the + * allocated colors when the current display gets disposed. + */ + public CssColorManager() { + this(true); + } + + /** + * Creates a new CSS color manager. + * + * @param autoDisposeOnDisplayDispose if true the color manager + * automatically disposes all managed colors when the current display + * gets disposed and all calls to + * {@link org.eclipse.jface.text.source.ISharedTextColors#dispose()} + * are ignored. + */ + public CssColorManager(boolean autoDisposeOnDisplayDispose) { + this.autoDisposeOnDisplayDispose = autoDisposeOnDisplayDispose; + } + + // IColorManager Implementation -------------------------------------------- + + /* + * @see org.eclipse.jface.text.source.ISharedTextColors#dispose() + */ + public void dispose() { + if (!this.autoDisposeOnDisplayDispose) { + dispose(Display.getCurrent()); + } + } + + /* + * @see org.eclipse.jface.text.source.ISharedTextColors#getColor(RGB) + */ + public Color getColor(RGB rgb) { + if (rgb == null) { + return null; + } + final Display display = Display.getCurrent(); + Map colorTable = (Map) this.displayTable.get(display); + if (colorTable == null) { + colorTable = new HashMap(10); + this.displayTable.put(display, colorTable); + if (this.autoDisposeOnDisplayDispose) { + display.disposeExec(new Runnable() { + public void run() { + dispose(display); + } + }); + } + } + Color color = (Color) colorTable.get(rgb); + if (color == null) { + color = new Color(Display.getCurrent(), rgb); + colorTable.put(rgb, color); + } + return color; + } + + /* + * @see IColorManager#bindColor(String, RGB) + */ + public void bindColor(String key, RGB rgb) { + Object value = this.keyTable.get(key); + if (value != null) { + throw new IllegalStateException(); + } + this.keyTable.put(key, rgb); + } + + /* + * @see IColorManager#getColor(String) + */ + public Color getColor(String key) { + if (key == null) { + return null; + } + RGB rgb = (RGB) this.keyTable.get(key); + return getColor(rgb); + } + + /* + * @see IColorManager#unbindColor(String) + */ + public void unbindColor(String key) { + this.keyTable.remove(key); + } + + // Private Methods --------------------------------------------------------- + + private void dispose(Display display) { + Map colorTable = (Map) this.displayTable.get(display); + if (colorTable != null) { + for (Iterator i = colorTable.values().iterator(); i.hasNext(); ) { + Color color = (Color) i.next(); + if (color != null && !color.isDisposed()) { + color.dispose(); + } + } + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssCommentScanner.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssCommentScanner.java new file mode 100644 index 0000000..5300fc4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssCommentScanner.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssCommentScanner.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; +import net.sourceforge.phpeclipse.css.ui.text.IColorManager; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.rules.IToken; + +/** + * + */ +public class CssCommentScanner extends AbstractCssScanner { + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param store The preference store + */ + public CssCommentScanner(IPreferenceStore store, IColorManager manager) { + super(store, manager); + + IToken commentToken = createToken( + CssUIPreferences.EDITOR_COMMENT_COLOR, + CssUIPreferences.EDITOR_COMMENT_BOLD); + + setDefaultReturnToken(commentToken); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssContentAssistProcessor.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssContentAssistProcessor.java new file mode 100644 index 0000000..c3a712e --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssContentAssistProcessor.java @@ -0,0 +1,408 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssContentAssistProcessor.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +import net.sourceforge.phpeclipse.core.model.ISourceReference; +import net.sourceforge.phpeclipse.css.core.internal.text.CssTextUtils; +import net.sourceforge.phpeclipse.css.core.model.IAtRule; +import net.sourceforge.phpeclipse.css.core.model.IDeclaration; +import net.sourceforge.phpeclipse.css.core.model.IPropertyInfo; +import net.sourceforge.phpeclipse.css.core.model.IRule; +import net.sourceforge.phpeclipse.css.core.model.IStyleRule; +import net.sourceforge.phpeclipse.css.core.model.IStyleSheet; +import net.sourceforge.phpeclipse.css.core.profiles.IProfile; +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.internal.CssDocumentProvider; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.contentassist.CompletionProposal; +import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.text.contentassist.IContextInformation; +import org.eclipse.jface.text.contentassist.IContextInformationValidator; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * Content assist processor for the CSS editor. + * + * TODO If a completion proposal is requested before the style sheet has been + * reconciled, we might not get any proposals, or they might be false. + */ +public class CssContentAssistProcessor implements IContentAssistProcessor { + + // Constants --------------------------------------------------------------- + + private static final String AUTOACTIVATION_TRIGGERS = + CssUIPreferences.CONTENTASSIST_AUTOACTIVATION_TRIGGERS; + + private static final String ORDER_PROPOSALS = + CssUIPreferences.CONTENTASSIST_ORDER_PROPOSALS; + + // Instance Variables ------------------------------------------------------ + + /** + * The preference store. + */ + private IPreferenceStore store; + + /** + * The current CSS profile. + */ + private IProfile profile; + + /** + * The associated text editor, if any. + */ + private ITextEditor editor; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param profile The CSS profile to use + */ + public CssContentAssistProcessor(IPreferenceStore store, IProfile profile, + ITextEditor editor) { + this.store = store; + this.profile = profile; + this.editor = editor; + } + + // IContentAssistProcessor ------------------------------------------------- + + /* + * @see IContentAssistProcessor#computeCompletionProposals + */ + public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, + int documentOffset) { + List retVal = Collections.EMPTY_LIST; + IDocument document = viewer.getDocument(); + try { + String prefix = getPrefix(document, documentOffset); + if (prefix.startsWith("@")) { //$NON-NLS-1$ + retVal = proposeAtKeywords(document, documentOffset, + prefix.substring(1)); + } else if (prefix.startsWith(":")) { //$NON-NLS-1$ + retVal = proposePseudoClasses(document, documentOffset, + prefix.substring(1)); + } else { + retVal = proposeProperties(document, documentOffset, prefix); + } + if ((store != null) && store.getBoolean(ORDER_PROPOSALS)) { + sortProposals(retVal); + } + } catch (BadLocationException e) { + CssUI.log( + "Unable to compute completion proposals", e); //$NON-NLS-1$ + } + return (ICompletionProposal[]) retVal.toArray( + new ICompletionProposal[retVal.size()]); + } + + /* + * @see IContentAssistProcessor#computeContextInformation + */ + public IContextInformation[] computeContextInformation(ITextViewer viewer, + int documentOffset) { + return new IContextInformation[0]; + } + + /* + * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters + */ + public char[] getCompletionProposalAutoActivationCharacters() { + String chars = store.getString(AUTOACTIVATION_TRIGGERS); + if (chars == null) { + return null; + } + return chars.toCharArray(); + } + + /* + * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters + */ + public char[] getContextInformationAutoActivationCharacters() { + return null; + } + + /* + * @see IContentAssistProcessor#getErrorMessage + */ + public String getErrorMessage() { + return null; + } + + /* + * @see IContentAssistProcessor#getContextInformationValidator + */ + public IContextInformationValidator getContextInformationValidator() { + return null; + } + + // Private Methods --------------------------------------------------------- + + /** + * Returns the part of the word immediately before the position at which + * content assist was requested. The prefix is lower-cased before it is + * returned, to enable case-insensitive matching. + * + * @param document the document + * @param offset the offset into the document + * @return the prefix + */ + private String getPrefix(IDocument document, int offset) { + try { + int startPos = offset; + while (startPos > 0) { + char c = document.getChar(startPos - 1); + if (!CssTextUtils.isCssIdentifierPart(c) + && (c != '@') && (c != ':')) { + break; + } + startPos--; + if ((c == '@') || (c == ':')) { + break; + } + } + if (startPos < offset) { + return document.get(startPos, offset - startPos).toLowerCase(); + } + } catch (BadLocationException e) { + e.printStackTrace(); + } + return ""; //$NON-NLS-1$ + } + + /** + * Returns the parsed model of the document loaded in the editor, or + * null if the editor hasn't been set or the model couldn't be + * retrieved. + * + * @return the parsed model + */ + private IStyleSheet getStyleSheet() { + if (editor != null) { + IDocumentProvider provider = editor.getDocumentProvider(); + if (provider instanceof CssDocumentProvider) { + return ((CssDocumentProvider) provider).getStyleSheet( + editor.getEditorInput()); + } + } + return null; + } + + public boolean isAtKeyword(IDocument document, int offset) + throws BadLocationException { + IStyleSheet styleSheet = getStyleSheet(); + if (styleSheet != null) { + IRule rule = styleSheet.getRuleAt(offset); + if (rule instanceof IAtRule) { + ISourceReference name = ((IAtRule) rule).getName(); + if (name != null) { + IRegion region = name.getSourceRegion(); + for (int j = region.getOffset(); j < offset; j++) { + char ch = document.getChar(j); + if (!CssTextUtils.isCssIdentifierPart(ch)) { + return false; + } + } + return true; + } + } else if (rule == null) { + return true; + } + } + return false; + } + + /** + * Determines whether the document contains a property at the specified + * offset, or at least whether a property is theoretically allowed at that + * offset. + * + * @param document the document + * @param offset the offset into the document + * @return true if the specified offset is a legal position for + * a property, false otherwise + * @throws BadLocationException if there was a problem accessing the + * document + */ + public boolean isProperty(IDocument document, int offset) + throws BadLocationException { + IStyleSheet styleSheet = getStyleSheet(); + if (styleSheet != null) { + IRule rule = styleSheet.getRuleAt(offset); + if (rule != null) { + IDeclaration declaration = rule.getDeclarationAt(offset); + if (declaration != null) { + IRegion region = declaration.getSourceRegion(); + for (int j = region.getOffset(); j < offset; j++) { + if (document.getChar(j) == ':') { + return false; + } + } + return true; + } else { + IRegion region = rule.getSourceRegion(); + for (int j = region.getOffset(); j < offset; j++) { + if (document.getChar(j) == '{') { + return true; + } + } + } + } + } + return false; + } + + /** + * Determines whether the document contains a selector at the specified + * offset, or at least whether a selector is theoretically allowed at that + * offset. + */ + public boolean isSelector(IDocument document, int offset) + throws BadLocationException { + IStyleSheet styleSheet = getStyleSheet(); + if (styleSheet != null) { + IRule rule = styleSheet.getRuleAt(offset); + if (rule instanceof IStyleRule) { + ISourceReference selector = ((IStyleRule) rule).getSelector(); + if (selector != null) { + IRegion region = selector.getSourceRegion(); + for (int j = region.getOffset(); j < offset; j++) { + if (document.getChar(j) == '{') { + return false; + } + } + return true; + } + } else if (rule == null) { + return true; + } + } + return false; + } + + private List proposeAtKeywords(IDocument document, int offset, + String prefix) throws BadLocationException { + List proposals = new ArrayList(); + if (isAtKeyword(document, offset)) { + Image icon = CssUI.getDefault().getImageRegistry().get( + CssUI.ICON_AT_RULE); + Collection atRuleNames = profile.getAtKeywords(); + for (Iterator i = atRuleNames.iterator(); i.hasNext(); ) { + String atRuleName = (String) i.next(); + if (atRuleName.startsWith(prefix)) { + ICompletionProposal proposal = new CompletionProposal( + atRuleName, offset - prefix.length(), prefix.length(), + atRuleName.length(), icon, atRuleName, null, null); + proposals.add(proposal); + } + } + } + return proposals; + } + + /** + * Computes the completion proposals for properties. A property may only + * appear at the left-hand side of a declaration, so we check whether the + * document offset for which the proposals were requested is a legal + * position for a property, and only then compute the actual proposals. + * + * @param document the document + * @param offset the offset into the document at which completion was + * requested + * @param prefix the string immediately before the offset + * @return the list of {@link ICompletionProposal}s + */ + private List proposeProperties(IDocument document, int offset, + String prefix) throws BadLocationException { + List proposals = new ArrayList(); + if (isProperty(document, offset - 1)) { + Image propertyIcon = + CssUI.getDefault().getImageRegistry().get( + CssUI.ICON_PROPERTY); + Image shorthandIcon = + CssUI.getDefault().getImageRegistry().get( + CssUI.ICON_SHORTHAND); + Collection propertyNames = profile.getProperties(); + for (Iterator i = propertyNames.iterator(); i.hasNext(); ) { + String propertyName = (String) i.next(); + if (propertyName.startsWith(prefix)) { + Image icon = propertyIcon; + IPropertyInfo info = profile.getPropertyInfo(propertyName); + if (info.isShorthand()) { + icon = shorthandIcon; + } + ICompletionProposal proposal = new CompletionProposal( + propertyName, offset - prefix.length(), + prefix.length(), propertyName.length(), icon, + propertyName, null, info.getDescription()); + proposals.add(proposal); + } + } + } + return proposals; + } + + private List proposePseudoClasses(IDocument document, int offset, + String prefix) throws BadLocationException { + List proposals = new ArrayList(); + if (isSelector(document, offset - 1)) { + Image icon = CssUI.getDefault().getImageRegistry().get( + CssUI.ICON_PSEUDO_CLASS); + Collection pseudoClassNames = profile.getPseudoClassNames(); + for (Iterator i = pseudoClassNames.iterator(); i.hasNext(); ) { + String pseudoClassName = (String) i.next(); + if (pseudoClassName.startsWith(prefix)) { + ICompletionProposal proposal = new CompletionProposal( + pseudoClassName, offset - prefix.length(), + prefix.length(), pseudoClassName.length(), icon, + pseudoClassName, null, null); + proposals.add(proposal); + } + } + } + return proposals; + } + + private void sortProposals(List proposals) { + Collections.sort(proposals, new Comparator() { + public int compare(Object o1, Object o2) { + String s1 = ((ICompletionProposal) o1).getDisplayString(); + if (s1 == null) { + return -1; + } + String s2 = ((ICompletionProposal) o2).getDisplayString(); + return s1.compareToIgnoreCase(s2); + } + }); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssDoubleClickStrategy.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssDoubleClickStrategy.java new file mode 100644 index 0000000..2e45960 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssDoubleClickStrategy.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssDoubleClickStrategy.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import net.sourceforge.phpeclipse.css.core.internal.text.CssTextUtils; +import net.sourceforge.phpeclipse.css.ui.CssUI; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextDoubleClickStrategy; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.source.ICharacterPairMatcher; +import org.eclipse.jface.util.Assert; + +/** + * Strategy for selecting CSS identifiers on double click in the editor. + * + * This strategy implements selection of CSS identifiers on double click inside + * an identifier, as well as selection of blocks delimited by square brackets, + * curly braces and parenthesis when the user double clicks directly after + * either the opening or the closing delimiter. + */ +public class CssDoubleClickStrategy implements ITextDoubleClickStrategy { + + // Instance Variables ------------------------------------------------------ + + /** + * The pair matcher used to select ranges delimited by matching pairs of + * braces, brackets and parenthesis. + */ + private ICharacterPairMatcher pairMatcher = new CssPairMatcher(); + + // ITextDoubleClickStrategy Implementation --------------------------------- + + /* + * @see ITextDoubleClickStrategy#doubleClicked(ITextViewer) + */ + public void doubleClicked(ITextViewer viewer) { + IDocument document = viewer.getDocument(); + if (document.getLength() == 0) { + return; + } + int offset = viewer.getSelectedRange().x; + Assert.isLegal(offset >= 0, + "Double click offset may not be negative"); //$NON-NLS-1$ + Assert.isLegal(offset <= document.getLength(), + "Double click offset out of range"); //$NON-NLS-1$ + IRegion region = pairMatcher.match(document, offset); + if ((region != null) && (region.getLength() >= 2)) { + viewer.setSelectedRange(region.getOffset() + 1, + region.getLength() - 2); + } else { + try { + region = getSurroundingIdentifier(document, offset); + if (region != null) { + viewer.setSelectedRange( + region.getOffset(), region.getLength()); + } + } catch (BadLocationException e) { + CssUI.log("Failed to get surrounding " + //$NON-NLS-1$ + "word for double click selection"); //$NON-NLS-1$ + } + } + } + + // Private Methods --------------------------------------------------------- + + /** + * Returns the region that delimits the identifier surrounding the given + * offset into the document. If no identifier is found at the specified + * offset, this method returns null. + * + * @param doc the document + * @param offset the zero-based offset into the document + * @return the region covered by the identifier, or null if no + * identifier was found at that offset + */ + private IRegion getSurroundingIdentifier(IDocument doc, int offset) + throws BadLocationException { + IRegion retVal = null; + int length = doc.getLength(); + offset = Math.min(offset, length - 1); + if (CssTextUtils.isCssIdentifierPart(doc.getChar(offset))) { + int start = offset; + while (start > 0) { + if (!CssTextUtils.isCssIdentifierPart(doc.getChar(start - 1))) { + break; + } + start--; + } + int end = offset; + while (end < (length - 1)) { + if (!CssTextUtils.isCssIdentifierPart(doc.getChar(end + 1))) { + break; + } + end++; + } + retVal = new Region(start, end - start + 1); + } + return retVal; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssPairMatcher.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssPairMatcher.java new file mode 100644 index 0000000..b308117 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssPairMatcher.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssPairMatcher.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import net.sourceforge.phpeclipse.css.core.internal.text.CssTextUtils; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.source.ICharacterPairMatcher; +import org.eclipse.jface.util.Assert; + +/** + * + */ +public class CssPairMatcher implements ICharacterPairMatcher { + + // Constants --------------------------------------------------------------- + + private static final char PAIRS[] = { + '{', '}', '(', ')', '[', ']' + }; + + // Instance Variables ------------------------------------------------------ + + private IDocument document; + + private int offset; + + private int anchor; + + // ICharacterPairMatcher Implementation ------------------------------------ + + /* + * @see ICharacterPairMatcher#clear + */ + public void clear() { + document = null; + offset = -1; + anchor = 0; + } + + /* + * @see ICharacterPairMatcher#dispose + */ + public void dispose() { + document = null; + } + + /* + * @see ICharacterPairMatcher#match + */ + public IRegion match(IDocument document, int offset) { + Assert.isNotNull(document); + Assert.isLegal(offset >= 0); + this.document = document; + this.offset = offset; + + IRegion retVal = null; + try { + retVal = matchPairsAt(); + } catch (BadLocationException e) { + // ignore, there's probably no matching character to highlight + } + return retVal; + } + + /* + * @see ICharacterPairMatcher#getAnchor + */ + public int getAnchor() { + return anchor; + } + + // Private Methods --------------------------------------------------------- + + private boolean isClosingCharacter(char ch) { + for (int i = 1; i < PAIRS.length; i += 2) { + if (ch == PAIRS[i]) { + return true; + } + } + return false; + } + + private boolean isOpeningCharacter(char ch) { + for (int i = 0; i < PAIRS.length; i += 2) { + if (ch == PAIRS[i]) { + return true; + } + } + return false; + } + + private IRegion matchPairsAt() throws BadLocationException { + int startPos = -1, endPos = -1; + char prevChar = document.getChar(Math.max(offset - 1, 0)); + if (isOpeningCharacter(prevChar)) { + startPos = offset - 1; + if (startPos >= 0) { + anchor = LEFT; + endPos = CssTextUtils.findMatchingClosingPeer( + document, startPos + 1, prevChar); + if (endPos > -1) { + return new Region(startPos, endPos - startPos + 1); + } + } + } + if (isClosingCharacter(prevChar)) { + endPos = offset - 1; + if (endPos >= 0) { + anchor = RIGHT; + startPos = CssTextUtils.findMatchingOpeningPeer( + document, endPos - 1, prevChar); + if (startPos > -1) { + return new Region(startPos, endPos - startPos + 1); + } + } + } + return null; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssPartitionScanner.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssPartitionScanner.java new file mode 100644 index 0000000..751041b --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssPartitionScanner.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssPartitionScanner.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.text.rules.IPredicateRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.MultiLineRule; +import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; +import org.eclipse.jface.text.rules.SingleLineRule; +import org.eclipse.jface.text.rules.Token; + +/** + * + */ +public class CssPartitionScanner extends RuleBasedPartitionScanner { + + // Constants --------------------------------------------------------------- + + public static final String CSS_COMMENT = + "__css_comment_partition_content_type"; //$NON-NLS-1$ + + public static final String CSS_STRING = + "__css_string_partition_content_type"; //$NON-NLS-1$ + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + */ + public CssPartitionScanner() { + + IToken commentToken = new Token(CSS_COMMENT); + IToken stringToken = new Token(CSS_STRING); + + List rules = new ArrayList(); + + rules.add(new MultiLineRule( + "/*", "*/", commentToken)); //$NON-NLS-1$ //$NON-NLS-2$ + + // TODO Strings can be continued over a new line using the escape + // character (#42613) + rules.add(new SingleLineRule( + "\"", "\"", stringToken, '\\')); //$NON-NLS-1$ //$NON-NLS-2$ + rules.add(new SingleLineRule( + "'", "'", stringToken, '\\')); //$NON-NLS-1$ //$NON-NLS-2$ + + setPredicateRules((IPredicateRule[]) + rules.toArray(new IPredicateRule[rules.size()])); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssReconcileStep.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssReconcileStep.java new file mode 100644 index 0000000..d5cbc26 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssReconcileStep.java @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssReconcileStep.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.sourceforge.phpeclipse.css.core.model.IStyleSheet; +import net.sourceforge.phpeclipse.css.core.parser.IProblem; +import net.sourceforge.phpeclipse.css.core.parser.IProblemCollector; +import net.sourceforge.phpeclipse.css.core.parser.LexicalErrorException; +import net.sourceforge.phpeclipse.css.core.parser.SyntaxErrorException; +import net.sourceforge.phpeclipse.css.ui.internal.CssDocumentProvider; + +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.reconciler.AbstractReconcileStep; +import org.eclipse.jface.text.reconciler.DirtyRegion; +import org.eclipse.jface.text.reconciler.IReconcilableModel; +import org.eclipse.jface.text.reconciler.IReconcileResult; +import org.eclipse.jface.text.reconciler.IReconcileStep; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * Implementation of a reconcile step for building the CSS parse tree on changes + * to the editor content. + */ +public class CssReconcileStep extends AbstractReconcileStep { + + // Inner Classes ----------------------------------------------------------- + + /** + * Adapts an IStyleSheet to the IReconcilableModel + * interface. + */ + private class StyleSheetAdapter implements IReconcilableModel { + + private IStyleSheet styleSheet; + + public StyleSheetAdapter(IStyleSheet styleSheet) { + this.styleSheet = styleSheet; + } + + public IStyleSheet getStyleSheet() { + return styleSheet; + } + + } + + /** + * Implementation of the problem collector interface for creating problem + * annotations when there are problems parsing the style sheet. + */ + private class ProblemCollector implements IProblemCollector { + + /** + * The list of problems added to this collector. + */ + private List collectedProblems = new ArrayList(); + + /** + * @see IProblemCollector#addProblem(IProblem) + */ + public void addProblem(IProblem problem) { + collectedProblems.add(problem); + } + + /** + * Returns the list of problems collected while the CSS source has been + * parsed, in the order they were reported. The list returned is + * immutable. + * + * @return the list of collected problems (of type {@link IProblem}) + */ + public List getProblems() { + return Collections.unmodifiableList(collectedProblems); + } + + } + + /** + * Adapter that adapts an {@link IProblem} to an {@link Annotation}. + */ + private class ProblemAdapter extends AnnotationAdapter { + + private IProblem problem; + private Position position; + + ProblemAdapter(IProblem problem) { + this.problem = problem; + } + + public Position getPosition() { + if (position == null) { + position = createPositionFromProblem(); + } + return position; + } + + public Annotation createAnnotation() { + int start = problem.getSourceStart(); + if (start < 0) { + return null; + } + int length = problem.getSourceEnd() - problem.getSourceStart() + 1; + if (length < 0) { + return null; + } + String type = null; + if (problem.isWarning()) { + type = "org.eclipse.ui.workbench.texteditor.warning"; //$NON-NLS-1$ + } else if (problem.isError()) { + type = "org.eclipse.ui.workbench.texteditor.error"; //$NON-NLS-1$ + } + return new Annotation(type, false, problem.getMessage()); + } + + private Position createPositionFromProblem() { + int start = problem.getSourceStart(); + if (start < 0) { + return null; + } + int length = problem.getSourceEnd() - problem.getSourceStart() + 1; + if (length < 0) { + return null; + } + return new Position(start, length); + } + + } + + // Instance Variables ------------------------------------------------------ + + private ITextEditor editor; + + private StyleSheetAdapter styleSheetAdapter; + + // Constructors ------------------------------------------------------------ + + /** + * Default constructor. + */ + public CssReconcileStep(ITextEditor editor) { + this.editor = editor; + styleSheetAdapter = new StyleSheetAdapter(getStyleSheet()); + } + + /** + * Constructor. + * + * @param step the step to add to the pipe + * @param editor the associated text editor + */ + public CssReconcileStep(IReconcileStep step, ITextEditor editor) { + super(step); + this.editor = editor; + styleSheetAdapter = new StyleSheetAdapter(getStyleSheet()); + } + + // AbstractReconcileStep Implementation ------------------------------------ + + /* + * @see AbstractReconcileStep#reconcileModel(DirtyRegion, IRegion) + */ + protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, + IRegion subRegion) { + IStyleSheet styleSheet = styleSheetAdapter.getStyleSheet(); + ProblemCollector problemCollector = new ProblemCollector(); + try { + styleSheet.reconcile(problemCollector); + } catch (LexicalErrorException e) { + // Already reported to the problem collector + } catch (SyntaxErrorException e) { + // Already reported to the problem collector + } + List problems = problemCollector.getProblems(); + IReconcileResult[] retVal = new IReconcileResult[problems.size()]; + for (int i = 0; i < problems.size(); i++) { + IProblem problem = (IProblem) problems.get(i); + retVal[i] = new ProblemAdapter(problem); + } + return retVal; + } + + /* + * @see AbstractReconcileStep#getModel() + */ + public IReconcilableModel getModel() { + return styleSheetAdapter; + } + + // Private Methods Implementation ------------------------------------------ + + /** + * Retrieve the style sheet associated with the editor input. + */ + private IStyleSheet getStyleSheet() { + IDocumentProvider documentProvider = editor.getDocumentProvider(); + if (documentProvider instanceof CssDocumentProvider) { + CssDocumentProvider cssDocumentProvider = (CssDocumentProvider) + documentProvider; + return cssDocumentProvider.getStyleSheet(editor.getEditorInput()); + } + return null; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssReconcilingStrategy.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssReconcilingStrategy.java new file mode 100644 index 0000000..c1ab039 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssReconcilingStrategy.java @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssReconcilingStrategy.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import java.lang.reflect.InvocationTargetException; +import java.util.Iterator; + +import net.sourceforge.phpeclipse.css.ui.CssUI; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.reconciler.DirtyRegion; +import org.eclipse.jface.text.reconciler.IReconcileResult; +import org.eclipse.jface.text.reconciler.IReconcileStep; +import org.eclipse.jface.text.reconciler.IReconcilingStrategy; +import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.actions.WorkspaceModifyOperation; +import org.eclipse.ui.texteditor.ITextEditor; + + +/** + * Reconciling strategy for CSS style sheets. This class is responsible for + * keeping the parsed model in sync with the text. + */ +public class CssReconcilingStrategy + implements IReconcilingStrategy, IReconcilingStrategyExtension { + + // Instance Variables ------------------------------------------------------ + + /** + * The associated text editor. + */ + private ITextEditor editor; + + /** + * A progress monitor that should be used for long-running operations. + */ + IProgressMonitor progressMonitor; + + /** + * The first (and only) reconcile step is the parsing of the style sheet. + */ + private IReconcileStep firstStep; + + // Constructors ------------------------------------------------------------ + + public CssReconcilingStrategy(ITextEditor editor) { + this.editor = editor; + firstStep = new CssReconcileStep(editor); + } + + // IReconcilingStrategy Implementation ------------------------------------- + + /** + * @see IReconcilingStrategy#reconcile(DirtyRegion, IRegion) + */ + public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { + removeTemporaryAnnotations(); + process(firstStep.reconcile(dirtyRegion, subRegion)); + } + + /** + * @see IReconcilingStrategy#reconcile(IRegion) + */ + public void reconcile(IRegion partition) { + removeTemporaryAnnotations(); + process(firstStep.reconcile(partition)); + } + + /** + * @see IReconcilingStrategy#setDocument(IDocument) + */ + public void setDocument(IDocument document) { + // FIXME + firstStep.setInputModel(null); //new DocumentAdapter(document); + } + + // IReconcilingStrategyExtension Implementation ---------------------------- + + /** + * @see IReconcilingStrategyExtension#initialReconcile() + */ + public void initialReconcile() { + process(firstStep.reconcile(null)); + } + + /** + * @see IReconcilingStrategyExtension#setProgressMonitor(IProgressMonitor) + */ + public void setProgressMonitor(IProgressMonitor monitor) { + firstStep.setProgressMonitor(monitor); + progressMonitor = monitor; + } + + // Private Methods --------------------------------------------------------- + + /** + * Returns the annotation model for the editor input. + * + * @return the annotation model + */ + IAnnotationModel getAnnotationModel() { + IEditorInput input = editor.getEditorInput(); + return editor.getDocumentProvider().getAnnotationModel(input); + } + + /** + * Adds results of the reconcilation to the annotation model. + */ + private void process(final IReconcileResult[] results) { + if (results == null) { + return; + } + + IRunnableWithProgress runnable = new WorkspaceModifyOperation() { + protected void execute(IProgressMonitor monitor) { + for (int i = 0; i < results.length; i++) { + if ((progressMonitor != null) + && (progressMonitor.isCanceled())) { + return; + } + + if (!(results[i] instanceof AnnotationAdapter)) { + continue; + } + + AnnotationAdapter result = (AnnotationAdapter) results[i]; + Position pos = result.getPosition(); + Annotation annotation = result.createAnnotation(); + getAnnotationModel().addAnnotation(annotation, pos); + } + } + }; + + try { + runnable.run(null); + } catch (InvocationTargetException e) { + CssUI.log(e); + } catch (InterruptedException e) { + CssUI.log(e); + } + + if (editor instanceof IReconcilingParticipant) { + ((IReconcilingParticipant) editor).reconciled(); + } + } + + /* + * TODO A "real" implementation must be smarter, i.e. don't remove and add + * the annotations which are the same. + */ + private void removeTemporaryAnnotations() { + Iterator i = getAnnotationModel().getAnnotationIterator(); + while (i.hasNext()) { + Annotation annotation = (Annotation) i.next(); + if (!annotation.isPersistent()) { + getAnnotationModel().removeAnnotation(annotation); + } + } + } +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssSourceViewerConfiguration.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssSourceViewerConfiguration.java new file mode 100644 index 0000000..534f8f1 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssSourceViewerConfiguration.java @@ -0,0 +1,369 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssSourceViewerConfiguration.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.phpeclipse.css.core.CssCore; +import net.sourceforge.phpeclipse.css.core.profiles.IProfile; +import net.sourceforge.phpeclipse.css.core.profiles.IProfileManager; +import net.sourceforge.phpeclipse.css.ui.CssUI; +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; +import net.sourceforge.phpeclipse.css.ui.text.CssTextTools; +import net.sourceforge.phpeclipse.css.ui.text.IColorManager; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.text.DefaultAutoIndentStrategy; +import org.eclipse.jface.text.DefaultTextDoubleClickStrategy; +import org.eclipse.jface.text.IAutoIndentStrategy; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextDoubleClickStrategy; +import org.eclipse.jface.text.ITextHover; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.IContentAssistant; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.reconciler.IReconciler; +import org.eclipse.jface.text.reconciler.MonoReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.source.IAnnotationHover; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * Source viewer configuration for CSS. This class takes care of setting up + * various aspects of the CSS editor, such as text hovers, syntax highlighting, + * reconciling or the double click strategy. + */ +public final class CssSourceViewerConfiguration + extends TextSourceViewerConfiguration { + + // Constants --------------------------------------------------------------- + + /** + * Alias for the preference constant CONTENTASSIST_AUTOINSERT. + */ + private static final String AUTOINSERT = + CssUIPreferences.CONTENTASSIST_AUTOINSERT; + + /** + * Alias for the preference constant + * CONTENTASSIST_AUTOACTIVATION. + */ + private static final String AUTOACTIVATION = + CssUIPreferences.CONTENTASSIST_AUTOACTIVATION; + + /** + * Alias for the preference constant + * CONTENTASSIST_AUTOACTIVATION_DELAY. + */ + private static final String AUTOACTIVATION_DELAY = + CssUIPreferences.CONTENTASSIST_AUTOACTIVATION_DELAY; + + /** + * Alias for the preference constant + * CONTENTASSIST_PROPOSALS_BACKGROUND. + */ + private static final String PROPOSALS_BACKGROUND = + CssUIPreferences.CONTENTASSIST_PROPOSALS_BACKGROUND; + + /** + * Alias for the preference constant + * CONTENTASSIST_PROPOSALS_FOREGROUND. + */ + private static final String PROPOSALS_FOREGROUND = + CssUIPreferences.CONTENTASSIST_PROPOSALS_FOREGROUND; + + /** + * Alias for the preference constant EDITOR_SPACES_FOR_TABS. + */ + private static final String SPACES_FOR_TABS = + CssUIPreferences.EDITOR_SPACES_FOR_TABS; + + // Instance Variables ------------------------------------------------------ + + /** + * The associated editor. + */ + private ITextEditor editor; + + /** + * The preference store used. + */ + private IPreferenceStore store; + + /** + * The CSS profile. + */ + private IProfile profile; + + /** + * The associated text tools. + */ + private CssTextTools textTools; + + // Constructors ------------------------------------------------------------ + + /** + * Default constructor. + */ + public CssSourceViewerConfiguration() { + this(CssUI.getDefault().getTextTools()); + } + + /** + * Constructor. + * + * @param textTools the CSS text tools to associate with the source viewer + * configuration + */ + public CssSourceViewerConfiguration(CssTextTools textTools) { + this(textTools, CssUI.getDefault().getPreferenceStore()); + } + + /** + * Constructor. + * + * @param textTools the CSS text tools to associate with the source viewer + * configuration + * @param store the preference store + */ + public CssSourceViewerConfiguration( + CssTextTools textTools, IPreferenceStore store + ) { + this(textTools, store, null); + } + + /** + * Constructor. + * + * @param textTools the CSS text tools to associate with the source viewer + * configuration + * @param store the preference store + * @param editor the text editor + */ + public CssSourceViewerConfiguration( + CssTextTools textTools, IPreferenceStore store, ITextEditor editor + ) { + this.textTools = textTools; + this.store = store; + this.editor = editor; + } + + // SourceViewerConfiguration Implementation -------------------------------- + + /* + * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer) + */ + public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { + return new CssAnnotationHover(); + } + + /* + * @see SourceViewerConfiguration#getAutoIndentStrategy(ISourceViewer, String) + */ + public IAutoIndentStrategy getAutoIndentStrategy( + ISourceViewer sourceViewer, String contentType + ) { + if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) { + return new CssAutoEditStrategy(); + } + + return new DefaultAutoIndentStrategy(); + } + + /* + * @see SourceViewerConfiguration#getConfiguredContentTypes(ISourceViewer) + */ + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { + return new String[] { + IDocument.DEFAULT_CONTENT_TYPE, + CssPartitionScanner.CSS_COMMENT, + CssPartitionScanner.CSS_STRING + }; + } + + /* + * @see SourceViewerConfiguration#getContentAssistant(ISourceViewer) + */ + public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { + ContentAssistant assistant = new ContentAssistant(); + assistant.setContentAssistProcessor( + new CssContentAssistProcessor(store, getProfile(), editor), + IDocument.DEFAULT_CONTENT_TYPE); + assistant.setInformationControlCreator( + getInformationControlCreator(sourceViewer)); + assistant.enableAutoInsert(store.getBoolean(AUTOINSERT)); + assistant.enableAutoActivation(store.getBoolean(AUTOACTIVATION)); + assistant.setAutoActivationDelay(store.getInt(AUTOACTIVATION_DELAY)); + assistant.setContextInformationPopupOrientation( + IContentAssistant.CONTEXT_INFO_BELOW); + assistant.setProposalPopupOrientation( + IContentAssistant.PROPOSAL_STACKED); + assistant.setProposalSelectorBackground(getColorManager().getColor( + PreferenceConverter.getColor(store, PROPOSALS_BACKGROUND))); + assistant.setProposalSelectorForeground(getColorManager().getColor( + PreferenceConverter.getColor(store, PROPOSALS_FOREGROUND))); + return assistant; + } + + /* + * @see SourceViewerConfiguration#getDoubleClickStrategy(ISourceViewer, String) + */ + public ITextDoubleClickStrategy getDoubleClickStrategy( + ISourceViewer sourceViewer, String contentType + ) { + if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) { + return new CssDoubleClickStrategy(); + } + return new DefaultTextDoubleClickStrategy(); + } + + /* + * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String) + */ + public String[] getIndentPrefixes( + ISourceViewer sourceViewer, String contentType + ) { + List retVal = new ArrayList(); + int tabWidth = getTabWidth(sourceViewer); + boolean useSpaces = store.getBoolean(SPACES_FOR_TABS); + for (int i = 0; i <= tabWidth; i++) { + StringBuffer prefix = new StringBuffer(); + if (useSpaces) { + for (int j = 0; j < tabWidth - i; j++) { + prefix.append(' '); + } + if (i > 0) { + prefix.append('\t'); + } + } else { + for (int j = 0; j < i; j++) { + prefix.append(' '); + } + if (i < tabWidth) { + prefix.append('\t'); + } + } + retVal.add(prefix.toString()); + } + retVal.add(""); //$NON-NLS-1$ + return (String[]) retVal.toArray(new String[retVal.size()]); + } + + /* + * @see SourceViewerConfiguration#getPresentationReconciler(ISourceViewer) + */ + public IPresentationReconciler getPresentationReconciler( + ISourceViewer sourceViewer + ) { + PresentationReconciler reconciler = new PresentationReconciler(); + DefaultDamagerRepairer dr; + + // Comments + dr = new DefaultDamagerRepairer(textTools.getCommentScanner()); + reconciler.setDamager(dr, CssPartitionScanner.CSS_COMMENT); + reconciler.setRepairer(dr, CssPartitionScanner.CSS_COMMENT); + + // Strings + dr = new DefaultDamagerRepairer(textTools.getStringScanner()); + reconciler.setDamager(dr, CssPartitionScanner.CSS_STRING); + reconciler.setRepairer(dr, CssPartitionScanner.CSS_STRING); + + // Code + dr = new DefaultDamagerRepairer(textTools.getCodeScanner(getProfile())); + reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + + return reconciler; + } + + /* + * @see SourceViewerConfiguration#getReconciler(ISourceViewer) + */ + public IReconciler getReconciler(ISourceViewer sourceViewer) { + if ((editor != null) && editor.isEditable()) { + MonoReconciler reconciler = new MonoReconciler( + new CssReconcilingStrategy(editor), false); + reconciler.setProgressMonitor(new NullProgressMonitor()); + reconciler.setDelay(500); + return reconciler; + } + + return null; + } + + /* + * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String) + */ + public ITextHover getTextHover( + ISourceViewer sourceViewer, String contentType + ) { + if (editor != null) { + IDocumentProvider provider = editor.getDocumentProvider(); + IEditorInput input = editor.getEditorInput(); + IAnnotationModel model = provider.getAnnotationModel(input); + return new CssTextHover(model); + } + + return super.getTextHover(sourceViewer, contentType); + } + + // Private Methods --------------------------------------------------------- + + /** + * Returns the color manager associated with this configuration. + * + * @return the color manager + */ + private IColorManager getColorManager() { + if (textTools != null) { + return textTools.getColorManager(); + } + return null; + } + + /** + * Returns the CSS profile for the resource currently being viewed, or + * the default profile if this source viewer configuration isn't associated + * with an editor. + * + * @return the profile + */ + private IProfile getProfile() { + if (profile == null) { + IResource resource = null; + if (editor != null) { + IEditorInput input = editor.getEditorInput(); + if (input instanceof IFileEditorInput) { + resource = ((IFileEditorInput) input).getFile(); + } + } + + IProfileManager mgr = CssCore.getDefault().getProfileManager(); + profile = mgr.getProfile(resource); + } + + return profile; + } +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssStringScanner.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssStringScanner.java new file mode 100644 index 0000000..3c66241 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssStringScanner.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssStringScanner.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; +import net.sourceforge.phpeclipse.css.ui.text.IColorManager; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.rules.IToken; + +/** + * + */ +public class CssStringScanner extends AbstractCssScanner { + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param store The preference store + */ + public CssStringScanner(IPreferenceStore store, IColorManager manager) { + super(store, manager); + + IToken stringToken = createToken( + CssUIPreferences.EDITOR_STRING_COLOR, + CssUIPreferences.EDITOR_STRING_BOLD); + + setDefaultReturnToken(stringToken); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssTextHover.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssTextHover.java new file mode 100644 index 0000000..7c52cfd --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssTextHover.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssTextHover.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import java.util.Iterator; + +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextHover; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.IAnnotationModel; + + +/** + * Implements simple annotation hover to show the associated messages. + */ +public class CssTextHover implements ITextHover { + /** + * This hovers annotation model. + */ + private IAnnotationModel model; + + /** + * Creates a new annotation hover. + * + * @param model this hover's annotation model + */ + public CssTextHover(IAnnotationModel model) { + this.model = model; + } + + /* + * @see ITextHover#getHoverInfo(ITextViewer, IRegion) + */ + public String getHoverInfo(ITextViewer textViewer, IRegion region) { + Iterator e = model.getAnnotationIterator(); + while (e.hasNext()) { + Annotation a = (Annotation) e.next(); + Position p = model.getPosition(a); + if (p.overlapsWith(region.getOffset(), region.getLength())) { + String text = a.getText(); + if ((text != null) && (text.trim().length() > 0)) { + return text; + } + } + } + + return null; + } + + /* + * @see ITextHover#getHoverRegion(ITextViewer, int) + */ + public IRegion getHoverRegion(ITextViewer textViewer, int offset) { + return CssWordFinder.findWord(textViewer.getDocument(), offset); + } +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssWordFinder.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssWordFinder.java new file mode 100644 index 0000000..ca30fd0 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssWordFinder.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Widespace, OU and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Igor Malinin - initial implementation + * + * $Id: CssWordFinder.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Region; + + +/** + * + * + * @author Igor Malinin + */ +public class CssWordFinder { + public static IRegion findWord(IDocument document, int offset) { + int length = document.getLength(); + + try { + int pos = offset; + + while (pos >= 0) { + if (!Character.isUnicodeIdentifierPart(document.getChar(pos))) { + break; + } + --pos; + } + + int start = pos; + + pos = offset; + + while (pos < length) { + if (!Character.isUnicodeIdentifierPart(document.getChar(pos))) { + break; + } + ++pos; + } + + int end = pos; + + if (start == offset) { + return new Region(start, end - start); + } + + return new Region(start + 1, end - start - 1); + } catch (BadLocationException x) { + return null; + } + } +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/IReconcilingParticipant.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/IReconcilingParticipant.java new file mode 100644 index 0000000..db1649e --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/IReconcilingParticipant.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API + * + * $Id: IReconcilingParticipant.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.internal.text; + +/** + * Interface for classes participating in reconciling. + */ +public interface IReconcilingParticipant { + + /** + * Called after reconciling has been finished. + */ + void reconciled(); + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/text/CssTextTools.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/text/CssTextTools.java new file mode 100644 index 0000000..34448bd --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/text/CssTextTools.java @@ -0,0 +1,300 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: CssTextTools.java,v 1.1 2004-09-02 18:11:51 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.text; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import net.sourceforge.phpeclipse.css.core.CssCore; +import net.sourceforge.phpeclipse.css.core.profiles.IProfile; +import net.sourceforge.phpeclipse.css.ui.internal.text.CssCodeScanner; +import net.sourceforge.phpeclipse.css.ui.internal.text.CssColorManager; +import net.sourceforge.phpeclipse.css.ui.internal.text.CssCommentScanner; +import net.sourceforge.phpeclipse.css.ui.internal.text.CssPartitionScanner; +import net.sourceforge.phpeclipse.css.ui.internal.text.CssStringScanner; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentExtension3; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.text.rules.DefaultPartitioner; +import org.eclipse.jface.text.rules.IPartitionTokenScanner; +import org.eclipse.jface.text.rules.RuleBasedScanner; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; + +/** + * Tools required to configure a CSS text viewer. + * + *

+ * The color manager and all scanners exist only one time, i.e. the same + * instances are returned to all clients. Thus, clients share those tools. + *

+ */ +public class CssTextTools { + + // Instance Variables ------------------------------------------------------ + + /** + * The preference store to use. + */ + private IPreferenceStore store; + + /** + * Listener for changes to the preference store. + */ + private IPropertyChangeListener propertyChangeListener = + new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + adaptToPreferenceChange(event); + } + }; + + /** + * The color manager. + */ + private IColorManager colorManager; + + /** + * The partition scanner. + */ + private CssPartitionScanner partitionScanner; + + /** + * Map of the code scanners, keyed by profile ID. + */ + private Map codeScanners = new HashMap(); + + /** + * The token scanner for syntax highlighting comments in CSS source. + */ + private CssCommentScanner commentScanner; + + /** + * The token scanner for syntax highlighting string literals in CSS source. + */ + private CssStringScanner stringScanner; + + // Constructors ------------------------------------------------------------ + + /** + * Creates a new CSS text tools collection. + * + * @param store the preference store to initialize the text tools. The text + * tools instance installs a listener on the passed preference store + * to adapt itself to changes in the preference store. + */ + public CssTextTools(IPreferenceStore store) { + this(store, true); + } + + /** + * Creates a new CSS text tools collection. + * + * @param store the preference store to initialize the text tools. The text + * tool instance installs a listener on the passed preference store + * to adapt itself to changes in the preference store. + * @param autoDisposeOnDisplayDispose if true the color + * manager automatically disposes all managed colors when the current + * display gets disposed and all calls to + * {@link org.eclipse.jface.text.source.ISharedTextColors#dispose()} + * are ignored. + */ + public CssTextTools(IPreferenceStore store, + boolean autoDisposeOnDisplayDispose) { + store.addPropertyChangeListener(propertyChangeListener); + this.store = store; + + colorManager = new CssColorManager(autoDisposeOnDisplayDispose); + partitionScanner = new CssPartitionScanner(); + commentScanner = new CssCommentScanner(store, colorManager); + stringScanner = new CssStringScanner(store, colorManager); + } + + // Public Methods ---------------------------------------------------------- + + /** + * Returns whether the specified change to the preference store would effect + * the presentation of CSS text. + * + * @param event the preference store change event + * @return true if the specified event affects the presentation + * of CSS text, false otherwise + */ + public boolean affectsPresentation(PropertyChangeEvent event) { + for (Iterator i = codeScanners.keySet().iterator(); i.hasNext();) { + CssCodeScanner scanner = (CssCodeScanner) + codeScanners.get(i.next()); + if (scanner.affectsPresentation(event)) { + return true; + } + } + if (commentScanner.affectsPresentation(event) + || stringScanner.affectsPresentation(event)) { + return true; + } + return false; + } + + /** + * Factory method for creating a Java-specific document partitioner + * using this object's partitions scanner. This method is a + * convenience method. + * + * @return a newly created Java document partitioner + */ + public IDocumentPartitioner createDocumentPartitioner() { + String[] types = new String[] { + CssPartitionScanner.CSS_COMMENT, + CssPartitionScanner.CSS_STRING + }; + return new DefaultPartitioner(getPartitionScanner(), types); + } + + /** + * Disposes all the individual tools of this tools collection. + */ + public void dispose() { + + // dispose the scanners + codeScanners.clear(); + commentScanner = null; + stringScanner = null; + partitionScanner = null; + + // dispose the color manager + if (colorManager != null) { + colorManager.dispose(); + colorManager = null; + } + + // detach from the preference store + if (store != null) { + store.removePropertyChangeListener(propertyChangeListener); + propertyChangeListener = null; + store = null; + } + } + + /** + * Returns the color manager which is used to manage + * any Java-specific colors needed for such things like syntax highlighting. + * + * @return the color manager to be used for Java text viewers + */ + public IColorManager getColorManager() { + return colorManager; + } + + /** + * Returns a scanner which is configured to scan CSS source code. + * + * @param profile the profile for which to retrieve the code scanner + * @return a CSS source code scanner + */ + public RuleBasedScanner getCodeScanner(IProfile profile) { + if (profile == null) { + // use the default profile + profile = CssCore.getDefault().getProfileManager().getProfile(null); + } + String profileId = profile.getDescriptor().getId(); + RuleBasedScanner codeScanner = (RuleBasedScanner) + codeScanners.get(profileId); + if (codeScanner == null) { + codeScanner = new CssCodeScanner(store, this.colorManager, profile); + codeScanners.put(profileId, codeScanner); + } + return codeScanner; + } + + /** + * Returns a scanner which is configured to scan CSS comments. + * + * @return a CSS comment scanner + */ + public RuleBasedScanner getCommentScanner() { + return commentScanner; + } + + /** + * Returns a scanner which is configured to scan CSS strings. + * + * @return a CSS string scanner + */ + public RuleBasedScanner getStringScanner() { + return stringScanner; + } + + /** + * Returns a scanner which is configured to scan CSS-specific partitions, + * which are comments, strings and regular code. + * + * @return a CSS partition scanner + */ + public IPartitionTokenScanner getPartitionScanner() { + return partitionScanner; + } + + /** + * Sets up the given document for the default partitioning. + * + * @param document the document to be set up + */ + public void setupDocument(IDocument document) { + setupDocument(document, IDocumentExtension3.DEFAULT_PARTITIONING); + } + + /** + * Sets up the given document for the given partitioning. + * + * @param document the document to be set up + * @param partitioning the document partitioning + */ + public void setupDocument(IDocument document, String partitioning) { + IDocumentPartitioner partitioner = createDocumentPartitioner(); + if (document instanceof IDocumentExtension3) { + IDocumentExtension3 extension = (IDocumentExtension3) document; + extension.setDocumentPartitioner(partitioning, partitioner); + } else { + document.setDocumentPartitioner(partitioner); + } + partitioner.connect(document); + } + + // Protected Methods ------------------------------------------------------- + + /** + * Adapts the behavior of the contained components to the change according + * to the given event. + * + * @param event the event to which to adapt + */ + protected void adaptToPreferenceChange(PropertyChangeEvent event) { + for (Iterator i = codeScanners.keySet().iterator(); i.hasNext();) { + CssCodeScanner scanner = (CssCodeScanner) + codeScanners.get(i.next()); + if (scanner.affectsPresentation(event)) { + scanner.adaptToPreferenceChange(event); + } + } + if (commentScanner.affectsPresentation(event)) { + commentScanner.adaptToPreferenceChange(event); + } + if (stringScanner.affectsPresentation(event)) { + stringScanner.adaptToPreferenceChange(event); + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/text/IColorManager.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/text/IColorManager.java new file mode 100644 index 0000000..253d0ca --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/text/IColorManager.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: IColorManager.java,v 1.1 2004-09-02 18:11:51 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.css.ui.text; + +import org.eclipse.jface.text.source.ISharedTextColors; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; + +/** + * Extends the ISharedTextColors interface by providing methods + * to bind and unbind colors to specific keys, and retrieve the colors by key. + * + * TODO Find out whether this can be replaced with the JFace ColorRegistry + */ +public interface IColorManager extends ISharedTextColors { + + /** + * Binds a color to the specified key. + * + * @param key the key to which the color should be bound + * @param rgb the color to bind to the key + */ + void bindColor(String key, RGB rgb); + + /** + * Returns the color bound to a specific key. + * + * @param key the key to which the color was previously bound + * @return the color bound to the specified key, or null if no + * color was bound to that key + */ + Color getColor(String key); + + /** + * Unbinds (and disposes) a color. + * + * @param key the key to which the color was previously bound + */ + void unbindColor(String key); + +} diff --git a/archive/net.sourceforge.phpeclipse.html.ui/.classpath b/archive/net.sourceforge.phpeclipse.html.ui/.classpath new file mode 100644 index 0000000..065ac06 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.html.ui/.cvsignore b/archive/net.sourceforge.phpeclipse.html.ui/.cvsignore new file mode 100644 index 0000000..ba077a4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/archive/net.sourceforge.phpeclipse.html.ui/.project b/archive/net.sourceforge.phpeclipse.html.ui/.project new file mode 100644 index 0000000..4c6b7dc --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/.project @@ -0,0 +1,31 @@ + + + net.sourceforge.phpeclipse.html.ui + + + net.sf.wdte.ui + net.sf.wdte.xml.core + net.sf.wdte.xml.ui + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/archive/net.sourceforge.phpeclipse.html.ui/build.properties b/archive/net.sourceforge.phpeclipse.html.ui/build.properties new file mode 100644 index 0000000..d13b964 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/build.properties @@ -0,0 +1,4 @@ +source.htmlui.jar = src/ +output.htmlui.jar = bin/ +bin.includes = plugin.xml,\ + htmlui.jar diff --git a/archive/net.sourceforge.phpeclipse.html.ui/icons/full/obj16/html.png b/archive/net.sourceforge.phpeclipse.html.ui/icons/full/obj16/html.png new file mode 100644 index 0000000000000000000000000000000000000000..178c94790969a683a540ced72f38b127a5397563 GIT binary patch literal 256 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFv4DbnY{r~@eLqo&=`}2W}`1tt! z`~NdA>}O_!@hljQC0!qCAg>jC6&7I;J! zGca%qfiUBxyLEqng6t)pzOL+-nFT~l^|bhPcLRkYJY5_^D&{07G%&k4Iyy2MIN!Vx z!E(mH%uKAP!N@1Zq31!+F)F?POi6@CtNvD r+IYrr9#hg9rY2Q|Hf|0D8Ab+qEy?P_9UDS`b})Fl`njxgN@xNA^r=+u literal 0 HcmV?d00001 diff --git a/archive/net.sourceforge.phpeclipse.html.ui/plugin.xml b/archive/net.sourceforge.phpeclipse.html.ui/plugin.xml new file mode 100644 index 0000000..277ae4f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/plugin.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/HTMLUI.java b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/HTMLUI.java new file mode 100644 index 0000000..06576ad --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/HTMLUI.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: HTMLUI.java,v 1.1 2004-09-02 18:13:31 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.html.ui; + +import org.eclipse.ui.plugin.AbstractUIPlugin; + +/** + * The main plugin class to be used in the desktop. + */ +public class HTMLUI extends AbstractUIPlugin { + + // Class Variables --------------------------------------------------------- + + /** The shared instance. */ + private static HTMLUI plugin; + + // Constructors ------------------------------------------------------------ + + /** + * The constructor. + */ + public HTMLUI() { + plugin = this; + } + + // Public Methods ---------------------------------------------------------- + + /** + * Returns the shared instance. + */ + public static HTMLUI getDefault() { + return plugin; + } +} diff --git a/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/HTMLUIMessages.java b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/HTMLUIMessages.java new file mode 100644 index 0000000..e777371 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/HTMLUIMessages.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: HTMLUIMessages.java,v 1.1 2004-09-02 18:13:32 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.html.ui.internal; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * Utility class that provides easy access to externalized strings. + */ +public final class HTMLUIMessages { + + // Constants --------------------------------------------------------------- + + /** + * Qualified name of the resource bundle containing the localized messages. + */ + private static final String RESOURCE_BUNDLE = + "net.sourceforge.phpeclipse.html.ui.internal.HTMLUIMessages"; //$NON-NLS-1$ + + // Class Variables --------------------------------------------------------- + + /** + * The resource bundle. + */ + private static ResourceBundle resourceBundle = + ResourceBundle.getBundle(RESOURCE_BUNDLE); + + // Constructors ------------------------------------------------------------ + + /** + * Hidden constructor. + */ + private HTMLUIMessages() { + // Hidden + } + + // Public Methods ---------------------------------------------------------- + + /** + * Returns the resource bundle. + * + * @return the resource bundle + */ + public static ResourceBundle getResourceBundle() { + return resourceBundle; + } + + /** + * Returns the message identified by the specified key. + * + * @param key the message key + * @return the localized message, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key) { + try { + return resourceBundle.getString(key); + } catch (MissingResourceException e) { + return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$ + } + } + + /** + * Returns the message identified by the specified key, replacing a single + * parameter with the provided value. + * + * @param key the message key + * @param arg the parameter value + * @return the formatted string, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key, String arg) { + return getString(key, new String[] { arg }); + } + + /** + * Returns the message identified by the specified key, replacing all + * parameters with the provided values. + * + * @param key the message key + * @param args the parameter values + * @return the formatted string, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key, String[] args) { + return MessageFormat.format(getString(key), args); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/HTMLUIMessages.properties b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/HTMLUIMessages.properties new file mode 100644 index 0000000..9cb2a3c --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/HTMLUIMessages.properties @@ -0,0 +1,12 @@ +# +# Copyright (c) 2004 Christopher Lenz and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Common Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/cpl-v10.html +# +# Contributors: +# Christopher Lenz - initial english resources +# +# $Id: HTMLUIMessages.properties,v 1.1 2004-09-02 18:13:32 jsurfer Exp $ +# diff --git a/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLDocumentProvider.java b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLDocumentProvider.java new file mode 100644 index 0000000..fdbb818 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLDocumentProvider.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: HTMLDocumentProvider.java,v 1.1 2004-09-02 18:13:32 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.html.ui.internal.editor; + +import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLDocumentProvider; + +/** + * Document provider for HTML files. + */ +public class HTMLDocumentProvider extends XMLDocumentProvider { + +} diff --git a/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLDocumentSetupParticipant.java b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLDocumentSetupParticipant.java new file mode 100644 index 0000000..92f2aed --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLDocumentSetupParticipant.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial implementation + * + * $Id: HTMLDocumentSetupParticipant.java,v 1.1 2004-09-02 18:13:32 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.html.ui.internal.editor; + +import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLDocumentSetupParticipant; + +/** + * Document setup participant that sets up the HTML specific partitioning. + */ +public class HTMLDocumentSetupParticipant extends XMLDocumentSetupParticipant { + +} diff --git a/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditor.java b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditor.java new file mode 100644 index 0000000..4ccff01 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditor.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial implementation + * + * $Id: HTMLEditor.java,v 1.1 2004-09-02 18:13:32 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.html.ui.internal.editor; + +import java.net.MalformedURLException; +import java.net.URL; + +import net.sourceforge.phpeclipse.html.ui.internal.preview.HTMLPreviewPage; +import net.sourceforge.phpeclipse.html.ui.internal.text.HTMLConfiguration; +import net.sourceforge.phpeclipse.ui.views.preview.IBrowserPreviewPage; +import net.sourceforge.phpeclipse.xml.ui.XMLPlugin; +import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLDocumentProvider; +import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLEditor; +import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools; + +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.action.IAction; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.texteditor.ContentAssistAction; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; + + +/** + * HTML editor implementation. + */ +public class HTMLEditor extends XMLEditor { + + // Instance Variables ------------------------------------------------------ + + /** The associated preview page. */ + private HTMLPreviewPage previewPage; + + // XMLEditor Implementation ------------------------------------------------ + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#editorSaved() + */ + protected void editorSaved() { + if (previewPage != null) { + previewPage.update(); + } + } + + /* + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) + */ + public Object getAdapter(Class adapter) { + if (adapter == IBrowserPreviewPage.class) { + if (previewPage == null) { + previewPage = createPreviewPage(); + } + return previewPage; + } + return super.getAdapter(adapter); + } + + // Private Methods --------------------------------------------------------- + + /** + * Creates the HTML preview page. + */ + private HTMLPreviewPage createPreviewPage() { + IEditorInput input = getEditorInput(); + if (input instanceof IFileEditorInput) { + IFile file = ((IFileEditorInput) input).getFile(); + try { + URL location = file.getLocation().toFile().toURL(); + return new HTMLPreviewPage(location); + } catch (MalformedURLException e) { } + } + return null; + } + protected void createActions() { + super.createActions(); + + IAction action = new ContentAssistAction(HTMLEditorMessages.getResourceBundle(), + "ContentAssistProposal.", this); //$NON-NLS-1$ + action + .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + setAction("ContentAssistProposal", action); //$NON-NLS-1$ + markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$ + +// IAction action= new TextOperationAction( +// TemplateMessages.getResourceBundle(), +// "Editor." + TEMPLATE_PROPOSALS + ".", //$NON-NLS-1$ //$NON-NLS-2$ +// this, +// ISourceViewer.CONTENTASSIST_PROPOSALS); +// action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); +// setAction(TEMPLATE_PROPOSALS, action); +// markAsStateDependentAction(TEMPLATE_PROPOSALS, true); + } + /* + * @see org.eclipse.ui.editors.text.TextEditor#initializeEditor() + */ + protected void initializeEditor() { + super.initializeEditor(); + + XMLTextTools xmlTextTools = XMLPlugin.getDefault().getXMLTextTools(); + setSourceViewerConfiguration(new HTMLConfiguration(xmlTextTools, this)); + setDocumentProvider(new XMLDocumentProvider()); + } +} diff --git a/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditorMessages.java b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditorMessages.java new file mode 100644 index 0000000..94c3dd0 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditorMessages.java @@ -0,0 +1,45 @@ +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation + Klaus Hartlage - www.eclipseproject.de +**********************************************************************/ +package net.sourceforge.phpeclipse.html.ui.internal.editor; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class HTMLEditorMessages { + + private static final String RESOURCE_BUNDLE= "net.sourceforge.phpeclipse.html.ui.internal.editor.HTMLEditorMessages";//$NON-NLS-1$ + + private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); + + private HTMLEditorMessages() { + } + + public static String getString(String key) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ + } + } + + /** + * Gets a string from the resource bundle and formats it with arguments + */ + public static String getFormattedString(String key, Object[] args) { + return MessageFormat.format(getString(key), args); + } + + public static ResourceBundle getResourceBundle() { + return fgResourceBundle; + } +} diff --git a/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditorMessages.properties b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditorMessages.properties new file mode 100644 index 0000000..bea66ef --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/editor/HTMLEditorMessages.properties @@ -0,0 +1,10 @@ +############################################################# +# +# (c) Copyright IBM Corp. 2000, 2001. +# All Rights Reserved. +# +############################################################# +ContentAssistProposal.label=Content Assist@Ctrl+SPACE +ContentAssistProposal.tooltip=Content Assist +ContentAssistProposal.image= +ContentAssistProposal.description=Content Assist diff --git a/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/preview/HTMLPreviewPage.java b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/preview/HTMLPreviewPage.java new file mode 100644 index 0000000..3608a09 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/preview/HTMLPreviewPage.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial implementation + * + * $Id: HTMLPreviewPage.java,v 1.1 2004-09-02 18:13:31 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.html.ui.internal.preview; + +import java.net.URL; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.browser.LocationAdapter; +import org.eclipse.swt.browser.LocationEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.part.Page; +import org.eclipse.ui.texteditor.IUpdate; + +import net.sourceforge.phpeclipse.ui.views.preview.IBrowserPreviewPage; + +/** + * Provides a HTML preview page based on the SWT browser control. + */ +public class HTMLPreviewPage extends Page + implements IBrowserPreviewPage, IUpdate { + + // Instance Variables ------------------------------------------------------ + + /** The browser widget. */ + private Browser browser; + + /** The URL of the resource to preview. */ + private URL location; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param location the URL of the resource to preview + */ + public HTMLPreviewPage(URL location) { + this.location = location; + } + + // IPage Implementation ---------------------------------------------------- + + /* + * @see org.eclipse.ui.part.IPage#createControl(Composite) + */ + public void createControl(Composite parent) { + browser = new Browser(parent, SWT.NONE); + browser.setLayout(new FillLayout()); + browser.setUrl(location.toString()); + browser.addLocationListener(new LocationAdapter() { + public void changing(LocationEvent event) { + if (event.location != null) { + event.doit = false; + } + } + }); + } + + /* + * @see org.eclipse.ui.part.IPage#getControl() + */ + public Control getControl() { + return browser; + } + + /* + * @see org.eclipse.ui.part.IPage#setFocus() + */ + public void setFocus() { + browser.setFocus(); + } + + // IUpdate Implementation -------------------------------------------------- + + /* + * @see IUpdate#update() + */ + public void update() { + browser.refresh(); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/text/HTMLCompletionProcessor.java b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/text/HTMLCompletionProcessor.java new file mode 100644 index 0000000..3f85ac0 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/text/HTMLCompletionProcessor.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpeclipse.html.ui.internal.text; + +import net.sourceforge.phpeclipse.ui.WebUI; +import net.sourceforge.phpeclipse.ui.templates.template.BasicCompletionProcessor; +import net.sourceforge.phpeclipse.ui.templates.template.HTMLContextType; + +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.templates.TemplateContextType; + + +/** + * A completion processor for XML templates. + */ +public class HTMLCompletionProcessor extends BasicCompletionProcessor { + + /** + * Return the XML context type that is supported by this plugin. + */ + protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) { + return WebUI.getDefault().getContextTypeRegistry().getContextType(HTMLContextType.HTML_CONTEXT_TYPE); + } + + +} diff --git a/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/text/HTMLConfiguration.java b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/text/HTMLConfiguration.java new file mode 100644 index 0000000..34ca886 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.html.ui/src/net/sourceforge/phpeclipse/html/ui/internal/text/HTMLConfiguration.java @@ -0,0 +1,53 @@ +/* + * Created on 25.08.2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package net.sourceforge.phpeclipse.html.ui.internal.text; + +import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration; +import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner; +import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.text.contentassist.IContentAssistant; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * @author khartlage + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates + */ +public class HTMLConfiguration extends XMLConfiguration { + public HTMLConfiguration(XMLTextTools tools) { + this(tools, null); + } + + public HTMLConfiguration(XMLTextTools tools, ITextEditor editor) { + super(tools, editor); + } + + public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { + ContentAssistant assistant = new ContentAssistant(); + assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); + + IContentAssistProcessor processor = new HTMLCompletionProcessor(); + assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_TAG); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_PI); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_COMMENT); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_DECL); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_TAG); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_ATTRIBUTE); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_CDATA); + + assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE); + assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer)); + + return assistant; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.core/.classpath b/archive/net.sourceforge.phpeclipse.js.core/.classpath new file mode 100644 index 0000000..065ac06 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.js.core/.cvsignore b/archive/net.sourceforge.phpeclipse.js.core/.cvsignore new file mode 100644 index 0000000..ba077a4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/archive/net.sourceforge.phpeclipse.js.core/.project b/archive/net.sourceforge.phpeclipse.js.core/.project new file mode 100644 index 0000000..3c10404 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/.project @@ -0,0 +1,28 @@ + + + net.sourceforge.phpeclipse.js.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/archive/net.sourceforge.phpeclipse.js.core/build.properties b/archive/net.sourceforge.phpeclipse.js.core/build.properties new file mode 100644 index 0000000..dd10961 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/build.properties @@ -0,0 +1,15 @@ +bin.includes = icons/,\ + jseditorsrc.zip,\ + plugin.xml,\ + plugin.properties,\ + net.sf.wdte.js.core.jar +src.includes = src/,\ + scripts/,\ + plugin.xml,\ + build.properties,\ + .project,\ + .classpath,\ + plugin.properties +source.net.sf.wdte.js.core.jar = src/ +jars.compile.order = net.sf.wdte.js.core.jar +output.net.sf.wdte.js.core.jar = bin/ diff --git a/archive/net.sourceforge.phpeclipse.js.core/plugin.properties b/archive/net.sourceforge.phpeclipse.js.core/plugin.properties new file mode 100644 index 0000000..d7fd576 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/plugin.properties @@ -0,0 +1,15 @@ +# +# Copyright (c) 2004 Christopher Lenz and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Common Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/cpl-v10.html +# +# Contributors: +# Christopher Lenz - initial english resources +# +# $Id: plugin.properties,v 1.1 2004-09-02 18:14:39 jsurfer Exp $ +# + +pluginName = Web Development Tools JavaScript Core +providerName= WDTE Project diff --git a/archive/net.sourceforge.phpeclipse.js.core/plugin.xml b/archive/net.sourceforge.phpeclipse.js.core/plugin.xml new file mode 100644 index 0000000..4a60e64 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/plugin.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/JSCorePlugin.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/JSCorePlugin.java new file mode 100644 index 0000000..2809937 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/JSCorePlugin.java @@ -0,0 +1,131 @@ +/* + * $RCSfile: JSCorePlugin.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.2 2004/05/22 16:14:37 l950637 + * Adapt for Eclipse 3.0M9 + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.3 2003/12/10 20:19:16 agfitzp + * 3.0 port + * + * Revision 1.2 2003/06/21 03:48:51 agfitzp + * fixed global variables as functions bug + * fixed length calculation of instance variables + * Automatic outlining is now a preference + * + * Revision 1.1 2003/05/28 15:17:12 agfitzp + * net.sourceforge.phpeclipse.js.core 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.core; + +import java.util.LinkedList; +import java.util.List; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Plugin; + + +/** + * The main plugin class to be used in the desktop. + */ +public class JSCorePlugin extends Plugin +{ + //The shared instance. + private static JSCorePlugin plugin; + + //Resource bundle. + private ResourceBundle resourceBundle; + + private boolean defaultsInitialized = false; + + /** + * current func list + */ + private List currentFunctions = new LinkedList(); + + /** + * The constructor. + * @param descriptor + */ + public JSCorePlugin() { + plugin = this; + + try { + resourceBundle = ResourceBundle.getBundle("net.sourceforge.phpeclipse.js.core.JSCorePluginResources"); + } catch(MissingResourceException x) { + resourceBundle = null; + } + } + + /** + * Returns the shared instance. + * @return + */ + public static JSCorePlugin getDefault() { + return plugin; + } + + /** + * Returns the workspace instance. + * @return + */ + public static IWorkspace getWorkspace() { + return ResourcesPlugin.getWorkspace(); + } + + /** + * Returns the string from the plugin's resource bundle, or 'key' if not found. + * @param key + * + * @return + */ + public static String getResourceString(String key) { + ResourceBundle bundle = JSCorePlugin.getDefault().getResourceBundle(); + + try { + return bundle.getString(key); + } catch(MissingResourceException e) { + return key; + } + } + + /** + * Returns the plugin's resource bundle, + * @return + */ + public ResourceBundle getResourceBundle() { + return resourceBundle; + } + + /** + * Returns the currentFunctions. + * @return List + */ + public List getCurrentFunctions() { + return currentFunctions; + } + + /** + * Sets the currentFunctions. + * @param currentFunctions The currentFunctions to set + */ + public void setCurrentFunctions(List currentFunctions) { + this.currentFunctions = currentFunctions; + } +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassElement.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassElement.java new file mode 100644 index 0000000..6e8ee1e --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassElement.java @@ -0,0 +1,80 @@ +/* + * Created on May 15, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + * + *======================================================================== +*/ +package net.sourceforge.phpeclipse.js.core.model; + +import java.util.HashMap; + +import org.eclipse.core.resources.IFile; + +/** + * @author fitzpata + * + */ +public class JSClassElement extends JSElement +{ + protected HashMap childrenByName; + protected boolean isPrototype = false; + + /** + * @param aName + * @param offset + * @param length + */ + public JSClassElement(IFile aFile, String aName, int offset, int length) + { + super(aFile, aName, offset, length); + childrenByName = new HashMap(); + } + + public void addChildElement(JSElement anElement) + { + String elementName = anElement.getName(); + if(!childrenByName.containsKey(elementName)) + { + this.children.add(anElement); + this.childrenByName.put(elementName, anElement); + anElement.setParent(this); + } + } + + public int category() + { + return CLASS; + } + + /** + * @return + */ + public boolean isPrototype() + { + return isPrototype; + } + + /** + * @param b + */ + public void setPrototype(boolean b) + { + isPrototype = b; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassMethodElement.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassMethodElement.java new file mode 100644 index 0000000..02832bb --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassMethodElement.java @@ -0,0 +1,42 @@ +/* + * Created on May 20, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.core.model; + +import org.eclipse.core.resources.IFile; + +/** + * @author fitzpata + * + */ +public class JSClassMethodElement extends JSFunctionElement +{ + public JSClassMethodElement(IFile aFile, String aName, String argumentString, int offset, int length) + { + super(aFile, aName, argumentString, offset, length); + } + + + public int category() + { + return CLASS_METHOD; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassVariableElement.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassVariableElement.java new file mode 100644 index 0000000..e1e483f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSClassVariableElement.java @@ -0,0 +1,47 @@ +/* + * Created on May 20, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.core.model; + +import org.eclipse.core.resources.IFile; + +/** + * @author fitzpata + * + */ +public class JSClassVariableElement extends JSElement +{ + + /** + * @param aName + * @param offset + * @param length + */ + public JSClassVariableElement(IFile aFile, String aName, int offset, int length) + { + super(aFile, aName, offset, length); + } + + public int category() + { + return CLASS_VARIABLE; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElement.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElement.java new file mode 100644 index 0000000..034b2e3 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElement.java @@ -0,0 +1,222 @@ +/* + * $RCSfile: JSElement.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.2 2004/02/27 18:28:10 cell + * Make model elements platform objects so they are automatically adapted + * + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:08 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + * Revision 1.1 2003/05/28 15:17:12 agfitzp + * net.sourceforge.phpeclipse.js.core 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.core.model; + +import java.util.List; +import java.util.LinkedList; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.PlatformObject; + +/** + * DOCUMENT ME! + * + * @author Addi + */ +abstract public class JSElement extends PlatformObject + implements JSElementCategories +{ + protected IFile file; + protected String name; + protected int offset; + protected int numberOfLines; + protected int length; + + protected JSElement parent; + protected List children; + + /** + * Creates a new JSElement and stores parent element and location in the text. + * + * @param aName text corresponding to the func + * @param offset the offset into the text + * @param length the length of the element + */ + public JSElement(IFile aFile, String aName, int offset, int length) + { + this.file = aFile; + this.name = aName; + this.offset = offset; + this.length = length; + this.children = new LinkedList(); + } + + /** + * Method declared on IWorkbenchAdapter + * @param o + * + * @return + */ + public String getLabel(Object o) + { + return name; + } + + /** + * Returns the number of characters in this section. + * @return + */ + public int getLength() + { + return length; + } + + /** + * Returns the number of lines in the element. + * + * @return the number of lines in the element + */ + public int getNumberOfLines() + { + return numberOfLines; + } + + /** + * Returns the offset of this section in the file. + * @return + */ + public int getStart() + { + return offset; + } + + /** + * Sets the number of lines in the element + * + * @param newNumberOfLines the number of lines in the element + */ + public void setNumberOfLines(int newNumberOfLines) + { + numberOfLines = newNumberOfLines; + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() + { + return getLabel(this); + } + + /** + * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(Object) + */ + public Object[] getChildren(Object o) + { + Object[] result = new Object[children.size()]; + return children.toArray(result); + } + + /** + * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(Object) + */ + public Object getParent(Object o) + { + return null; + } + + /** + * + * @return A category enumeration for sub-types. + */ + abstract public int category(); + + /** + * @return + */ + public String getName() + { + return name; + } + + /** + * @return + */ + public int getOffset() + { + return offset; + } + + /** + * @return + */ + public JSElement getParent() + { + return parent; + } + + /** + * @param element + */ + protected void setParent(JSElement element) + { + parent = element; + } + + /** + * @param anElement + * @return + */ + public boolean sharesParentWith(JSElement anElement) + { + if(parent == null) { + return anElement.getParent() == null; + } + + return parent.equals(anElement.getParent()); + } + + /** + * @param anElement + * @return + */ + public boolean equals(JSElement anElement) + { + return sharesParentWith(anElement) && name.equals(anElement.getName()); + } + + /** + * @return Returns the file. + */ + public IFile getFile() { + return file; + } + + /** + * @param file The file to set. + */ + protected void setFile(IFile file) { + this.file = file; + } + +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElementCategories.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElementCategories.java new file mode 100644 index 0000000..0b0b9d9 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElementCategories.java @@ -0,0 +1,36 @@ +/* + * Created on May 20, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.core.model; + +/** + * @author fitzpata + * + */ +public interface JSElementCategories +{ + static final int CLASS = 1; + static final int FUNCTION = 2; + static final int VARIABLE = 3; + static final int CLASS_VARIABLE = 4; + static final int INSTANCE_VARIABLE = 5; + static final int CLASS_METHOD = 6; + static final int INSTANCE_METHOD = 7; +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElementList.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElementList.java new file mode 100644 index 0000000..e20096d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSElementList.java @@ -0,0 +1,205 @@ +/* + * $RCSfile: JSElementList.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.2 2004/02/27 18:28:10 cell + * Make model elements platform objects so they are automatically adapted + * + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.1 2003/05/30 20:53:08 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + * Revision 1.1 2003/05/28 15:17:11 agfitzp + * net.sourceforge.phpeclipse.js.core 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.core.model; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.PlatformObject; + +/** + * DOCUMENT ME! + * + * @author Addi + */ +public class JSElementList extends PlatformObject +{ + protected List children = new ArrayList(); + + /** + * Creates a new adaptable list with the given children. + */ + public JSElementList() + { + } + + /** + * Creates a new adaptable list with the given children. + * @param newChildren + */ + public JSElementList(JSElement[] newChildren) + { + for (int i = 0; i < newChildren.length; i++) + { + children.add(newChildren[i]); + } + } + + /** + * Creates a new adaptable list with the given children. + * @param newChildren + */ + public JSElementList(List newChildren) + { + for (int i = 0; i < newChildren.size(); i++) + { + children.add(newChildren.get(i)); + } + } + + /** + * Adds all the adaptable objects in the given enumeration to this list. Returns this list. + * @param iterator + * + * @return + */ + public JSElementList add(Iterator iterator) + { + while (iterator.hasNext()) + { + add((JSElement) iterator.next()); + } + + return this; + } + + /** + * Adds the given adaptable object to this list. Returns this list. + * @param adaptable + * + * @return + */ + public JSElementList add(JSElement anElement) + { + children.add(anElement); + + return this; + } + + /** + * Returns the elements in this list. + * @return + */ + public Object[] getChildren() + { + return children.toArray(); + } + + /** + * + * + * @param o + * + * @return + */ + public Object[] getChildren(Object o) + { + return children.toArray(); + } + + /** + * + * + * @param object + * + * @return + */ + public String getLabel(Object object) + { + return object == null ? "" : object.toString(); + } + + /** + * + * + * @param object + * + * @return + */ + public Object getParent(Object object) + { + return null; + } + + /** + * Removes the given adaptable object from this list. + * @param adaptable + */ + public void remove(JSElement anElement) + { + children.remove(anElement); + } + + /** + * Returns the number of items in the list + * @return + */ + public int size() + { + return children.size(); + } + + public JSElement findEquivilent(JSElement anElement) + { + for(int i = 0; i < size();i++) + { + JSElement aCandidate = (JSElement) children.get(i); + if(anElement.equals(aCandidate)) + { + return aCandidate; + } + } + + + return null; + } + + public JSElement get(int index) + { + if(index >= size()) + { + return null; + } + return (JSElement) children.get(index); + } + + /** + * @return + */ + public IAdaptable asAdaptable() { + // TODO Auto-generated method stub + return null; + } +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSFunctionElement.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSFunctionElement.java new file mode 100644 index 0000000..0169913 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSFunctionElement.java @@ -0,0 +1,72 @@ +/* + * Created on May 15, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.core.model; + +import org.eclipse.core.resources.IFile; + +/** + * @author fitzpata + */ +public class JSFunctionElement extends JSElement +{ + + protected String arguments; + /** + * @param aName + * @param offset + * @param length + */ + public JSFunctionElement(IFile aFile, String aName, String argumentString, int offset, int length) + { + super(aFile, aName, offset, length); + arguments = argumentString; + } + + /** + * Method declared on IWorkbenchAdapter + * @param o + * + * @return + */ + public String getLabel(Object o) + { + String firstPart = name; + if(firstPart.length() <= 0){ + firstPart = ""; + } + + return firstPart + arguments; + } + + public int category() + { + return FUNCTION; + } + + /** + * @return + */ + public String getArguments() + { + return arguments; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSGlobalVariableElement.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSGlobalVariableElement.java new file mode 100644 index 0000000..5a37558 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSGlobalVariableElement.java @@ -0,0 +1,47 @@ +/* + * Created on May 20, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.core.model; + +import org.eclipse.core.resources.IFile; + +/** + * @author fitzpata + * + */ +public class JSGlobalVariableElement extends JSElement +{ + + /** + * @param aName + * @param offset + * @param length + */ + public JSGlobalVariableElement(IFile aFile, String aName, int offset, int length) + { + super(aFile, aName, offset, length); + } + + public int category() + { + return VARIABLE; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSInstanceMethodElement.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSInstanceMethodElement.java new file mode 100644 index 0000000..3b74f05 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSInstanceMethodElement.java @@ -0,0 +1,41 @@ +/* + * Created on May 20, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.core.model; + +import org.eclipse.core.resources.IFile; + +/** + * @author fitzpata + * + */ +public class JSInstanceMethodElement extends JSFunctionElement +{ + public JSInstanceMethodElement(IFile aFile, String aName, String argumentString, int offset, int length) + { + super(aFile, aName, argumentString, offset, length); + } + + public int category() + { + return INSTANCE_METHOD; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSInstanceVariableElement.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSInstanceVariableElement.java new file mode 100644 index 0000000..a1747dc --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/model/JSInstanceVariableElement.java @@ -0,0 +1,47 @@ +/* + * Created on May 20, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.core.model; + +import org.eclipse.core.resources.IFile; + +/** + * @author fitzpata + * + */ +public class JSInstanceVariableElement extends JSElement +{ + + /** + * @param aName + * @param offset + * @param length + */ + public JSInstanceVariableElement(IFile aFile, String aName, int offset, int length) + { + super(aFile, aName, offset, length); + } + + public int category() + { + return INSTANCE_VARIABLE; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSParser.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSParser.java new file mode 100644 index 0000000..7796b4a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSParser.java @@ -0,0 +1,926 @@ +/* + * $RCSfile: JSParser.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.6 2003/12/10 20:19:16 agfitzp + * 3.0 port + * + * Revision 1.5 2003/06/21 03:48:51 agfitzp + * fixed global variables as functions bug + * fixed length calculation of instance variables + * Automatic outlining is now a preference + * + * Revision 1.4 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + * Revision 1.3 2003/05/28 20:47:58 agfitzp + * Outline the document, not the file. + * + * Revision 1.2 2003/05/28 15:20:00 agfitzp + * Trivial change to test CVS commit + * + * Revision 1.1 2003/05/28 15:17:12 agfitzp + * net.sourceforge.phpeclipse.js.core 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.core.parser; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +import net.sourceforge.phpeclipse.js.core.model.*; + +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.rules.IToken; + +/** + * DOCUMENT ME! + * + * @author Addi + */ +public class JSParser +{ + + public static final String FUNCTION = "function"; + + /** + * line separator + */ + public static final String LINE_SEPARATOR = System.getProperty("line.separator"); + + /** + * Array of system types to ignore. + */ + private static String[] systemClassNames= {"Array","String"}; + + + protected HashMap systemClassMap = new HashMap(); + + protected IFile sourceFile; + protected IDocument sourceDocument; + protected HashMap functions = new HashMap(); + protected HashMap classes = new HashMap(); + protected HashMap globalVariables = new HashMap(); + protected List elementList = new LinkedList(); + protected JSSyntaxScanner scanner = new JSSyntaxScanner(); + + /** + * Constructor for JSParser. + */ + public JSParser() + { + super(); + + int i; + + for(i = 0;i < systemClassNames.length; i++) + { + String aName = systemClassNames[i]; + systemClassMap.put(aName, aName); + } + } + + /** + * Returns a string containing the contents of the given file. Returns an empty string if there + * were any errors reading the file. + * @param file + * + * @return + */ + protected static String getText(IFile file) + { + try + { + InputStream in = file.getContents(); + return streamToString(in); + } catch (Exception e) + { + e.printStackTrace(); + } + return ""; + } + + protected static String streamToString(InputStream in) throws IOException + { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buf = new byte[1024]; + int read = in.read(buf); + + while (read > 0) + { + out.write(buf, 0, read); + read = in.read(buf); + } + + return out.toString(); + } + + /** + * Skips ahead and finds next non-whitespace token. + * + */ + public IToken nextNonWhitespaceToken() + { + IToken aToken = scanner.nextToken(); + + while (!aToken.isEOF() && aToken.isWhitespace()) + { + aToken = scanner.nextToken(); + } + + return aToken; + } + + /** + * Parses the input given by the argument. + * + * @param file the element containing the input text + * + * @return an element collection representing the parsed input + */ + public List parse(IFile file) + { + this.sourceFile = file; + return parse(new Document(getText(file))); + } + + /** + * Parses the input given by the argument. + * + * @param aSourceDocument the element containing the input text + * + * @return an element collection representing the parsed input + */ + public List parse(IDocument aSourceDocument) + { + sourceDocument = aSourceDocument; + + scanner.setRange(sourceDocument, 0, sourceDocument.getLength()); + IToken token = scanner.nextToken(); + while (!token.isEOF()) + { + int offset = scanner.getTokenOffset(); + int length = scanner.getTokenLength(); + String expression = getExpression(offset, length); + + if (token.equals(JSSyntaxScanner.TOKEN_FUNCTION)) + { + addFunction(expression, offset, length); + } + + if (token.equals(JSSyntaxScanner.TOKEN_DEFAULT)) + { + //We need to check if the token is already a function or class + if (functions.containsKey(expression) || classes.containsKey(expression)) + { + token = nextNonWhitespaceToken(); + if (token.equals(JSSyntaxScanner.TOKEN_MEMBER)) + { + detectInstanceMethod(offset, expression); + } else + { + detectClassMethod(token, offset, expression); + } + } else + { + if (expression.equals("var")) + { + detectGlobalVariable(); + } + } + } + token = scanner.nextToken(); + } + return elementList; + } + + private void addFunction(String expression, int offset, int length) + { + String functionSignature = getNaked(expression); + int braceOffset = functionSignature.indexOf("("); + String functionName = functionSignature.substring(0, braceOffset).trim(); + String arguments = + functionSignature.substring(functionSignature.indexOf("("), functionSignature.indexOf(")") + 1); + + if (functionName.indexOf(".") >= 0) + { + //If the function signature includes .prototype. then it's a member. + if (functionName.indexOf(".prototype.") >= 0) + { + String className = functionName.substring(0, functionName.indexOf(".")); + String memberName = functionName.substring(functionName.lastIndexOf(".") + 1); + JSInstanceMethodElement aMethod = + this.addInstanceMethod(memberName, className, arguments, offset, offset, length); + detectInstanceMethodContext(className, aMethod); + } else + { + String className = functionName.substring(0, functionName.indexOf(".")); + if (functions.containsKey(className) || classes.containsKey(className)) + { + String memberName = functionName.substring(functionName.lastIndexOf(".") + 1); + JSFunctionElement aMethod = + this.addClassMethod(memberName, className, arguments, offset, offset, length); + } + } + } else + { + if(! functions.containsKey(functionName)) + { + JSFunctionElement aFunction = new JSFunctionElement(this.sourceFile, functionName, arguments, offset, length); + + elementList.add(aFunction); + functions.put(functionName, aFunction); + + detectFunctionContext(aFunction); + } + } + } + + /** + * + */ + private void checkForSpecialGlobalTypes(JSGlobalVariableElement aVariable) + { + IToken token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + if(!checkForDynamicClass(aVariable, token)) + { + checkForAnonymousFunction(aVariable, token); + } + } + } + + /** + * + */ + private boolean checkForDynamicClass(JSGlobalVariableElement aVariable, IToken rhsToken) + { + if (rhsToken.equals(JSSyntaxScanner.TOKEN_DEFAULT)) + { + int offset = scanner.getTokenOffset(); + int length = scanner.getTokenLength(); + + String expression = getExpression(offset, length); + + if (expression.equals("new")) + { + IToken token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + if (token.equals(JSSyntaxScanner.TOKEN_DEFAULT)) + { + offset = scanner.getTokenOffset(); + length = scanner.getTokenLength(); + expression = getExpression(offset, length); + + if(! isSystemClass(expression)) + { + JSClassElement aClass = findOrCreateClass(aVariable.getName()); + if(aClass != null) + { + //Tell the class it's dynamically declared: what we will parse as class methods & vars are really instance methods & vars + aClass.setPrototype(true); + + return true; + } + } + } + } + } + } + return false; + } + + /** + * + */ + private boolean checkForAnonymousFunction(JSGlobalVariableElement aVariable, IToken rhsToken) + { + if (rhsToken.equals(JSSyntaxScanner.TOKEN_FUNCTION)) + { + String functionName = aVariable.getName(); + int offset = aVariable.getOffset(); + int length = aVariable.getLength(); + + int functionOffset = scanner.getTokenOffset(); + int functionLength = scanner.getTokenLength(); + String functionSignature = + getExpression(functionOffset, functionLength); + String arguments = getArgumentString(functionSignature); + + JSFunctionElement aFunction = new JSFunctionElement(this.sourceFile, functionName, arguments, offset, functionOffset - offset + functionLength); + + elementList.add(aFunction); + functions.put(functionName, aFunction); + + elementList.remove(aVariable); + globalVariables.remove(functionName); + + detectFunctionContext(aFunction); + + return true; + } + + return false; + } + + /** + * + */ + private String getExpression(int offset, int length) + { + String expression; + try { + expression = sourceDocument.get(offset, length);//sourceBuffer.substring(offset, offset + length); + } catch(BadLocationException e) + { + expression = ""; + } + return expression; + } + + /** + * + */ + private void detectGlobalVariable() + { + IToken token; + int length; + int offset; + + token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + if (token.equals(JSSyntaxScanner.TOKEN_DEFAULT)) + { + int varOffset = scanner.getTokenOffset(); + length = scanner.getTokenLength(); + String variableName = getExpression(varOffset, length); + + token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + offset = scanner.getTokenOffset(); + length = scanner.getTokenLength(); + String expression = getExpression(offset, length); + if (expression.equals("=")) + { + JSGlobalVariableElement aVariable = addGlobalVariable(variableName, varOffset); + checkForSpecialGlobalTypes(aVariable); + } + } + } + } + } + + private void detectClassMethod(IToken token, int classOffset, String className) + { + int offset = scanner.getTokenOffset(); + int length = scanner.getTokenLength(); + String expression = getExpression(offset, length); + + if (expression.equals(".")) + { + + token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + offset = scanner.getTokenOffset(); + length = scanner.getTokenLength(); + String memberName = getExpression(offset, length); + + token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + offset = scanner.getTokenOffset(); + length = scanner.getTokenLength(); + expression = getExpression(offset, length); + if (expression.equals("=")) + { + + token = nextNonWhitespaceToken(); + int tokenOffset = scanner.getTokenOffset(); + int tokenLength = scanner.getTokenLength(); + + if (token.equals(JSSyntaxScanner.TOKEN_FUNCTION)) + { + String functionSignature = getExpression(tokenOffset, tokenLength); + String arguments = getArgumentString(functionSignature); + + JSFunctionElement aMethod = + addClassMethod(memberName, className, arguments, classOffset, tokenOffset, tokenLength); + + + } else + { + addClassVariable(memberName, className, classOffset); + } + } + } + } + } + } + + private String getArgumentString(String functionSignature) + { + return functionSignature.substring( + functionSignature.indexOf("("), + functionSignature.indexOf(")") + 1); + } + + private void detectInstanceMethod(int classOffset, String className) + { + String expression; + IToken token; + int length; + int offset; + + token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + offset = scanner.getTokenOffset(); + length = scanner.getTokenLength(); + expression = getExpression(offset, length); + + if (expression.equals(".")) + { + + token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + offset = scanner.getTokenOffset(); + length = scanner.getTokenLength(); + String memberName = getExpression(offset, length); + + token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + offset = scanner.getTokenOffset(); + length = scanner.getTokenLength(); + expression = getExpression(offset, length); + if (expression.equals("=")) + { + token = nextNonWhitespaceToken(); + if (token.equals(JSSyntaxScanner.TOKEN_FUNCTION)) + { + int functionOffset = scanner.getTokenOffset(); + int functionLength = scanner.getTokenLength(); + String functionSignature = + getExpression(functionOffset, functionLength); + String arguments = getArgumentString(functionSignature); + + JSInstanceMethodElement aMethod = + addInstanceMethod( + memberName, + className, + arguments, + classOffset, + functionOffset, + functionLength); + + detectInstanceMethodContext(className, aMethod); + + } else + { + addInstanceVariable(memberName, className, classOffset, (".prototype.").length()); + } + + } + } + } + } + } + } + + private void parseInstanceMethodContext(String className, JSFunctionElement aMethod) + { + IToken token; + + token = nextNonWhitespaceToken(); + while (!token.isEOF()) + { + int offset = scanner.getTokenOffset(); + int length = scanner.getTokenLength(); + String expression = getExpression(offset, length); + + // if (token.equals(JSSyntaxScanner.TOKEN_END_CONTEXT)) + if (expression.equals("}")) + { + return; + } else if (expression.equals("{")) + { + parseInstanceMethodContext(className, aMethod); + } else if (token.equals(JSSyntaxScanner.TOKEN_DEFAULT)) + { + if (expression.equals("this")) + { + handleThisReference(className, offset); + } + } + + token = nextNonWhitespaceToken(); + } + } + + private void detectInstanceMethodContext(String className, JSFunctionElement aMethod) + { + IToken token; + + token = nextNonWhitespaceToken(); + while (!token.isEOF()) + { + int offset = scanner.getTokenOffset(); + int length = scanner.getTokenLength(); + String expression = getExpression(offset, length); + + // if (token.equals(JSSyntaxScanner.TOKEN_BEGIN_CONTEXT)) + if (expression.equals("{")) + { + parseInstanceMethodContext(className, aMethod); + return; + } + + token = nextNonWhitespaceToken(); + } + } + + private void parseClassMethodContext(JSFunctionElement aMethod) + { + IToken token; + + token = nextNonWhitespaceToken(); + while (!token.isEOF()) + { + int offset = scanner.getTokenOffset(); + int length = scanner.getTokenLength(); + String expression = getExpression(offset, length); + + if (expression.equals("}")) + { + return; + } else if (expression.equals("{")) + { + parseClassMethodContext(aMethod); + } + + token = nextNonWhitespaceToken(); + } + } + + private void detectClassMethodContext(JSFunctionElement aMethod) + { + IToken token = nextNonWhitespaceToken(); + while (!token.isEOF()) + { + int offset = scanner.getTokenOffset(); + int length = scanner.getTokenLength(); + String expression = getExpression(offset, length); + + if (expression.equals("{")) + { + parseClassMethodContext(aMethod); + return; + } + + token = nextNonWhitespaceToken(); + } + } + + private void handleThisReference(String className, int expressionStart) + { + IToken token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + int offset = scanner.getTokenOffset(); + int length = scanner.getTokenLength(); + + String expression = getExpression(offset, length); + + if(expression.equals(".")) + { + token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + int memberStart = scanner.getTokenOffset(); + length = scanner.getTokenLength(); + + String memberName = getExpression(memberStart, length); + + token = nextNonWhitespaceToken(); + if (!token.isEOF()) + { + offset = scanner.getTokenOffset(); + length = scanner.getTokenLength(); + expression = getExpression(offset, length); + + if (expression.equals("=")) + { + addInstanceVariable(memberName, className, expressionStart, 1 + 4 - className.length()); + } + } + } + } + } + } + + private void parseFunctionContext(JSFunctionElement aFunction) + { + IToken token; + + token = nextNonWhitespaceToken(); + while (!token.isEOF()) + { + int offset = scanner.getTokenOffset(); + int length = scanner.getTokenLength(); + String expression = getExpression(offset, length); + + if (expression.equals("}")) + { + return; + } else if (expression.equals("{")) + { + parseFunctionContext(aFunction); + } else if (token.equals(JSSyntaxScanner.TOKEN_DEFAULT)) + { + if (expression.equals("this")) + { + handleThisReference(aFunction.getName(), offset); + } + } + + token = nextNonWhitespaceToken(); + } + } + + private void detectFunctionContext(JSFunctionElement aFunction) + { + IToken token = nextNonWhitespaceToken(); + while (!token.isEOF()) + { + int offset = scanner.getTokenOffset(); + int length = scanner.getTokenLength(); + String expression = getExpression(offset, length); + + if (expression.equals("{")) + { + parseFunctionContext(aFunction); + return; + } + + token = nextNonWhitespaceToken(); + } + } + + private JSInstanceMethodElement addInstanceMethod( + String memberName, + String className, + String arguments, + int classOffset, + int functionOffset, + int functionLength) + { + int signatureLength = functionOffset - classOffset + functionLength; + JSInstanceMethodElement aMethod = + new JSInstanceMethodElement(this.sourceFile, memberName, arguments, classOffset, signatureLength); + + findOrCreateClass(className).addChildElement(aMethod); + + return aMethod; + } + + private JSFunctionElement addClassMethod( + String memberName, + String className, + String arguments, + int classOffset, + int functionOffset, + int functionLength) + { + JSClassElement aClass = findOrCreateClass(className); + int signatureLength = functionOffset - classOffset + functionLength; + JSFunctionElement aMethod; + + if(aClass.isPrototype()) { + aMethod = new JSInstanceMethodElement(this.sourceFile, memberName, arguments, classOffset, signatureLength); + + aClass.addChildElement(aMethod); + detectInstanceMethodContext(className, aMethod); + } else { + aMethod = new JSClassMethodElement(this.sourceFile, memberName, arguments, classOffset, signatureLength); + + aClass.addChildElement(aMethod); + detectClassMethodContext(aMethod); + } + + return aMethod; + } + + /** + * @param memberName + * @param className + * @param classOffset + * @return + */ + private JSElement addClassVariable(String memberName, String className, int classOffset) + { + //One extra char for "." + JSElement aVariable; + JSClassElement aClass = findOrCreateClass(className); + + if(aClass.isPrototype()) + { + aVariable = new JSInstanceVariableElement(this.sourceFile, memberName, classOffset, className.length() + memberName.length() + 1); + + } else { + aVariable = new JSClassVariableElement(this.sourceFile, memberName, classOffset, className.length() + memberName.length() + 1); + } + aClass.addChildElement(aVariable); + + return aVariable; + } + + private JSInstanceVariableElement addInstanceVariable( + String memberName, + String className, + int classOffset, + int paddingWidth) + { + //11 extra chars for ".prototype." + JSInstanceVariableElement aVariable = + new JSInstanceVariableElement( + this.sourceFile, + memberName, + classOffset, + className.length() + memberName.length() + paddingWidth); + + findOrCreateClass(className).addChildElement(aVariable); + + return aVariable; + } + + private JSGlobalVariableElement addGlobalVariable(String variableName, int offset) + { + JSGlobalVariableElement aVariable; + if (!globalVariables.containsKey(variableName)) + { + aVariable = new JSGlobalVariableElement(this.sourceFile, variableName, offset, variableName.length()); + + elementList.add(aVariable); + globalVariables.put(variableName, aVariable); + } else + { + aVariable = (JSGlobalVariableElement) classes.get(variableName); + } + + return aVariable; + } + + private JSClassElement findOrCreateClass(String className) + { + JSClassElement aClass = null; + if (!classes.containsKey(className)) + { + if(functions.containsKey(className)) + { + //if we're creating a class from an existing function we must + //migrate the existing function to become a constructor in the class. + JSFunctionElement constructor = (JSFunctionElement) functions.get(className); + + aClass = new JSClassElement(this.sourceFile, className, constructor.getStart(), constructor.getLength()); + aClass.addChildElement(constructor); + + elementList.remove(constructor); + elementList.add(aClass); + classes.put(className, aClass); + } else if(globalVariables.containsKey(className)) + { + //if we're creating a class from an existing global variable we must + //migrate the existing function to become a constructor in the class. + JSGlobalVariableElement aVariable = (JSGlobalVariableElement) globalVariables.get(className); + + aClass = new JSClassElement(this.sourceFile, className, aVariable.getStart(), aVariable.getLength()); + + elementList.remove(aVariable); + elementList.add(aClass); + classes.put(className, aClass); + globalVariables.remove(className); + } else { + //The final case is if we have no idea where this class came from, but shouldn't be ignored. + aClass = new JSClassElement(this.sourceFile, className, 0, 0); + + elementList.add(aClass); + classes.put(className, aClass); + } + } else + { + aClass = (JSClassElement) classes.get(className); + } + + return aClass; + } + + public boolean isSystemClass(String aClassName) + { + return systemClassMap.containsKey(aClassName); + } + + /** + * Method getNaked. + * @param funcName + */ + private String getNaked(String funcName) + { + if (funcName == null) + { + return null; + } + + funcName = funcName.trim().substring(FUNCTION.length()).trim(); + funcName = replaceInString(funcName.trim(), LINE_SEPARATOR, ""); + + StringBuffer strBuf = new StringBuffer(""); + int len = funcName.length(); + boolean wasSpace = false; + for (int i = 0; i < len; i++) + { + char ch = funcName.charAt(i); + if (ch == ' ') + { + wasSpace = true; + } else // not space + { + if (wasSpace) + { + strBuf.append(' '); + } + strBuf.append(ch); + wasSpace = false; + } + } + return strBuf.toString(); + } + + /** + * replace in a string a string sequence with another string sequence + */ + public static String replaceInString(String source, String whatBefore, String whatAfter) + { + if (null == source || source.length() == 0) + { + return source; + } + int beforeLen = whatBefore.length(); + if (beforeLen == 0) + { + return source; + } + StringBuffer result = new StringBuffer(""); + int lastIndex = 0; + int index = source.indexOf(whatBefore, lastIndex); + while (index >= 0) + { + result.append(source.substring(lastIndex, index)); + result.append(whatAfter); + lastIndex = index + beforeLen; + + // get next + index = source.indexOf(whatBefore, lastIndex); + } + result.append(source.substring(lastIndex)); + return result.toString(); + } + + /** + * @return Returns the elementList. + */ + public List getElementList() { + return elementList; + } + +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSPartitionScanner.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSPartitionScanner.java new file mode 100644 index 0000000..f5a05ae --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSPartitionScanner.java @@ -0,0 +1,108 @@ +/* + * $RCSfile: JSPartitionScanner.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.3 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + * Revision 1.2 2003/05/28 20:47:58 agfitzp + * Outline the document, not the file. + * + * Revision 1.1 2003/05/28 15:17:12 agfitzp + * net.sourceforge.phpeclipse.js.core 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.core.parser; + +import java.util.ArrayList; +import java.util.List; +//import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.rules.*; + +/** + * + * + * @author $Author: jsurfer $, $Date: 2004-09-02 18:14:38 $ + * + * @version $Revision: 1.1 $ + */ +public class JSPartitionScanner extends RuleBasedPartitionScanner { + public final static String JS_DEFAULT = "__js_default"; + public final static String JS_COMMENT = "__js_comment"; + public final static String JS_KEYWORD = "__js_keyword"; + public final static String JS_STRING = "__js_string"; + + public final static IToken TOKEN_STRING = new Token(JS_STRING); + public final static IToken TOKEN_COMMENT = new Token(JS_COMMENT); + public final static IToken TOKEN_DEFAULT = new Token(JS_DEFAULT); + public final static IToken TOKEN_KEYWORD = new Token(JS_KEYWORD); + + /** + * Array of keyword token strings. + */ + private static String[] keywordTokens= { + "break", + "case", "catch", "continue", + "default", "do", + "else", + "for", "function", + "goto", + "if", "in", + "new", + "return", + "switch", + "this", "throw", "try", + "var", "void", + "while", "with" + }; + + /** + * Array of constant token strings. + */ + private static String[] constantTokens= { "false", "null", "true" }; + + + /** + * Creates a new JSPartitionScanner object. + */ + public JSPartitionScanner() { + List rules = new ArrayList(); + + rules.add(new MultiLineRule("/*", "*/", TOKEN_COMMENT)); + rules.add(new SingleLineRule("//", "", TOKEN_COMMENT)); + rules.add(new SingleLineRule("\"", "\"", TOKEN_STRING, '\\')); + rules.add(new SingleLineRule("'", "'", TOKEN_STRING, '\\')); + + PredicateWordRule keywordRule = new PredicateWordRule(new JSWordDetector(), TOKEN_DEFAULT, keywordTokens, TOKEN_KEYWORD); + keywordRule.addWords(constantTokens, TOKEN_KEYWORD); + rules.add(keywordRule); + + setRuleList(rules); + } + + + private void setRuleList(List rules) + { + IPredicateRule[] result = new IPredicateRule[rules.size()]; + rules.toArray(result); + setPredicateRules(result); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSReferenceDetector.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSReferenceDetector.java new file mode 100644 index 0000000..d8be925 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSReferenceDetector.java @@ -0,0 +1,34 @@ +/* + * Created on May 14, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.core.parser; + +/** + * @author fitzpata + */ +public class JSReferenceDetector extends JSWordDetector { + /** + * @see IWordDetector#isWordStart + * Try to detect tokens starting with a reference operator. + */ + public boolean isWordStart(char c) { + return (c == '.'); + } +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSScanner.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSScanner.java new file mode 100644 index 0000000..7fbb3e6 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSScanner.java @@ -0,0 +1,62 @@ +/* + * $RCSfile: JSScanner.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.1 2003/05/28 15:17:12 agfitzp + * net.sourceforge.phpeclipse.js.core 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.core.parser; + +import java.util.*; +import org.eclipse.jface.text.rules.*; +import org.eclipse.jface.text.*; + +import org.eclipse.swt.graphics.Color; + +/** + * + * + * @author $Author: jsurfer $, $Date: 2004-09-02 18:14:38 $ + * + * @version $Revision: 1.1 $ + */ +public class JSScanner extends RuleBasedScanner +{ + /** + * Creates a new JSScanner object. + * + * @param manager + */ + public JSScanner(Color aColor) + { + List rules = new ArrayList(); + IToken procInstr = new Token(new TextAttribute(aColor)); + + // Add generic whitespace rule. + rules.add(new WhitespaceRule(new JSWhitespaceDetector())); + + IRule[] result = new IRule[rules.size()]; + rules.toArray(result); + setRules(result); + } + +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSStringScanner.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSStringScanner.java new file mode 100644 index 0000000..b9cbaf4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSStringScanner.java @@ -0,0 +1,77 @@ +/* + * $RCSfile: JSStringScanner.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.1 2003/05/28 15:17:11 agfitzp + * net.sourceforge.phpeclipse.js.core 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.core.parser; + +import org.eclipse.jface.text.*; +import java.util.*; +import org.eclipse.jface.text.rules.*; + +import org.eclipse.swt.graphics.Color; + + +/** + * + * + * @author $Author: jsurfer $, $Date: 2004-09-02 18:14:38 $ + * + * @version $Revision: 1.1 $ + */ +public class JSStringScanner extends RuleBasedScanner +{ + /** + * Creates a new JSFuncScanner object. + * + * @param manager + */ + public JSStringScanner(Color aColor) + { + IToken string = new Token(new TextAttribute(aColor)); + Vector rules = new Vector(); + + // Add rule for single and double quotes + rules.add(new SingleLineRule("\"", "\"", string, '\\')); + rules.add(new SingleLineRule("'", "'", string, '\\')); + + + // Add generic whitespace rule. + rules.add(new WhitespaceRule(new JSWhitespaceDetector())); + + IRule[] result = new IRule[rules.size()]; + rules.copyInto(result); + setRules(result); + } + + /** + * + * + * @return + */ + public IToken nextToken() + { + return super.nextToken(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSSyntaxModelFactory.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSSyntaxModelFactory.java new file mode 100644 index 0000000..2d4b149 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSSyntaxModelFactory.java @@ -0,0 +1,157 @@ +/* + * $RCSfile: JSSyntaxModelFactory.java,v $ + * + * Copyright 2002 CH-1700 Fribourg, Switzerland All rights reserved. + * + * ======================================================================== + * Modifications history + * ======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.2 2004/02/27 17:25:25 cell + * Fix NPE for files without an extension + * + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * Revision 1.3 2003/05/30 20:53:08 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + * Revision 1.2 2003/05/28 20:47:56 agfitzp Outline the document, not the file. + * + * Revision 1.1 2003/05/28 15:17:11 agfitzp net.sourceforge.phpeclipse.js.core 0.0.1 code + * base + * + * ======================================================================== + */ + +package net.sourceforge.phpeclipse.js.core.parser; + +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.IDocument; + +import net.sourceforge.phpeclipse.js.core.model.*; + +/** + * @author Addi + */ +public class JSSyntaxModelFactory { + private static JSSyntaxModelFactory instance = new JSSyntaxModelFactory(); + + /** + * Creates a new JSSyntaxModelFactory. + */ + private JSSyntaxModelFactory() { + } + /** + * @param adaptable + * + * @return + */ + public JSElementList getContentOutline(IProject aProject) { + return new JSElementList(getSyntacticElements(aProject)); + } + + /** + * @param adaptable + * + * @return + */ + public JSElementList getContentOutline(IFile adaptable) { + return new JSElementList(getSyntacticElements(adaptable)); + } + + /** + * @param document + * + * @return + */ + public JSElementList getContentOutline(IDocument document) { + return new JSElementList(getSyntacticElements(document)); + } + + /** + * Returns the singleton. + * + * @return + */ + public static JSSyntaxModelFactory getInstance() { + return instance; + } + + /** + * @param file + * + * @return + */ + private List getSyntacticElements(IProject aProject) { + int i; + JSParser aParser = new JSParser(); + Object[] jsFiles = getJSFilesFor(aProject); + + for (i = 0; i < jsFiles.length; i++) { + aParser.parse((IFile) jsFiles[i]); + } + return aParser.getElementList(); + } + + /** + * @param project + * @return + */ + private Object[] getJSFilesFor(IProject project) { + LinkedList files = new LinkedList(); + collectJSFiles(project, files); + return files.toArray(); + } + + private void collectJSFiles(IContainer aContainer, LinkedList files) { + try { + int i; + IResource[] members = aContainer.members(); + for (i = 0; i < members.length; i++) { + IResource aResource = members[i]; + if (aResource.getType() == IResource.FILE) { + IFile aFile = (IFile) aResource; + String ext = aFile.getFileExtension(); + if ((ext != null) && ext.equals("js")) { + files.add(aFile); + } + } else if (aResource.getType() == IResource.FOLDER) { + collectJSFiles((IFolder) aResource, files); + } + } + } catch (CoreException e) { + } + } + /** + * @param file + * + * @return + */ + + private List getSyntacticElements(IFile file) { + return (new JSParser()).parse(file); + } + + /** + * @param file + * + * @return + */ + private List getSyntacticElements(IDocument document) { + return (new JSParser()).parse(document); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSSyntaxScanner.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSSyntaxScanner.java new file mode 100644 index 0000000..544e96f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSSyntaxScanner.java @@ -0,0 +1,86 @@ +/* + * Created on May 16, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.core.parser; + +import java.util.ArrayList; +import java.util.List; +import org.eclipse.jface.text.rules.*; + +/** + * Scanner for detecting syntactic elements: comments, strings, classes, functions + * + * @author fitzpata + * + */ +public class JSSyntaxScanner extends BufferedRuleBasedScanner { + public final static String JS_DEFAULT = "__js_default"; + public final static String JS_COMMENT = "__js_comment"; + public final static String JS_FUNCTION = "__js_function"; + public final static String JS_STRING = "__js_string"; + public final static String JS_MEMBER = "__js_member"; + public final static String JS_PERIOD = "__js_period"; + + public final static IToken TOKEN_STRING = new Token(JS_STRING); + public final static IToken TOKEN_COMMENT = new Token(JS_COMMENT); + public final static IToken TOKEN_DEFAULT = new Token(JS_DEFAULT); + public final static IToken TOKEN_FUNCTION = new Token(JS_FUNCTION); + public final static IToken TOKEN_MEMBER = new Token(JS_MEMBER); + public final static IToken TOKEN_PERIOD = new Token(JS_PERIOD); + + /** + * String for detecting member declarations. + */ + private static String memberToken= ".prototype"; + + /** + * Creates a new JSSyntaxScanner object. + */ + public JSSyntaxScanner() { + List rules = new ArrayList(); + + rules.add(new MultiLineRule("/*", "*/", TOKEN_COMMENT)); + rules.add(new SingleLineRule("//", "", TOKEN_COMMENT)); + rules.add(new SingleLineRule("\"", "\"", TOKEN_STRING, '\\')); + rules.add(new SingleLineRule("'", "'", TOKEN_STRING, '\\')); + + rules.add(new WhitespaceRule(new JSWhitespaceDetector())); + + rules.add(new MultiLineRule("function(", ")", TOKEN_FUNCTION)); + rules.add(new MultiLineRule("function ", ")", TOKEN_FUNCTION)); + + rules.add(new WordRule(new JSWordDetector(), TOKEN_DEFAULT)); + rules.add(new PredicateWordRule(new JSReferenceDetector(), memberToken, TOKEN_MEMBER)); + + setRuleList(rules); + } + + + /** + * set the rule list + * @param rules + */ + private void setRuleList(List rules) + { + IRule[] result = new IRule[rules.size()]; + rules.toArray(result); + setRules(result); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSWhitespaceDetector.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSWhitespaceDetector.java new file mode 100644 index 0000000..625be0f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSWhitespaceDetector.java @@ -0,0 +1,52 @@ +/* + * $RCSfile: JSWhitespaceDetector.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.1 2003/05/28 15:17:12 agfitzp + * net.sourceforge.phpeclipse.js.core 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.core.parser; + +import org.eclipse.jface.text.rules.IWhitespaceDetector; + + +/** + * + * + * @author $Author: jsurfer $, $Date: 2004-09-02 18:14:38 $ + * + * @version $Revision: 1.1 $ + */ +public class JSWhitespaceDetector implements IWhitespaceDetector +{ + /** + * + * + * @param c + * + * @return + */ + public boolean isWhitespace(char c) + { + return (c == ' ' || c == '\t' || c == '\n' || c == '\r'); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSWordDetector.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSWordDetector.java new file mode 100644 index 0000000..98a69b4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/JSWordDetector.java @@ -0,0 +1,54 @@ +/* + * Created on May 13, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.core.parser; + +/** + * @author fitzpata + * + */ + +import org.eclipse.jface.text.rules.IWordDetector; + +/** + * A JavaScript aware word detector. + * JavaScript tokens are almost identical to Java so this + * class is borrowed from org.eclipse.jdt.internal.ui.text.JavaWordDetector. + */ +public class JSWordDetector implements IWordDetector { + + /** + * @see IWordDetector#isWordStart + * JavaScript tokens are almost identical to Java so for now + * we can just borrow this behavior. + */ + public boolean isWordStart(char c) { + return Character.isJavaIdentifierStart(c); + } + + /** + * @see IWordDetector#isWordPart + * JavaScript tokens are almost identical to Java so for now + * we can just borrow this behavior. + */ + public boolean isWordPart(char c) { + return Character.isJavaIdentifierPart(c); + } +} diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/NonRuleBasedDamagerRepairer.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/NonRuleBasedDamagerRepairer.java new file mode 100644 index 0000000..0f99bfd --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/NonRuleBasedDamagerRepairer.java @@ -0,0 +1,175 @@ +/* + * $RCSfile: NonRuleBasedDamagerRepairer.java,v $ + * + * Copyright 2002 + * CH-1700 Fribourg, Switzerland + * All rights reserved. + * + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.1 2003/05/28 15:17:11 agfitzp + * net.sourceforge.phpeclipse.js.core 0.0.1 code base + * + *======================================================================== +*/ + +package net.sourceforge.phpeclipse.js.core.parser; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.TextPresentation; +import org.eclipse.jface.text.presentation.IPresentationDamager; +import org.eclipse.jface.text.presentation.IPresentationRepairer; +//import org.eclipse.jface.util.Assert; +import org.eclipse.swt.custom.StyleRange; + + +/** + * + * + * @author $Author: jsurfer $, $Date: 2004-09-02 18:14:38 $ + * + * @version $Revision: 1.1 $ + */ +public class NonRuleBasedDamagerRepairer implements IPresentationDamager, IPresentationRepairer +{ + /** The document this object works on */ + protected IDocument fDocument; + + /** The default text attribute if non is returned as data by the current token */ + protected TextAttribute fDefaultTextAttribute; + + /** + * Constructor for NonRuleBasedDamagerRepairer. + * @param defaultTextAttribute + */ + public NonRuleBasedDamagerRepairer(TextAttribute defaultTextAttribute) + { +// Assert.isNotNull(defaultTextAttribute); + + fDefaultTextAttribute = defaultTextAttribute; + } + + /** + * @see IPresentationRepairer#setDocument(IDocument) + */ + public void setDocument(IDocument document) + { + fDocument = document; + } + + /** + * Returns the end offset of the line that contains the specified offset or if the offset is + * inside a line delimiter, the end offset of the next line. + * + * @param offset the offset whose line end offset must be computed + * + * @return the line end offset for the given offset + * + * @exception BadLocationException if offset is invalid in the current document + */ + protected int endOfLineOf(int offset) throws BadLocationException + { + IRegion info = fDocument.getLineInformationOfOffset(offset); + + if(offset <= info.getOffset() + info.getLength()) + { + return info.getOffset() + info.getLength(); + } + + int line = fDocument.getLineOfOffset(offset); + + try + { + info = fDocument.getLineInformation(line + 1); + + return info.getOffset() + info.getLength(); + } + catch(BadLocationException x) + { + return fDocument.getLength(); + } + } + + /** + * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean) + */ + public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, + boolean documentPartitioningChanged) + { + if(!documentPartitioningChanged) + { + try + { + IRegion info = fDocument.getLineInformationOfOffset(event.getOffset()); + int start = Math.max(partition.getOffset(), info.getOffset()); + + int end = event.getOffset() + + (event.getText() == null ? event.getLength() + : event.getText().length()); + + if(info.getOffset() <= end && end <= info.getOffset() + info.getLength()) + { + // optimize the case of the same line + end = info.getOffset() + info.getLength(); + } + else + { + end = endOfLineOf(end); + } + + end = Math.min(partition.getOffset() + partition.getLength(), end); + + return new Region(start, end - start); + } + catch(BadLocationException x) + { + } + } + + return partition; + } + + /** + * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion) + */ + public void createPresentation(TextPresentation presentation, ITypedRegion region) + { + addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextAttribute); + } + + /** + * Adds style information to the given text presentation. + * + * @param presentation the text presentation to be extended + * @param offset the offset of the range to be styled + * @param length the length of the range to be styled + * @param attr the attribute describing the style of the range to be styled + */ + protected void addRange(TextPresentation presentation, int offset, int length, + TextAttribute attr) + { + if(attr != null) + { + presentation.addStyleRange( + new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), + attr.getStyle())); + } + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/PredicateWordRule.java b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/PredicateWordRule.java new file mode 100644 index 0000000..d59d81c --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.js.core/src/net/sourceforge/phpeclipse/js/core/parser/PredicateWordRule.java @@ -0,0 +1,107 @@ +/* + * Created on May 13, 2003 + *======================================================================== + * Modifications history + *======================================================================== + * $Log: not supported by cvs2svn $ + * Revision 1.1 2004/02/26 02:25:42 agfitzp + * renamed packages to match xml & css + * + * Revision 1.1 2004/02/05 03:10:08 agfitzp + * Initial Submission + * + * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp + * Experimental work for Classes view + * + * Revision 1.2 2003/05/30 20:53:09 agfitzp + * 0.0.2 : Outlining is now done as the user types. Some other bug fixes. + * + *======================================================================== + */ +package net.sourceforge.phpeclipse.js.core.parser; + +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IPredicateRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.rules.WordRule; +import org.eclipse.jface.text.rules.IWordDetector; + +/** + * @author fitzpata + */ +public class PredicateWordRule extends WordRule implements IPredicateRule { + + /* (non-Javadoc) + * @see org.eclipse.jface.text.rules.IPredicateRule#getSuccessToken() + */ + + protected IToken successToken = Token.UNDEFINED; + + public void addWords(String[] tokens, IToken token) + { + for (int i = 0; i < tokens.length; i++) { + addWord(tokens[i], token); + } + + } + + public IToken getSuccessToken() { + return successToken; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.rules.IPredicateRule#evaluate(org.eclipse.jface.text.rules.ICharacterScanner, boolean) + */ + public IToken evaluate(ICharacterScanner scanner, boolean resume) { + successToken = this.evaluate(scanner, resume);//true); + return successToken; + } + + /** + * Creates a rule which, with the help of an word detector, will return the token + * associated with the detected word. If no token has been associated, the scanner + * will be rolled back and an undefined token will be returned in order to allow + * any subsequent rules to analyze the characters. + * + * @param detector the word detector to be used by this rule, may not be null + * + * @see #addWord + */ + + public PredicateWordRule(IWordDetector detector) { + super(detector); + } + + /** + * Creates a rule which, with the help of an word detector, will return the token + * associated with the detected word. If no token has been associated, the + * specified default token will be returned. + * + * @param detector the word detector to be used by this rule, may not be null + * @param defaultToken the default token to be returned on success + * if nothing else is specified, may not be null + * + * @see #addWord + */ + public PredicateWordRule(IWordDetector detector, IToken defaultToken) { + super(detector, defaultToken); + } + + + public PredicateWordRule(IWordDetector detector, String tokenString, IToken tokenType) { + super(detector); + this.addWord(tokenString, tokenType); + } + + public PredicateWordRule(IWordDetector detector, String[] tokens, IToken tokenType) { + super(detector); + this.addWords(tokens, tokenType); + } + + public PredicateWordRule(IWordDetector detector, IToken defaultToken, String[] tokens, IToken tokenType) { + super(detector, defaultToken); + this.addWords(tokens, tokenType); + } + +} diff --git a/net.sourceforge.phpeclipse.core/.classpath b/net.sourceforge.phpeclipse.core/.classpath new file mode 100644 index 0000000..065ac06 --- /dev/null +++ b/net.sourceforge.phpeclipse.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/net.sourceforge.phpeclipse.core/.cvsignore b/net.sourceforge.phpeclipse.core/.cvsignore new file mode 100644 index 0000000..ba077a4 --- /dev/null +++ b/net.sourceforge.phpeclipse.core/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/net.sourceforge.phpeclipse.core/.project b/net.sourceforge.phpeclipse.core/.project new file mode 100644 index 0000000..09c002a --- /dev/null +++ b/net.sourceforge.phpeclipse.core/.project @@ -0,0 +1,28 @@ + + + net.sourceforge.phpeclipse.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/net.sourceforge.phpeclipse.core/build.properties b/net.sourceforge.phpeclipse.core/build.properties new file mode 100644 index 0000000..212d6fb --- /dev/null +++ b/net.sourceforge.phpeclipse.core/build.properties @@ -0,0 +1,4 @@ +source.webcore.jar = src/ +output.webcore.jar = bin/ +bin.includes = plugin.xml,\ + webcore.jar diff --git a/net.sourceforge.phpeclipse.core/plugin.xml b/net.sourceforge.phpeclipse.core/plugin.xml new file mode 100644 index 0000000..4e119fa --- /dev/null +++ b/net.sourceforge.phpeclipse.core/plugin.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/WebCore.java b/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/WebCore.java new file mode 100644 index 0000000..52621b2 --- /dev/null +++ b/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/WebCore.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: WebCore.java,v 1.1 2004-09-02 18:05:22 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.core; + +import org.eclipse.core.runtime.Plugin; + +//import net.sourceforge.phpeclipse.core.parser.ISourceParser; + +/** + * The main plugin class to be used in the desktop. + */ +public class WebCore extends Plugin { + + // Instance Variables ------------------------------------------------------ + + /** The shared instance. */ + private static WebCore plugin; + + // Constructors ------------------------------------------------------------ + + /** + * The constructor. + */ + public WebCore() { + plugin = this; + } + + // Public Methods ---------------------------------------------------------- + + /** + * Returns the shared instance. + */ + public static WebCore getDefault() { + return plugin; + } + + /** + * Creates and returns a parser that can handle resources of the specified + * MIME type. + * + * @param mimeType the MIME type of the resource for which a parser should + * be created + * @return the instantiated parser, or null if no parser for that + * MIME type is registered + */ +// public ISourceParser createParser(String mimeType) { +// return null; +// } +} diff --git a/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/ISourceModel.java b/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/ISourceModel.java new file mode 100644 index 0000000..7c63cbb --- /dev/null +++ b/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/ISourceModel.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial implementation + * + * $Id: ISourceModel.java,v 1.1 2004-09-02 18:05:21 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.core.model; + +/** + * + */ +public interface ISourceModel { + + /** + * Returns the top-level elements of the source model. + * + * @return an array of the top-level elements + */ + ISourceReference[] getElements(); + + /** + * Returns the elements that are direct children of the given element. + * + * @param element the element for which to return the child elements + * @return an array of child elements, or an empty array if the given + * element has no children + */ + ISourceReference[] getChildren(ISourceReference element); + + /** + * Returns the direct parent element of the specified element. + * + * @param element the element for which the parent should be returned + * @return the parent element, or null if the specified element + * does not have a parent (meaning it is a top-level element) + */ + ISourceReference getParent(ISourceReference element); + +} diff --git a/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/ISourceReference.java b/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/ISourceReference.java new file mode 100644 index 0000000..b5efffa --- /dev/null +++ b/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/ISourceReference.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API + * + * $Id: ISourceReference.java,v 1.1 2004-09-02 18:05:21 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.core.model; + +import org.eclipse.jface.text.IRegion; + +/** + * Common protocol for model elements that have associated source code. + */ +public interface ISourceReference { + + /** + * Returns the source code associated with this model element. + * + *

+ * This method extracts the substring from the source buffer containing + * this source element. This corresponds to the source regione that would + * be returned by {@link ISourceReference#getSourceRegion()}. + *

+ * + * @return The source code, or null if this element has no + * associated source code + */ + String getSource(); + + /** + * Returns the source range associated with this element. + * + * @return The source region, or null if this element has no + * associated source code + */ + IRegion getSourceRegion(); + +} diff --git a/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/SourceReference.java b/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/SourceReference.java new file mode 100644 index 0000000..ece105c --- /dev/null +++ b/net.sourceforge.phpeclipse.core/src/net/sourceforge/phpeclipse/core/model/SourceReference.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2003-2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: SourceReference.java,v 1.1 2004-09-02 18:05:21 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.core.model; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Region; + +/** + * Default implementation of {@link ISourceReference} based on + * {@link IDocument}. + */ +public class SourceReference implements ISourceReference { + + // Instance Variables ------------------------------------------------------ + + /** The associated document. */ + private IDocument document; + + /** The region in the document that maps to the source reference. */ + private IRegion sourceRegion; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param document The document that contains the source reference + */ + public SourceReference(IDocument document) { + this(document, 0, 0); + } + + /** + * Constructor. + * + * @param document The document that contains the source reference + */ + public SourceReference(IDocument document, int offset) { + this(document, offset, 0); + } + + /** + * Constructor. + * + * @param document The document that contains the source reference + */ + public SourceReference(IDocument document, int offset, int length) { + this.document = document; + this.sourceRegion = new Region(offset, length); + } + + // ISourceReference Implementation ----------------------------------------- + + /* + * @see ISourceReference#getSource() + */ + public String getSource() { + try { + return document.get(sourceRegion.getOffset(), + sourceRegion.getLength()); + } catch (BadLocationException e) { + throw new IllegalStateException( + "Model not synchronized with document"); //$NON-NLS-1$ + } + } + + /* + * @see ISourceReference#getSourceRegion() + */ + public IRegion getSourceRegion() { + return sourceRegion; + } + + // Public Methods ---------------------------------------------------------- + + /** + * Sets the source region covered by the element. + * + * @param offset the offset of the region + * @param length the length of the region + */ + public final void setSourceRegion(int offset, int length) { + sourceRegion = new Region(offset, length); + } + + /** + * Sets the source region covered by the element. + * + * @param region the source region to set + */ + public final void setSourceRegion(IRegion region) { + setSourceRegion(region.getOffset(), region.getLength()); + } + + // Protected Methods ------------------------------------------------------- + + /** + * Returns the underlying document. + * + * @return the underlying document + */ + protected final IDocument getDocument() { + return document; + } + +} -- 1.7.1