Clean up codebase and improve file loading
- Moved plugins to proper sub groups (autopairs, code_minimap, colorize, commentzar, info_bar, markdown_preview, prettify_json, search_replace, tabs_bar, telescope, toggle_source_view, lsp_client) - Add filter_out_loaded_files to prevent opening already-loaded files - Add INDEPENDENT source view state - Fix cursor scroll position on buffer switch - Fix signal blocking during file load - Fix word boundary in completion provider - Refactor code events into single events module
This commit is contained in:
3
plugins/code/commands/commentzar/__init__.py
Normal file
3
plugins/code/commands/commentzar/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Module
|
||||
"""
|
||||
3
plugins/code/commands/commentzar/__main__.py
Normal file
3
plugins/code/commands/commentzar/__main__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Package
|
||||
"""
|
||||
66
plugins/code/commands/commentzar/commenter.py
Normal file
66
plugins/code/commands/commentzar/commenter.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from .mixins.code_comment_tags_mixin import CodeCommentTagsMixin
|
||||
|
||||
|
||||
|
||||
class Commenter(CodeCommentTagsMixin):
|
||||
def __init__(self):
|
||||
...
|
||||
|
||||
|
||||
def keyboard_tggl_comment(self, buffer):
|
||||
language = buffer.get_language()
|
||||
if language is None: return
|
||||
|
||||
start_tag, end_tag = self.get_comment_tags(language)
|
||||
# Note: Only handling line comment tag- no block comment option
|
||||
if not start_tag and not end_tag: return
|
||||
|
||||
bounds = buffer.get_selection_bounds()
|
||||
if bounds:
|
||||
self._bounds_comment(
|
||||
start_tag, end_tag, bounds, buffer
|
||||
)
|
||||
else:
|
||||
self._line_comment(start_tag, end_tag, buffer)
|
||||
|
||||
|
||||
def _line_comment(self, start_tag, end_tag, buffer):
|
||||
start_itr = buffer.get_iter_at_mark( buffer.get_insert() ).copy()
|
||||
end_itr = start_itr.copy()
|
||||
if not start_itr.starts_line():
|
||||
start_itr.set_line_offset(0)
|
||||
if not end_itr.ends_line():
|
||||
end_itr.forward_to_line_end()
|
||||
|
||||
text = buffer.get_text(start_itr, end_itr, True)
|
||||
text = text.replace(start_tag, "") if text.startswith(start_tag) else start_tag + text
|
||||
|
||||
buffer.begin_user_action()
|
||||
buffer.delete(start_itr, end_itr)
|
||||
buffer.insert(start_itr, text)
|
||||
buffer.end_user_action()
|
||||
|
||||
|
||||
def _bounds_comment(self, start_tag, end_tag, bounds, buffer):
|
||||
start_itr, end_itr = bounds
|
||||
if not start_itr.starts_line():
|
||||
start_itr.set_line_offset(0)
|
||||
if not end_itr.ends_line():
|
||||
end_itr.forward_to_line_end()
|
||||
|
||||
text = buffer.get_text(start_itr, end_itr, True)
|
||||
text = "\n".join(
|
||||
line.replace(start_tag, "") if line.startswith(start_tag) else start_tag + line
|
||||
for line in text.splitlines()
|
||||
)
|
||||
|
||||
buffer.begin_user_action()
|
||||
buffer.delete(start_itr, end_itr)
|
||||
buffer.insert(start_itr, text)
|
||||
buffer.end_user_action()
|
||||
|
||||
7
plugins/code/commands/commentzar/manifest.json
Normal file
7
plugins/code/commands/commentzar/manifest.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "Commentzar",
|
||||
"author": "ITDominator",
|
||||
"version": "0.0.1",
|
||||
"support": "",
|
||||
"requests": {}
|
||||
}
|
||||
3
plugins/code/commands/commentzar/mixins/__init__.py
Normal file
3
plugins/code/commands/commentzar/mixins/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Module Mixin
|
||||
"""
|
||||
30
plugins/code/commands/commentzar/mixins/code_comment_tags_mixin.py
Executable file
30
plugins/code/commands/commentzar/mixins/code_comment_tags_mixin.py
Executable file
@@ -0,0 +1,30 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class CodeCommentTagsMixin:
|
||||
def get_comment_tags(self, language):
|
||||
start_tag, end_tag = self.get_line_comment_tags(language)
|
||||
if (start_tag, end_tag) == (None, None):
|
||||
start_tag, end_tag = self.get_block_comment_tags(language)
|
||||
|
||||
return start_tag, end_tag
|
||||
|
||||
def get_block_comment_tags(self, language):
|
||||
start_tag = language.get_metadata('block-comment-start')
|
||||
end_tag = language.get_metadata('block-comment-end')
|
||||
|
||||
if start_tag and end_tag: return (start_tag, end_tag)
|
||||
|
||||
return (None, None)
|
||||
|
||||
def get_line_comment_tags(self, language):
|
||||
start_tag = language.get_metadata('line-comment-start')
|
||||
|
||||
if start_tag: return (start_tag, None)
|
||||
|
||||
return (None, None)
|
||||
51
plugins/code/commands/commentzar/plugin.py
Normal file
51
plugins/code/commands/commentzar/plugin.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# 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 .commenter import Commenter
|
||||
|
||||
|
||||
|
||||
commenter = Commenter()
|
||||
|
||||
|
||||
|
||||
class Plugin(PluginCode):
|
||||
def __init__(self):
|
||||
super(Plugin, self).__init__()
|
||||
|
||||
|
||||
def _controller_message(self, event: Code_Event_Types.CodeEvent):
|
||||
...
|
||||
|
||||
def load(self):
|
||||
event = Event_Factory.create_event("register_command",
|
||||
command_name = "keyboard_tggl_comment",
|
||||
command = Handler,
|
||||
binding_mode = "released",
|
||||
binding = "<Control>slash"
|
||||
)
|
||||
|
||||
self.emit_to("source_views", event)
|
||||
|
||||
def run(self):
|
||||
...
|
||||
|
||||
|
||||
class Handler:
|
||||
@staticmethod
|
||||
def execute(
|
||||
view: any,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
logger.debug("Command: Toggle Comment")
|
||||
commenter.keyboard_tggl_comment( view.get_buffer() )
|
||||
Reference in New Issue
Block a user