Skip to content

Commit

Permalink
feat: new UI for MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Gorniv committed May 23, 2020
1 parent 2141bea commit 6c4528c
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 112 deletions.
99 changes: 61 additions & 38 deletions lib/project/project_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:doppio_dev_ixn/core/index.dart';
import 'package:doppio_dev_ixn/generated/l10n.dart';
import 'package:doppio_dev_ixn/main.dart';
import 'package:doppio_dev_ixn/project_setting/index.dart';
import 'package:doppio_dev_ixn/service/index.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:doppio_dev_ixn/project/index.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -66,7 +68,13 @@ class _ProjectPageState extends State<ProjectPage> {
onWillPop: () => _willPop(currentState as InProjectState),
child: Scaffold(
appBar: AppBar(
title: Text(i10n.project_name_title(name)),
title: Row(
children: [
if (!kIsWeb) _addWidget(i10n),
Expanded(child: Center(child: Text(i10n.project_name_title(name)))),
if (!kIsWeb) ..._actionsWidget(),
],
),
actions: [
IconButton(
icon: Icon(Icons.settings),
Expand All @@ -85,51 +93,66 @@ class _ProjectPageState extends State<ProjectPage> {
)
],
),
persistentFooterButtons: <Widget>[
Container(
width: ContextService().deviceSize.width,
child: Row(
children: [
IconButton(
onPressed: () async {
_addKey();
},
tooltip: i10n.project_add,
icon: Icon(Icons.add),
),
Spacer(),
IconButton(
onPressed: () async {
await projectModel.export();
},
tooltip: i10n.project_export,
icon: Icon(Icons.file_upload),
),
IconButton(
onPressed: () async {
await _import();
},
tooltip: i10n.project_import,
icon: Icon(Icons.file_download),
persistentFooterButtons: kIsWeb
? <Widget>[
Container(
width: ContextService().deviceSize.width,
child: Row(
children: [
_addWidget(i10n),
Spacer(),
..._actionsWidget(),
],
),
),
IconButton(
onPressed: () async {
_projectBloc.add(SaveProjectEvent(projectModel));
},
tooltip: i10n.project_save,
icon: Icon(Icons.save),
),
],
),
),
],
]
: null,
body: projectScreen,
),
);
},
);
}

List<Widget> _actionsWidget() {
final i10n = TranslateService().locale;
return [
IconButton(
onPressed: () async {
await projectModel.export();
},
tooltip: i10n.project_export,
icon: Icon(Icons.file_upload),
),
IconButton(
onPressed: () async {
await _import();
},
tooltip: i10n.project_import,
icon: Icon(Icons.file_download),
),
IconButton(
onPressed: () async {
_projectBloc.add(SaveProjectEvent(projectModel));
},
tooltip: i10n.project_save,
icon: Icon(Icons.save),
)
];
}

IconButton _addWidget(S i10n) {
return IconButton(
onPressed: projectModel?.defaultLocale == null
? null
: () async {
_addKey();
},
tooltip: i10n.project_add,
icon: Icon(Icons.add),
);
}

Future<bool> _willPop(InProjectState currentState) async {
var canPop = currentState.project == projectModel;
final i10n = TranslateService().locale;
Expand Down
79 changes: 50 additions & 29 deletions lib/project_setting/project_setting_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:doppio_dev_ixn/main.dart';
import 'package:doppio_dev_ixn/project/index.dart';
import 'package:doppio_dev_ixn/service/index.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:doppio_dev_ixn/project_setting/index.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -52,37 +53,33 @@ class _ProjectSettingPageState extends State<ProjectSettingPage> {
onWillPop: _willPop,
child: Scaffold(
appBar: AppBar(
title: Text(i10n.page_settings),
title: Row(
children: [
_undoWidget(currentState),
Expanded(
child: Center(
child: Text(i10n.page_settings),
),
),
_saveWidget(),
],
),
actions: [],
),
persistentFooterButtons: <Widget>[
Container(
width: ContextService().deviceSize.width,
child: Row(
children: [
IconButton(
icon: const Icon(Icons.undo),
onPressed: () {
setState(() {
if (currentState is InProjectSettingState) {
projectModel = currentState.project.copyWith();
projectModelBackup = projectModel == null ? null : projectModel.copyWith();
backuped = true;
}
});
},
tooltip: i10n.discard,
persistentFooterButtons: kIsWeb
? <Widget>[
Container(
width: ContextService().deviceSize.width,
child: Row(
children: [
_undoWidget(currentState),
Spacer(),
_saveWidget(),
],
),
),
Spacer(),
IconButton(
icon: const Icon(Icons.save),
onPressed: _save,
tooltip: i10n.save,
),
],
),
),
],
]
: null,
body: screen,
),
),
Expand All @@ -91,6 +88,30 @@ class _ProjectSettingPageState extends State<ProjectSettingPage> {
);
}

