Skip to content

Commit

Permalink
Add tab method refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Feb 13, 2025
1 parent 782cca6 commit 8c25797
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class TabDesignerPlugin implements ICreatorPlugin {
}

constructor(private creator: SurveyCreatorModel) {
creator.addPluginTab({ name: "designer", plugin: this, iconName: "icon-config" });
creator.addTab({ name: "designer", plugin: this, iconName: "icon-config" });
this.tabControlModel = new TabControlModel(this.creator.sidebar);
this.propertyGrid = new PropertyGridModel(undefined, creator, creator.getPropertyGridDefinition());
this.showOneCategoryInPropertyGrid = creator.showOneCategoryInPropertyGrid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class TabJsonEditorAcePlugin
implements ICreatorPlugin {
constructor(creator: SurveyCreatorModel) {
super(creator);
creator.addPluginTab({ name: "json", plugin: this, iconName: "icon-codeeditor-24x24", componentName: "svc-tab-json-editor-ace" });
creator.addTab({ name: "json", plugin: this, iconName: "icon-codeeditor-24x24", componentName: "svc-tab-json-editor-ace" });
}
protected createModel(
creator: SurveyCreatorModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class TabJsonEditorTextareaPlugin
implements ICreatorPlugin {
constructor(creator: SurveyCreatorModel) {
super(creator);
creator.addPluginTab({ name: "json", plugin: this, iconName: "icon-codeeditor-24x24", componentName: "svc-tab-json-editor-textarea" });
creator.addTab({ name: "json", plugin: this, iconName: "icon-codeeditor-24x24", componentName: "svc-tab-json-editor-textarea" });
}
protected createModel(
creator: SurveyCreatorModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class TabLogicPlugin implements ICreatorPlugin {
private fastEntryAction: Action;
public model: SurveyLogicUI;
constructor(private creator: SurveyCreatorModel) {
creator.addPluginTab({ name: "logic", plugin: this, iconName: "icon-logic-24x24" });
creator.addTab({ name: "logic", plugin: this, iconName: "icon-logic-24x24" });
this.createActions().forEach(action => creator.toolbar.actions.push(action));
}
public activate(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class TabTestPlugin implements ICreatorPlugin {
}

constructor(private creator: SurveyCreatorModel) {
creator.addPluginTab({ name: "preview", plugin: this, iconName: "icon-preview" });
creator.addTab({ name: "preview", plugin: this, iconName: "icon-preview" });
this.setPreviewTheme(this.creator.previewTheme);
this.createActions().forEach(action => creator.toolbar.actions.push(action));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class ThemeTabPlugin implements ICreatorPlugin {
}

constructor(private creator: SurveyCreatorModel) {
creator.addPluginTab({ name: "theme", plugin: this, iconName: "icon-theme" });
creator.addTab({ name: "theme", plugin: this, iconName: "icon-theme" });
this.simulatorCssClasses = surveyCss[defaultThemeName];
this.tabControlModel = new TabControlModel(this.creator.sidebar);
this.createActions().forEach(action => creator.toolbar.actions.push(action));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class TabTranslationPlugin implements ICreatorPlugin {
}

constructor(private creator: SurveyCreatorModel) {
creator.addPluginTab({ name: "translation", plugin: this, iconName: "icon-language" });
creator.addTab({ name: "translation", plugin: this, iconName: "icon-language" });
this.showOneCategoryInPropertyGrid = creator.showOneCategoryInPropertyGrid;
this.tabControlModel = new TabControlModel(this.creator.sidebar);
this.sidebarTab = this.creator.sidebar.addPage("translation");
Expand Down
37 changes: 15 additions & 22 deletions packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
addIconsToThemeSet,
SvgThemeSets
} from "survey-core";
import { ICreatorPlugin, ISurveyCreatorOptions, settings, ICollectionItemAllowOperations } from "./creator-settings";
import { ICreatorPlugin, ISurveyCreatorOptions, settings, ICollectionItemAllowOperations, ITabOptions } from "./creator-settings";
import { editorLocalization, setupLocale } from "./editorLocalization";
import { SurveyJSON5 } from "./json5";
import { DragDropChoices } from "survey-core";
Expand Down Expand Up @@ -471,31 +471,24 @@ export class SurveyCreatorModel extends Base
* @param index A zero-based index that specifies the tab's position relative to other tabs.
*/
public addPluginTab(
nameOrParams: string | {
name: string,
plugin: ICreatorPlugin,
title?: string,
iconName?: string,
componentName?: string,
index?: number
},
plugin?: ICreatorPlugin,
name: string,
plugin: ICreatorPlugin,
title?: string,
componentName?: string,
index?: number
) {
let name = nameOrParams as string;
let iconName: string = undefined;
if (typeof nameOrParams === "object") {
({
name,
plugin,
title,
iconName,
componentName,
index
} = nameOrParams);
}
this.tabbedMenu.addTab(name, plugin, title, undefined, componentName, index);
this.addPlugin(name, plugin);
}
public addTab(tabOptions: ITabOptions) {
let {
name,
plugin,
title,
iconName,
componentName,
index
} = tabOptions;
if (!name || !plugin) {
throw new Error("Plugin or name is not set");
}
Expand Down
9 changes: 9 additions & 0 deletions packages/survey-creator-core/src/creator-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ export interface ICreatorPlugin {
model: Base;
}

export interface ITabOptions {
name: string,
plugin: ICreatorPlugin,
title?: string,
iconName?: string,
componentName?: string,
index?: number
}

export interface ISurveyCreatorOptions {
isMobileView: boolean;
alwaySaveTextInPropertyEditors: boolean;
Expand Down

0 comments on commit 8c25797

Please sign in to comment.