This repository has been archived by the owner on May 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
154 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
[ | ||
{ "command": "toggle_readonly", "caption": "Toggle Readonly", "id": "end" } | ||
{ | ||
"caption": "-", | ||
"id": "separator" | ||
}, | ||
{ | ||
"caption": "Set Readonly", | ||
"command": "set_readonly" | ||
}, | ||
{ | ||
"caption": "Set Writable", | ||
"command": "set_writable" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[ | ||
{ | ||
"caption": "Preferences", | ||
"children": [ | ||
{ | ||
"caption": "Package Settings", | ||
"children": [ | ||
{ | ||
"caption": "Toggle Readonly", | ||
"children": [ | ||
{ | ||
"args": { | ||
"file": "${packages}/toggle-readonly/toggle-readonly.sublime-settings" | ||
}, | ||
"caption": "Settings \u2013 Default", | ||
"command": "open_file" | ||
}, | ||
{ | ||
"args": { | ||
"file": "${packages}/User/toggle-readonly.sublime-settings" | ||
}, | ||
"caption": "Settings \u2013 User", | ||
"command": "open_file" | ||
} | ||
] | ||
} | ||
], | ||
"id": "package-settings", | ||
"mnemonic": "P" | ||
} | ||
], | ||
"id": "preferences", | ||
"mnemonic": "n" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
[ | ||
{ "command": "toggle_readonly", "caption": "Toggle Readonly" } | ||
{ | ||
"caption": "-", | ||
"id": "separator" | ||
}, | ||
|
||
{ | ||
"command": "set_readonly", | ||
"caption": "Set Readonly" | ||
}, | ||
{ | ||
"command": "set_writable", | ||
"caption": "Set Writable" | ||
} | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
[ | ||
{ "command": "toggle_readonly", "caption": "Toggle Readonly", "id": "end" } | ||
{ | ||
"caption": "-", | ||
"id": "separator" | ||
}, | ||
|
||
{ | ||
"command": "set_readonly", | ||
"caption": "Set Readonly" | ||
}, | ||
{ | ||
"command": "set_writable", | ||
"caption": "Set Writable" | ||
} | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"None are so hopelessly enslaved as those who falsely believe they are free." | ||
Johann Wolfgang von Goethe | ||
Original author: jbrooksuk | ||
|
||
Copyright (C) 2012 Tito Bouzout <tito.bouzout@gmail.com> | ||
|
||
This license apply to all the files inside this program unless noted | ||
different for some files or portions of code inside these files. | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation. http://www.gnu.org/licenses/gpl.html | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see http://www.gnu.org/licenses/gpl.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"url": "http://github.com/reflog/toggle-readonly/", "version": "1.0", "description": "Toggle file's readonly state from context menu."} | ||
{"url": "http://github.com/reflog/toggle-readonly/", "version": "2.0", "description": "Toggle file's readonly state from context menu."} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"auto_remove_readonly_on_save": false, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,57 @@ | ||
import sublime, sublime_plugin, os, stat | ||
|
||
class ToggleReadonlyCommand(sublime_plugin.TextCommand): | ||
s = sublime.load_settings('toggle-readonly.sublime-settings') | ||
|
||
|
||
def changeReadonly(filename, state): | ||
if (os.name == 'nt'): | ||
flag = ~stat.S_IWRITE | ||
if not state: | ||
flag = ~flag; | ||
os.chmod(filename, flag) | ||
else: | ||
flag = ~stat.UF_IMMUTABLE | ||
if not state: | ||
flag = flag; | ||
os.chflags(filename, flag) | ||
|
||
def isReadonly(filename): | ||
if not filename or len(filename) <= 0: | ||
return False | ||
|
||
fileAtt = os.stat(filename)[0] | ||
|
||
if (os.name == 'nt'): | ||
return not (fileAtt & stat.S_IWRITE) | ||
else: | ||
return not (fileAtt & stat.UF_IMMUTABLE) | ||
|
||
|
||
class ClearChangesCommand(sublime_plugin.EventListener): | ||
def on_pre_save(self, view): | ||
print (s.get('auto_remove_readonly_on_save')) | ||
if s.get('auto_remove_readonly_on_save'): | ||
if isReadonly(view.file_name()): | ||
changeReadonly(view.file_name(), False) | ||
|
||
|
||
class SetReadonlyCommand(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
myFile = self.view.file_name() | ||
fileAtt = os.stat(myFile)[0] | ||
myPlatform = os.name | ||
|
||
if (myPlatform == 'nt'): | ||
if (not fileAtt & stat.S_IWRITE): | ||
sublime.status_message("Making "+myFile+" writable") | ||
os.chmod(myFile, stat.S_IWRITE) | ||
else: | ||
if (fileAtt & stat.UF_IMMUTABLE): | ||
sublime.status_message("Making "+myFile+" mutable") | ||
os.chflags(myFile, not stat.UF_IMMUTABLE) | ||
changeReadonly(self.view.file_name(), True) | ||
|
||
def is_enabled(self): | ||
return self.view.file_name() and len(self.view.file_name()) > 0 | ||
return not isReadonly(self.view.file_name()) | ||
|
||
def is_visible(self): | ||
return self.is_enabled() | ||
|
||
|
||
class SetWritableCommand(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
changeReadonly(self.view.file_name(), False) | ||
|
||
def is_enabled(self): | ||
return isReadonly(self.view.file_name()) | ||
|
||
def is_visible(self): | ||
return self.is_enabled() |
Binary file not shown.