Skip to content

Commit

Permalink
Merge branch 'dummy-text-generator'
Browse files Browse the repository at this point in the history
  • Loading branch information
junichi11 committed Aug 30, 2013
2 parents 66d54c3 + 0ebc3f1 commit 00decdc
Show file tree
Hide file tree
Showing 10 changed files with 801 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Support for some small features.
## Features

- Smart delete (Ctrl + Shift + BACK_SPACE)
- Generate dummy text (Alt + Insert > Dummy Text)

### Smart delete

Expand All @@ -26,6 +27,16 @@ e.g.
<?php $somethingVariable;?> -> <?php $;?>
```

### Generate dummy text

We can use this feature on PHP and Html editors.
Please set base text on the Dialog. It will be looped with option.

#### options

- loop count
- text length

## License

[Common Development and Distribution License (CDDL) v1.0 and GNU General Public License (GPL) v2](http://netbeans.org/cddl-gplv2.html)
2 changes: 1 addition & 1 deletion manifest.mf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Manifest-Version: 1.0
OpenIDE-Module: com.junichi11.netbeans.php.enhancements
OpenIDE-Module-Localizing-Bundle: com/junichi11/netbeans/php/enhancements/Bundle.properties
OpenIDE-Module-Specification-Version: 0.1.2
OpenIDE-Module-Specification-Version: 0.2.0

4 changes: 2 additions & 2 deletions nbproject/genfiles.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build.xml.data.CRC32=3ff2120d
build.xml.data.CRC32=0c89d8c8
build.xml.script.CRC32=fcc7be51
build.xml.stylesheet.CRC32=[email protected]
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=3ff2120d
nbproject/build-impl.xml.data.CRC32=0c89d8c8
nbproject/build-impl.xml.script.CRC32=17f3ae36
nbproject/build-impl.xml.stylesheet.CRC32=[email protected]
26 changes: 26 additions & 0 deletions nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
<specification-version>1.71.2.5.21.40</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.editor.codetemplates</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.30.1.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
<build-prerequisite/>
Expand All @@ -24,6 +33,15 @@
<specification-version>1.71.2.40</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.29.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.lexer</code-name-base>
<build-prerequisite/>
Expand All @@ -49,6 +67,14 @@
<specification-version>7.55.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.dialogs</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.28.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.filesystems</code-name-base>
<build-prerequisite/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2013 Oracle and/or its affiliates. All rights reserved.
*
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
* Development and Distribution License("CDDL") (collectively, the
* "License"). You may not use this file except in compliance with the
* License. You can obtain a copy of the License at
* http://www.netbeans.org/cddl-gplv2.html
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
* specific language governing permissions and limitations under the
* License. When distributing the software, include this License Header
* Notice in each file and include the License file at
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the
* License Header, with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* If you wish your version of this file to be governed by only the CDDL
* or only the GPL Version 2, indicate your decision by adding
* "[Contributor] elects to include this software in this distribution
* under the [CDDL or GPL Version 2] license." If you do not indicate a
* single choice of license, a recipient has the option to distribute
* your version of this file under either the CDDL, the GPL Version 2 or
* to extend the choice of license to its licensees as provided above.
* However, if you add GPL Version 2 code and therefore, elected the GPL
* Version 2 license, then the option applies only if the new code is
* made subject to such option by the copyright holder.
*
* Contributor(s):
*
* Portions Copyrighted 2013 Sun Microsystems, Inc.
*/
package com.junichi11.netbeans.php.enhancements.editor.generator;

import com.junichi11.netbeans.php.enhancements.editor.generator.ui.DummyTextPanel;
import java.awt.Dialog;
import java.util.Collections;
import java.util.List;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
import org.netbeans.api.editor.mimelookup.MimeRegistrations;
import org.netbeans.lib.editor.codetemplates.api.CodeTemplate;
import org.netbeans.lib.editor.codetemplates.api.CodeTemplateManager;
import org.netbeans.spi.editor.codegen.CodeGenerator;
import org.netbeans.spi.editor.codegen.CodeGeneratorContextProvider;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;

public class DummyTextGenerator implements CodeGenerator {

JTextComponent textComp;

/**
*
* @param context containing JTextComponent and possibly other items
* registered by {@link CodeGeneratorContextProvider}
*/
private DummyTextGenerator(Lookup context) { // Good practice is not to save Lookup outside ctor
textComp = context.lookup(JTextComponent.class);
}

@MimeRegistrations({
@MimeRegistration(mimeType = "text/x-php5", service = CodeGenerator.Factory.class),
@MimeRegistration(mimeType = "text/html", service = CodeGenerator.Factory.class)
})
public static class Factory implements CodeGenerator.Factory {

@Override
public List<? extends CodeGenerator> create(Lookup context) {
JTextComponent jtc = context.lookup(JTextComponent.class);
if (jtc == null) {
return Collections.emptyList();
}
return Collections.singletonList(new DummyTextGenerator(context));
}
}

/**
* The name which will be inserted inside Insert Code dialog
*/
@NbBundle.Messages("DummyTextGenerator.DisplayName=Dummy Text")
@Override
public String getDisplayName() {
return Bundle.DummyTextGenerator_DisplayName();
}

/**
* This will be invoked when user chooses this Generator from Insert Code
* dialog
*/
@Override
public void invoke() {
Document document = textComp.getDocument();
if (document == null) {
return;
}

// create dialog
DummyTextPanel dummyTextPanel = DummyTextPanel.getDefault();
DialogDescriptor descriptor = new DialogDescriptor(dummyTextPanel, Bundle.DummyTextGenerator_DisplayName());
Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor);
dialog.setVisible(true);
dialog.dispose();

if (descriptor.getValue() == DialogDescriptor.OK_OPTION) {
// text for inserting
String text = dummyTextPanel.getInsertText();
if (text == null || text.isEmpty()) {
return;
}

// insert code with CodeTemplateManager
CodeTemplateManager templateManager = CodeTemplateManager.get(document);
CodeTemplate codeTemplate = templateManager.createTemporary(text);
codeTemplate.insert(textComp);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DummyTextPanel.textLabel.text=Text:
DummyTextPanel.loopCheckBox.text=&Loop:
DummyTextPanel.textLengthRadioButton.text=Text Len&gth
DummyTextPanel.loopCountRadioButton.text=Loop &Count
DummyTextPanel.saveAsDefaultButton.text=Save as Default
DummyTextPanel.loadDefaultButton.text=Load Default
Loading

0 comments on commit 00decdc

Please sign in to comment.