|
| 1 | +/* |
| 2 | + * GNU AGPL-3.0 License |
| 3 | + * |
| 4 | + * Copyright (c) 2021 - present core.ai . All rights reserved. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify it under |
| 7 | + * the terms of the GNU Affero General Public License as published by the Free |
| 8 | + * Software Foundation, either version 3 of the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 11 | + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | + * See the GNU Affero General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU Affero General Public License along |
| 15 | + * with this program. If not, see https://opensource.org/licenses/AGPL-3.0. |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +/** |
| 20 | + * DefaultPanelView - A launcher panel shown in the bottom panel area when no |
| 21 | + * other panels are open. Provides quick-access buttons for common panels |
| 22 | + * (Problems, Find in Files, Git, Custom Snippets, Keyboard Shortcuts) and a |
| 23 | + * link to the documentation. |
| 24 | + * |
| 25 | + * @module view/DefaultPanelView |
| 26 | + */ |
| 27 | +define(function (require, exports, module) { |
| 28 | + |
| 29 | + const AppInit = require("utils/AppInit"), |
| 30 | + Commands = require("command/Commands"), |
| 31 | + CommandManager = require("command/CommandManager"), |
| 32 | + Strings = require("strings"), |
| 33 | + WorkspaceManager = require("view/WorkspaceManager"), |
| 34 | + PanelView = require("view/PanelView"); |
| 35 | + |
| 36 | + const DOCS_URL = "https://docs.phcode.dev"; |
| 37 | + |
| 38 | + /** |
| 39 | + * Descriptors for each launcher button. |
| 40 | + * `commandID` may be undefined if the command is registered later (e.g. Git). |
| 41 | + */ |
| 42 | + const _panelButtons = [ |
| 43 | + { |
| 44 | + id: "problems", |
| 45 | + icon: "fa-solid fa-triangle-exclamation", |
| 46 | + label: Strings.CMD_VIEW_TOGGLE_PROBLEMS || "Problems", |
| 47 | + commandID: Commands.VIEW_TOGGLE_PROBLEMS |
| 48 | + }, |
| 49 | + { |
| 50 | + id: "search", |
| 51 | + icon: "fa-solid fa-magnifying-glass", |
| 52 | + label: Strings.CMD_FIND_IN_FILES || "Find in Files", |
| 53 | + commandID: Commands.CMD_FIND_IN_FILES |
| 54 | + }, |
| 55 | + { |
| 56 | + id: "git", |
| 57 | + icon: "fa-solid fa-code-branch", |
| 58 | + label: Strings.GIT_PANEL_TITLE || "Git", |
| 59 | + commandID: Commands.CMD_GIT_TOGGLE_PANEL |
| 60 | + }, |
| 61 | + { |
| 62 | + id: "snippets", |
| 63 | + icon: "fa-solid fa-code", |
| 64 | + label: Strings.CUSTOM_SNIPPETS_PANEL_TITLE || "Custom Snippets", |
| 65 | + commandID: "custom_snippets" |
| 66 | + }, |
| 67 | + { |
| 68 | + id: "shortcuts", |
| 69 | + icon: "fa-solid fa-keyboard", |
| 70 | + label: Strings.KEYBOARD_SHORTCUT_PANEL_TITLE || "Keyboard Shortcuts", |
| 71 | + commandID: Commands.HELP_TOGGLE_SHORTCUTS_PANEL |
| 72 | + } |
| 73 | + ]; |
| 74 | + |
| 75 | + /** @type {Panel} The default panel instance */ |
| 76 | + let _panel; |
| 77 | + |
| 78 | + /** |
| 79 | + * Build the panel DOM. |
| 80 | + * @return {jQueryObject} |
| 81 | + * @private |
| 82 | + */ |
| 83 | + function _buildPanelHTML() { |
| 84 | + let $panel = $('<div id="default-panel" class="bottom-panel"></div>'); |
| 85 | + let $content = $('<div class="default-panel-content"></div>'); |
| 86 | + let $heading = $('<div class="default-panel-heading"></div>') |
| 87 | + .text(Strings.BOTTOM_PANEL_DEFAULT_HEADING); |
| 88 | + $content.append($heading); |
| 89 | + |
| 90 | + let $buttonsRow = $('<div class="default-panel-buttons"></div>'); |
| 91 | + |
| 92 | + _panelButtons.forEach(function (btn) { |
| 93 | + let $button = $('<button class="default-panel-btn"></button>') |
| 94 | + .attr("data-command", btn.commandID) |
| 95 | + .attr("title", btn.label); |
| 96 | + let $icon = $('<i></i>').addClass(btn.icon); |
| 97 | + let $label = $('<span class="default-panel-btn-label"></span>').text(btn.label); |
| 98 | + $button.append($icon).append($label); |
| 99 | + $buttonsRow.append($button); |
| 100 | + }); |
| 101 | + |
| 102 | + $content.append($buttonsRow); |
| 103 | + |
| 104 | + let $readMore = $('<a class="default-panel-read-more" target="_blank"></a>') |
| 105 | + .attr("href", DOCS_URL) |
| 106 | + .text(Strings.BOTTOM_PANEL_DEFAULT_READ_MORE + " \u2192"); |
| 107 | + $content.append($readMore); |
| 108 | + |
| 109 | + $panel.append($content); |
| 110 | + return $panel; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Initialise the default panel. Called once at appReady. |
| 115 | + * @private |
| 116 | + */ |
| 117 | + function _init() { |
| 118 | + let $panel = _buildPanelHTML(); |
| 119 | + _panel = WorkspaceManager.createBottomPanel( |
| 120 | + WorkspaceManager.DEFAULT_PANEL_ID, |
| 121 | + $panel, |
| 122 | + undefined, |
| 123 | + Strings.BOTTOM_PANEL_DEFAULT_TITLE |
| 124 | + ); |
| 125 | + |
| 126 | + // Button click handler: execute the command to open the target panel. |
| 127 | + // The auto-hide listener (EVENT_PANEL_SHOWN) will close the default panel. |
| 128 | + $panel.on("click", ".default-panel-btn", function () { |
| 129 | + let commandID = $(this).attr("data-command"); |
| 130 | + if (commandID) { |
| 131 | + CommandManager.execute(commandID); |
| 132 | + } |
| 133 | + }); |
| 134 | + |
| 135 | + // Auto-hide when any other panel is shown. |
| 136 | + // hide() is a no-op if the panel is already closed, so no guard needed. |
| 137 | + PanelView.on(PanelView.EVENT_PANEL_SHOWN, function (event, panelID) { |
| 138 | + if (panelID !== WorkspaceManager.DEFAULT_PANEL_ID) { |
| 139 | + _panel.hide(); |
| 140 | + } |
| 141 | + }); |
| 142 | + } |
| 143 | + |
| 144 | + AppInit.appReady(_init); |
| 145 | +}); |
0 commit comments