status bar

This commit is contained in:
Sarah Jamie Lewis 2022-10-08 19:54:56 -07:00
parent 3ed60ca3d8
commit 01eb1e24b1
4 changed files with 70 additions and 19 deletions

View File

@ -22,6 +22,8 @@ class LineFile extends ChangeNotifier {
ItemScrollController scrollController = ItemScrollController(); ItemScrollController scrollController = ItemScrollController();
var status = "";
void openFile(String path, int startLine) { void openFile(String path, int startLine) {
this.path = path; this.path = path;
File f = File(path); File f = File(path);
@ -124,6 +126,8 @@ class LineFile extends ChangeNotifier {
} }
void saveFile() { void saveFile() {
status = "Saving...";
notifyListeners();
String content = ''; String content = '';
String notes = ''; String notes = '';
for (var l in backingLines) { for (var l in backingLines) {
@ -137,6 +141,9 @@ class LineFile extends ChangeNotifier {
File("$path.subwrite.notes").writeAsStringSync(notes); File("$path.subwrite.notes").writeAsStringSync(notes);
File(path).writeAsStringSync(content); File(path).writeAsStringSync(content);
status = "Saved";
notifyListeners();
} }
void handleDelete() { void handleDelete() {
@ -214,6 +221,9 @@ class LineFile extends ChangeNotifier {
} }
void insertChar(String ch) { void insertChar(String ch) {
status = "Unsaved Changes";
notifyListeners();
var beforeInsertedChar = backingLines[cursor.line - 1].text.substring(0, cursor.column); var beforeInsertedChar = backingLines[cursor.line - 1].text.substring(0, cursor.column);
var afterInsertedChar = backingLines[cursor.line - 1].text.substring(cursor.column); var afterInsertedChar = backingLines[cursor.line - 1].text.substring(cursor.column);
backingLines[cursor.line - 1].text = beforeInsertedChar + ch + afterInsertedChar; backingLines[cursor.line - 1].text = beforeInsertedChar + ch + afterInsertedChar;
@ -222,6 +232,9 @@ class LineFile extends ChangeNotifier {
} }
void insertLine() { void insertLine() {
status = "Unsaved Changes";
notifyListeners();
// get the content that will be moved to the next line // get the content that will be moved to the next line
var restOfLine = backingLines[cursor.line - 1].text.substring(cursor.column); var restOfLine = backingLines[cursor.line - 1].text.substring(cursor.column);
// split off the line after the cursor // split off the line after the cursor
@ -236,6 +249,10 @@ class LineFile extends ChangeNotifier {
} }
void renumberFrom(int startLine) { void renumberFrom(int startLine) {
// Catch many unsaved changes here...
status = "Unsaved Changes";
notifyListeners();
for (int line = startLine; line < backingLines.length; line++) { for (int line = startLine; line < backingLines.length; line++) {
backingLines[line].lineNumber = line + 1; backingLines[line].lineNumber = line + 1;
backingLines[line].notifyListeners(); backingLines[line].notifyListeners();
@ -419,4 +436,8 @@ class LineFile extends ChangeNotifier {
description: note)); description: note));
notifyListeners(); notifyListeners();
} }
int wordCount() {
return backingLines.map((e) => e.text.trim().split(" ").length).fold(0, (previousValue, element) => previousValue + element);
}
} }

View File

@ -146,9 +146,7 @@ class LineInfo extends ChangeNotifier {
child: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ child: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
Container( Container(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
decoration: BoxDecoration( decoration: BoxDecoration(color: sidebarAlt, border: Border(right: BorderSide(width: 1, color: border))),
color: sidebarAlt,
),
width: gutterWidth - 1, width: gutterWidth - 1,
height: idealHeight, height: idealHeight,
margin: EdgeInsets.only(right: 1, top: 0, bottom: 0, left: 0), margin: EdgeInsets.only(right: 1, top: 0, bottom: 0, left: 0),

View File

@ -50,19 +50,50 @@ class _SarahDownApp extends State<SarahDownApp> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Material( return Material(
color: sidebarAlt, color: sidebarAlt,
child: Row( child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
mainAxisAlignment: MainAxisAlignment.start, Expanded(
crossAxisAlignment: CrossAxisAlignment.stretch, child: Row(
children: [ mainAxisAlignment: MainAxisAlignment.start,
Flexible( crossAxisAlignment: CrossAxisAlignment.stretch,
flex: 2, children: [
child: Column( Flexible(
mainAxisSize: MainAxisSize.max, flex: 2,
crossAxisAlignment: CrossAxisAlignment.stretch, child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max,
children: [Expanded(child: Outline()), Container(color: comment)])), crossAxisAlignment: CrossAxisAlignment.stretch,
Flexible(flex: 5, child: Editor()) mainAxisAlignment: MainAxisAlignment.start,
], children: [Expanded(child: Outline()), Container(color: comment)])),
)); Flexible(flex: 5, child: Editor())
],
)),
Container(
height: 16,
decoration: BoxDecoration(color: sidebarAlt, border: Border(top: BorderSide(width: 1, color: border))),
child: Padding(
padding: EdgeInsets.symmetric(vertical: 2.0, horizontal: 5.0),
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Text(
"${Provider.of<LineFile>(context).status}",
textAlign: TextAlign.left,
style: TextStyle(
fontFamily: 'Iosevka',
fontSize: 10,
fontWeight: FontWeight.bold,
color: foreground,
backgroundColor: Colors.transparent,
),
),
Text(
"Word Count: ${Provider.of<LineFile>(context).wordCount()}",
textAlign: TextAlign.right,
style: TextStyle(
fontFamily: 'Iosevka',
fontSize: 10,
color: foreground,
backgroundColor: Colors.transparent,
),
)
])))
]));
} }
} }

View File

@ -1,7 +1,7 @@
import 'dart:ui'; import 'dart:ui';
Color foreground = const Color(0xfff8f8f2); Color foreground = const Color(0xfff8f8f2);
Color background = const Color(0xff000000); //Color(0xFF1A0F1C); Color background = const Color(0xff111111); //Color(0xFF1A0F1C);
Color comment = const Color(0xffd684e8); Color comment = const Color(0xffd684e8);
Color selection = const Color(0xff777889); Color selection = const Color(0xff777889);
@ -15,7 +15,8 @@ Color field = header;
Color risk = const Color(0xff45353b); Color risk = const Color(0xff45353b);
Color sidebarAlt = const Color(0xFF110F15); Color sidebarAlt = const Color(0xFF070607);
Color sidebar = const Color(0xff202023); Color sidebar = const Color(0xff202023);
Color border = const Color(0xff202023);
Color tabs = const Color(0xFF342036); Color tabs = const Color(0xFF342036);
Color sidebarHighlight = const Color(0xFF38213D); Color sidebarHighlight = const Color(0xFF38213D);