From e4ea41b0d8f6ad39cdc0998125e6130d65b4c492 Mon Sep 17 00:00:00 2001 From: Eugeny Date: Sun, 19 Jun 2022 05:25:04 -0700 Subject: [PATCH] Add ContextMenu into SidePane Now u can open new workspace from SidePane ContextMenu --- lib/main.dart | 5 ++++ lib/widgets/context_menu.dart | 26 ++++++++++--------- lib/widgets/side_pane.dart | 49 ++++++++++++++++++++++++++--------- 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 77fdd13..5cc7a8d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -116,6 +116,11 @@ class _FilesHomeState extends State { SidePane( destinations: sideDestinations, workspace: workspaces[currentWorkspace], + onNewTab: (String tabPath) { + workspaces.add(WorkspaceController(initialDir: tabPath)); + currentWorkspace = workspaces.length - 1; + setState(() {}); + }, ), Expanded( child: Material( diff --git a/lib/widgets/context_menu.dart b/lib/widgets/context_menu.dart index 4b2b6f2..f9a3226 100644 --- a/lib/widgets/context_menu.dart +++ b/lib/widgets/context_menu.dart @@ -94,8 +94,10 @@ class _ContextMenuEntryState extends State { IconTheme.merge( data: IconThemeData( size: 20, - color: - Theme.of(context).colorScheme.onSurface.withOpacity(0.7), + color: Theme.of(context) + .colorScheme + .onSurface + .withOpacity(0.7), ), child: widget.icon!, ), @@ -110,24 +112,24 @@ class _ContextMenuEntryState extends State { .onSurface .withOpacity(0.7), ), - child: widget.text, overflow: TextOverflow.ellipsis, + child: widget.text, ), ), if (widget.shortcut != null) Padding( padding: const EdgeInsets.only(right: 8), child: DefaultTextStyle( - style: TextStyle( - fontSize: 16, - color: Theme.of(context) - .colorScheme - .onSurface - .withOpacity(0.5), + style: TextStyle( + fontSize: 16, + color: Theme.of(context) + .colorScheme + .onSurface + .withOpacity(0.5), + ), + overflow: TextOverflow.ellipsis, + child: widget.shortcut!, ), - child: widget.shortcut!, - overflow: TextOverflow.ellipsis, - ), ), ], ), diff --git a/lib/widgets/side_pane.dart b/lib/widgets/side_pane.dart index 7ef61cb..5eb0dec 100644 --- a/lib/widgets/side_pane.dart +++ b/lib/widgets/side_pane.dart @@ -1,14 +1,17 @@ import 'package:collection/collection.dart'; +import 'package:files/widgets/context_menu.dart'; import 'package:files/widgets/workspace.dart'; import 'package:flutter/material.dart'; class SidePane extends StatefulWidget { final List destinations; final WorkspaceController workspace; + final void Function(String tabPath) onNewTab; const SidePane({ required this.destinations, required this.workspace, + required this.onNewTab, Key? key, }) : super(key: key); @@ -49,24 +52,46 @@ class _SidePaneState extends State { child: Material( color: Theme.of(context).colorScheme.surface, child: ListView( + padding: const EdgeInsets.only(top: 56), children: widget.destinations .mapIndexed( - (index, d) => ListTile( - dense: true, - leading: Icon(widget.destinations[index].icon), - selected: widget.workspace.currentDir == - widget.destinations[index].path, - selectedTileColor: - Theme.of(context).colorScheme.secondary.withOpacity(0.1), - title: Text( - widget.destinations[index].label, + (index, d) => ContextMenu( + entries: [ + ContextMenuEntry( + id: 'open', + text: const Text("Open"), + onTap: () => widget.workspace.currentDir = + widget.destinations[index].path, + ), + ContextMenuEntry( + id: 'open_in_new_tab', + text: const Text("Open in new tab"), + onTap: () => widget.onNewTab(widget.destinations[index].path), + ), + ContextMenuEntry( + id: 'open_in_new_window', + text: const Text("Copy in new window"), + onTap: () {}, + ), + ], + child: ListTile( + dense: true, + leading: Icon(widget.destinations[index].icon), + selected: widget.workspace.currentDir == + widget.destinations[index].path, + selectedTileColor: Theme.of(context) + .colorScheme + .secondary + .withOpacity(0.1), + title: Text( + widget.destinations[index].label, + ), + onTap: () => widget.workspace.currentDir = + widget.destinations[index].path, ), - onTap: () => widget.workspace.currentDir = - widget.destinations[index].path, ), ) .toList(), - padding: const EdgeInsets.only(top: 56), ), ), );