Skip to content

Commit

Permalink
🚀 NEW Text Filtering Panel, just click the expand icon on the `All …
Browse files Browse the repository at this point in the history
…Texts` Panel.
  • Loading branch information
omegaui committed Jan 11, 2024
1 parent bf7212a commit be7cb69
Show file tree
Hide file tree
Showing 21 changed files with 817 additions and 241 deletions.
5 changes: 5 additions & 0 deletions lib/app/clipboard/presentation/clipboard_state_machine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,19 @@ class ClipboardStateMachine
case ClipboardLoadingEvent:
currentState =
ClipboardLoadingState((e as ClipboardLoadingEvent).fastLoad);
break;
case ClipboardDaemonMissingEvent:
currentState = ClipboardDaemonMissingState();
break;
case ClipboardDaemonIntegrationEvent:
currentState = ClipboardDaemonIntegrationState();
break;
case ClipboardEmptyEvent:
currentState = ClipboardEmptyState((e as ClipboardEmptyEvent).cause);
break;
case ClipboardInitializedEvent:
currentState = ClipboardInitializedState();
break;
case ClipboardUpdateEvent:
currentState = ClipboardUpdateState();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/app/commands/presentation/commands_state_machine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ class CommandsStateMachine extends StateMachine<CommandsState, CommandsEvent> {
switch (e.runtimeType) {
case CommandsLoadingEvent:
currentState = CommandsLoadingState();
break;
case CommandsEmptyEvent:
currentState = CommandsEmptyState((e as CommandsEmptyEvent).cause);
break;
case CommandsInitializedEvent:
currentState = CommandsInitializedState();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/app/emojis/presentation/emojis_state_machine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ class EmojisStateMachine extends StateMachine<EmojisState, EmojisEvent> {
switch (e.runtimeType) {
case EmojisLoadingEvent:
currentState = EmojisLoadingState();
break;
case EmojisEmptyEvent:
currentState = EmojisEmptyState();
break;
case EmojisInitializedEvent:
currentState = EmojisInitializedState();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/app/notes/presentation/notes_state_machine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ class NotesStateMachine extends StateMachine<NotesState, NotesEvent> {
switch (e.runtimeType) {
case NotesLoadingEvent:
currentState = NotesLoadingState();
break;
case NotesEmptyEvent:
currentState = NotesEmptyState((e as NotesEmptyEvent).cause);
break;
case NotesInitializedEvent:
currentState = NotesInitializedState();
}
Expand Down
49 changes: 49 additions & 0 deletions lib/app/powermode/domain/text_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
enum TextType { code, url, word, sentence, paragraph }

TextType determineTextType(String text) {
// Check if the text is code
if (isCode(text)) {
return TextType.code;
}

// Check if the text is a URL
if (Uri.tryParse(text)?.isAbsolute ?? false) {
return TextType.url;
}

// Check if the text is a single word
if (!text.trim().contains(' ')) {
return TextType.word;
}

// Check if the text is a single sentence
if (text.endsWith('.') || text.endsWith('!') || text.endsWith('?')) {
return TextType.sentence;
}

// If none of the above conditions are met, consider it a paragraph
return TextType.paragraph;
}

bool isCode(String text) {
// Check for keywords and punctuation common in code.
final keywords = RegExp(
r"\b(if|else|for|while|try|except|def|class|return|import|from|print)\b");
final punctuation = RegExp(r"[{}()\[\];,.<>?:]+");
final operators = RegExp(r"[+\-*/%|=!<>&]");

// Check for presence of keywords, punctuation, and operators.
if (keywords.hasMatch(text) ||
punctuation.hasMatch(text) ||
operators.hasMatch(text)) {
return true;
}

// Check for specific patterns like comments or imports.
if (RegExp(r"#.*").hasMatch(text) || RegExp(r"import\s+.*").hasMatch(text)) {
return true;
}

// If none of the above patterns are found, the text is likely not code.
return false;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ignore_for_file: use_build_context_synchronously

import 'package:cliptopia/app/clipboard/data/clipboard_repository.dart';
import 'package:cliptopia/app/powermode/presentation/power_mode_app.dart';
import 'package:cliptopia/app/powermode/presentation/states/power_mode_loaded_state_view.dart';
import 'package:cliptopia/config/assets/app_animations.dart';
import 'package:cliptopia/config/assets/app_icons.dart';
import 'package:cliptopia/config/themes/app_theme.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:cliptopia/app/clipboard/domain/entity/clipboard_entity.dart';
import 'package:cliptopia/app/powermode/domain/entity_info.dart';
import 'package:cliptopia/app/powermode/presentation/power_mode_app.dart';
import 'package:cliptopia/app/powermode/presentation/states/power_mode_loaded_state_view.dart';
import 'package:cliptopia/app/settings/presentation/widgets/option.dart';
import 'package:cliptopia/core/powermode/power_utils.dart';
import 'package:cliptopia/config/assets/app_icons.dart';
import 'package:cliptopia/config/themes/app_theme.dart';
import 'package:cliptopia/core/powermode/power_utils.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:intl/intl.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:cliptopia/app/powermode/presentation/power_mode_app.dart';
import 'package:cliptopia/app/powermode/presentation/states/power_mode_loaded_state_view.dart';
import 'package:cliptopia/app/settings/presentation/widgets/option.dart';
import 'package:cliptopia/config/assets/app_artworks.dart';
import 'package:cliptopia/config/assets/app_icons.dart';
Expand Down
10 changes: 8 additions & 2 deletions lib/app/powermode/presentation/panels/collection_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
import 'package:cliptopia/app/powermode/presentation/panels/collections/command_panel.dart';
import 'package:cliptopia/app/powermode/presentation/panels/collections/file_panel.dart';
import 'package:cliptopia/app/powermode/presentation/panels/collections/text_panel.dart';
import 'package:cliptopia/app/powermode/presentation/power_mode_controller.dart';
import 'package:cliptopia/config/themes/app_theme.dart';
import 'package:cliptopia/core/powermode/power_data_handler.dart';
import 'package:cliptopia/main.dart';
import 'package:flutter/material.dart';

class CollectionPanel extends StatefulWidget {
const CollectionPanel({super.key});
const CollectionPanel({
super.key,
required this.controller,
});

final PowerModeController controller;

@override
State<CollectionPanel> createState() => _CollectionPanelState();
Expand Down Expand Up @@ -46,7 +52,7 @@ class _CollectionPanelState extends State<CollectionPanel> {
),
child: Row(
children: [
TextPanel(),
TextPanel(controller: widget.controller),
CommandPanel(),
FilePanel(),
],
Expand Down
24 changes: 21 additions & 3 deletions lib/app/powermode/presentation/panels/collections/text_panel.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:cliptopia/app/powermode/domain/entity/typedefs.dart';
import 'package:cliptopia/app/powermode/presentation/panels/widgets/text_card.dart';
import 'package:cliptopia/app/powermode/presentation/power_mode_controller.dart';
import 'package:cliptopia/config/assets/app_animations.dart';
import 'package:cliptopia/config/assets/app_icons.dart';
import 'package:cliptopia/config/themes/app_theme.dart';
Expand All @@ -11,7 +12,12 @@ import 'package:gap/gap.dart';
import 'package:lottie/lottie.dart';

class TextPanel extends StatefulWidget {
const TextPanel({super.key});
const TextPanel({
super.key,
required this.controller,
});

final PowerModeController controller;

@override
State<TextPanel> createState() => _TextPanelState();
Expand Down Expand Up @@ -90,7 +96,18 @@ class _TextPanelState extends State<TextPanel> {
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
if (!isEmpty)
if (!isEmpty) ...[
IconButton(
onPressed: () {
widget.controller.gotoTextView();
},
tooltip: "Expand this view",
icon: Icon(
Icons.fullscreen_exit,
color: Colors.grey.shade800,
),
),
const Gap(5),
IconButton(
onPressed: () {
for (var e in PowerDataHandler.texts) {
Expand All @@ -104,7 +121,8 @@ class _TextPanelState extends State<TextPanel> {
color: Colors.red,
),
),
const Gap(5),
const Gap(5),
],
],
),
),
Expand Down
Loading

0 comments on commit be7cb69

Please sign in to comment.