Skip to content

Commit

Permalink
Add ContextMenu into SidePane
Browse files Browse the repository at this point in the history
Now u can open new workspace from SidePane ContextMenu
  • Loading branch information
chesnoksatan committed Jun 19, 2022
1 parent 7205afe commit e4ea41b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ class _FilesHomeState extends State<FilesHome> {
SidePane(
destinations: sideDestinations,
workspace: workspaces[currentWorkspace],
onNewTab: (String tabPath) {
workspaces.add(WorkspaceController(initialDir: tabPath));
currentWorkspace = workspaces.length - 1;
setState(() {});
},
),
Expanded(
child: Material(
Expand Down
26 changes: 14 additions & 12 deletions lib/widgets/context_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ class _ContextMenuEntryState extends State<ContextMenuEntry> {
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!,
),
Expand All @@ -110,24 +112,24 @@ class _ContextMenuEntryState extends State<ContextMenuEntry> {
.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,
),
),
],
),
Expand Down
49 changes: 37 additions & 12 deletions lib/widgets/side_pane.dart
Original file line number Diff line number Diff line change
@@ -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<SideDestination> 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);

Expand Down Expand Up @@ -49,24 +52,46 @@ class _SidePaneState extends State<SidePane> {
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),
),
),
);
Expand Down

0 comments on commit e4ea41b

Please sign in to comment.