增加子窗口
This commit is contained in:
parent
8eaa7cfea2
commit
759ce30427
@ -17,29 +17,21 @@ export struct SWNewFile {
|
|||||||
@Local scaleBtn:number=0.05;
|
@Local scaleBtn:number=0.05;
|
||||||
//文本宽度统一缩放系数
|
//文本宽度统一缩放系数
|
||||||
@Local scalingText:number=0.04;
|
@Local scalingText:number=0.04;
|
||||||
@Local subWin: window.Window | undefined = undefined;
|
|
||||||
aboutToAppear(): void {
|
aboutToAppear(): void {
|
||||||
this.docCreateTime=CurrentTime();
|
this.docCreateTime=CurrentTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
async initSubWindow(){
|
selectDir():string{
|
||||||
this.subWin= await mwsInfo.winStage?.createSubWindow('dirPicker');
|
|
||||||
this.subWin?.loadContent('pages/SubWindow/File/SWNewFile');
|
|
||||||
}
|
|
||||||
|
|
||||||
async selectDir(): Promise<string>{
|
|
||||||
let selectDirStr='';
|
let selectDirStr='';
|
||||||
let context =this.getUIContext().getHostContext() as common.Context;
|
let context =this.getUIContext().getHostContext() as common.Context;
|
||||||
if(this.subWin){
|
|
||||||
this.subWin.destroyWindow();
|
|
||||||
}
|
|
||||||
await this.initSubWindow();
|
|
||||||
try {
|
try {
|
||||||
let documentSelectOptions = new picker.DocumentSelectOptions();
|
let documentSelectOptions = new picker.DocumentSelectOptions();
|
||||||
let documentPicker = new picker.DocumentViewPicker(context,this.subWin as window.Window);
|
let documentPicker = new picker.DocumentViewPicker(context);
|
||||||
documentSelectOptions.selectMode=picker.DocumentSelectMode.FOLDER;
|
documentSelectOptions.selectMode=picker.DocumentSelectMode.FOLDER;
|
||||||
documentPicker.select(documentSelectOptions,(err: BusinessError,documentSelectResult: Array<string>) => {
|
documentPicker.select(documentSelectOptions,(err: BusinessError,documentSelectResult: Array<string>) => {
|
||||||
selectDirStr =documentSelectResult.toString();
|
selectDirStr =documentSelectResult.toString();
|
||||||
|
return selectDirStr;
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const err: BusinessError = error as BusinessError;
|
const err: BusinessError = error as BusinessError;
|
||||||
@ -69,8 +61,8 @@ export struct SWNewFile {
|
|||||||
.fontColor($r('sys.color.font_emphasize'))
|
.fontColor($r('sys.color.font_emphasize'))
|
||||||
.fontWeight(FontWeight.Medium)
|
.fontWeight(FontWeight.Medium)
|
||||||
.fontSize($r('sys.float.Body_L'))
|
.fontSize($r('sys.float.Body_L'))
|
||||||
.onClick(async () => {
|
.onClick(() => {
|
||||||
this.dir= await this.selectDir();
|
this.dir= this.selectDir();
|
||||||
})
|
})
|
||||||
}.height('10%')
|
}.height('10%')
|
||||||
Row({space:5}){
|
Row({space:5}){
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { FileMenuData } from "../layout/FileMenuData";
|
|||||||
import { mwInfo } from '../displaywindowinfo/DispWinInfo'
|
import { mwInfo } from '../displaywindowinfo/DispWinInfo'
|
||||||
import { SubColumnMenu} from "../customcontroller/Button";
|
import { SubColumnMenu} from "../customcontroller/Button";
|
||||||
import { fileIo } from "@kit.CoreFileKit";
|
import { fileIo } from "@kit.CoreFileKit";
|
||||||
|
import { common,Want } from "@kit.AbilityKit";
|
||||||
|
|
||||||
@ComponentV2
|
@ComponentV2
|
||||||
export struct TitleColumnSub {
|
export struct TitleColumnSub {
|
||||||
@ -66,7 +66,17 @@ export struct TitleColumnSub {
|
|||||||
SubColumnMenu({menus:DisplayMode})
|
SubColumnMenu({menus:DisplayMode})
|
||||||
Blank().layoutWeight(1)
|
Blank().layoutWeight(1)
|
||||||
Button('TabsBar显示/隐藏').onClick(()=>{
|
Button('TabsBar显示/隐藏').onClick(()=>{
|
||||||
this.$subOverlayState(!this.subOverlayState);
|
//this.$subOverlayState(!this.subOverlayState);
|
||||||
|
let want: Want = {
|
||||||
|
deviceId: '',
|
||||||
|
bundleName: 'com.example.opencax',
|
||||||
|
abilityName: 'SubWinAbility'
|
||||||
|
};
|
||||||
|
// 调用 context 启动
|
||||||
|
let context =getContext(this) as common.UIAbilityContext;
|
||||||
|
context.startAbility(want).then(() => {
|
||||||
|
console.info('yes');
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}.width('100%')
|
}.width('100%')
|
||||||
.height('100%')
|
.height('100%')
|
||||||
|
|||||||
72
entry/src/main/ets/subwinability/SubWinAbility.ets
Normal file
72
entry/src/main/ets/subwinability/SubWinAbility.ets
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
|
||||||
|
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||||
|
import { window, display, AppStorageV2, ColorMetrics } from '@kit.ArkUI';
|
||||||
|
|
||||||
|
const DOMAIN = 0x0000;
|
||||||
|
|
||||||
|
export default class SubWinAbility extends UIAbility {
|
||||||
|
|
||||||
|
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
||||||
|
try {
|
||||||
|
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
|
||||||
|
} catch (err) {
|
||||||
|
hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err));
|
||||||
|
}
|
||||||
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
|
||||||
|
}
|
||||||
|
|
||||||
|
onDestroy(): void {
|
||||||
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||||
|
}
|
||||||
|
|
||||||
|
onWindowStageCreate(windowStage: window.WindowStage): void {
|
||||||
|
//Load page
|
||||||
|
windowStage.loadContent('pages/subpages/file/SWNewFile', (err) => {
|
||||||
|
if (err.code) {
|
||||||
|
hilog.error(DOMAIN, 'Tag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
|
||||||
|
});
|
||||||
|
|
||||||
|
//Get Main Window
|
||||||
|
windowStage.getMainWindow((err, data) => {
|
||||||
|
if (err.code) {
|
||||||
|
console.error(`Failed to obtain the main window. Code: ${err.code}, message: ${err.message}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//moveWindowTo
|
||||||
|
data.moveWindowTo(50, 50)
|
||||||
|
//resize mainWindow Size
|
||||||
|
data.resize(200,400, (err) => {
|
||||||
|
if (err.code) {
|
||||||
|
console.error(`Failed to resize the window. Code: ${err.code}, message: ${err.message}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let color: string = '#00000000';
|
||||||
|
try {
|
||||||
|
data.setWindowBackgroundColor(color);
|
||||||
|
data.setWindowShadowEnabled(true);
|
||||||
|
} catch (exception) {
|
||||||
|
console.error(`Failed to set the background color. Cause code: ${exception.code}, message: ${exception.message}`);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onWindowStageDestroy(): void {
|
||||||
|
// Main window is destroyed, release UI related resources
|
||||||
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
||||||
|
}
|
||||||
|
|
||||||
|
onForeground(): void {
|
||||||
|
// Ability has brought to foreground
|
||||||
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground');
|
||||||
|
}
|
||||||
|
|
||||||
|
onBackground(): void {
|
||||||
|
// Ability has back to background
|
||||||
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -42,6 +42,27 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SubWinAbility",
|
||||||
|
"srcEntry": "./ets/subwinability/SubWinAbility.ets",
|
||||||
|
"description": "$string:EntryAbility_desc",
|
||||||
|
"icon": "$media:base_opencax_logo",
|
||||||
|
"label": "$string:EntryAbility_label",
|
||||||
|
"startWindowIcon": "$media:base_start_background",
|
||||||
|
"startWindowBackground": "$color:start_window_background",
|
||||||
|
"exported": true,
|
||||||
|
"launchType":"standard",
|
||||||
|
"skills": [
|
||||||
|
{
|
||||||
|
"entities": [
|
||||||
|
"entity.system.home"
|
||||||
|
],
|
||||||
|
"actions": [
|
||||||
|
"action.system.home"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"extensionAbilities": [
|
"extensionAbilities": [
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user