mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 06:37:14 +09:00
Add readonly option
This commit is contained in:
@@ -196,6 +196,10 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
|
||||
b.EventHandler = NewEventHandler(b.SharedBuffer, b.cursors)
|
||||
}
|
||||
|
||||
if b.Settings["readonly"].(bool) {
|
||||
b.Type.Readonly = true
|
||||
}
|
||||
|
||||
b.Path = path
|
||||
b.AbsPath = absPath
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
|
||||
}
|
||||
} else if option == "encoding" {
|
||||
b.isModified = true
|
||||
} else if option == "readonly" {
|
||||
b.Type.Readonly = nativeValue.(bool)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -194,14 +194,27 @@ func DefaultGlobalSettings() map[string]interface{} {
|
||||
return common
|
||||
}
|
||||
|
||||
// LocalSettings is a list of the local only settings
|
||||
var LocalSettings = []string{"filetype", "readonly"}
|
||||
|
||||
// DefaultLocalSettings returns the default local settings
|
||||
// Note that filetype is a local only option
|
||||
func DefaultLocalSettings() map[string]interface{} {
|
||||
common := DefaultCommonSettings()
|
||||
common["filetype"] = "unknown"
|
||||
common["readonly"] = false
|
||||
return common
|
||||
}
|
||||
|
||||
func DefaultAllSettings() map[string]interface{} {
|
||||
global := DefaultGlobalSettings()
|
||||
local := DefaultLocalSettings()
|
||||
for k, v := range global {
|
||||
local[k] = v
|
||||
}
|
||||
return local
|
||||
}
|
||||
|
||||
func GetNativeValue(option string, realValue interface{}, value string) (interface{}, error) {
|
||||
var native interface{}
|
||||
kind := reflect.TypeOf(realValue).Kind()
|
||||
|
||||
Reference in New Issue
Block a user