Home Download Buy Blog Forum Support

Read-only files

Read-only files

Postby mikecline on Sat Mar 24, 2012 5:16 am

Hello,

I really like Sublime Editor, but one thing that keeps me from fully liking it is that it doesn't have some basic features for handling read-only files that are common to almost all other decent editors that I have used:

- as far as I can tell, there is nothing on the screen to indicate whether a file is read-only
- most editors have a mode to disallow editing of read-only files (it prevents you from changing the text), as far as I can tell sublime does not have this.

Because i use Perforce and perforce locks the read-only flag of files which are not checked out, these features are very important to me.
mikecline
 
Posts: 6
Joined: Sat Mar 24, 2012 5:07 am

Re: Read-only files

Postby ibarrac on Sun Apr 22, 2012 11:49 pm

Here kind of a solution.

I ported this to SublimeText 2 from a previous solution posted previously by I think sublimator to the forums for the last version of the editor. It sets the view read only if the file is read-only.

Save the file as MakeReadonly.py under Packages/User (to find the directory choose menu item Preferences --> Settings - User)

------------------- cut -----------------
Code: Select all
#!/usr/bin/env python
#coding: utf8
#################################### IMPORTS ###################################

# Std Libs
import os

# Sublime Libs
import sublime
import sublime_plugin

################################################################################

class MakeReadOnly(sublime_plugin.EventListener):
    def on_activated(self, view):
        fn = view.file_name()
        if not fn: return
        view.set_read_only(not os.access(fn, os.W_OK))

################################################################################
ibarrac
 
Posts: 1
Joined: Sat Oct 30, 2010 12:51 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 37 guests