Skip to content

Commit 226ca06

Browse files
committed
Adjust Project handling to look for python specific files instead of customer.txt
1 parent 8d7bb03 commit 226ca06

File tree

5 files changed

+39
-18
lines changed

5 files changed

+39
-18
lines changed

pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
<plugin>
2828
<groupId>org.apache.maven.plugins</groupId>
2929
<artifactId>maven-jar-plugin</artifactId>
30-
<!-- <version>3.2.2</version> -->
3130
<version>3.1.2</version>
3231
<configuration>
3332
<archive>
@@ -169,7 +168,6 @@
169168
<groupId>org.netbeans.api</groupId>
170169
<artifactId>org-netbeans-modules-projectuiapi</artifactId>
171170
<version>RELEASE126</version>
172-
<scope>provided</scope>
173171
</dependency>
174172
<dependency>
175173
<groupId>org.netbeans.api</groupId>

src/main/java/org/apache/netbeans/modules/python4nb/editor/file/MIMETypes.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ private MIMETypes() {
3131
public static final String PY = "text/x-python";
3232
public static final String PYC = "application/x-python-code";
3333
public static final String PYO = "application/x-python-code";
34+
35+
public static final String PY_EXT = "py";
36+
public static final String PYC_EXT = "pyc";
37+
public static final String PYO_EXT = "pyo";
3438
}

src/main/java/org/apache/netbeans/modules/python4nb/editor/file/PythonFile.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.netbeans.api.annotations.common.CheckForNull;
4949
import org.netbeans.api.annotations.common.NonNull;
5050
import org.netbeans.api.annotations.common.NullAllowed;
51+
import org.netbeans.api.annotations.common.StaticResource;
5152
import org.netbeans.modules.editor.indent.api.Reformat;
5253
import org.netbeans.modules.web.clientproject.api.util.WatchedFile;
5354
import org.openide.cookies.EditorCookie;
@@ -65,6 +66,9 @@
6566
*/
6667
public final class PythonFile {
6768

69+
@StaticResource()
70+
public static final String PYTHON_ICON = "org/apache/netbeans/modules/python4nb/editor/py.png";
71+
6872
private static final Logger LOGGER = Logger.getLogger(PythonFile.class.getName());
6973

7074
// TODO: Determine if some python equivalent needed here

src/main/java/org/apache/netbeans/modules/python4nb/project/PythonProject.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class PythonProject implements Project {
4949
private final ProjectState state;
5050
private Lookup lkp;
5151

52+
53+
@StaticResource()
54+
public static final String PYTHON_PROJECT_ICON = "org/apache/netbeans/modules/python4nb/editor/py_module.png";
5255
PythonProject(FileObject dir, ProjectState state) {
5356
this.projectDir = dir;
5457
this.state = state;
@@ -64,9 +67,8 @@ public Lookup getLookup() {
6467
if (lkp == null) {
6568
lkp = Lookups.fixed(new Object[]{
6669
new PythonInfo(),
67-
// new PythonProjectLogicalView(this)
68-
// ,
69-
// new CustomizerProvider() {
70+
new PythonProjectLogicalView(this)
71+
// , new CustomizerProvider() {
7072
// @Override
7173
// public void showCustomizer() {
7274
// JOptionPane.showMessageDialog(
@@ -84,12 +86,13 @@ public Lookup getLookup() {
8486

8587
private final class PythonInfo implements ProjectInformation {
8688

87-
@StaticResource()
88-
public static final String PYTHON_ICON = "org/apache/netbeans/modules/python4nb/editor/py.png";
89+
//@StaticResource()
90+
// public static final String PYTHON_ICON = "org/apache/netbeans/modules/python4nb/editor/py.png";
8991

9092
@Override
9193
public Icon getIcon() {
92-
return new ImageIcon(ImageUtilities.loadImage(PYTHON_ICON));
94+
return new ImageIcon(ImageUtilities.loadImage(PYTHON_PROJECT_ICON));
95+
// return new ImageIcon(ImageUtilities.loadImage(PYTHON_ICON));
9396
}
9497

9598
@Override
@@ -120,8 +123,11 @@ public Project getProject() {
120123

121124
class PythonProjectLogicalView implements LogicalViewProvider {
122125

123-
@StaticResource()
124-
public static final String PYTHON_ICON = "org/apache/netbeans/modules/python4nb/editor/py.png";
126+
// @StaticResource()
127+
// public static final String PYTHON_ICON = "org/apache/netbeans/modules/python4nb/editor/py.png";
128+
//
129+
// @StaticResource()
130+
// public static final String PYTHON_PROJECT_ICON = "org/apache/netbeans/modules/python4nb/editor/py_module.png";
125131

126132
private final PythonProject project;
127133

@@ -170,12 +176,15 @@ public Action[] getActions(boolean arg0) {
170176
CommonProjectActions.deleteProjectAction(),
171177
CommonProjectActions.customizeProjectAction(),
172178
CommonProjectActions.closeProjectAction()
179+
// TODO Establish applicable Python Project Actions
180+
// , CommonProjectActions.TODO (see auto completion)
173181
};
174182
}
175183

176184
@Override
177185
public Image getIcon(int type) {
178-
return ImageUtilities.loadImage(PYTHON_ICON);
186+
// return ImageUtilities.loadImage(PYTHON_ICON);
187+
return ImageUtilities.loadImage(PYTHON_PROJECT_ICON);
179188
}
180189

181190
@Override
@@ -187,7 +196,6 @@ public Image getOpenedIcon(int type) {
187196
public String getDisplayName() {
188197
return project.getProjectDirectory().getName();
189198
}
190-
191199
}
192200

193201
@Override

src/main/java/org/apache/netbeans/modules/python4nb/project/PythonProjectFactory.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.apache.netbeans.modules.python4nb.project;
1717

1818
import java.io.IOException;
19+
import org.apache.netbeans.modules.python4nb.editor.file.MIMETypes;
1920
import org.netbeans.api.project.Project;
2021
import org.netbeans.spi.project.ProjectFactory;
2122
import org.netbeans.spi.project.ProjectState;
@@ -25,20 +26,26 @@
2526
*
2627
* @author ebres
2728
*/
28-
29-
30-
3129

3230
@ServiceProvider(service=ProjectFactory.class)
3331
public class PythonProjectFactory implements ProjectFactory {
3432

35-
public static final String PROJECT_FILE = "customer.txt";
36-
3733
//Specifies when a project is a project, i.e.,
3834
//if "customer.txt" is present in a folder:*
3935
@Override
4036
public boolean isProject(FileObject projectDirectory) {
41-
return projectDirectory.getFileObject(PROJECT_FILE) != null;
37+
// search if there are any
38+
FileObject[] childen = projectDirectory.getChildren();
39+
boolean isPythonProject = false;
40+
for (FileObject file: childen) {
41+
if (file.existsExt(MIMETypes.PY_EXT) ||
42+
file.existsExt(MIMETypes.PYC_EXT) ||
43+
file.existsExt(MIMETypes.PYO_EXT)
44+
) {
45+
isPythonProject = true;
46+
}
47+
}
48+
return isPythonProject;
4249
}
4350

4451
//Specifies when the project will be opened, i.e., if the project exists:*

0 commit comments

Comments
 (0)