Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to move a file to project #95

Open
tukusejssirs opened this issue Oct 7, 2020 · 4 comments
Open

Option to move a file to project #95

tukusejssirs opened this issue Oct 7, 2020 · 4 comments

Comments

@tukusejssirs
Copy link

I think that this feature request is a bit out of scope of Project Manager, but still it might a be a good idea to implement it.

I’d like to be able to move currently open file to a specific project. Just open the Project Manager, select Move this file to a project, a list of projects opens, I select a specific project and that file is closed in the current window, and it is opened (appended) in the selected project, preferably in background [i.e. (1) the file in that project won’t be open in foreground; (2) if the particular project is not open, it should not be open after file is moved].

Why this should be implemented in Project Manager? Your package manages projects and already provides the list of projects. 😃

@tukusejssirs
Copy link
Author

@Val95240, sorry to mention you, but I have forgotten I have already requested this feature and today came to my mind again.

Would this feature be interesting to you? Would you try to implement this please? If not, could you just point me how I could accomplish this?

IMHO the project list pop-up is already implemented in PM, therefore it is easy to call up, but how could I simply move a tab to another project? I might be easier to move it to an open project, but what about one that is currently not open (i.e. it is only saved in Projects/)? Would we need to open it prior to adding (appending a file)? Or would we simply load the JSON into memory, add a subobject to buffers? Or is there a way to append a file using one of the ST libraries?

Thanks for reply! 😉

@Val95240
Copy link

Val95240 commented Jul 3, 2021

Hey !
In my opinion, this feature is too specific to be implemented in the general plugin, even if the necessary modifications shouldn't be too difficult to add. In Sublime, projects correspond to folders rather than to individual files, so transferring a single file not included in the projects' folders is quite peculiar, and I don't think it is standard enough to be in ProjectManager.

In my opinion, the most direct way of implementing that behavior would indeed be to load the JSON of the target workspace into memory and add a sub-object to buffers. The code to select the target workspace could be reused from the main run method in the main Plugin class.

Sorry for not adding this feature, but don't hesitate to ask me other questions !

@tukusejssirs
Copy link
Author

Thanks, @Val95240, for your comment! 😉

In my opinion, this feature is too specific to be implemented in the general plugin, even if the necessary modifications shouldn't be too difficult to add.

I see. Then I’d like to have a separate plugin with a dependency on Project Manager. 😉

In Sublime, projects correspond to folders rather than to individual files, so transferring a single file not included in the projects' folders is quite peculiar, and I don't think it is standard enough to be in ProjectManager.

Well, I meant workspaces instead of projects actually. 😉 That is: I’d like to move a tab (be it a file or just an unsaved buffer) to another workspace selected from a list of workspaces.

In my opinion, the most direct way of implementing that behavior would indeed be to load the JSON of the target workspace into memory and add a sub-object to buffers. The code to select the target workspace could be reused from the main run method in the main Plugin class.

Sorry for not adding this feature, but don't hesitate to ask me other questions !

No problem with not adding the feature, but could at least help me with the basic algorithm implementation? ATM, I have just one big question:

  1. How can I get the buffer of the active tab?
    • It is quite easy to get a buffer of a file that is already saved to disk (not all modifications has to be saved to disk), because each buffer object contains a file property with value of absolute path of the file, which might be quite easy to match with the active tab filename, but what about unsaved buffers (they contain only content, settings and undo_stack properties)? Should we match than the whole content?
    • I have just became aware of a limitation: the workspaces (with all the buffers) are not saved immediately when a buffer changes, but when the workspace is closed. It may be saved in intervals of some time periods, but when I closed a file a buffere and opened that particular workspace file (*.sublime-workspace), the change was not yet there. Don’t you know how could be check if the particular workspace is open and if so, how could we directly access the workspace data in memory used by Sublime Text?

@Val95240
Copy link

Val95240 commented Jul 7, 2021

It is quite easy to get a buffer of a file that is already saved to disk (not all modifications has to be saved to disk), because each buffer object contains a file property with value of absolute path of the file, which might be quite easy to match with the active tab filename, but what about unsaved buffers (they contain only content, settings and undo_stack properties)? Should we match than the whole content?

I can't see another method than matching the whole content in the case of unsaved buffers, so that's indeed what I'd do.


I have just became aware of a limitation: the workspaces (with all the buffers) are not saved immediately when a buffer changes, but when the workspace is closed. It may be saved in intervals of some time periods, but when I closed a file a buffere and opened that particular workspace file (*.sublime-workspace), the change was not yet there. Don’t you know how could be check if the particular workspace is open and if so, how could we directly access the workspace data in memory used by Sublime Text?

Unfortunately, Sublime Text is quite opaque with its use of workspace files and I don't think it is possible to access the underlying data in memory.
To find if a given workspace is open, I don't think you could do it in Sublime Text 3, but with Sublime Text 4 they introduced the window.workspace_file_name() function that returns the path to the currently used workspace file. So you could do something like:

for win in sublime.windows():
    if win.workspace_file_name() == target_workspace:
        print("Workspace open")
        break

(that's already what I do in ProjectManager to mark open workspaces).

In the case where the target workspace is already open, I think your best chance is to create a new file (window.new_file()), then copy the content of the tab into that file (view.insert()) and copy the name of the tab (view.set_name()) directly in the corresponding window, because (as you said) any modification on the workspace file would be overwritten when closing the workspace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants