Skip to content

Commit

Permalink
Merge pull request #2 from MarvinQuevedo/stable_desktop
Browse files Browse the repository at this point in the history
Stable desktop
  • Loading branch information
MarvinQuevedo authored Mar 30, 2023
2 parents 0bdf0de + 143b8df commit da3e7dd
Show file tree
Hide file tree
Showing 20 changed files with 819 additions and 215 deletions.
2 changes: 1 addition & 1 deletion lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class _MyAppState extends State<MyApp> {
ChangeNotifierProvider.value(
value: Get.find<ProjectsHandlerProvider>(),
),
Provider.value(
ChangeNotifierProvider.value(
value: Get.find<PuzzleUncompressersProvider>(),
),
ChangeNotifierProvider.value(
Expand Down
13 changes: 10 additions & 3 deletions lib/src/features/editor/data/temp_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ class TempRepository {
Timer? _timer;
Directory? _appDocDic;
TempRepository._();
final _temp = <String, String>{};
final _temp = <String, String>{};

void set(String key, String value) {
_temp[key] = value;
_writeData();
}

void _writeData() {
if (_timer != null) {
_timer!.cancel();
}
_timer = Timer(const Duration(seconds: 2), () async {
_timer = Timer(const Duration(milliseconds: 750), () async {
/* _lastSaved = DateTime.now();
_lastSavedData = value; */
final watch = Stopwatch()..start();
Expand Down Expand Up @@ -69,5 +73,8 @@ class TempRepository {

String? get(String key) => _temp[key];

void remove(String key) => _temp.remove(key);
void remove(String key) {
_temp.remove(key);
_writeData();
}
}
94 changes: 71 additions & 23 deletions lib/src/features/editor/presentation/pages/editor_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import '../../utils/dir_splitter.dart';
import '../../utils/monokai_sublime_theme_with_font.dart';
import '../../utils/save_file_dialog.dart';
import '../../utils/snackbar.dart';
import '../widgets/editor_drawer.dart';
import '../widgets/mobile_editor_drawer.dart';
import 'result_controls_page.dart';

class EditorPage extends StatefulWidget {
Expand All @@ -39,6 +39,7 @@ class EditorPageState extends State<EditorPage> with EditorActionHelper {
late final FocusNode _editorFocusNode;
bool _editorInitialized = false;
late final PlaygroundProvider _playProvider;
ProjectData? _projectData;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -87,7 +88,7 @@ class EditorPageState extends State<EditorPage> with EditorActionHelper {
child: Scaffold(
backgroundColor: theme['root']!.backgroundColor,
appBar: appBar2,
drawer: const EditorDrawer(),
drawer: const MobileEditorDrawer(),
body: ListView(
padding: const EdgeInsets.only(top: 0),
children: [
Expand Down Expand Up @@ -191,7 +192,7 @@ class EditorPageState extends State<EditorPage> with EditorActionHelper {
}

@override
void openRunPage() async {
void openRunPage({bool isDesktop = false}) async {
final activeProject = _playProvider.activeProject;

if (activeProject == null) {
Expand All @@ -201,19 +202,48 @@ class EditorPageState extends State<EditorPage> with EditorActionHelper {
fileName(activeProject.path),
_controller.text,
);

Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChangeNotifierProvider.value(
value: _playProvider,
child: Builder(
builder: (context) => ResultControlsPage(
code: _controller.text,
theme: theme,
if (isDesktop) {
showGeneralDialog(
barrierColor: const Color(0x80000000),
context: context,
barrierDismissible: true,
barrierLabel: "close",
pageBuilder: (context, a, b) {
return Align(
alignment: Alignment.topRight,
child: Dialog(
elevation: 5,
shadowColor: Colors.white,
backgroundColor: Colors.transparent,
insetPadding: EdgeInsets.zero,
child: SizedBox(
width: 450,
child: ChangeNotifierProvider.value(
value: _playProvider,
child: Builder(
builder: (context) => ResultControlsPage(
code: _controller.text,
theme: theme,
),
)),
),
)),
));
),
);
});
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChangeNotifierProvider.value(
value: _playProvider,
child: Builder(
builder: (context) => ResultControlsPage(
code: _controller.text,
theme: theme,
),
)),
));
}
}
}

Expand All @@ -231,6 +261,8 @@ class EditorPageState extends State<EditorPage> with EditorActionHelper {
await _playProvider.saveProject(
fileName(activeProject.path), _controller.text);
// ignore: use_build_context_synchronously

// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(const MeSnackbar(
content: Text("File saved", style: TextStyle(color: Colors.white)),
));
Expand Down Expand Up @@ -270,6 +302,8 @@ class EditorPageState extends State<EditorPage> with EditorActionHelper {
context,
listen: false,
);
_projectData = proHandler.currentProject;
puzzlesProvider.addListener(_puzzlesUpdated);
projectsProvider.addListener(_updateProjectsNames);
_playProvider
.init(
Expand All @@ -282,10 +316,10 @@ class EditorPageState extends State<EditorPage> with EditorActionHelper {
_controller.autocompleter.setCustomWords(_playProvider.includeFilesNames);
_editorFocusNode.addListener(_forceInitializedEditor);
FocusScope.of(context).requestFocus(_editorFocusNode);
_playProvider.savedNotifier.addListener(_onTextChanged);
_controller.addListener(_onTextChanged);
});

_playProvider.savedNotifier.addListener(_onTextChanged);
_controller.addListener(_onTextChanged);
EditorActionsProvider.of(context, listen: false).editorActionHelper = this;
}

Expand All @@ -305,21 +339,35 @@ class EditorPageState extends State<EditorPage> with EditorActionHelper {
}

void _onTextChanged() {
if (!mounted) return;
final proHandler = Provider.of<ProjectsHandlerProvider>(
context,
listen: false,
);
final saved = _playProvider.savedNotifier.value;
var saved = _playProvider.savedNotifier.value;

if (_controller.text == _playProvider.activeProjectCode) {
saved = true;
} else {
saved = false;
}

final activeProject = proHandler.currentProject;
if (activeProject != null) {
if (_projectData != null) {
proHandler.onChangeText(
projectData: activeProject, value: _controller.text);
proHandler.updateValue(activeProject.copyWith(
projectData: _projectData!,
value: _controller.text,
saved: saved,
));
);
}
}

void _puzzlesUpdated() {
final puzzlesProvider = Provider.of<PuzzleUncompressersProvider>(
context,
listen: false,
);
_playProvider.updatePuzzlesNames(puzzlesProvider.puzzlesFilesNames);
}
}

class _ActionButton extends StatelessWidget {
Expand Down
52 changes: 22 additions & 30 deletions lib/src/features/editor/presentation/pages/projects_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'dart:io';

import 'package:chialisp_playground/src/features/editor/providers/playground_provider.dart';
import 'package:chialisp_playground/src/features/editor/providers/projects_provider.dart';
import '../../providers/projects_provider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../../home/presentation/pages/home_page.dart';
import '../../providers/projects_handler_provider.dart';
import '../../utils/dir_splitter.dart';

class ProjectsPage extends StatefulWidget {
Expand Down Expand Up @@ -40,42 +39,35 @@ class _ProjectsPageState extends State<ProjectsPage> {
itemCount: provider.projects!.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(fileName(provider.projects![index].path)),
subtitle:
Text(formatFileDate(provider.projects![index])),
onTap: () {
_openProject(provider.projects![index], context);
},
trailing: IconButton(
icon: const Icon(Icons.keyboard_arrow_right),
onPressed: () {
_openProject(provider.projects![index], context);
title: Text(fileName(provider.projects![index].path)),
subtitle: Text(
formatFileDate(
provider.projects![index],
),
style: const TextStyle(
color: Colors.grey, fontSize: 12),
),
onTap: () {
_openProject(context, provider.projects![index]);
},
)
);
trailing: IconButton(
icon: const Icon(Icons.keyboard_arrow_right),
onPressed: () {
_openProject(context, provider.projects![index]);
},
));
},
));
},
);
}

void _openProject(File file, BuildContext context) async{
final provider = Provider.of<PlaygroundProvider>(context, listen: false);

await provider.loadProject(file);
_goToHomePage();
}

void _goToHomePage() {
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (context) => const HomePage(),
),
(route) => false);
_openProject(BuildContext context, File file) {
Provider.of<ProjectsHandlerProvider>(context, listen: false)
.openProject(file, false);
Navigator.maybePop(context);
}



String formatFileDate(File file) {
final date = file.lastModifiedSync();
return "${date.year}-${date.month}-${date.day} ${date.hour}:${date.minute}:${date.second}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';

import '../../../home/presentation/pages/home_page.dart';
import '../../providers/playground_provider.dart';

import '../../providers/projects_handler_provider.dart';
import '../../utils/save_file_dialog.dart';
import '../../utils/show_install_cypher_libs.dart';
import '../pages/projects_page.dart';

class EditorDrawer extends StatelessWidget {
const EditorDrawer({super.key});
class MobileEditorDrawer extends StatelessWidget {
const MobileEditorDrawer({super.key});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -44,7 +45,7 @@ class EditorDrawer extends StatelessWidget {
style: TextStyle(color: Colors.white, fontSize: 20),
),
const Text(
"v0.0.1",
"v0.0.5",
style: TextStyle(color: Colors.white, fontSize: 10),
),
],
Expand All @@ -60,13 +61,22 @@ class EditorDrawer extends StatelessWidget {
),
ListTile(
leading: const Icon(Icons.list, color: Colors.white),
title: const Text("Files", style: TextStyle(color: Colors.white)),
title: const Text("Projects", style: TextStyle(color: Colors.white)),
trailing: const Icon(
Icons.keyboard_arrow_right,
color: Colors.white,
),
onTap: () => _openProjectsPage(context),
),
ListTile(
leading: const Icon(Icons.install_mobile, color: Colors.white),
title: const Text("Install Cypher", style: TextStyle(color: Colors.white)),
trailing: const Icon(
Icons.keyboard_arrow_right,
color: Colors.white,
),
onTap: () => showInstallCipherLibs(context),
),
]),
);
}
Expand All @@ -79,16 +89,13 @@ class EditorDrawer extends StatelessWidget {
_createNewProject(BuildContext context) {
showSaveFileDialog(context, "", title: "Create new file").then((result) {
if (result != null) {
final playProvider =
Provider.of<PlaygroundProvider>(context, listen: false);
playProvider.loadProjectWithFilename(result).then((value) {
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (context) => const HomePage(),
),
(route) => false);
});
Provider.of<ProjectsHandlerProvider>(context, listen: false)
.openProjectWithName(result, false);
Navigator.maybePop(context);
}
});
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ abstract class EditorActionHelper {
void undoCode( );
void redoCode( );
void saveFile( {String title = 'Save file'});
void openRunPage( );
void openRunPage({bool isDesktop = false});
}

class EditorActionsProvider extends ChangeNotifier{
Expand Down
Loading

0 comments on commit da3e7dd

Please sign in to comment.