Getting project data when using external execution.
-
When I run an external command I need the information about the current project. A list of the files would be ideal but even the address of the ‘prjs’ file would be adequate.
Is there a current parameter that will allow this? -
@grandad
Is this a question about code you are writing in Notepad++, or a question about Notepad++ itself? Because this is not a general programming forum. That’s what StackOverflow is for. -
@grandad said in Getting project data when using external execution.:
need the information about the current project
First, Notepad++ doesn’t have great “project” support. You may end up disappointed. :-(
By “project”, what do you mean? If you mean the editing tabs representing all of the files you currently have loaded, then you really mean the “session”, and information about that can be obtained by looking at
session.xml
.If you really do mean “project” as in Project1, Project2, or Project3, then these are wrapped in a “workspace” file that is also xml but doesn’t have a fixed name; you assign the name when you save the project workspace.
So, really, some more info is probably needed from you in order to answer you better.
-
@Alan-Kilborn
I have a script to create a program from several source files using a custom assembler and I am looking for a simple way of providing a simple IDE. It appears that Notepad++ has all the capabilities to do this as a quick fix without getting into modifying a current IDE with its obscure documentation.I collect all the files for the make in a single ‘project’ as in the ‘project panel’.
I need to acquire the file list for this project.
A list of these files would be ideal.
An alternative would be a pointer the project file which would be adequate if I only include one project in each workspace or the project file and project name would allow more than one project/workspace. -
@grandad said in Getting project data when using external execution.:
I need to acquire the file list for this project.
When you open the View > Project Panels > Project Panel N and Save a new Workspace, you picked the name and location of the Workspace file. This Workspace file is what holds the list of filenames. So whereever you saved that Workspace file is where it is. If you’ve forgotten, you can hover over the Workspace name, and it will show you:
If you open that file, then it will be (as Alan said) an XML file, which includes a list of all the projects, folders, and referenced files in that Workspace.
-
Here’s an demo PythonScript that can obtain project and filepath data from a Notepad++ workspace file. I call it
ParseWorkspaceForProjectFileList.py
and here is its listing:# -*- coding: utf-8 -*- from __future__ import print_function # references: # https://community.notepad-plus-plus.org/topic/25466 # for newbie info on PythonScripts, see https://community.notepad-plus-plus.org/topic/23039/faq-desk-how-to-install-and-run-a-script-in-pythonscript from Npp import * import xml.etree.ElementTree as et # https://docs.python.org/3/library/xml.etree.elementtree.html #------------------------------------------------------------------------------- class PWFPFL(object): def __init__(self): workspace_filepath = r'C:\...' # <-- put your workspace file path here! root_node = et.parse(workspace_filepath) output_line_list = [] eol = [ '\r\n', '\r', '\n' ][editor.getEOLMode()] for proj_node in root_node.iter('Project'): output_line_list.append(proj_node.attrib['name']) for file_node in proj_node.iter('File'): output_line_list.append('\t' + file_node.attrib['name']) notepad.new() editor.setText(eol.join(output_line_list)) #------------------------------------------------------------------------------- if __name__ == '__main__': PWFPFL()
The script creates output in a new Notepad++ tab as follows:
project name for first project
tab then filepath1 for first project
tab then filepath2 for first project
tab then filepath… for first project
project name for second project (if second project present)
tab then filepath1 for first project
tab then filepath2 for first project
tab then filepath… for first project
…Note that workspace files can contain multiple “projects” and projects can have “folders” embedded in them. The demo script simply lists out all projects, and ignores folders (but pulls their contained files into the output).
Obviously, you can change the script to pull whatever you need and put it in whatever format you desire, e.g., direct text file output to disk in the format needed for whatever tool you are going to feed it into.
-
-
@Alan-Kilborn
I need to demonstrate:I have a project in the project panel:
Having selected the projectdata entry I now run the command Compile which is as follows:
This is fine for the current open file but I need something instead of $(FULL_CURRENT_PATH)
that will give me the file name and location of the workspace (prjs) and the name of the project (projectdata) or the list of files in the project.I know I can get this information manually.
I could get <ProjectPanels> from the config.xml file and the project file from this but I do not know which panel is selected or which project within the file to use.I hope this is enough explanation of my problem.
-
Reference back a few posts where I said:
First, Notepad++ doesn’t have great “project” support. You may end up disappointed.
I think we’re at that point now.
Maybe you would consider putting in a FEATURE REQUEST to hopefully achieve what you’re after.
-
@grandad ,
Notepad++ is not a full IDE, and doesn’t know about the project in the same way that Visual Studio has the full .vcxproj to track all the files that need to be involved in a compile action.
What many Notepad++ users do is they write an NppExec script that includes more of the logic. NppExec is a plugin which provides a “batch” language for doing actions that are too complex for the simple Run-menu entries. But even NppExec cannot extract that information from the Project Panel GUI interface.
Notepad++ doesn’t provide an easy API for plugins to use to extract information from the Project Panel. You either have to be willing to parse the project-panel’s Workspace file, or you need to use arcane Win32 API calls to find the active Project Panel GUI elements and extract the needed information. (And if you have multiple Project Panels, and thus multiple Workspace files you’d have to search, then you would either have to search them all and figure out based on which Workspace file includes the active filename, or you would have to use the Win32 API to extract which Project Panel and Workspace file are active.)
If you have a Makefile, or some similar file that your compiler/linker understands (like maybe it understands your
.prjs
file; though I will call it the Makefile for this example), a common idiom using a NppExec would be to start in the directory for the active file: if that directory contains the Makefile, then run the compiler with that Makefile; if not, go up a directory and try again; keep searching up until it finds the Makefile; if it reaches the root without finding a Makefile, you should exit out (or otherwise define what you want to do). (Similar logic could of course be programmed in a script for the PythonScript plugin or similar automation plugins.) -
@PeterJones
OK. I get the picture now. Although notepad++ has many features - great editing and the ability to run external programs - it lacks the ability to handle projects properly.The ability to have $(CURRENT_PROJECT_FILE) and $(CURRENT_PROJECT_NAME) is all it would take.
Although notepad++ is my editor of choice I will just have to ‘bite the bullet’ and carry on as I currently do. I manually create a file containing the file list and compile that.
I can currently do what I require by creating the panel information file in my data directory with the extension npp then looking for this file in the current addressed directory. Only one project/directory allowed.