Skip to content

Commit

Permalink
Implemented: Adding widgets and actions using context menu #659
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Dec 8, 2024
1 parent cc0a139 commit 05377da
Show file tree
Hide file tree
Showing 29 changed files with 872 additions and 190 deletions.
29 changes: 29 additions & 0 deletions packages/eez-studio-ui/_stylesheets/project-editor.less
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@
margin: 2px;
padding: 4px;
cursor: grab;
&[draggable="false"] {
cursor: pointer;
}
display: flex;
flex-direction: row;
align-items: center;
Expand Down Expand Up @@ -523,7 +526,13 @@
}

.EezStudio_PropertiesPanel_Body {
height: 100%;
overflow: auto;

.EezStudio_PropertyGrid_NothingSelected {
height: 100%;
background-color: @panelHeaderColor;
}
}
}

Expand Down Expand Up @@ -3824,3 +3833,23 @@
white-space: nowrap;
border-radius: 4px;
}

.EezStudio_ProjectEditor_SelectComponentDialog {
.modal-content {
width: 530px;
max-height: calc(100vh - 200px);
.modal-body {
padding: 0;
overflow: hidden;
display: flex;
.EezStudio_ComponentsPalette_Enclosure {
height: unset;
}
}
}
}

.EezStudio_PageStructure_NoPageSelected {
height: 100%;
background-color: @panelHeaderColor;
}
1 change: 0 additions & 1 deletion packages/eez-studio-ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ export const BootstrapDialog = observer(
additionalFooterControl?: React.ReactNode;
backdrop?: "static" | boolean;
className?: string;
modalContentStyle?: React.CSSProperties;
}> {
div: HTMLDivElement | null = null;
form: HTMLFormElement | null = null;
Expand Down
22 changes: 22 additions & 0 deletions packages/home/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ ipcRenderer.on("mru-changed", async (sender: any, mru: IMruItem[]) => {

////////////////////////////////////////////////////////////////////////////////

const getShowComponentsPaletteInProjectEditor = function () {
return ipcRenderer.sendSync("getShowComponentsPaletteInProjectEditor");
};

const setShowComponentsPaletteInProjectEditor = function (value: boolean) {
ipcRenderer.send("setShowComponentsPaletteInProjectEditor", value);
};

////////////////////////////////////////////////////////////////////////////////

class SettingsController {
activetLocale = getLocale();
activeDateFormat = getDateFormat();
Expand All @@ -130,6 +140,9 @@ class SettingsController {
pythonUseCustomPath: boolean = false;
pythonCustomPath: string = "";

_showComponentsPaletteInProjectEditor: boolean =
getShowComponentsPaletteInProjectEditor();

constructor() {
this.pythonUseCustomPath =
window.localStorage.getItem("pythonUseCustomPath") == "1"
Expand Down Expand Up @@ -397,6 +410,15 @@ class SettingsController {
}
showDialog(<CompactDatabaseDialog database={this.selectedDatabase} />);
};

get showComponentsPaletteInProjectEditor() {
return this._showComponentsPaletteInProjectEditor;
}

set showComponentsPaletteInProjectEditor(value: boolean) {
this._showComponentsPaletteInProjectEditor = value;
setShowComponentsPaletteInProjectEditor(value);
}
}

export const settingsController = new SettingsController();
Expand Down
8 changes: 8 additions & 0 deletions packages/home/tabs-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ export class ProjectEditorTab implements IHomeTab {
projectStore.navigationStore.selectedPanel.selectAll();
}
};
const onToggleComponentsPalette = () => {
projectStore.layoutModels.toggleComponentsPalette();
};
const onResetLayoutModels = () => {
if (!this.runMode) {
projectStore.layoutModels.reset();
Expand Down Expand Up @@ -674,6 +677,7 @@ export class ProjectEditorTab implements IHomeTab {
ipcRenderer.on("delete", deleteSelection);
ipcRenderer.on("select-all", selectAll);

ipcRenderer.on("toggleComponentsPalette", onToggleComponentsPalette);
ipcRenderer.on("resetLayoutModels", onResetLayoutModels);

ipcRenderer.on("reload-project", onReloadProject);
Expand All @@ -698,6 +702,10 @@ export class ProjectEditorTab implements IHomeTab {
ipcRenderer.removeListener("delete", deleteSelection);
ipcRenderer.removeListener("select-all", selectAll);

ipcRenderer.removeListener(
"toggleComponentsPalette",
onToggleComponentsPalette
);
ipcRenderer.removeListener(
"resetLayoutModels",
onResetLayoutModels
Expand Down
13 changes: 13 additions & 0 deletions packages/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,19 @@ function buildViewMenu(win: IWindow | undefined) {
type: "separator"
});

viewSubmenu.push({
label: settings.showComponentsPaletteInProjectEditor
? "Hide Components Palette"
: "Show Components Palette",
click: function (item) {
if (win) {
win.browserWindow.webContents.send(
"toggleComponentsPalette"
);
}
}
});

viewSubmenu.push({
label: "Reset Layout",
click: function (item) {
Expand Down
33 changes: 32 additions & 1 deletion packages/main/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Settings {

_loaded: boolean = false;

showComponentsPaletteInProjectEditor: boolean = true;

async loadSettings() {
if (this._loaded) {
return;
Expand Down Expand Up @@ -89,7 +91,8 @@ class Settings {
locale: observable,
dateFormat: observable,
timeFormat: observable,
isDarkTheme: observable
isDarkTheme: observable,
showComponentsPaletteInProjectEditor: observable
});

reaction(
Expand Down Expand Up @@ -182,6 +185,11 @@ class Settings {
if (settingsJs.isDarkTheme != undefined) {
this.isDarkTheme = settingsJs.isDarkTheme;
}

if (settingsJs.showComponentsPaletteInProjectEditor != undefined) {
this.showComponentsPaletteInProjectEditor =
settingsJs.showComponentsPaletteInProjectEditor;
}
}
}

Expand Down Expand Up @@ -467,3 +475,26 @@ ipcMain.on("setIsDarkTheme", function (event: any, value: boolean) {
});

////////////////////////////////////////////////////////////////////////////////

function getShowComponentsPaletteInProjectEditor() {
return settings.showComponentsPaletteInProjectEditor;
}

function setShowComponentsPaletteInProjectEditor(value: boolean) {
runInAction(() => {
settings.showComponentsPaletteInProjectEditor = value;
});
}

ipcMain.on("getShowComponentsPaletteInProjectEditor", function (event: any) {
event.returnValue = getShowComponentsPaletteInProjectEditor();
});

ipcMain.on(
"setShowComponentsPaletteInProjectEditor",
function (event: any, value: boolean) {
setShowComponentsPaletteInProjectEditor(value);
}
);

////////////////////////////////////////////////////////////////////////////////
35 changes: 31 additions & 4 deletions packages/project-editor/core/objectAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createTransformer } from "mobx-utils";
import { map, find, each, pickBy } from "lodash";

import { stringCompare } from "eez-studio-shared/string";
import { Rect } from "eez-studio-shared/geometry";
import { Point, Rect } from "eez-studio-shared/geometry";

import {
getProperty,
Expand All @@ -24,7 +24,8 @@ import {
getParent,
getId,
EezObject,
setKey
setKey,
getKey
} from "project-editor/core/object";

import {
Expand Down Expand Up @@ -54,7 +55,9 @@ import {
addItem,
isObjectReferencable,
canContain,
getProjectEditorDataFromClipboard
getProjectEditorDataFromClipboard,
getAncestorOfType,
getAddItemName
} from "project-editor/store";

import { DragAndDropManager } from "project-editor/core/dd";
Expand Down Expand Up @@ -555,6 +558,7 @@ export class TreeObjectAdapter {
add?: boolean;
pasteSelection?: () => void;
duplicateSelection?: () => void;
atPoint?: Point;
},
editable?: boolean,
additionalMenuItems?: Electron.MenuItem[]
Expand Down Expand Up @@ -594,12 +598,13 @@ export class TreeObjectAdapter {
if (
editable &&
parentObject &&
!(parentObject instanceof ProjectEditor.FlowClass) &&
canAdd(parentObject) &&
!(actions?.add === false)
) {
menuItems.push(
new MenuItem({
label: "Add",
label: `Add ${getAddItemName(parentObject)}...`,
click: async () => {
const aNewObject = await addItem(parentObject!);
if (aNewObject) {
Expand Down Expand Up @@ -757,7 +762,29 @@ export class TreeObjectAdapter {
menuItems = menuItems.concat(additionalMenuItems);
}

console.log("selectedObject", selectedObject);
console.log("parentObject", parentObject);
if (
editable &&
getAncestorOfType(
selectedObject || parentObject,
ProjectEditor.FlowClass.classInfo
) &&
getKey(parentObject) != "localVariables"
) {
ProjectEditor.newComponentMenuItem(
selectedObject || parentObject,
menuItems,
actions?.atPoint
);
}

if (menuItems.length > 0) {
// remove separator at the end
if (menuItems[menuItems.length - 1].type == "separator") {
menuItems.splice(menuItems.length - 1, 1);
}

const menu = new Menu();
menuItems.forEach(menuItem => menu.append(menuItem));
return menu;
Expand Down
11 changes: 11 additions & 0 deletions packages/project-editor/features/changes/flow-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,17 @@ class FlowDocument implements IDocument {
targetObjectId: string,
connectionInput: string
) {}

connectToNewTarget(
sourceObjectId: string,
connectionOutput: string,
atPoint: Point
) {}
connectToNewSource(
targetObjectId: string,
connectionInput: string,
atPoint: Point
) {}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 6 additions & 1 deletion packages/project-editor/features/page/PagesNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,12 @@ export const PageStructure = observer(
/>
</Body>
</VerticalHeaderWithBody>
) : null;
) : (
<div
className="EezStudio_PageStructure_NoPageSelected"
onContextMenu={e => e.preventDefault()}
></div>
);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const AddButton = observer(
render() {
return (
<IconAction
title="Add Item"
title="Add Style..."
icon="material:add"
iconSize={16}
onClick={this.onAdd}
Expand Down
1 change: 0 additions & 1 deletion packages/project-editor/features/style/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,6 @@ const propertiesMap: { [propertyName: string]: PropertyInfo } = {};
for (const property of properties) {
propertiesMap[property.name] = property;
}
console.log(propertiesMap);

////////////////////////////////////////////////////////////////////////////////

Expand Down
Loading

0 comments on commit 05377da

Please sign in to comment.