Files
Python-With-Gtk-Template/plugins/code/event-watchers/prettify_json/prettify_json.py
itdominator 220a8c2743 Moved plugins and add loaded file filtering
- Moved prettify_json and lsp_completer plugins to sub categories
- Add filter_out_loaded_files to prevent opening already-loaded files
- Refactor code events into single events module
- Fix signal blocking during file load operations
- Include READONLY state in source view lifecycle handling
2026-03-08 00:46:21 -06:00

32 lines
778 B
Python

# Python imports
import json
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
def add_prettify_json(buffer, menu):
menu.append( Gtk.SeparatorMenuItem() )
def on_prettify_json(menuitem, buffer):
start_itr, \
end_itr = buffer.get_start_iter(), buffer.get_end_iter()
data = buffer.get_text(start_itr, end_itr, False)
text = json.dumps(json.loads(data), separators = (',', ':'), indent = 4)
buffer.begin_user_action()
buffer.delete(start_itr, end_itr)
buffer.insert(start_itr, text)
buffer.end_user_action()
item = Gtk.MenuItem(label = "Prettify JSON")
item.connect("activate", on_prettify_json, buffer)
menu.append(item)