Sublime Forum

Read-only files

#1

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.

0 Likes

#2

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]#!/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))

################################################################################[/code]

0 Likes

#3

I appreciate your work
Is there anything rather than stopping to edit file we can show different color of read-only files on toolbar or side-bar it will be better for developers as it is providing in netbeans

0 Likes

[Finished]How to open a file in read-only mode
#4

You could enhance @ibarrac’s script by also putting a message in the status bar. Something like:

def on_activated(self, view):
    fn = view.file_name()
    if not fn: return
    if not os.access(fn, os.W_OK):
        view.set_read_only(True)
        view.set_status(str(self), "read-only")
    else:
        view.erase_status(str(self))
0 Likes

#5

Can’t We have something that shows Different Color of read-only Files
And it is not working for status bar

0 Likes