jEdit Community - Resources for users of the jEdit Text Editor
Current project directory
Submitted by takeshin on Saturday, 1 November, 2008 - 12:11
Hi!

How to get current project directory? (stored in ProjectViewer's xml)
I'd like to have action "add new file to this project".

--
takeshin
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
:)
by elberry on Sun, 02/11/2008 - 17:42
It's in the documentation for the ProjectViewer plugin under "Getting the project of the given view".

[code]
VPTProject prj=ProjectViewer.getActiveProject(org.gjt.sp.jedit.View aView);
ProjectViewer pv=ProjectViewer.getViewer(org.gjt.sp.jedit.View view);

[/code]

Basically if you want to write some beanshell (a macro, or action) to get the ProjectViewer for the current view, you just write something like:
[code]
VPTProject prj=ProjectViewer.getActiveProject(view);
ProjectViewer pv=ProjectViewer.getViewer(view);

[/code]

Learn from the past. Live in the present. Plan for the future.
11101000
Blog
 
null
by takeshin on Mon, 03/11/2008 - 09:44
I want to determine the path to last used project (or project selected in ProjectViewer pane) to add a new file to this project.

When I create a new file, or open non project file, this code always returns null:


import projectviewer.ProjectViewer;
import projectviewer.vpt.VPTProject;

VPTProject prj=ProjectViewer.getActiveProject(view);
ProjectViewer pv=ProjectViewer.getViewer(view);
Macros.message(view, "Current project is: " + pv);


So I am unable to do what I want - save the file automatically to project path (attach the file to the project).
I tried to retrieve VPTNode, but it also returns null.

I suppose the best way would be to add this feature to ProjectViewer plugin, because now we need to browse all directories to add new files to the projects.

--
regards,
takeshin
 
I've had this problem too. Do
by elberry on Mon, 03/11/2008 - 21:16
I've had this problem too. Double check to make sure you actually have a project selected in the ProjectViewer.

Sometimes jEdit starts up and the project viewer doesn't have a project selected.

Learn from the past. Live in the present. Plan for the future.
11101000
Blog
 
indeed :)
by takeshin on Tue, 04/11/2008 - 21:25
Thanks.
Finally, here is my macro to save current buffer to current project directory:


import projectviewer.ProjectViewer;
import projectviewer.vpt.VPTProject;
import projectviewer.vpt.VPTNode;

void saveFile(String path) {
String name = Macros.input(view, "Filename (without path)", buffer.getName());
if (name == "Untitled-1" || name == "Untitled-2") {
name = "index.php";
}
path = path + System.getProperty("file.separator") + name;
buffer.save(view, path);
}

void newProjectFile() {
VPTProject prj=ProjectViewer.getActiveProject(view);
ProjectViewer pv=ProjectViewer.getViewer(view);
if (pv == null) {
Macros.error(view, "Please select project in ProjectViewer.");
return;
}
VPTNode node = pv.getSelectedNode();
if (node == null) {
node = pv.getRoot();
}
if (node.isProject() || node.isProject()) {
String path = node.getNodePath();
saveFile(path);
} else if (node.isFile()) {
String path = new File(node.getNodePath()).getParent();
saveFile(path);
} else {
Macros.error(view, "Please select project, directory or file.");
}
}

newProjectFile();



But now, I do not know (yet), how to make ProjectViewer automatically import this file Smiling
Any hints?

--
takeshin
 
I actually did something diff
by alourie on Tue, 02/12/2008 - 10:00
I actually did something different. I wanted to "Add file to a project" without creating a new buffer manually first. So I've made the following macro:

_____________________________________________

import projectviewer.ProjectViewer;
import projectviewer.vpt.VPTProject;
import projectviewer.vpt.VPTNode;

void CreateFile(String path, Buffer buff) {
String name = Macros.input(view, "Filename (without path)", buffer.getName());
if (name == "Untitled-1" || name == "Untitled-2") {
name = "index.php";
}
path = path + System.getProperty("file.separator") + name;

buff.save(view, path);
}

void newProjectFile() {
jEdit.newFile(view);
Buffer buff = buffer.getNext();
VPTProject prj=ProjectViewer.getActiveProject(view);
ProjectViewer pv=ProjectViewer.getViewer(view);
if (pv == null) {
Macros.error(view, "Please select project in ProjectViewer.");
return;
}
VPTNode node = pv.getSelectedNode();
if (node == null) {
node = pv.getRoot();
}
if (node.isDirectory() || node.isProject()) {
String path = node.getNodePath();
CreateFile(path, buff);
} else if (node.isFile()) {
String path = new File(node.getNodePath()).getParent();
CreateFile(path, buff);
} else {
Macros.error(view, "Please select project, directory or file.");
}
}

newProjectFile();
______________________________________



Then, I went to ProjectViewer plugin options, and added this macro to context menu.

Now, if I select any directory/file/root in a ProjectViewer, click right mouse button and select newProjectFile, I get nice dialog asking for file name, and then new buffer opens with this name and it also gets automatically added to the project in correct location (for example, if directory was selected, it will be added in that directory).
User login
Browse archives
« November 2024  
MoTuWeThFrSaSu
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   101634
Context Free Art (*.cfdg)   0.31   46062
BBEdit scheme   1.0   18601
JBuilder scheme   .001   18502
ColdFusion scheme   1.0   18031
R Edit Mode - extensive version   0.1   17481
Advanced HTML edit mode   1.0   16213
Matlab Edit Mode   1.0   16075
jEdit XP icons   1.0   15236
XP icons for jEdit   1.1   14300