IconButton _saveWidget() {
return IconButton(
icon: const Icon(Icons.save),
onPressed: _save,
tooltip: i10n.save,
);
}

IconButton _undoWidget(ProjectSettingState currentState) {
return IconButton(
icon: const Icon(Icons.undo),
onPressed: () {
setState(() {
if (currentState is InProjectSettingState) {
projectModel = currentState.project.copyWith();
projectModelBackup = projectModel == null ? null : projectModel.copyWith();
backuped = true;
}
});
},
tooltip: i10n.discard,
);
}

void _save() {
if (!autoValidate) {
autoValidate = true;
Expand Down Expand Up @@ -133,6 +154,6 @@ class _ProjectSettingPageState extends State<ProjectSettingPage> {
),
);
}
return Future.value(canPop);
return canPop;
}
}
110 changes: 66 additions & 44 deletions lib/projects/projects_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:doppio_dev_ixn/project/index.dart';
import 'package:doppio_dev_ixn/service/index.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:doppio_dev_ixn/projects/index.dart';
import 'package:line_awesome_icons/line_awesome_icons.dart';
Expand All @@ -24,54 +25,75 @@ class _ProjectsPageState extends State<ProjectsPage> {
Widget build(BuildContext context) {
final i10n = TranslateService().locale;
return Scaffold(
key: Key('projecs_sc'),
appBar: AppBar(
title: Text(i10n.projects_title),
actions: [
IconButton(
icon: Icon(LineAwesomeIcons.github),
onPressed: () async {
final url = 'https://github.com/doppio-dev/iXn';
if (await canLaunch(url)) {
await launch(url);
}
},
)
key: Key('projecs_sc'),
appBar: AppBar(
title: Row(
children: [
_actionsWidget(),
Expanded(child: Center(child: Text(i10n.projects_title))),
],
),
body: projectsScreen,
persistentFooterButtons: <Widget>[
Container(
width: ContextService().deviceSize.width,
child: Row(
children: [
IconButton(
onPressed: () async {
projectsScreen.projectsBloc.add(AddProjectsEvent(projectModel: ProjectModel(id: Uuid().v4())));
},
tooltip: i10n.projects_add,
icon: Icon(Icons.add),
actions: [
IconButton(
icon: Icon(LineAwesomeIcons.github),
onPressed: () async {
final url = 'https://github.com/doppio-dev/iXn';
if (await canLaunch(url)) {
await launch(url);
}
},
)
],
),
body: projectsScreen,
persistentFooterButtons: kIsWeb
? [
Container(
width: ContextService().deviceSize.width,
child: Row(
children: [Expanded(child: _actionsWidget())],
),
IconButton(
onPressed: () async {
showRemove = !showRemove;
projectsScreen.projectsBloc.add(ViewProjectsEvent(showRemove: showRemove));
},
tooltip: i10n.projects_show_remove,
icon: Icon(Icons.remove),
),
Spacer(),
// IconButton(
// onPressed: () async {
// await _import();
// },
// tooltip: i10n.projects_import,
// icon: Icon(Icons.file_download),
// ),
],
),
),
]
: null,
);
}

Widget _actionsWidget() {
final i10n = TranslateService().locale;
return Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
IconButton(
onPressed: () async {
projectsScreen.projectsBloc.add(AddProjectsEvent(projectModel: ProjectModel(id: Uuid().v4())));
},
tooltip: i10n.projects_add,
icon: Icon(Icons.add),
),
IconButton(
onPressed: () async {
showRemove = !showRemove;
projectsScreen.projectsBloc.add(ViewProjectsEvent(showRemove: showRemove));
},
tooltip: i10n.projects_show_remove,
icon: Icon(Icons.remove),
),
],
),
]);
// IconButton(
// onPressed: () async {
// await _import();
// },
// tooltip: i10n.projects_import,
// icon: Icon(Icons.file_download),
// ),
],
),
);
}

// Future _import() async {
Expand Down
2 changes: 1 addition & 1 deletion lib/widget/edit_lang_word.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class _EditLangWordState extends State<EditLangWord> {
Widget build(BuildContext context) {
final i10n = TranslateService().locale;
final key = widget.projectModel.keys[widget.index];
final newkey = '${key.id}${widget.locale.key}';
final newkey = '${key.id}${widget.locale?.key}';
final keyOrigin = '${key.id}${widget.projectModel.defaultLocale.key}';
var word = widget.projectModel.getWord(newkey, key, widget.locale);
var wordOrigin = widget.projectModel.getWord(keyOrigin, key, widget.projectModel.defaultLocale);
Expand Down
2 changes: 2 additions & 0 deletions macos/Runner/doppio_dev_ixnDebug.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
</dict>
</plist>

0 comments on commit 6c4528c

Please sign in to comment.