codis 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
src/_app_settings.py
ADDED
|
@@ -0,0 +1,1385 @@
|
|
|
1
|
+
"""Mixin ``_AppSettingsMixin`` - gerenciamento das configurações do Codis.
|
|
2
|
+
|
|
3
|
+
Expõe métodos para abrir a janela de configurações, aplicar preferências de
|
|
4
|
+
fonte, tema, indentação e idioma em tempo real sem reinicialização.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import contextlib
|
|
10
|
+
import logging
|
|
11
|
+
import re
|
|
12
|
+
import tkinter as tk
|
|
13
|
+
from collections.abc import Callable
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from tkinter import filedialog, messagebox, ttk
|
|
16
|
+
from typing import TYPE_CHECKING, Any
|
|
17
|
+
|
|
18
|
+
from src.constants import APP_NAME, TAB_SIZE
|
|
19
|
+
from src.editor.pane import EditorPane
|
|
20
|
+
from src.i18n import _t
|
|
21
|
+
from src.ui.command_palette import CommandPalette
|
|
22
|
+
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
logger = logging.getLogger("Codis")
|
|
27
|
+
|
|
28
|
+
__all__ = ["_AppSettingsMixin"]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class _AppSettingsMixin:
|
|
32
|
+
"""Mixin de Settings do CodisApp."""
|
|
33
|
+
|
|
34
|
+
def _toggle_panel(self) -> None:
|
|
35
|
+
"""Alterna a visibilidade do painel inferior."""
|
|
36
|
+
if self._panel_visible:
|
|
37
|
+
self._hide_bottom_panel()
|
|
38
|
+
else:
|
|
39
|
+
self._show_bottom_panel()
|
|
40
|
+
|
|
41
|
+
def _show_bottom_panel(self) -> None:
|
|
42
|
+
"""Exibe o painel inferior."""
|
|
43
|
+
h = self._cfg.get("panel_height", 220)
|
|
44
|
+
self._panel_visible = True
|
|
45
|
+
self._update_panel_toggle_arrows()
|
|
46
|
+
|
|
47
|
+
def _do_show():
|
|
48
|
+
with contextlib.suppress(tk.TclError):
|
|
49
|
+
self._v_paned.paneconfigure(
|
|
50
|
+
self._bottom_frame, minsize=80, height=h)
|
|
51
|
+
total_h = self._v_paned.winfo_height()
|
|
52
|
+
if total_h > 100:
|
|
53
|
+
self._v_paned.sash_place(0, 0, max(80, total_h - h))
|
|
54
|
+
|
|
55
|
+
self._root.update_idletasks()
|
|
56
|
+
_do_show()
|
|
57
|
+
|
|
58
|
+
self._root.after(30, _do_show)
|
|
59
|
+
|
|
60
|
+
def _hide_bottom_panel(self) -> None:
|
|
61
|
+
"""Oculta o painel inferior."""
|
|
62
|
+
self._panel_visible = False
|
|
63
|
+
self._update_panel_toggle_arrows()
|
|
64
|
+
|
|
65
|
+
def _do_hide():
|
|
66
|
+
with contextlib.suppress(tk.TclError):
|
|
67
|
+
self._v_paned.paneconfigure(
|
|
68
|
+
self._bottom_frame, minsize=0, height=0)
|
|
69
|
+
total_h = self._v_paned.winfo_height()
|
|
70
|
+
if total_h > 0:
|
|
71
|
+
self._v_paned.sash_place(0, 0, total_h + 50)
|
|
72
|
+
|
|
73
|
+
self._root.update_idletasks()
|
|
74
|
+
_do_hide()
|
|
75
|
+
self._root.after(30, _do_hide)
|
|
76
|
+
|
|
77
|
+
def _show_problems(self) -> None:
|
|
78
|
+
"""Exibe o painel de problemas."""
|
|
79
|
+
self._show_panel("problems")
|
|
80
|
+
|
|
81
|
+
def _toggle_git_panel(self) -> None:
|
|
82
|
+
"""Alterna o painel Git na barra lateral."""
|
|
83
|
+
self._activity("git")
|
|
84
|
+
|
|
85
|
+
def _goto_problem_pos(self, line: int, col: int) -> None:
|
|
86
|
+
"""Vai para a posição (linha, coluna) no editor ativo."""
|
|
87
|
+
e = self._active_editor()
|
|
88
|
+
if e:
|
|
89
|
+
e.goto_line(line, col)
|
|
90
|
+
with contextlib.suppress(tk.TclError):
|
|
91
|
+
e.text.focus_set()
|
|
92
|
+
|
|
93
|
+
def _e(self) -> EditorPane | None:
|
|
94
|
+
"""Retorna o editor ativo, se existir."""
|
|
95
|
+
if 0 <= self._active_idx < len(self._editors):
|
|
96
|
+
return self._editors[self._active_idx]
|
|
97
|
+
return None
|
|
98
|
+
|
|
99
|
+
def _undo(self) -> None:
|
|
100
|
+
"""Desfaz a última ação no editor ativo."""
|
|
101
|
+
e = self._e()
|
|
102
|
+
if e:
|
|
103
|
+
with contextlib.suppress(tk.TclError):
|
|
104
|
+
e.text.edit_undo()
|
|
105
|
+
|
|
106
|
+
def _redo(self) -> None:
|
|
107
|
+
"""Refaz a ação desfeita no editor ativo."""
|
|
108
|
+
e = self._e()
|
|
109
|
+
if e:
|
|
110
|
+
with contextlib.suppress(tk.TclError):
|
|
111
|
+
e.text.edit_redo()
|
|
112
|
+
|
|
113
|
+
def _cut(self) -> None:
|
|
114
|
+
"""Recorta o texto selecionado no editor ativo."""
|
|
115
|
+
e = self._e()
|
|
116
|
+
if not e:
|
|
117
|
+
return
|
|
118
|
+
with contextlib.suppress(tk.TclError):
|
|
119
|
+
sel = e.text.get(tk.SEL_FIRST, tk.SEL_LAST)
|
|
120
|
+
if sel:
|
|
121
|
+
self._record_clipboard(sel, kind="cut")
|
|
122
|
+
e.text.event_generate("<<Cut>>")
|
|
123
|
+
|
|
124
|
+
def _copy(self) -> None:
|
|
125
|
+
"""Copia o texto selecionado no editor ativo."""
|
|
126
|
+
e = self._e()
|
|
127
|
+
if not e:
|
|
128
|
+
return
|
|
129
|
+
with contextlib.suppress(tk.TclError):
|
|
130
|
+
sel = e.text.get(tk.SEL_FIRST, tk.SEL_LAST)
|
|
131
|
+
if sel:
|
|
132
|
+
self._record_clipboard(sel, kind="copy")
|
|
133
|
+
e.text.event_generate("<<Copy>>")
|
|
134
|
+
|
|
135
|
+
def _paste(self) -> None:
|
|
136
|
+
"""Cola o conteúdo da área de transferência no editor ativo."""
|
|
137
|
+
if e := self._e():
|
|
138
|
+
with contextlib.suppress(tk.TclError):
|
|
139
|
+
text = self._root.clipboard_get()
|
|
140
|
+
if text:
|
|
141
|
+
self._record_clipboard(text, kind="copy")
|
|
142
|
+
e.text.event_generate("<<Paste>>")
|
|
143
|
+
|
|
144
|
+
def _record_clipboard(self, text: str, kind: str = "copy") -> None:
|
|
145
|
+
"""Adiciona o texto ao histórico global de área de transferência.
|
|
146
|
+
|
|
147
|
+
Delega para ``_on_copy_event`` (definido em ``app.py``), que é a
|
|
148
|
+
única fonte de verdade do histórico (``_copy_history``), também
|
|
149
|
+
usada pelo polling do clipboard do SO e pelo diálogo de histórico
|
|
150
|
+
de colagem (Ctrl+Shift+V).
|
|
151
|
+
"""
|
|
152
|
+
if not text:
|
|
153
|
+
return
|
|
154
|
+
on_copy = getattr(self, "_on_copy_event", None)
|
|
155
|
+
if callable(on_copy):
|
|
156
|
+
on_copy(text, kind)
|
|
157
|
+
|
|
158
|
+
def _select_all(self) -> None:
|
|
159
|
+
""" """
|
|
160
|
+
widget_foco = self._root.focus_get()
|
|
161
|
+
|
|
162
|
+
if isinstance(widget_foco, (tk.Entry, ttk.Entry)):
|
|
163
|
+
with contextlib.suppress(tk.TclError):
|
|
164
|
+
widget_foco.select_range(0, "end")
|
|
165
|
+
widget_foco.icursor("end")
|
|
166
|
+
return
|
|
167
|
+
|
|
168
|
+
if isinstance(widget_foco, tk.Text):
|
|
169
|
+
with contextlib.suppress(tk.TclError):
|
|
170
|
+
widget_foco.tag_add(tk.SEL, "1.0", "end")
|
|
171
|
+
widget_foco.mark_set(tk.INSERT, "end")
|
|
172
|
+
return
|
|
173
|
+
|
|
174
|
+
if e := self._e():
|
|
175
|
+
e.text.tag_add(tk.SEL, "1.0", "end")
|
|
176
|
+
e.text.mark_set(tk.INSERT, "end")
|
|
177
|
+
|
|
178
|
+
def _toggle_comment(self) -> None:
|
|
179
|
+
"""Alterna comentário nas linhas selecionadas."""
|
|
180
|
+
if e := self._e():
|
|
181
|
+
e.toggle_comment()
|
|
182
|
+
|
|
183
|
+
def _duplicate_line(self) -> None:
|
|
184
|
+
"""Duplica a linha atual."""
|
|
185
|
+
if e := self._e():
|
|
186
|
+
e.duplicate_line()
|
|
187
|
+
|
|
188
|
+
def _delete_line(self) -> None:
|
|
189
|
+
"""Apaga a linha atual."""
|
|
190
|
+
if e := self._e():
|
|
191
|
+
e.delete_line()
|
|
192
|
+
|
|
193
|
+
def _move_line_up(self) -> None:
|
|
194
|
+
"""Move a linha atual para cima."""
|
|
195
|
+
if e := self._e():
|
|
196
|
+
e.move_line(-1)
|
|
197
|
+
|
|
198
|
+
def _move_line_down(self) -> None:
|
|
199
|
+
"""Move a linha atual para baixo."""
|
|
200
|
+
if e := self._e():
|
|
201
|
+
e.move_line(+1)
|
|
202
|
+
|
|
203
|
+
def _join_lines(self) -> None:
|
|
204
|
+
"""Junta a linha atual com a próxima."""
|
|
205
|
+
if e := self._e():
|
|
206
|
+
e.join_lines()
|
|
207
|
+
|
|
208
|
+
def _select_line(self) -> None:
|
|
209
|
+
"""Seleciona a linha atual."""
|
|
210
|
+
if e := self._e():
|
|
211
|
+
e.select_line()
|
|
212
|
+
|
|
213
|
+
def _transform(self, mode: str) -> None:
|
|
214
|
+
"""Transforma o texto selecionado para maiúsculas/minúsculas/título."""
|
|
215
|
+
if e := self._e():
|
|
216
|
+
e.transform_case(mode)
|
|
217
|
+
|
|
218
|
+
def _sort_lines(self, reverse: bool) -> None:
|
|
219
|
+
"""Ordena as linhas selecionadas ou todo o documento, direto ou reverso."""
|
|
220
|
+
if e := self._e():
|
|
221
|
+
e.sort_lines(reverse)
|
|
222
|
+
|
|
223
|
+
def _trim_trailing(self) -> None:
|
|
224
|
+
"""Remove espaços em branco no final das linhas."""
|
|
225
|
+
if e := self._e():
|
|
226
|
+
e.trim_trailing_whitespace()
|
|
227
|
+
|
|
228
|
+
def _copy_line_up(self) -> None:
|
|
229
|
+
"""Copia a linha atual para cima."""
|
|
230
|
+
e = self._e()
|
|
231
|
+
if not e:
|
|
232
|
+
return
|
|
233
|
+
with contextlib.suppress(tk.TclError):
|
|
234
|
+
ln = int(e.text.index(tk.INSERT).split(".")[0])
|
|
235
|
+
line = e.text.get(f"{ln}.0", f"{ln}.end")
|
|
236
|
+
e.text.insert(f"{ln}.0", line + "\n")
|
|
237
|
+
|
|
238
|
+
def _copy_line_down(self) -> None:
|
|
239
|
+
"""Copia a linha atual para baixo."""
|
|
240
|
+
e = self._e()
|
|
241
|
+
if not e:
|
|
242
|
+
return
|
|
243
|
+
with contextlib.suppress(tk.TclError):
|
|
244
|
+
ln = int(e.text.index(tk.INSERT).split(".")[0])
|
|
245
|
+
line = e.text.get(f"{ln}.0", f"{ln}.end")
|
|
246
|
+
e.text.insert(f"{ln}.end", "\n" + line)
|
|
247
|
+
|
|
248
|
+
def _format_document(self) -> None:
|
|
249
|
+
"""Formata o documento atual usando o formatador adequado."""
|
|
250
|
+
e = self._e()
|
|
251
|
+
if e:
|
|
252
|
+
if self._fire_hook("before_format", e, cancellable=True):
|
|
253
|
+
return
|
|
254
|
+
e.format_document(self._plugin_formatted(e))
|
|
255
|
+
self._fire_hook("after_format", e)
|
|
256
|
+
|
|
257
|
+
def _plugin_formatted(self, e: Any) -> str | None:
|
|
258
|
+
"""Texto devolvido pelo primeiro formatador de plugin que funcionar para a linguagem."""
|
|
259
|
+
content = e.get_content()
|
|
260
|
+
for ext in self._extensions.get("formatter", e.lang):
|
|
261
|
+
try:
|
|
262
|
+
result = ext.fn(content)
|
|
263
|
+
except Exception as exc:
|
|
264
|
+
logger.warning("Formatador de %s falhou: %s", ext.owner or "plugin", exc)
|
|
265
|
+
continue
|
|
266
|
+
if isinstance(result, str):
|
|
267
|
+
return result
|
|
268
|
+
return None
|
|
269
|
+
|
|
270
|
+
def _lint_file(self) -> None:
|
|
271
|
+
"""Executa o lint no arquivo atual."""
|
|
272
|
+
e = self._e()
|
|
273
|
+
if e:
|
|
274
|
+
self._lint_mgr.schedule(e.path, e.get_content(), e.lang)
|
|
275
|
+
self._status.notify(_t("msg.lint_running"), duration=1500)
|
|
276
|
+
|
|
277
|
+
def _fix_all(self) -> None:
|
|
278
|
+
"""Aplica correções automáticas para problemas no arquivo atual."""
|
|
279
|
+
e = self._e()
|
|
280
|
+
if e:
|
|
281
|
+
e.fix_all()
|
|
282
|
+
self._status.notify(_t("lsp.auto_fixed"), level="ok")
|
|
283
|
+
|
|
284
|
+
def _run_file(self) -> None:
|
|
285
|
+
"""Executa o arquivo atual no terminal usando o Code Runner configurado."""
|
|
286
|
+
e = self._e()
|
|
287
|
+
if not e or not e.path:
|
|
288
|
+
self._status.notify(_t("msg.save_before_run"), level="warn")
|
|
289
|
+
return
|
|
290
|
+
|
|
291
|
+
if self._terminal.active_is_internal():
|
|
292
|
+
# O REPL interno executa o arquivo no próprio processo, em vez de digitar um comando de shell.
|
|
293
|
+
self._show_panel("terminal")
|
|
294
|
+
self._terminal.run_file(str(e.path))
|
|
295
|
+
return
|
|
296
|
+
|
|
297
|
+
cmd_list = self._runner_store.build_command(e.lang, e.path)
|
|
298
|
+
if not cmd_list:
|
|
299
|
+
self._status.notify(
|
|
300
|
+
_t("msg.no_formatter", lang=e.lang)
|
|
301
|
+
+ " - configure em Ferramentas > Code Runners",
|
|
302
|
+
level="warn",
|
|
303
|
+
)
|
|
304
|
+
return
|
|
305
|
+
|
|
306
|
+
use_shell = (
|
|
307
|
+
self._runner_store.get_runner(e.lang).get("shell", False)
|
|
308
|
+
if self._runner_store.get_runner(e.lang)
|
|
309
|
+
else False
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
if use_shell:
|
|
313
|
+
cmd_str = " ".join(cmd_list)
|
|
314
|
+
else:
|
|
315
|
+
cmd_str = " ".join(f'"{c}"' if " " in c else c for c in cmd_list)
|
|
316
|
+
|
|
317
|
+
self._show_panel("terminal")
|
|
318
|
+
self._terminal.run_command(cmd_str)
|
|
319
|
+
|
|
320
|
+
def _run_selection(self) -> None:
|
|
321
|
+
"""Executa o trecho selecionado no terminal."""
|
|
322
|
+
e = self._e()
|
|
323
|
+
if not e:
|
|
324
|
+
return
|
|
325
|
+
try:
|
|
326
|
+
sel = e.text.get(tk.SEL_FIRST, tk.SEL_LAST)
|
|
327
|
+
except tk.TclError:
|
|
328
|
+
sel = e.text.get(tk.INSERT + " linestart", tk.INSERT + " lineend")
|
|
329
|
+
if sel.strip():
|
|
330
|
+
self._show_panel("terminal")
|
|
331
|
+
self._terminal.run_command(sel.strip())
|
|
332
|
+
|
|
333
|
+
def _show_find(self) -> None:
|
|
334
|
+
"""Exibe a barra de busca local."""
|
|
335
|
+
e = self._e()
|
|
336
|
+
initial = ""
|
|
337
|
+
if e:
|
|
338
|
+
with contextlib.suppress(tk.TclError):
|
|
339
|
+
initial = e.text.get(tk.SEL_FIRST, tk.SEL_LAST)
|
|
340
|
+
if not initial:
|
|
341
|
+
initial = e.get_word_at_cursor()
|
|
342
|
+
self._search_bar.show("find", initial)
|
|
343
|
+
|
|
344
|
+
def _show_replace(self) -> None:
|
|
345
|
+
"""Exibe a barra de busca e substituição."""
|
|
346
|
+
e = self._e()
|
|
347
|
+
initial = ""
|
|
348
|
+
if e:
|
|
349
|
+
with contextlib.suppress(tk.TclError):
|
|
350
|
+
initial = e.text.get(tk.SEL_FIRST, tk.SEL_LAST)
|
|
351
|
+
self._search_bar.show("replace", initial)
|
|
352
|
+
|
|
353
|
+
def _show_find_files(self, initial_query: str = "") -> None:
|
|
354
|
+
"""Ativa o painel 'Buscar em Arquivos' com uma consulta inicial."""
|
|
355
|
+
self._activity("search")
|
|
356
|
+
if initial_query and hasattr(self, "_find_files"):
|
|
357
|
+
self._find_files.start_with_query(initial_query)
|
|
358
|
+
|
|
359
|
+
def _on_escape(self, _e: Any = None) -> None:
|
|
360
|
+
"""Manipula a tecla Esc: esconde a barra de busca se visível."""
|
|
361
|
+
if self._search_bar.is_visible():
|
|
362
|
+
self._search_bar.hide()
|
|
363
|
+
|
|
364
|
+
def _goto_line(self) -> None:
|
|
365
|
+
"""Abre diálogo para ir a uma linha específica."""
|
|
366
|
+
if e := self._e():
|
|
367
|
+
e.goto_line_dialog()
|
|
368
|
+
|
|
369
|
+
def _goto_symbol(self) -> None:
|
|
370
|
+
"""Abre diálogo para ir a um símbolo do arquivo."""
|
|
371
|
+
e = self._e()
|
|
372
|
+
if not e:
|
|
373
|
+
return
|
|
374
|
+
|
|
375
|
+
ac = getattr(e, "autocomplete", None)
|
|
376
|
+
syms: list[str] = list(getattr(ac, "_doc_symbols", [])) if ac else []
|
|
377
|
+
if not syms:
|
|
378
|
+
self._status.notify(_t("msg.no_symbols"), level="info")
|
|
379
|
+
return
|
|
380
|
+
cmds = [
|
|
381
|
+
(s, f"Symbol: {s}", lambda sym=s: self._jump_to_sym(sym)) for s in syms]
|
|
382
|
+
CommandPalette.open(self._root, self._tmgr, cmds, [])
|
|
383
|
+
|
|
384
|
+
def _jump_to_sym(self, name: str) -> None:
|
|
385
|
+
"""Salta para a posição de um símbolo no editor."""
|
|
386
|
+
e = self._e()
|
|
387
|
+
if not e:
|
|
388
|
+
return
|
|
389
|
+
content = e.get_content()
|
|
390
|
+
m = re.search(rf"\b{re.escape(name)}\b", content)
|
|
391
|
+
if m:
|
|
392
|
+
idx = e.text.index(f"1.0 + {m.start()}c")
|
|
393
|
+
ln, col = map(int, idx.split("."))
|
|
394
|
+
e.goto_line(ln, col)
|
|
395
|
+
|
|
396
|
+
def _goto_bracket(self) -> None:
|
|
397
|
+
"""Vai para o parêntese/colchete/chave correspondente."""
|
|
398
|
+
if e := self._e():
|
|
399
|
+
e.hl.match_brackets()
|
|
400
|
+
|
|
401
|
+
def _next_problem(self) -> None:
|
|
402
|
+
"""Vai para o próximo problema (erro/aviso) no arquivo."""
|
|
403
|
+
e = self._e()
|
|
404
|
+
if not e or not e._diags:
|
|
405
|
+
return
|
|
406
|
+
try:
|
|
407
|
+
cur = int(e.text.index(tk.INSERT).split(".")[0])
|
|
408
|
+
except (tk.TclError, ValueError):
|
|
409
|
+
cur = 0
|
|
410
|
+
for d in sorted(e._diags, key=lambda x: x.line):
|
|
411
|
+
if d.line > cur:
|
|
412
|
+
e.goto_line(d.line, d.col)
|
|
413
|
+
return
|
|
414
|
+
e.goto_line(e._diags[0].line, e._diags[0].col)
|
|
415
|
+
|
|
416
|
+
def _prev_problem(self) -> None:
|
|
417
|
+
"""Vai para o problema anterior no arquivo."""
|
|
418
|
+
e = self._e()
|
|
419
|
+
if not e or not e._diags:
|
|
420
|
+
return
|
|
421
|
+
try:
|
|
422
|
+
cur = int(e.text.index(tk.INSERT).split(".")[0])
|
|
423
|
+
except (tk.TclError, ValueError):
|
|
424
|
+
cur = 99999
|
|
425
|
+
for d in sorted(e._diags, key=lambda x: x.line, reverse=True):
|
|
426
|
+
if d.line < cur:
|
|
427
|
+
e.goto_line(d.line, d.col)
|
|
428
|
+
return
|
|
429
|
+
last = max(e._diags, key=lambda x: x.line)
|
|
430
|
+
e.goto_line(last.line, last.col)
|
|
431
|
+
|
|
432
|
+
def _next_hunk(self) -> None:
|
|
433
|
+
"""Vai para o próximo trecho de diff no painel de diff."""
|
|
434
|
+
if self._diff_pane.winfo_ismapped():
|
|
435
|
+
self._diff_pane.next_hunk()
|
|
436
|
+
|
|
437
|
+
def _prev_hunk(self) -> None:
|
|
438
|
+
"""Vai para o trecho anterior de diff no painel de diff."""
|
|
439
|
+
if self._diff_pane.winfo_ismapped():
|
|
440
|
+
self._diff_pane.prev_hunk()
|
|
441
|
+
|
|
442
|
+
def _command_palette(self) -> None:
|
|
443
|
+
"""Abre a paleta de comandos."""
|
|
444
|
+
cmds = self._build_command_list()
|
|
445
|
+
recent = [str(p) for p in self._cfg.get_recent_files()]
|
|
446
|
+
|
|
447
|
+
def _goto(line: int) -> None:
|
|
448
|
+
if e := self._e():
|
|
449
|
+
e.goto_line(line)
|
|
450
|
+
|
|
451
|
+
CommandPalette.open(
|
|
452
|
+
self._root,
|
|
453
|
+
self._tmgr,
|
|
454
|
+
cmds,
|
|
455
|
+
recent,
|
|
456
|
+
goto_line_callback=_goto,
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
def _quick_open(self) -> None:
|
|
460
|
+
"""Abre a paleta de abertura rápida de arquivos."""
|
|
461
|
+
recent = [str(p) for p in self._cfg.get_recent_files()]
|
|
462
|
+
cmds = [(Path(f).name, f, lambda p=f: self._open_file(p))
|
|
463
|
+
for f in recent]
|
|
464
|
+
|
|
465
|
+
def _goto(line: int) -> None:
|
|
466
|
+
if e := self._e():
|
|
467
|
+
e.goto_line(line)
|
|
468
|
+
|
|
469
|
+
CommandPalette.open(
|
|
470
|
+
self._root,
|
|
471
|
+
self._tmgr,
|
|
472
|
+
cmds,
|
|
473
|
+
recent,
|
|
474
|
+
goto_line_callback=_goto,
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
def _build_command_list(self) -> list[tuple[str, str, Callable]]:
|
|
478
|
+
"""Constrói a lista de comandos para a paleta de comandos."""
|
|
479
|
+
base: list[tuple[str, str, Callable]] = [
|
|
480
|
+
(_t("file.new"), "Ctrl+N", self.new_file),
|
|
481
|
+
(_t("file.open"), "Ctrl+O", self.open_file_dialog),
|
|
482
|
+
(_t("file.open_folder"), "", self.open_folder_dialog),
|
|
483
|
+
(_t("file.save"), "Ctrl+S", self.save_file),
|
|
484
|
+
(_t("file.save_all"), "", self.save_all),
|
|
485
|
+
(_t("file.revert"), "", self.revert_file),
|
|
486
|
+
(_t("edit.find"), "Ctrl+F", self._show_find),
|
|
487
|
+
(_t("edit.find_replace"), "Ctrl+H", self._show_replace),
|
|
488
|
+
(_t("edit.find_in_files"), "Ctrl+Shift+F", self._show_find_files),
|
|
489
|
+
(_t("edit.toggle_comment"), "Ctrl+/", self._toggle_comment),
|
|
490
|
+
(_t("edit.duplicate_line"), "Ctrl+D", self._duplicate_line),
|
|
491
|
+
(_t("edit.delete_line"), "Ctrl+Shift+K", self._delete_line),
|
|
492
|
+
(_t("edit.sort_lines"), "", lambda: self._sort_lines(False)),
|
|
493
|
+
(_t("edit.trim_trailing"), "", self._trim_trailing),
|
|
494
|
+
(_t("view.problems"), "Ctrl+Shift+M",
|
|
495
|
+
lambda: self._show_panel("problems")),
|
|
496
|
+
(_t("view.terminal"), "Ctrl+`", lambda: self._show_panel("terminal")),
|
|
497
|
+
(_t("view.word_wrap"), "", self._toggle_word_wrap),
|
|
498
|
+
(_t("view.minimap"), "", self._toggle_minimap),
|
|
499
|
+
(_t("run.run_file"), "F5", self._run_file),
|
|
500
|
+
(_t("run.format_document"), "Shift+Alt+F", self._format_document),
|
|
501
|
+
(_t("run.fix_all"), "", self._fix_all),
|
|
502
|
+
("Toggle Theme", "", self._tmgr.cycle),
|
|
503
|
+
("Diff: File vs Saved", "", self._show_file_diff),
|
|
504
|
+
("Diff: Two Files", "", self._show_diff_two_files),
|
|
505
|
+
(_t("go.to_line"), "Ctrl+G", self._goto_line),
|
|
506
|
+
(_t("go.to_symbol"), "Ctrl+Shift+O", self._goto_symbol),
|
|
507
|
+
("Zoom In", "Ctrl+=", lambda: self._zoom(+1)),
|
|
508
|
+
("Zoom Out", "Ctrl+-", lambda: self._zoom(-1)),
|
|
509
|
+
("Reset Zoom", "Ctrl+0", lambda: self._zoom(0)),
|
|
510
|
+
(_t("view.ui_scale_up"), "Ctrl+Alt+=", lambda: self._ui_scale_step(+1)),
|
|
511
|
+
(_t("view.ui_scale_down"), "Ctrl+Alt+-", lambda: self._ui_scale_step(-1)),
|
|
512
|
+
(_t("view.ui_scale_auto"), "Ctrl+Alt+0", self._ui_scale_auto),
|
|
513
|
+
("Toggle Full Screen", "F11", self._toggle_fullscreen),
|
|
514
|
+
("Split Editor", "", self._split_editor),
|
|
515
|
+
("Welcome Screen", "", self._show_welcome),
|
|
516
|
+
("Settings", "Ctrl+,", lambda: self._activity("settings")),
|
|
517
|
+
("Change Language", "", self._pick_language),
|
|
518
|
+
("About Codis", "", self._about_dialog),
|
|
519
|
+
]
|
|
520
|
+
|
|
521
|
+
for info in self._commands.all(only_available=True):
|
|
522
|
+
if info.owner == "core" or ".__atalho" in info.id:
|
|
523
|
+
continue
|
|
524
|
+
label = f"{info.category}: {info.label}" if info.category else info.label
|
|
525
|
+
base.append((label, ", ".join(info.keys), lambda c=info.id: self._commands.run(c)))
|
|
526
|
+
return base
|
|
527
|
+
|
|
528
|
+
def _plugin_menu_target(self, menu_path: str, create: bool) -> Any | None:
|
|
529
|
+
"""Menu (ou submenu) do menu Plugins indicado por ``menu_path``."""
|
|
530
|
+
from src.ui.menu_bar import MenuDef
|
|
531
|
+
|
|
532
|
+
root_menu = self._plugin_menu_cache
|
|
533
|
+
if not root_menu:
|
|
534
|
+
return None
|
|
535
|
+
parts = [p.strip() for p in menu_path.split("/")]
|
|
536
|
+
if len(parts) <= 1:
|
|
537
|
+
return root_menu
|
|
538
|
+
sub_label = parts[1]
|
|
539
|
+
end_index = root_menu.index("end")
|
|
540
|
+
for i in range(end_index + 1 if end_index is not None else 0):
|
|
541
|
+
with contextlib.suppress(tk.TclError):
|
|
542
|
+
if root_menu.type(i) == "cascade" and root_menu.entrycget(i, "label") == sub_label:
|
|
543
|
+
return root_menu.nametowidget(root_menu.entrycget(i, "menu"))
|
|
544
|
+
if not create:
|
|
545
|
+
return None
|
|
546
|
+
sub = MenuDef()
|
|
547
|
+
root_menu.add_cascade(label=sub_label, menu=sub)
|
|
548
|
+
return sub
|
|
549
|
+
|
|
550
|
+
def _add_plugin_menu_item(
|
|
551
|
+
self, menu_path: str, label: str, handler: Callable, accelerator: str = ""
|
|
552
|
+
) -> None:
|
|
553
|
+
"""Adiciona um item ao menu Plugins (usado pela API de plugins)."""
|
|
554
|
+
|
|
555
|
+
def _run() -> None:
|
|
556
|
+
try:
|
|
557
|
+
handler()
|
|
558
|
+
except Exception as exc:
|
|
559
|
+
logger.warning("Item de menu '%s' falhou: %s", label, exc)
|
|
560
|
+
|
|
561
|
+
with contextlib.suppress(tk.TclError):
|
|
562
|
+
target = self._plugin_menu_target(menu_path, create=True)
|
|
563
|
+
if target is not None:
|
|
564
|
+
options: dict[str, Any] = {"label": label, "command": _run}
|
|
565
|
+
if accelerator:
|
|
566
|
+
options["accelerator"] = accelerator
|
|
567
|
+
target.add_command(**options)
|
|
568
|
+
|
|
569
|
+
def _remove_plugin_menu_item(self, menu_path: str, label: str) -> None:
|
|
570
|
+
"""Remove um item adicionado por :meth:`_add_plugin_menu_item`."""
|
|
571
|
+
with contextlib.suppress(tk.TclError):
|
|
572
|
+
target = self._plugin_menu_target(menu_path, create=False)
|
|
573
|
+
if target is None:
|
|
574
|
+
return
|
|
575
|
+
end_index = target.index("end")
|
|
576
|
+
for i in range((end_index + 1) if end_index is not None else 0):
|
|
577
|
+
if target.type(i) == "command" and target.entrycget(i, "label") == label:
|
|
578
|
+
target.delete(i)
|
|
579
|
+
return
|
|
580
|
+
|
|
581
|
+
def _update_breadcrumb(self) -> None:
|
|
582
|
+
"""Atualiza o breadcrumb com o caminho do arquivo ativo."""
|
|
583
|
+
if not self._cfg.get("breadcrumbs", True):
|
|
584
|
+
return
|
|
585
|
+
e = self._e()
|
|
586
|
+
if e:
|
|
587
|
+
self._breadcrumb.set_path(e.path)
|
|
588
|
+
|
|
589
|
+
def _update_title(self) -> None:
|
|
590
|
+
"""Atualiza o título da janela com o nome do arquivo e workspace."""
|
|
591
|
+
e = self._e()
|
|
592
|
+
parts = [APP_NAME]
|
|
593
|
+
if e and e.path:
|
|
594
|
+
mod = "● " if e.modified else ""
|
|
595
|
+
parts = [f"{mod}{e.path.name}", " - ", APP_NAME]
|
|
596
|
+
if self._workspace:
|
|
597
|
+
parts.append(f" [{self._workspace.name}]")
|
|
598
|
+
with contextlib.suppress(tk.TclError):
|
|
599
|
+
self._root.title("".join(parts))
|
|
600
|
+
|
|
601
|
+
def _update_status_bar(self) -> None:
|
|
602
|
+
"""Atualiza os indicadores da barra de status."""
|
|
603
|
+
e = self._e()
|
|
604
|
+
if e:
|
|
605
|
+
self._status.set_lang(e.lang)
|
|
606
|
+
self._status.set_encoding(e.encoding)
|
|
607
|
+
self._status.set_eol(e.eol)
|
|
608
|
+
self._status.set_indent(
|
|
609
|
+
self._cfg.get("tab_size", TAB_SIZE), not self._cfg.get(
|
|
610
|
+
"use_spaces", True)
|
|
611
|
+
)
|
|
612
|
+
self._status.set_zoom(self._zoom_pct)
|
|
613
|
+
|
|
614
|
+
def _ui_scale_step(self, direction: int) -> None:
|
|
615
|
+
"""Aumenta (+1) ou diminui (-1) a escala da interface em passos de 10%."""
|
|
616
|
+
pct = self._ui_scaler.step(direction)
|
|
617
|
+
self._cfg.save()
|
|
618
|
+
self._flash_ui_scale(pct)
|
|
619
|
+
|
|
620
|
+
def _ui_scale_auto(self) -> None:
|
|
621
|
+
"""Volta a escala da interface ao modo automático (ajustado à tela)."""
|
|
622
|
+
pct = self._ui_scaler.reset()
|
|
623
|
+
self._cfg.save()
|
|
624
|
+
self._flash_ui_scale(pct)
|
|
625
|
+
|
|
626
|
+
def _flash_ui_scale(self, pct: int) -> None:
|
|
627
|
+
"""Mostra o percentual atual na barra de status, se disponível."""
|
|
628
|
+
with contextlib.suppress(AttributeError, tk.TclError):
|
|
629
|
+
self._status.notify(f"UI {pct}%", duration=1500)
|
|
630
|
+
|
|
631
|
+
def _zoom(self, delta: int) -> None:
|
|
632
|
+
"""Aplica zoom ao editor (delta em passos de 10%)."""
|
|
633
|
+
if delta == 0:
|
|
634
|
+
self._zoom_pct = 100
|
|
635
|
+
for e in self._editors:
|
|
636
|
+
e.zoom(0)
|
|
637
|
+
else:
|
|
638
|
+
new_pct = max(50, min(300, self._zoom_pct + delta * 10))
|
|
639
|
+
|
|
640
|
+
steps = (new_pct - self._zoom_pct) // 10
|
|
641
|
+
for e in self._editors:
|
|
642
|
+
for _ in range(abs(steps)):
|
|
643
|
+
e.zoom(1 if steps > 0 else -1)
|
|
644
|
+
self._zoom_pct = new_pct
|
|
645
|
+
self._status.set_zoom(self._zoom_pct)
|
|
646
|
+
|
|
647
|
+
def _toggle_word_wrap(self) -> None:
|
|
648
|
+
"""Alterna a quebra de linha no editor."""
|
|
649
|
+
for e in self._editors:
|
|
650
|
+
e.toggle_word_wrap()
|
|
651
|
+
self._cfg.set("word_wrap", not self._cfg.get("word_wrap", False))
|
|
652
|
+
|
|
653
|
+
def _toggle_minimap(self) -> None:
|
|
654
|
+
"""Alterna a visibilidade do minimapa."""
|
|
655
|
+
for e in self._editors:
|
|
656
|
+
e.toggle_minimap()
|
|
657
|
+
self._cfg.set("minimap", not self._cfg.get("minimap", True))
|
|
658
|
+
|
|
659
|
+
def _toggle_breadcrumbs(self) -> None:
|
|
660
|
+
"""Alterna a exibição do breadcrumb."""
|
|
661
|
+
show = not self._cfg.get("breadcrumbs", True)
|
|
662
|
+
self._cfg.set("breadcrumbs", show)
|
|
663
|
+
if show:
|
|
664
|
+
self._breadcrumb.pack(fill="x", after=self._tabbar)
|
|
665
|
+
else:
|
|
666
|
+
self._breadcrumb.pack_forget()
|
|
667
|
+
|
|
668
|
+
def _set_menubar_position(self, position: str) -> None:
|
|
669
|
+
"""Reancora a MenuBar holográfica em ``"top"`` ou ``"bottom"``.
|
|
670
|
+
|
|
671
|
+
Os dois checkbuttons do submenu "Posição da Barra de Menus" agem
|
|
672
|
+
como um par mutuamente exclusivo (a MenuDef não modela radiobuttons
|
|
673
|
+
nativamente): ao escolher um lado, o outro é desmarcado e a barra é
|
|
674
|
+
reancorada em tempo real, já trocando a direção em que os dropdowns
|
|
675
|
+
abrem (para baixo no topo, para cima na base).
|
|
676
|
+
"""
|
|
677
|
+
position = position if position in ("top", "bottom") else "top"
|
|
678
|
+
menubar = getattr(self, "_menubar", None)
|
|
679
|
+
if menubar is not None:
|
|
680
|
+
with contextlib.suppress(tk.TclError):
|
|
681
|
+
menubar.set_position(position)
|
|
682
|
+
self._cfg.set("menubar_position", position)
|
|
683
|
+
self._cfg.save()
|
|
684
|
+
|
|
685
|
+
top_var = getattr(self, "_mbp_top_var", None)
|
|
686
|
+
bottom_var = getattr(self, "_mbp_bottom_var", None)
|
|
687
|
+
if top_var is not None:
|
|
688
|
+
with contextlib.suppress(tk.TclError):
|
|
689
|
+
top_var.set(position == "top")
|
|
690
|
+
if bottom_var is not None:
|
|
691
|
+
with contextlib.suppress(tk.TclError):
|
|
692
|
+
bottom_var.set(position == "bottom")
|
|
693
|
+
|
|
694
|
+
def _toggle_fullscreen(self) -> None:
|
|
695
|
+
"""Alterna o modo tela cheia."""
|
|
696
|
+
cur = self._root.attributes("-fullscreen")
|
|
697
|
+
self._root.attributes("-fullscreen", not cur)
|
|
698
|
+
|
|
699
|
+
def _split_tab_to_right(self, tab_idx: int) -> None:
|
|
700
|
+
"""Abre a aba `tab_idx` no lado direito do modo dual, ativando o dual se necessário."""
|
|
701
|
+
if not self._dual_mode:
|
|
702
|
+
self._open_dual_mode()
|
|
703
|
+
if 0 <= tab_idx < len(self._editors):
|
|
704
|
+
path = self._editors[tab_idx].path
|
|
705
|
+
if path:
|
|
706
|
+
for i, e in enumerate(self._dual_right_editors):
|
|
707
|
+
if e.path == path:
|
|
708
|
+
self._dual_right_select(i)
|
|
709
|
+
return
|
|
710
|
+
self._create_dual_right_editor(path)
|
|
711
|
+
|
|
712
|
+
def _split_editor(self) -> None:
|
|
713
|
+
"""Alterna o modo dual (split side-by-side)."""
|
|
714
|
+
if self._dual_mode:
|
|
715
|
+
self._close_dual_mode()
|
|
716
|
+
else:
|
|
717
|
+
self._open_dual_mode()
|
|
718
|
+
|
|
719
|
+
def _open_dual_mode(self) -> None:
|
|
720
|
+
"""Ativa o modo dual: divide o editor_container em dois painéis lado a lado.
|
|
721
|
+
|
|
722
|
+
Estratégia de layout correta:
|
|
723
|
+
- Esconde o conteúdo atual do _editor_container
|
|
724
|
+
- Cria um PanedWindow que preenche o _editor_container
|
|
725
|
+
- Lado esquerdo: frame que hospeda os editores existentes (re-pack com pai correto)
|
|
726
|
+
- Lado direito: frame com tabbar e editores novos
|
|
727
|
+
- Os EditorPane são sempre criados com o frame correto como pai real (não usa in_=)
|
|
728
|
+
"""
|
|
729
|
+
if self._dual_mode:
|
|
730
|
+
return
|
|
731
|
+
t = self._tmgr.theme
|
|
732
|
+
|
|
733
|
+
for e in self._editors:
|
|
734
|
+
with contextlib.suppress(tk.TclError):
|
|
735
|
+
e.pack_forget()
|
|
736
|
+
if self._welcome.winfo_ismapped():
|
|
737
|
+
self._welcome.pack_forget()
|
|
738
|
+
|
|
739
|
+
self._dual_paned = tk.PanedWindow(
|
|
740
|
+
self._editor_container,
|
|
741
|
+
orient="horizontal",
|
|
742
|
+
bg=t.border,
|
|
743
|
+
sashwidth=5,
|
|
744
|
+
sashrelief="flat",
|
|
745
|
+
sashcursor="sb_h_double_arrow",
|
|
746
|
+
)
|
|
747
|
+
self._dual_paned.pack(fill="both", expand=True)
|
|
748
|
+
|
|
749
|
+
self._dual_left_container = tk.Frame(self._dual_paned, bg=t.editor_bg)
|
|
750
|
+
self._dual_right_container = tk.Frame(self._dual_paned, bg=t.editor_bg)
|
|
751
|
+
|
|
752
|
+
self._dual_paned.add(self._dual_left_container, stretch="always")
|
|
753
|
+
self._dual_paned.add(self._dual_right_container, stretch="always")
|
|
754
|
+
|
|
755
|
+
if 0 <= self._active_idx < len(self._editors):
|
|
756
|
+
old_e = self._editors[self._active_idx]
|
|
757
|
+
old_path = old_e.path
|
|
758
|
+
new_left = EditorPane(
|
|
759
|
+
self._dual_left_container,
|
|
760
|
+
self._tmgr,
|
|
761
|
+
self._cfg,
|
|
762
|
+
self._lint_mgr,
|
|
763
|
+
self._snippets,
|
|
764
|
+
on_change=self._on_editor_change,
|
|
765
|
+
on_cursor=self._on_cursor_change,
|
|
766
|
+
on_title=self._on_editor_title,
|
|
767
|
+
idx=self._active_idx,
|
|
768
|
+
)
|
|
769
|
+
if self._lsp_mgr:
|
|
770
|
+
new_left.set_lsp_manager(self._lsp_mgr)
|
|
771
|
+
new_left.set_goto_callback(self._open_file_at_line)
|
|
772
|
+
new_left.set_workspace_edit_callback(self._apply_edits_to_path)
|
|
773
|
+
if old_path:
|
|
774
|
+
new_left.load(old_path)
|
|
775
|
+
new_left.pack(fill="both", expand=True)
|
|
776
|
+
self._editors[self._active_idx] = new_left
|
|
777
|
+
self._active_pane = new_left
|
|
778
|
+
with contextlib.suppress(tk.TclError):
|
|
779
|
+
old_e.destroy()
|
|
780
|
+
|
|
781
|
+
self._dual_mode = True
|
|
782
|
+
self._dual_right_active = False
|
|
783
|
+
self._add_dual_right_tabbar(t)
|
|
784
|
+
self._create_dual_right_editor()
|
|
785
|
+
|
|
786
|
+
self._root.bind("<Control-backslash>",
|
|
787
|
+
lambda _: self._toggle_dual_focus())
|
|
788
|
+
with contextlib.suppress(AttributeError):
|
|
789
|
+
self._status.set_dual_mode(True)
|
|
790
|
+
self._status.notify(
|
|
791
|
+
_t("view.split_editor")
|
|
792
|
+
+ " ON - Ctrl+\\ alterna foco - clique em ✕ Split para fechar",
|
|
793
|
+
duration=4000,
|
|
794
|
+
level="ok",
|
|
795
|
+
)
|
|
796
|
+
|
|
797
|
+
def _add_dual_right_tabbar(self, t: object) -> None:
|
|
798
|
+
"""Adiciona tabbar + botão fechar ao container direito do modo dual."""
|
|
799
|
+
from src.ui.tab_bar import TabBar as _TabBar
|
|
800
|
+
|
|
801
|
+
top = tk.Frame(
|
|
802
|
+
self._dual_right_container, bg=getattr(t, "tabbar_bg", "#1e1e2e"), height=34
|
|
803
|
+
)
|
|
804
|
+
top.pack(fill="x")
|
|
805
|
+
top.pack_propagate(False)
|
|
806
|
+
|
|
807
|
+
close_btn = tk.Label(
|
|
808
|
+
top,
|
|
809
|
+
text=_t("editor.split_close", " ✕ Split "),
|
|
810
|
+
bg=getattr(t, "tabbar_bg", "#1e1e2e"),
|
|
811
|
+
fg=getattr(t, "fg_muted", "#888888"),
|
|
812
|
+
font=(getattr(t, "ui_font", "Segoe UI"), 9),
|
|
813
|
+
cursor="hand2",
|
|
814
|
+
)
|
|
815
|
+
close_btn.pack(side="right", padx=(0, 4))
|
|
816
|
+
_accent = getattr(t, "accent", "#f38ba8")
|
|
817
|
+
_muted = getattr(t, "fg_muted", "#888888")
|
|
818
|
+
close_btn.bind("<Enter>", lambda _: close_btn.config(fg=_accent))
|
|
819
|
+
close_btn.bind("<Leave>", lambda _: close_btn.config(fg=_muted))
|
|
820
|
+
close_btn.bind("<Button-1>", lambda _: self._close_dual_mode())
|
|
821
|
+
|
|
822
|
+
tb = _TabBar(
|
|
823
|
+
top,
|
|
824
|
+
self._tmgr,
|
|
825
|
+
on_select=self._dual_right_select,
|
|
826
|
+
on_close=self._dual_right_close,
|
|
827
|
+
)
|
|
828
|
+
tb.pack(fill="both", expand=True, side="left")
|
|
829
|
+
self._dual_right_tabbar = tb
|
|
830
|
+
|
|
831
|
+
self._dual_right_editor_frame = tk.Frame(
|
|
832
|
+
self._dual_right_container,
|
|
833
|
+
bg=getattr(t, "editor_bg", "#1e1e1e"),
|
|
834
|
+
)
|
|
835
|
+
self._dual_right_editor_frame.pack(fill="both", expand=True)
|
|
836
|
+
|
|
837
|
+
def _create_dual_right_editor(self, path: Path | None = None) -> EditorPane:
|
|
838
|
+
"""Cria um EditorPane no lado direito do modo dual.
|
|
839
|
+
|
|
840
|
+
O EditorPane é criado com _dual_right_editor_frame como pai real,
|
|
841
|
+
garantindo que o path de widget do Tkinter seja válido e estável.
|
|
842
|
+
"""
|
|
843
|
+
if self._dual_right_editor_frame is None:
|
|
844
|
+
raise RuntimeError("_dual_right_editor_frame não inicializado")
|
|
845
|
+
|
|
846
|
+
e = EditorPane(
|
|
847
|
+
self._dual_right_editor_frame,
|
|
848
|
+
self._tmgr,
|
|
849
|
+
self._cfg,
|
|
850
|
+
self._lint_mgr,
|
|
851
|
+
self._snippets,
|
|
852
|
+
on_change=self._on_editor_change,
|
|
853
|
+
on_cursor=self._on_cursor_change,
|
|
854
|
+
on_title=lambda title, mod, idx=None: self._on_dual_right_title(
|
|
855
|
+
title, mod),
|
|
856
|
+
idx=0,
|
|
857
|
+
)
|
|
858
|
+
if self._lsp_mgr:
|
|
859
|
+
e.set_lsp_manager(self._lsp_mgr)
|
|
860
|
+
e.set_goto_callback(self._open_file_at_line)
|
|
861
|
+
e.set_workspace_edit_callback(self._apply_edits_to_path)
|
|
862
|
+
|
|
863
|
+
if path is None:
|
|
864
|
+
current_e = self._e()
|
|
865
|
+
if current_e and current_e.path:
|
|
866
|
+
path = current_e.path
|
|
867
|
+
|
|
868
|
+
title = path.name if path else _t("ui.tab_untitled")
|
|
869
|
+
if self._dual_right_tabbar:
|
|
870
|
+
self._dual_right_tabbar.add_tab(title, path)
|
|
871
|
+
|
|
872
|
+
idx = len(self._dual_right_editors)
|
|
873
|
+
|
|
874
|
+
if idx > 0 and 0 <= self._dual_right_idx < len(self._dual_right_editors):
|
|
875
|
+
with contextlib.suppress(tk.TclError):
|
|
876
|
+
self._dual_right_editors[self._dual_right_idx].pack_forget()
|
|
877
|
+
|
|
878
|
+
self._dual_right_editors.append(e)
|
|
879
|
+
self._dual_right_idx = idx
|
|
880
|
+
|
|
881
|
+
if self._dual_right_tabbar:
|
|
882
|
+
self._dual_right_tabbar.set_active(idx)
|
|
883
|
+
|
|
884
|
+
e.pack(fill="both", expand=True)
|
|
885
|
+
|
|
886
|
+
if path:
|
|
887
|
+
e.load(path)
|
|
888
|
+
with contextlib.suppress(tk.TclError):
|
|
889
|
+
e.text.focus_set()
|
|
890
|
+
self._dual_right_active = True
|
|
891
|
+
return e
|
|
892
|
+
|
|
893
|
+
def _dual_right_select(self, idx: int) -> None:
|
|
894
|
+
"""Seleciona aba no lado direito do modo dual."""
|
|
895
|
+
if (
|
|
896
|
+
not self._dual_right_editors
|
|
897
|
+
or idx < 0
|
|
898
|
+
or idx >= len(self._dual_right_editors)
|
|
899
|
+
):
|
|
900
|
+
return
|
|
901
|
+
if 0 <= self._dual_right_idx < len(self._dual_right_editors):
|
|
902
|
+
with contextlib.suppress(tk.TclError):
|
|
903
|
+
self._dual_right_editors[self._dual_right_idx].pack_forget()
|
|
904
|
+
self._dual_right_idx = idx
|
|
905
|
+
self._dual_right_editors[idx].pack(fill="both", expand=True)
|
|
906
|
+
with contextlib.suppress(tk.TclError):
|
|
907
|
+
self._dual_right_editors[idx].text.focus_set()
|
|
908
|
+
self._dual_right_active = True
|
|
909
|
+
if self._dual_right_tabbar:
|
|
910
|
+
self._dual_right_tabbar.set_active(idx)
|
|
911
|
+
|
|
912
|
+
def _dual_right_close(self, idx: int) -> None:
|
|
913
|
+
"""Fecha aba no lado direito do modo dual."""
|
|
914
|
+
if (
|
|
915
|
+
not self._dual_right_editors
|
|
916
|
+
or idx < 0
|
|
917
|
+
or idx >= len(self._dual_right_editors)
|
|
918
|
+
):
|
|
919
|
+
return
|
|
920
|
+
e = self._dual_right_editors.pop(idx)
|
|
921
|
+
with contextlib.suppress(tk.TclError):
|
|
922
|
+
e.destroy()
|
|
923
|
+
if self._dual_right_tabbar:
|
|
924
|
+
self._dual_right_tabbar.remove_tab(idx)
|
|
925
|
+
if not self._dual_right_editors:
|
|
926
|
+
self._close_dual_mode()
|
|
927
|
+
return
|
|
928
|
+
new_idx = min(idx, len(self._dual_right_editors) - 1)
|
|
929
|
+
self._dual_right_idx = -1
|
|
930
|
+
self._dual_right_select(new_idx)
|
|
931
|
+
|
|
932
|
+
def _on_dual_right_title(self, title: str, modified: bool) -> None:
|
|
933
|
+
"""Atualiza título da aba ativa no lado direito."""
|
|
934
|
+
if self._dual_right_tabbar and 0 <= self._dual_right_idx < len(
|
|
935
|
+
self._dual_right_editors
|
|
936
|
+
):
|
|
937
|
+
e = self._dual_right_editors[self._dual_right_idx]
|
|
938
|
+
tab_title = e.path.name if e.path else _t("ui.tab_untitled")
|
|
939
|
+
with contextlib.suppress(tk.TclError):
|
|
940
|
+
self._dual_right_tabbar.update_tab(
|
|
941
|
+
self._dual_right_idx, tab_title, modified
|
|
942
|
+
)
|
|
943
|
+
|
|
944
|
+
def _toggle_dual_focus(self) -> None:
|
|
945
|
+
"""Alterna o foco entre lado esquerdo e direito no modo dual."""
|
|
946
|
+
if not self._dual_mode:
|
|
947
|
+
return
|
|
948
|
+
if self._dual_right_active:
|
|
949
|
+
self._dual_right_active = False
|
|
950
|
+
e = self._e()
|
|
951
|
+
if e:
|
|
952
|
+
with contextlib.suppress(tk.TclError):
|
|
953
|
+
e.text.focus_set()
|
|
954
|
+
else:
|
|
955
|
+
self._dual_right_active = True
|
|
956
|
+
if self._dual_right_editors and 0 <= self._dual_right_idx < len(
|
|
957
|
+
self._dual_right_editors
|
|
958
|
+
):
|
|
959
|
+
with contextlib.suppress(tk.TclError):
|
|
960
|
+
self._dual_right_editors[self._dual_right_idx].text.focus_set(
|
|
961
|
+
)
|
|
962
|
+
|
|
963
|
+
def _close_dual_mode(self) -> None:
|
|
964
|
+
"""Desativa o modo dual e restaura o layout original."""
|
|
965
|
+
if not self._dual_mode:
|
|
966
|
+
return
|
|
967
|
+
self._dual_mode = False
|
|
968
|
+
self._dual_right_active = False
|
|
969
|
+
|
|
970
|
+
for e in self._dual_right_editors:
|
|
971
|
+
with contextlib.suppress(tk.TclError):
|
|
972
|
+
e.destroy()
|
|
973
|
+
self._dual_right_editors.clear()
|
|
974
|
+
self._dual_right_idx = -1
|
|
975
|
+
self._dual_right_tabbar = None
|
|
976
|
+
self._dual_right_editor_frame = None
|
|
977
|
+
|
|
978
|
+
if self._dual_paned:
|
|
979
|
+
with contextlib.suppress(tk.TclError):
|
|
980
|
+
self._dual_paned.destroy()
|
|
981
|
+
self._dual_paned = None
|
|
982
|
+
self._dual_left_container = None
|
|
983
|
+
self._dual_right_container = None
|
|
984
|
+
|
|
985
|
+
old_path: Path | None = None
|
|
986
|
+
if 0 <= self._active_idx < len(self._editors):
|
|
987
|
+
with contextlib.suppress(tk.TclError):
|
|
988
|
+
old_path = self._editors[self._active_idx].path
|
|
989
|
+
self._editors[self._active_idx].destroy()
|
|
990
|
+
|
|
991
|
+
if old_path is not None:
|
|
992
|
+
new_e = EditorPane(
|
|
993
|
+
self._editor_container,
|
|
994
|
+
self._tmgr,
|
|
995
|
+
self._cfg,
|
|
996
|
+
self._lint_mgr,
|
|
997
|
+
self._snippets,
|
|
998
|
+
on_change=self._on_editor_change,
|
|
999
|
+
on_cursor=self._on_cursor_change,
|
|
1000
|
+
on_title=self._on_editor_title,
|
|
1001
|
+
idx=self._active_idx,
|
|
1002
|
+
)
|
|
1003
|
+
if self._lsp_mgr:
|
|
1004
|
+
new_e.set_lsp_manager(self._lsp_mgr)
|
|
1005
|
+
new_e.set_goto_callback(self._open_file_at_line)
|
|
1006
|
+
new_e.set_workspace_edit_callback(self._apply_edits_to_path)
|
|
1007
|
+
new_e.load(old_path)
|
|
1008
|
+
self._editors[self._active_idx] = new_e
|
|
1009
|
+
self._active_pane = new_e
|
|
1010
|
+
new_e.pack(fill="both", expand=True)
|
|
1011
|
+
with contextlib.suppress(tk.TclError):
|
|
1012
|
+
new_e.text.focus_set()
|
|
1013
|
+
elif not self._editors:
|
|
1014
|
+
self._welcome.pack(fill="both", expand=True)
|
|
1015
|
+
|
|
1016
|
+
with contextlib.suppress(tk.TclError):
|
|
1017
|
+
self._root.unbind("<Control-backslash>")
|
|
1018
|
+
with contextlib.suppress(AttributeError):
|
|
1019
|
+
self._status.set_dual_mode(False)
|
|
1020
|
+
self._status.notify(_t("view.split_editor") +
|
|
1021
|
+
" OFF", duration=2000, level="ok")
|
|
1022
|
+
|
|
1023
|
+
def _dual_open_file(self, path: Path) -> None:
|
|
1024
|
+
"""Abre um arquivo no lado direito (ou esquerdo) dependendo do foco."""
|
|
1025
|
+
if self._dual_mode and self._dual_right_active:
|
|
1026
|
+
for i, e in enumerate(self._dual_right_editors):
|
|
1027
|
+
if e.path == path:
|
|
1028
|
+
self._dual_right_select(i)
|
|
1029
|
+
return
|
|
1030
|
+
self._create_dual_right_editor(path)
|
|
1031
|
+
else:
|
|
1032
|
+
self._open_file(path)
|
|
1033
|
+
|
|
1034
|
+
def _show_file_diff(self) -> None:
|
|
1035
|
+
"""Mostra o diff entre o arquivo atual e a versão salva."""
|
|
1036
|
+
e = self._e()
|
|
1037
|
+
if not e:
|
|
1038
|
+
return
|
|
1039
|
+
self._diff_pane.load(
|
|
1040
|
+
e._last_saved_content,
|
|
1041
|
+
e.get_content(),
|
|
1042
|
+
f"{e.path.name if e.path else 'untitled'} (saved)",
|
|
1043
|
+
f"{e.path.name if e.path else 'untitled'} (current)",
|
|
1044
|
+
)
|
|
1045
|
+
self._show_panel("diff")
|
|
1046
|
+
|
|
1047
|
+
def _show_diff_two_files(self) -> None:
|
|
1048
|
+
"""Abre diálogo para selecionar dois arquivos e mostrar o diff."""
|
|
1049
|
+
paths = filedialog.askopenfilenames(
|
|
1050
|
+
title=_t("hc.app.select_2_files_to_diff"),
|
|
1051
|
+
parent=self._root,
|
|
1052
|
+
)
|
|
1053
|
+
if len(paths) >= 2:
|
|
1054
|
+
try:
|
|
1055
|
+
a = Path(paths[0]).read_text(
|
|
1056
|
+
encoding="utf-8", errors="replace")
|
|
1057
|
+
b = Path(paths[1]).read_text(
|
|
1058
|
+
encoding="utf-8", errors="replace")
|
|
1059
|
+
self._diff_pane.show(
|
|
1060
|
+
a,
|
|
1061
|
+
b,
|
|
1062
|
+
Path(paths[0]).name,
|
|
1063
|
+
Path(paths[1]).name,
|
|
1064
|
+
)
|
|
1065
|
+
self._show_panel("diff")
|
|
1066
|
+
except (OSError, ValueError) as exc:
|
|
1067
|
+
messagebox.showerror(_t("err.diff"), str(exc))
|
|
1068
|
+
|
|
1069
|
+
def _new_terminal(self) -> None:
|
|
1070
|
+
"""Abre um novo terminal."""
|
|
1071
|
+
self._terminal.new_shell()
|
|
1072
|
+
self._show_panel("terminal")
|
|
1073
|
+
|
|
1074
|
+
def _clear_terminal(self) -> None:
|
|
1075
|
+
"""Limpa o terminal ativo."""
|
|
1076
|
+
self._terminal.clear_active()
|
|
1077
|
+
|
|
1078
|
+
def _kill_terminal(self) -> None:
|
|
1079
|
+
"""Mata o terminal ativo."""
|
|
1080
|
+
self._terminal.kill_active()
|
|
1081
|
+
|
|
1082
|
+
def _open_settings_window(self) -> None:
|
|
1083
|
+
"""Abre a janela flutuante de configurações (Ctrl+,).
|
|
1084
|
+
|
|
1085
|
+
Janela única: mantém referência à janela e verifica winfo_exists()
|
|
1086
|
+
para evitar múltiplas instâncias mesmo quando o evento <Destroy> não
|
|
1087
|
+
dispara corretamente (ex: fechamento pelo botão engrenagem).
|
|
1088
|
+
"""
|
|
1089
|
+
|
|
1090
|
+
existing: tk.Toplevel | None = getattr(self, "_settings_win_ref", None)
|
|
1091
|
+
if existing is not None:
|
|
1092
|
+
with contextlib.suppress(Exception):
|
|
1093
|
+
if existing.winfo_exists():
|
|
1094
|
+
existing.lift()
|
|
1095
|
+
existing.focus_set()
|
|
1096
|
+
return
|
|
1097
|
+
self._settings_win_ref = None
|
|
1098
|
+
|
|
1099
|
+
from src.ui.settings_window import SettingsWindow
|
|
1100
|
+
|
|
1101
|
+
win = SettingsWindow(
|
|
1102
|
+
self._root,
|
|
1103
|
+
self._tmgr,
|
|
1104
|
+
self._cfg,
|
|
1105
|
+
on_change=self._on_setting_change,
|
|
1106
|
+
on_show_settings_panel=self._show_settings_panel,
|
|
1107
|
+
)
|
|
1108
|
+
self._settings_win_ref = win
|
|
1109
|
+
win._app_ref = self
|
|
1110
|
+
|
|
1111
|
+
def _on_close() -> None:
|
|
1112
|
+
self._settings_win_ref = None
|
|
1113
|
+
|
|
1114
|
+
win.protocol("WM_DELETE_WINDOW", lambda: (win.destroy(), _on_close()))
|
|
1115
|
+
win.bind("<Destroy>", lambda e: _on_close()
|
|
1116
|
+
if e.widget is win else None)
|
|
1117
|
+
|
|
1118
|
+
def _open_settings_window_cursor(self) -> None:
|
|
1119
|
+
"""Abre a janela flutuante de configurações diretamente na aba Cursor."""
|
|
1120
|
+
|
|
1121
|
+
existing: tk.Toplevel | None = getattr(self, "_settings_win_ref", None)
|
|
1122
|
+
if existing is not None:
|
|
1123
|
+
with contextlib.suppress(Exception):
|
|
1124
|
+
if existing.winfo_exists():
|
|
1125
|
+
existing.lift()
|
|
1126
|
+
existing.focus_set()
|
|
1127
|
+
existing._show_category("cursor")
|
|
1128
|
+
return
|
|
1129
|
+
self._settings_win_ref = None
|
|
1130
|
+
|
|
1131
|
+
from src.ui.settings_window import SettingsWindow
|
|
1132
|
+
|
|
1133
|
+
win = SettingsWindow(
|
|
1134
|
+
self._root,
|
|
1135
|
+
self._tmgr,
|
|
1136
|
+
self._cfg,
|
|
1137
|
+
on_change=self._on_setting_change,
|
|
1138
|
+
on_show_settings_panel=self._show_settings_panel,
|
|
1139
|
+
)
|
|
1140
|
+
self._settings_win_ref = win
|
|
1141
|
+
win._app_ref = self
|
|
1142
|
+
win._show_category("cursor")
|
|
1143
|
+
|
|
1144
|
+
def _on_close() -> None:
|
|
1145
|
+
self._settings_win_ref = None
|
|
1146
|
+
|
|
1147
|
+
win.protocol("WM_DELETE_WINDOW", lambda: (win.destroy(), _on_close()))
|
|
1148
|
+
win.bind("<Destroy>", lambda e: _on_close()
|
|
1149
|
+
if e.widget is win else None)
|
|
1150
|
+
|
|
1151
|
+
def _run_reset(self, mode: str) -> None:
|
|
1152
|
+
"""Executa um reset direto sem abrir o wizard completo.
|
|
1153
|
+
|
|
1154
|
+
Args:
|
|
1155
|
+
mode: ``"soft"`` | ``"wizard"`` | ``"full"``
|
|
1156
|
+
"""
|
|
1157
|
+
import shutil
|
|
1158
|
+
|
|
1159
|
+
from src.constants import (
|
|
1160
|
+
CONFIG_DIR,
|
|
1161
|
+
DEFAULT_CONFIG,
|
|
1162
|
+
)
|
|
1163
|
+
|
|
1164
|
+
labels = {
|
|
1165
|
+
"soft": "Soft Reset",
|
|
1166
|
+
"wizard": "Soft Reset + Wizard",
|
|
1167
|
+
"full": "Limpeza Completa",
|
|
1168
|
+
}
|
|
1169
|
+
label = labels.get(mode, mode)
|
|
1170
|
+
|
|
1171
|
+
msg = {
|
|
1172
|
+
"soft": _t(
|
|
1173
|
+
"reset.quick_soft_msg",
|
|
1174
|
+
"Isso irá redefinir TODAS as configurações para os valores padrão.\n"
|
|
1175
|
+
"Plugins, sessão e arquivos de projeto são mantidos.\n\nContinuar?",
|
|
1176
|
+
),
|
|
1177
|
+
"wizard": _t(
|
|
1178
|
+
"reset.quick_wizard_msg",
|
|
1179
|
+
"Redefinirá as configurações E ativará o assistente na próxima abertura.\n\nContinuar?",
|
|
1180
|
+
),
|
|
1181
|
+
"full": _t(
|
|
1182
|
+
"reset.quick_full_msg",
|
|
1183
|
+
"Isso irá remover configurações, cache de sessão e histórico recente.\n"
|
|
1184
|
+
"Esta ação NÃO pode ser desfeita.\n\nContinuar?",
|
|
1185
|
+
),
|
|
1186
|
+
}.get(mode, "Continuar?")
|
|
1187
|
+
|
|
1188
|
+
if not tk.messagebox.askyesno(label, msg, parent=self._root, icon="warning"):
|
|
1189
|
+
return
|
|
1190
|
+
|
|
1191
|
+
try:
|
|
1192
|
+
self._cfg._data = dict(DEFAULT_CONFIG)
|
|
1193
|
+
|
|
1194
|
+
if mode == "wizard":
|
|
1195
|
+
self._cfg.set("_setup_wizard_pending", True)
|
|
1196
|
+
|
|
1197
|
+
if mode in ("wizard", "full"):
|
|
1198
|
+
self._cfg.set("recent_files", [])
|
|
1199
|
+
self._cfg.set("session_files", [])
|
|
1200
|
+
self._cfg.set("last_workspace", "")
|
|
1201
|
+
|
|
1202
|
+
if mode == "full":
|
|
1203
|
+
extras = [
|
|
1204
|
+
CONFIG_DIR / "sessions",
|
|
1205
|
+
CONFIG_DIR / "cache",
|
|
1206
|
+
CONFIG_DIR / "history.json",
|
|
1207
|
+
CONFIG_DIR / "snippets_custom.json",
|
|
1208
|
+
]
|
|
1209
|
+
for p in extras:
|
|
1210
|
+
target = Path(str(p))
|
|
1211
|
+
with contextlib.suppress(OSError):
|
|
1212
|
+
if target.is_dir():
|
|
1213
|
+
shutil.rmtree(str(target))
|
|
1214
|
+
elif target.exists():
|
|
1215
|
+
target.unlink()
|
|
1216
|
+
|
|
1217
|
+
self._cfg.save()
|
|
1218
|
+
tk.messagebox.showinfo(
|
|
1219
|
+
label,
|
|
1220
|
+
_t(
|
|
1221
|
+
"reset.quick_done_msg",
|
|
1222
|
+
"{label} concluído.\nO Codis será reiniciado para aplicar as mudanças.",
|
|
1223
|
+
label=label,
|
|
1224
|
+
),
|
|
1225
|
+
parent=self._root,
|
|
1226
|
+
)
|
|
1227
|
+
self._root.after(200, self._restart_ui)
|
|
1228
|
+
|
|
1229
|
+
except Exception as exc:
|
|
1230
|
+
logger.error("Erro no reset rápido (%s): %s",
|
|
1231
|
+
mode, exc, exc_info=True)
|
|
1232
|
+
tk.messagebox.showerror(
|
|
1233
|
+
_t("reset.err_title", "Erro no Reset"),
|
|
1234
|
+
_t("reset.err_msg",
|
|
1235
|
+
"Não foi possível completar o reset:\n{e}", e=exc),
|
|
1236
|
+
parent=self._root,
|
|
1237
|
+
)
|
|
1238
|
+
|
|
1239
|
+
def _reset_single_key(self) -> None:
|
|
1240
|
+
"""Abre diálogo para redefinir uma única chave de configuração ao padrão."""
|
|
1241
|
+
from src.constants import DEFAULT_CONFIG
|
|
1242
|
+
|
|
1243
|
+
dlg = tk.Toplevel(self._root)
|
|
1244
|
+
t = self._tmgr.theme
|
|
1245
|
+
dlg.title(_t("reset.single_key_title",
|
|
1246
|
+
"Redefinir Configuração Específica"))
|
|
1247
|
+
dlg.geometry("460x320")
|
|
1248
|
+
dlg.configure(bg=t.floating_bg)
|
|
1249
|
+
dlg.transient(self._root)
|
|
1250
|
+
from src.ui.grab_safe import safe_grab_set
|
|
1251
|
+
|
|
1252
|
+
safe_grab_set(dlg)
|
|
1253
|
+
|
|
1254
|
+
tk.Label(
|
|
1255
|
+
dlg,
|
|
1256
|
+
text=_t("reset.single_key_title",
|
|
1257
|
+
"Redefinir Configuração Específica"),
|
|
1258
|
+
bg=t.floating_bg,
|
|
1259
|
+
fg=t.fg,
|
|
1260
|
+
font=("Segoe UI", 12, "bold"),
|
|
1261
|
+
pady=12,
|
|
1262
|
+
anchor="w",
|
|
1263
|
+
padx=16,
|
|
1264
|
+
).pack(fill="x")
|
|
1265
|
+
tk.Label(
|
|
1266
|
+
dlg,
|
|
1267
|
+
text=_t(
|
|
1268
|
+
"reset.single_key_label",
|
|
1269
|
+
"Digite o nome da chave de configuração a ser redefinida:",
|
|
1270
|
+
),
|
|
1271
|
+
bg=t.floating_bg,
|
|
1272
|
+
fg=t.fg_muted,
|
|
1273
|
+
font=("Segoe UI", 9),
|
|
1274
|
+
anchor="w",
|
|
1275
|
+
padx=16,
|
|
1276
|
+
).pack(fill="x")
|
|
1277
|
+
|
|
1278
|
+
entry_var = tk.StringVar()
|
|
1279
|
+
entry = tk.Entry(
|
|
1280
|
+
dlg,
|
|
1281
|
+
textvariable=entry_var,
|
|
1282
|
+
bg=t.input_bg,
|
|
1283
|
+
fg=t.fg,
|
|
1284
|
+
insertbackground=t.fg,
|
|
1285
|
+
font=("Consolas", 10),
|
|
1286
|
+
relief="flat",
|
|
1287
|
+
)
|
|
1288
|
+
entry.pack(fill="x", padx=16, pady=(8, 4))
|
|
1289
|
+
entry.focus_set()
|
|
1290
|
+
|
|
1291
|
+
keys_text = tk.Text(
|
|
1292
|
+
dlg,
|
|
1293
|
+
bg=t.sidebar_bg,
|
|
1294
|
+
fg=t.fg_muted,
|
|
1295
|
+
font=("Consolas", 8),
|
|
1296
|
+
height=8,
|
|
1297
|
+
relief="flat",
|
|
1298
|
+
state="normal",
|
|
1299
|
+
)
|
|
1300
|
+
keys_text.pack(fill="both", expand=True, padx=16, pady=(0, 4))
|
|
1301
|
+
keys_text.insert("1.0", " ".join(sorted(DEFAULT_CONFIG.keys())))
|
|
1302
|
+
keys_text.config(state="disabled")
|
|
1303
|
+
|
|
1304
|
+
result_lbl = tk.Label(
|
|
1305
|
+
dlg, text="", bg=t.floating_bg, fg=t.fg_muted, font=("Segoe UI", 8), padx=16
|
|
1306
|
+
)
|
|
1307
|
+
result_lbl.pack(fill="x")
|
|
1308
|
+
|
|
1309
|
+
def _do_reset():
|
|
1310
|
+
key = entry_var.get().strip()
|
|
1311
|
+
if key not in DEFAULT_CONFIG:
|
|
1312
|
+
result_lbl.config(
|
|
1313
|
+
text=_t(
|
|
1314
|
+
"reset.key_not_found", "Chave '{k}' não encontrada.", k=key
|
|
1315
|
+
),
|
|
1316
|
+
fg=t.err_fg,
|
|
1317
|
+
)
|
|
1318
|
+
return
|
|
1319
|
+
self._cfg.set(key, DEFAULT_CONFIG[key])
|
|
1320
|
+
self._cfg.save()
|
|
1321
|
+
result_lbl.config(
|
|
1322
|
+
text=_t(
|
|
1323
|
+
"reset.key_reset_ok",
|
|
1324
|
+
"'{k}' redefinida para: {v}",
|
|
1325
|
+
k=key,
|
|
1326
|
+
v=repr(DEFAULT_CONFIG[key]),
|
|
1327
|
+
),
|
|
1328
|
+
fg=t.accent,
|
|
1329
|
+
)
|
|
1330
|
+
|
|
1331
|
+
btn_frame = tk.Frame(dlg, bg=t.floating_bg)
|
|
1332
|
+
btn_frame.pack(fill="x", padx=16, pady=8)
|
|
1333
|
+
for text, cmd, is_primary in (
|
|
1334
|
+
(_t("reset.btn_cancel", "Cancelar"), dlg.destroy, False),
|
|
1335
|
+
(_t("reset.btn_reset", "Redefinir"), _do_reset, True),
|
|
1336
|
+
):
|
|
1337
|
+
bg = t.accent if is_primary else t.btn_bg
|
|
1338
|
+
b = tk.Label(
|
|
1339
|
+
btn_frame,
|
|
1340
|
+
text=text,
|
|
1341
|
+
bg=bg,
|
|
1342
|
+
fg="#ffffff" if is_primary else t.fg,
|
|
1343
|
+
font=("Segoe UI", 9, "bold" if is_primary else "normal"),
|
|
1344
|
+
cursor="hand2",
|
|
1345
|
+
padx=14,
|
|
1346
|
+
pady=5,
|
|
1347
|
+
relief="flat",
|
|
1348
|
+
)
|
|
1349
|
+
b.pack(side="right", padx=4)
|
|
1350
|
+
b.bind("<Button-1>", lambda _, c=cmd: c())
|
|
1351
|
+
|
|
1352
|
+
entry.bind("<Return>", lambda _: _do_reset())
|
|
1353
|
+
|
|
1354
|
+
def _reset_session_only(self) -> None:
|
|
1355
|
+
"""Limpa apenas a sessão, recentes e histórico, sem alterar outras configs."""
|
|
1356
|
+
if not tk.messagebox.askyesno(
|
|
1357
|
+
_t("reset.session_title", "Limpar Sessão"),
|
|
1358
|
+
_t(
|
|
1359
|
+
"reset.session_msg",
|
|
1360
|
+
"Isso irá limpar:\n• Abas recentes\n• Arquivos recentes\n• Histórico de workspace\n\nContinuar?",
|
|
1361
|
+
),
|
|
1362
|
+
parent=self._root,
|
|
1363
|
+
icon="warning",
|
|
1364
|
+
):
|
|
1365
|
+
return
|
|
1366
|
+
|
|
1367
|
+
import contextlib as _cl
|
|
1368
|
+
|
|
1369
|
+
for key in (
|
|
1370
|
+
"recent_files",
|
|
1371
|
+
"session_files",
|
|
1372
|
+
"last_workspace",
|
|
1373
|
+
"recent_folders",
|
|
1374
|
+
):
|
|
1375
|
+
with _cl.suppress(Exception):
|
|
1376
|
+
self._cfg.set(key, [] if key != "last_workspace" else "")
|
|
1377
|
+
|
|
1378
|
+
self._cfg.save()
|
|
1379
|
+
tk.messagebox.showinfo(
|
|
1380
|
+
_t("reset.session_done_title", "Sessão Limpa"),
|
|
1381
|
+
_t(
|
|
1382
|
+
"reset.session_done_msg", "Sessão e histórico foram limpos com sucesso."
|
|
1383
|
+
),
|
|
1384
|
+
parent=self._root,
|
|
1385
|
+
)
|