mirror of
https://gitcode.com/shufeng2012/ohos-xournalpp.git
synced 2026-11-07 07:21:11 +08:00
✨ 完成menubar的显示了!!!
This commit is contained in:
1 parent
ace2ea9a2c
commit
47b7b34472
4 files changed
+1093
-21
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import { UIComponent, analysisXML } from "../utils/XMLHandler";
|
||||
import { common } from '@kit.AbilityKit';
|
||||
import { util } from '@kit.ArkTS';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
|
||||
|
||||
|
||||
@ComponentV2
|
||||
|
||||
|
||||
export struct Menubar {
|
||||
private content: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
|
||||
@Local ui_components: UIComponent[] = [];
|
||||
|
||||
aboutToAppear() {
|
||||
const xml_string = this.getXML();
|
||||
this.ui_components = analysisXML(xml_string);
|
||||
}
|
||||
|
||||
getXML(): string {
|
||||
try {
|
||||
let data: Uint8Array = this.content.resourceManager.getRawFileContentSync("mainmenubar.xml");
|
||||
let text_decoder: util.TextDecoder = util.TextDecoder.create("utf-8", { ignoreBOM: true });
|
||||
let xml_string: string = text_decoder.decodeToString(data, { stream: false });
|
||||
return xml_string;
|
||||
} catch (err) {
|
||||
let code: number = (err as BusinessError).code;
|
||||
let message: string = (err as BusinessError).message;
|
||||
console.log(`[Error](${code}): ${message}`);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Builder
|
||||
buildMenu(items: UIComponent[]) {
|
||||
Menu() {
|
||||
ForEach(items, (item: UIComponent) => {
|
||||
if (item.isSection === true) {
|
||||
MenuItemGroup() {
|
||||
ForEach(item.children || [], (sub: UIComponent) => {
|
||||
this.buildMenuItem(sub);
|
||||
}, (sub: UIComponent, idx) => idx.toString())
|
||||
}
|
||||
} else {
|
||||
this.buildMenuItem(item);
|
||||
}
|
||||
}, (item: UIComponent, idx) => idx.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Builder
|
||||
buildMenuItem(item: UIComponent) {
|
||||
if (item.children && item.children?.length > 0) {
|
||||
MenuItem({ content: item.label, labelInfo: item.accel }) {
|
||||
this.buildSubMenu(item.children || []);
|
||||
}
|
||||
} else {
|
||||
MenuItem({ content: item.label, labelInfo: item.accel });
|
||||
}
|
||||
}
|
||||
|
||||
@Builder
|
||||
buildSubMenu(items: UIComponent[]) {
|
||||
Menu() {
|
||||
ForEach(items, (sub: UIComponent) => {
|
||||
if (sub.children && sub.children?.length > 0) {
|
||||
MenuItem({ content: sub.label, labelInfo: sub.accel }) {
|
||||
this.buildSubMenu(sub.children || []);
|
||||
}
|
||||
} else {
|
||||
MenuItem({ content: sub.label, labelInfo: sub.accel });
|
||||
}
|
||||
}, (sub: UIComponent, idx) => idx.toString())
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
ForEach(this.ui_components, (menu: UIComponent) => {
|
||||
Text(menu.label)
|
||||
.bindMenu(this.buildMenu(menu.children || []))
|
||||
.padding('10vp')
|
||||
}, (menu: UIComponent, idx) => idx.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user