mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-01 23:21:59 +01:00
implement defaultwidgets
This commit is contained in:
parent
ca3f418dc5
commit
a639fc3c8d
@ -21,6 +21,7 @@
|
||||
width: 50px;
|
||||
overflow: hidden;
|
||||
padding-top: 4px;
|
||||
padding-bottom: 4px;
|
||||
|
||||
.widget {
|
||||
display: flex;
|
||||
@ -46,7 +47,22 @@
|
||||
.widget-label {
|
||||
font-size: 10px;
|
||||
margin-top: 3px;
|
||||
}
|
||||
width: 100%;
|
||||
padding: 0 2px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.widget-divider {
|
||||
margin-left: 6px;
|
||||
height: 2px;
|
||||
background-color: var(--border-color);
|
||||
}
|
||||
|
||||
.widget-spacer {
|
||||
flex-grow: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import { ModalsRenderer } from "@/app/modals/modalsrenderer";
|
||||
import { TabBar } from "@/app/tab/tabbar";
|
||||
import { TabContent } from "@/app/tab/tabcontent";
|
||||
import { atoms, createBlock } from "@/store/global";
|
||||
import * as services from "@/store/services";
|
||||
import * as util from "@/util/util";
|
||||
import * as jotai from "jotai";
|
||||
import * as React from "react";
|
||||
@ -18,46 +17,36 @@ const iconRegex = /^[a-z0-9-]+$/;
|
||||
const Widgets = React.memo(() => {
|
||||
const settingsConfig = jotai.useAtomValue(atoms.settingsConfigAtom);
|
||||
const newWidgetModalVisible = React.useState(false);
|
||||
async function clickTerminal() {
|
||||
const termBlockDef: BlockDef = {
|
||||
const helpWidget: WidgetsConfigType = {
|
||||
icon: "circle-question",
|
||||
label: "help",
|
||||
blockdef: {
|
||||
meta: {
|
||||
controller: "shell",
|
||||
view: "term",
|
||||
view: "help",
|
||||
},
|
||||
},
|
||||
};
|
||||
createBlock(termBlockDef);
|
||||
}
|
||||
const showHelp = settingsConfig?.["widget:showhelp"] ?? true;
|
||||
const showDivider = settingsConfig?.defaultwidgets?.length > 0 && settingsConfig?.widgets?.length > 0;
|
||||
return (
|
||||
<div className="workspace-widgets">
|
||||
{settingsConfig?.defaultwidgets?.map((data, idx) => <Widget key={`defwidget-${idx}`} widget={data} />)}
|
||||
{showDivider ? <div className="widget-divider" /> : null}
|
||||
{settingsConfig?.widgets?.map((data, idx) => <Widget key={`widget-${idx}`} widget={data} />)}
|
||||
{showHelp ? (
|
||||
<>
|
||||
<div className="widget-spacer" />
|
||||
<Widget key="help" widget={helpWidget} />
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
async function clickHome() {
|
||||
const editDef: BlockDef = {
|
||||
meta: {
|
||||
view: "preview",
|
||||
file: "~",
|
||||
},
|
||||
};
|
||||
createBlock(editDef);
|
||||
}
|
||||
async function clickWeb() {
|
||||
const editDef: BlockDef = {
|
||||
meta: {
|
||||
view: "web",
|
||||
url: "https://waveterm.dev/",
|
||||
},
|
||||
};
|
||||
createBlock(editDef);
|
||||
}
|
||||
async function handleWidgetSelect(blockDef: BlockDef) {
|
||||
createBlock(blockDef);
|
||||
}
|
||||
|
||||
async function handleCreateWidget(newWidget: WidgetsConfigType) {
|
||||
await services.FileService.AddWidget(newWidget);
|
||||
}
|
||||
|
||||
async function handleRemoveWidget(idx: number) {
|
||||
await services.FileService.RemoveWidget(idx);
|
||||
}
|
||||
|
||||
function isIconValid(icon: string): boolean {
|
||||
if (util.isBlank(icon)) {
|
||||
return false;
|
||||
@ -72,33 +61,17 @@ const Widgets = React.memo(() => {
|
||||
return `fa fa-solid fa-${icon} fa-fw`;
|
||||
}
|
||||
|
||||
const Widget = React.memo(({ widget }: { widget: WidgetsConfigType }) => {
|
||||
return (
|
||||
<div className="workspace-widgets">
|
||||
<div className="widget" onClick={() => clickTerminal()}>
|
||||
<div className="widget-icon">
|
||||
<i className="fa fa-solid fa-square-terminal fa-fw" />
|
||||
</div>
|
||||
<div className="widget-label">terminal</div>
|
||||
</div>
|
||||
<div className="widget" onClick={() => clickHome()}>
|
||||
<div className="widget-icon">
|
||||
<i className="fa-sharp fa-solid fa-folder"></i>
|
||||
</div>
|
||||
<div className="widget-label">files</div>
|
||||
</div>
|
||||
{settingsConfig?.widgets?.map((data, idx) => (
|
||||
<div
|
||||
className="widget"
|
||||
onClick={() => handleWidgetSelect(data.blockdef)}
|
||||
key={`widget-${idx}`}
|
||||
title={data.description || data.label}
|
||||
onClick={() => handleWidgetSelect(widget.blockdef)}
|
||||
title={widget.description || widget.label}
|
||||
>
|
||||
<div className="widget-icon" style={{ color: data.color }}>
|
||||
<i className={getIconClass(data.icon)}></i>
|
||||
<div className="widget-icon" style={{ color: widget.color }}>
|
||||
<i className={getIconClass(widget.icon)}></i>
|
||||
</div>
|
||||
{!util.isBlank(data.label) ? <div className="widget-label">{data.label}</div> : null}
|
||||
</div>
|
||||
))}
|
||||
{!util.isBlank(widget.label) ? <div className="widget-label">{widget.label}</div> : null}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
3
frontend/types/gotypes.d.ts
vendored
3
frontend/types/gotypes.d.ts
vendored
@ -341,14 +341,15 @@ declare global {
|
||||
mimetypes: {[key: string]: MimeTypeConfigType};
|
||||
term: TerminalConfigType;
|
||||
ai: AiConfigType;
|
||||
defaultwidgets: WidgetsConfigType[];
|
||||
widgets: WidgetsConfigType[];
|
||||
"widget:showhelp": boolean;
|
||||
blockheader: BlockHeaderOpts;
|
||||
autoupdate: AutoUpdateOpts;
|
||||
termthemes: {[key: string]: TermThemeType};
|
||||
window: WindowSettingsType;
|
||||
web: WebConfigType;
|
||||
telemetry: TelemetrySettingsType;
|
||||
defaultmeta?: MetaType;
|
||||
presets?: {[key: string]: MetaType};
|
||||
};
|
||||
|
||||
|
@ -104,15 +104,15 @@ type SettingsConfigType struct {
|
||||
MimeTypes map[string]MimeTypeConfigType `json:"mimetypes"`
|
||||
Term TerminalConfigType `json:"term"`
|
||||
Ai *AiConfigType `json:"ai"`
|
||||
DefaultWidgets []WidgetsConfigType `json:"defaultwidgets"`
|
||||
Widgets []WidgetsConfigType `json:"widgets"`
|
||||
WidgetShowHelp *bool `json:"widget:showhelp"`
|
||||
BlockHeader BlockHeaderOpts `json:"blockheader"`
|
||||
AutoUpdate *AutoUpdateOpts `json:"autoupdate"`
|
||||
TermThemes TermThemesConfigType `json:"termthemes"`
|
||||
WindowSettings WindowSettingsType `json:"window"`
|
||||
Web WebConfigType `json:"web"`
|
||||
Telemetry *TelemetrySettingsType `json:"telemetry"`
|
||||
|
||||
DefaultMeta *waveobj.MetaMapType `json:"defaultmeta,omitempty"`
|
||||
Presets map[string]*waveobj.MetaMapType `json:"presets,omitempty"`
|
||||
}
|
||||
|
||||
@ -279,6 +279,26 @@ func applyDefaultSettings(settings *SettingsConfigType) {
|
||||
}
|
||||
}
|
||||
defaultWidgets := []WidgetsConfigType{
|
||||
{
|
||||
Icon: "square-terminal",
|
||||
Label: "terminal",
|
||||
BlockDef: wstore.BlockDef{
|
||||
Meta: map[string]any{
|
||||
wstore.MetaKey_View: "term",
|
||||
wstore.MetaKey_Controller: "shell",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Icon: "folder",
|
||||
Label: "files",
|
||||
BlockDef: wstore.BlockDef{
|
||||
Meta: map[string]any{
|
||||
wstore.MetaKey_View: "preview",
|
||||
wstore.MetaKey_File: "~",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Icon: "globe",
|
||||
Label: "web",
|
||||
@ -307,18 +327,9 @@ func applyDefaultSettings(settings *SettingsConfigType) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Icon: "circle-question",
|
||||
Label: "help",
|
||||
BlockDef: wstore.BlockDef{
|
||||
Meta: map[string]any{
|
||||
wstore.MetaKey_View: "help",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if settings.Widgets == nil {
|
||||
settings.Widgets = defaultWidgets
|
||||
if settings.DefaultWidgets == nil {
|
||||
settings.DefaultWidgets = defaultWidgets
|
||||
}
|
||||
if settings.TermThemes == nil {
|
||||
settings.TermThemes = make(map[string]TermThemeType)
|
||||
|
Loading…
Reference in New Issue
Block a user