Home Download Buy Blog Forum Support

view.set_name in 2.x alpha

view.set_name in 2.x alpha

Postby lunixbochs on Mon Jan 31, 2011 8:00 am

when I call view.set_name('name'), it marks the buffer as dirty and will no longer save to the original filename.
is there any way currently around this, or could there be in the future? I'm working on a plugin to distinguish between identically-named files in the file list - I want to be able to change their name but still save them as the original file.
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm

Re: view.set_name in 2.x alpha

Postby adzenith on Mon Jan 31, 2011 5:30 pm

The view name is the same as the file name, so when you change the name of the view you're changing the name of the file.
A possible workaround:
Check if the buffer is clean. If it is, then after view.set_name, save the buffer so it still seems clean. This will have the side-effect of creating a new file.
Listen for on_pre_save, and in the callback set the view name back to its original, save the view, and change the name back to the new name (which will then be saved).
Listen for on_close, and in the callback delete the new file. This will leave you with just the original-named file, but still allow it to have have a different name while it's being edited.

I haven't tried it, but I think that should work. Good luck!
adzenith
 
Posts: 1215
Joined: Mon Oct 19, 2009 9:12 pm

Re: view.set_name in 2.x alpha

Postby lunixbochs on Tue Feb 01, 2011 12:30 am

I tried on_pre_save, doesn't seem to trigger in time.
do we have any plugins changing the view name? if it doesn't break anything in existence, I'd be for a separation of view name and file name - give us a way to set the title and the file it will save to.
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm

Re: view.set_name in 2.x alpha

Postby adzenith on Tue Feb 01, 2011 12:48 am

It doesn't trigger in time? Could you just listen to on_post_save and do things in a different order?
I agree it would be cool if view names and file names could be separate. It would also be cool if identically-named files automatically had part of their path names added to their view names so that you could tell them apart.
adzenith
 
Posts: 1215
Joined: Mon Oct 19, 2009 9:12 pm

Re: view.set_name in 2.x alpha

Postby lunixbochs on Sun Feb 06, 2011 7:06 pm

adzenith wrote:It would also be cool if identically-named files automatically had part of their path names added to their view names so that you could tell them apart.
that's exactly what I was working on. it's working but going to save the file will prompt you to choose where to save... making it much less seamless, even if I were to swap it back on post_save. Jon? :)

for anyone curious, my renaming method is as follows:
1. get the name of all views (I use a hack for this, but it should be in the api in the future :P)
2. group any views with the same filename
3. find the common suffix of each group (by reversing and using os.path.commonprefix)
4. chop the common suffix, jump to the closest directory separator, hack the pathname based on conditions:
a) if there are one or more folders in the common suffix, prefix /.../ to the filename, otherwise prefix /
b) add the topmost folder name before this

this logic produces results as follows:
input:
1. foo/bar/common.py
2. foo/baz/common.py
3. bar/foo/common.py

output (instead of just showing common.py):
1. bar/common.py
2. baz/common.py
3. foo/common.py

input:
1. foo/common/__init__.py
2. bar/common/__init__.py
3. baz/common/__init__.py

output (instead of just showing __init__.py):
1. foo/.../__init__.py
2. bar/.../__init__.py
3. baz/.../__init__.py
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm


Return to Plugin Development

Who is online

Users browsing this forum: Majestic-12 [Bot] and 4 guests