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
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Module
|
||||
"""
|
||||
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Package
|
||||
"""
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "File State Watcher",
|
||||
"author": "ITDominator",
|
||||
"version": "0.0.1",
|
||||
"support": "",
|
||||
"requests": {}
|
||||
}
|
||||
32
plugins/code/event-watchers/file_state_watcher/plugin.py
Normal file
32
plugins/code/event-watchers/file_state_watcher/plugin.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from libs.event_factory import Event_Factory, Code_Event_Types
|
||||
|
||||
from plugins.plugin_types import PluginCode
|
||||
|
||||
from .watcher_checks import *
|
||||
|
||||
|
||||
|
||||
class Plugin(PluginCode):
|
||||
def __init__(self):
|
||||
super(Plugin, self).__init__()
|
||||
|
||||
|
||||
def _controller_message(self, event: Code_Event_Types.CodeEvent):
|
||||
if isinstance(event, Code_Event_Types.TextChangedEvent):
|
||||
event.file.check_file_on_disk()
|
||||
|
||||
if event.file.is_deleted():
|
||||
file_is_deleted(event)
|
||||
elif event.file.is_externally_modified():
|
||||
file_is_externally_modified(event)
|
||||
|
||||
def load(self):
|
||||
...
|
||||
|
||||
def run(self):
|
||||
...
|
||||
@@ -0,0 +1,32 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from libs.event_factory import Event_Factory, Code_Event_Types
|
||||
|
||||
|
||||
|
||||
def file_is_deleted(event):
|
||||
event.file.was_deleted = True
|
||||
event = Event_Factory.create_event(
|
||||
"file_externally_deleted",
|
||||
file = event.file,
|
||||
buffer = event.buffer
|
||||
)
|
||||
self.emit(event)
|
||||
|
||||
|
||||
def file_is_externally_modified(event):
|
||||
# event = Event_Factory.create_event(
|
||||
# "file_externally_modified",
|
||||
# file = event.file,
|
||||
# buffer = event.buffer
|
||||
# )
|
||||
# self.emit(event)
|
||||
|
||||
...
|
||||
|
||||
3
plugins/code/event-watchers/prettify_json/__init__.py
Normal file
3
plugins/code/event-watchers/prettify_json/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Module
|
||||
"""
|
||||
3
plugins/code/event-watchers/prettify_json/__main__.py
Normal file
3
plugins/code/event-watchers/prettify_json/__main__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Package
|
||||
"""
|
||||
7
plugins/code/event-watchers/prettify_json/manifest.json
Normal file
7
plugins/code/event-watchers/prettify_json/manifest.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "Prettify JSON",
|
||||
"author": "ITDominator",
|
||||
"version": "0.0.1",
|
||||
"support": "",
|
||||
"requests": {}
|
||||
}
|
||||
36
plugins/code/event-watchers/prettify_json/plugin.py
Normal file
36
plugins/code/event-watchers/prettify_json/plugin.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
gi.require_version('Gtk', '3.0')
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from libs.event_factory import Event_Factory, Code_Event_Types
|
||||
|
||||
from plugins.plugin_types import PluginCode
|
||||
|
||||
from .prettify_json import add_prettify_json
|
||||
|
||||
|
||||
|
||||
class Plugin(PluginCode):
|
||||
def __init__(self):
|
||||
super(Plugin, self).__init__()
|
||||
|
||||
|
||||
def _controller_message(self, event: Code_Event_Types.CodeEvent):
|
||||
if isinstance(event, Code_Event_Types.PopulateSourceViewPopupEvent):
|
||||
language = event.buffer.get_language()
|
||||
if not language: return
|
||||
|
||||
if "json" == language.get_id():
|
||||
add_prettify_json(event.buffer, event.menu)
|
||||
|
||||
def load(self):
|
||||
...
|
||||
|
||||
def run(self):
|
||||
...
|
||||
31
plugins/code/event-watchers/prettify_json/prettify_json.py
Normal file
31
plugins/code/event-watchers/prettify_json/prettify_json.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# 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)
|
||||
Reference in New Issue
Block a user