mozers
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Код: -- Наглядная установка/снятие режима "только для чтения" -- индикация текущего режима буфера в строке состояния и цветом фона -- VladVRO, mozers -- Подключение: -- В файл SciTEStartup.lua добавьте строку: -- require (props["SciteDefaultHome"].."\\tools\\ReadOnly.lua") -- включите scite.readonly в статусную строку: -- statusbar.text.1=Line:$(LineNumber) Col:$(ColumnNumber) [$(scite.readonly)] -- задайте в файле .properties цвет фона в режиме "только для чтения": -- style.back.readonly=#F2F2F1 ------------------------------------------------ -- Функция преобразования цвета из RGB в win local function encodeRGB(color) if string.sub(color,1,1)=="#" and string.len(color)>6 then return tonumber(string.sub(color,6,7)..string.sub(color,4,5)..string.sub(color,2,3), 16) else return color end end local function SetViewMode() if props["style.back.readonly"]~='' then local color = encodeRGB(props["style.back.readonly"]) editor.StyleBack[0] = color editor.StyleBack[2] = color editor.StyleBack[4] = color editor.StyleBack[5] = color editor.StyleBack[6] = color editor.StyleBack[10] = color editor.StyleBack[11] = color editor.StyleBack[32] = color end end local function SetEditMode() if editor.ReadOnly then local s,e,back = string.find(props["style.*.32"], "back#%x%x%x%x%x%x)") if back~=nil then local color = encodeRGB(back) editor.StyleBack[0] = color editor.StyleBack[2] = color editor.StyleBack[4] = color editor.StyleBack[5] = color editor.StyleBack[6] = color editor.StyleBack[10] = color editor.StyleBack[11] = color editor.StyleBack[32] = color end end end local function SetReadOnly(ro) if ro then SetViewMode() props["scite.readonly"] = "VIEW" else SetEditMode() props["scite.readonly"] = "EDIT" end scite.UpdateStatusBar() return true end -- Добавляем свой обработчик события OnSwitchFile local old_OnSwitchFile = OnSwitchFile function OnSwitchFile(file) local result if old_OnSwitchFile then result = old_OnSwitchFile(file) end if SetReadOnly(editor.ReadOnly) then return true end return result end -- Добавляем свой обработчик события OnOpen local old_OnOpen = OnOpen function OnOpen(file) local result if old_OnOpen then result = old_OnOpen(file) end if SetReadOnly(editor.ReadOnly) then return true end return result end -- Добавляем свой обработчик события, возникающего при вызове пункта меню "Read-Only" local old_OnSendEditor = OnSendEditor function OnSendEditor(id_msg, wp, lp) local result if old_OnSendEditor then result = old_OnSendEditor(id_msg, wp, lp) end if id_msg == SCI_SETREADONLY then if SetReadOnly(wp~=0) then return true end end return result end |
| Всего записей: 2187 | Зарегистр. 03-01-2002 | Отправлено: 21:22 08-11-2006 | Исправлено: mozers, 23:22 08-11-2006 |
|