Skip to content

Commit

Permalink
Added manual setting
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Nov 7, 2023
1 parent 727dd4f commit 4f65c91
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 42 deletions.
41 changes: 39 additions & 2 deletions krokiet/src/connect_directories_changes.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@
use rfd::FileDialog;
use slint::{ComponentHandle, Model, ModelRc, VecModel};

use crate::{MainWindow, Settings};
use crate::{Callabler, MainWindow, Settings};

pub fn connect_add_remove_directories(app: &MainWindow) {
connect_add_directories(app);
connect_remove_directories(app);
connect_add_manual_directories(app);
}

fn connect_add_manual_directories(app: &MainWindow) {
let a = app.as_weak();
app.global::<Callabler>().on_added_manual_directories(move |included_directories, list_of_files_to_add| {
let non_empty_lines = list_of_files_to_add.lines().filter(|x| !x.is_empty()).collect::<Vec<_>>();
if non_empty_lines.is_empty() {
return;
}
let app = a.upgrade().unwrap();
let settings = app.global::<Settings>();

if included_directories {
let included_model = settings.get_included_directories();
let mut included_model = included_model.iter().collect::<Vec<_>>();
included_model.extend(non_empty_lines.iter().map(|x| {
let mut element = slint::StandardListViewItem::default();
element.text = slint::SharedString::from(x.to_string());
element
}));
included_model.sort_by_cached_key(|x| x.text.to_string());
included_model.dedup();
settings.set_included_directories(ModelRc::new(VecModel::from(included_model)));
} else {
let excluded_model = settings.get_excluded_directories();
let mut excluded_model = excluded_model.iter().collect::<Vec<_>>();
excluded_model.extend(non_empty_lines.iter().map(|x| {
let mut element = slint::StandardListViewItem::default();
element.text = slint::SharedString::from(x.to_string());
element
}));
excluded_model.sort_by_cached_key(|x| x.text.to_string());
excluded_model.dedup();
settings.set_excluded_directories(ModelRc::new(VecModel::from(excluded_model)));
}
});
}

fn connect_remove_directories(app: &MainWindow) {
let a = app.as_weak();
app.global::<Settings>().on_remove_item_directories(move |included_directories, current_index| {
app.global::<Callabler>().on_remove_item_directories(move |included_directories, current_index| {
// Nothing selected
if current_index == -1 {
return;
Expand Down
40 changes: 13 additions & 27 deletions krokiet/ui/bottom_panel.slint
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import {Button, StandardListView, VerticalBox, ScrollView, TextEdit} from "std-widgets.slint";
import {Settings} from "settings.slint";
import {BottomPanelVisibility} from "common.slint";
import {Callabler} from "callabler.slint";

component DirectoriesPanel {
callback folder-choose-requested(bool);
callback show_manual_add_dialog(bool);

// Included directories
HorizontalLayout {
Expand All @@ -19,7 +21,13 @@ component DirectoriesPanel {
Button {
text: "Remove";
clicked => {
Settings.remove_item_directories(true, included-list.current-item);
Callabler.remove_item_directories(true, included-list.current-item);
}
}
Button {
text: "Manual Add";
clicked => {
show_manual_add_dialog(true);
}
}
Rectangle {
Expand Down Expand Up @@ -50,13 +58,13 @@ component DirectoriesPanel {
Button {
text: "Remove";
clicked => {
Settings.remove_item_directories(false, excluded-list.current-item);
Callabler.remove_item_directories(false, excluded-list.current-item);
}
}
Button {
text: "Manual Add";
clicked => {
popup_item.show();
show_manual_add_dialog(false);
}
}
Rectangle {
Expand All @@ -75,30 +83,6 @@ component DirectoriesPanel {
}
}
}

popup_item := PopupWindow {
height: root.height;
width: root.width;

private property <string> text_data;

close-on-click: false;

TextEdit {
text <=> text-data;
}
TextEdit {

}

Rectangle {
background: red;
border-radius: 3px;
border-width: 2px;
border-color: blue;
}

}
}
// TODO this should be a normal read only Text editor
component TextErrorsPanel inherits TextEdit {
Expand All @@ -113,6 +97,7 @@ export component BottomPanel {
in-out property <string> console_text;

callback folder-choose-requested(bool);
callback show_manual_add_dialog(bool);
callback set_console_text(string);

min-height: bottom-panel-visibility == BottomPanelVisibility.NotVisible ? 0px : 150px;
Expand All @@ -122,6 +107,7 @@ export component BottomPanel {
width: parent.width;
height: parent.height;
folder-choose-requested(included-directories) => {root.folder-choose-requested(included-directories)}
show_manual_add_dialog(included-directories) => {root.show_manual_add_dialog(included-directories)}
}

if bottom-panel-visibility == BottomPanelVisibility.TextErrors : TextErrorsPanel {
Expand Down
4 changes: 4 additions & 0 deletions krokiet/ui/callabler.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export global Callabler {
callback remove_item_directories(bool, int);
callback added_manual_directories(bool, string);
}
7 changes: 5 additions & 2 deletions krokiet/ui/color_palette.slint
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { StyleMetrics } from "std-widgets.slint";

export global ColorPalette {
// Tabs at left side
in-out property<color> tab_selected_color: StyleMetrics.dark-color-scheme ? red : blue;
in-out property<color> tab_hovered_color: StyleMetrics.dark-color-scheme ? green : yellow;
in-out property<color> tab_selected_color: StyleMetrics.dark-color-scheme ? #353535 : #5e5e5e;
in-out property<color> tab_hovered_color: StyleMetrics.dark-color-scheme ? #49494926 : #80808014;

// ListView
in-out property<color> list_view_normal_color: StyleMetrics.dark-color-scheme ? #474747 : #dddddd;
in-out property<color> list_view_normal_header_color: StyleMetrics.dark-color-scheme ? #292929 : #888888;
in-out property<color> list_view_normal_selected_header: StyleMetrics.dark-color-scheme ? #575757 : #cccccc;

// Popup
in-out property<color> popup_background: StyleMetrics.dark-color-scheme ? #353535 : #5e5e5e;
}
1 change: 0 additions & 1 deletion krokiet/ui/left_side_panel.slint
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ component TabItem {
width: parent.width;
horizontal-stretch: 1.0;
background: touch-area.has-hover ? ColorPalette.tab-hovered-color : transparent;
opacity: 0.05;

touch_area:= TouchArea {
clicked => {
Expand Down
74 changes: 71 additions & 3 deletions krokiet/ui/main_window.slint
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Button, VerticalBox , HorizontalBox, TabWidget, ListView, StandardListView, StandardTableView, CheckBox, LineEdit} from "std-widgets.slint";
import { Button, VerticalBox ,TextEdit, HorizontalBox, TabWidget, ListView, StandardListView, StandardTableView, CheckBox, LineEdit} from "std-widgets.slint";
import {SelectableTableView} from "selectable_tree_view.slint";
import {LeftSidePanel} from "left_side_panel.slint";
import {MainList} from "main_lists.slint";
import {CurrentTab, ProgressToSend} from "common.slint";
import { ActionButtons } from "action_buttons.slint";
import { Progress } from "progress.slint";
import {MainListModel} from "common.slint";
import {Settings, SettingsModel} from "settings.slint";
import {Settings} from "settings.slint";
import {Callabler} from "callabler.slint";
import { BottomPanel } from "bottom_panel.slint";
import {ColorPalette} from "color_palette.slint";

export {Settings}
export {Settings, Callabler}

export component MainWindow inherits Window {
callback deleted;
Expand Down Expand Up @@ -114,10 +116,76 @@ export component MainWindow inherits Window {
read-only: true;
}
bottom_panel := BottomPanel {
property <bool> included-directories; // TODO why cannot set popup_item property? Strange limitation

bottom-panel-visibility <=> action_buttons.bottom-panel-visibility;
vertical-stretch: 0.0;
folder-choose-requested(included-directories) => {root.folder-choose-requested(included-directories)}
show_manual_add_dialog(included-directories) => {
self.included-directories = included-directories;
popup-item.show()
}
}
}

popup_item := PopupWindow {
height: root.height;
width: root.width;

property <bool> included_directories;
private property <string> text_data;

callback set_included_directories(bool);

close-on-click: false;

set-included-directories(included-directories) => {
self.included-directories = included-directories;
}

HorizontalLayout {
alignment: LayoutAlignment.center;
VerticalLayout {
alignment: LayoutAlignment.center;
Rectangle {
clip: true;
width: popup_item.width - 20px;
height: popup_item.height - 20px;
border-radius: 20px;
background: ColorPalette.popup_background; // TODO Dark theme
VerticalLayout {
// width: parent.width - 20px;
// height: parent.height - 20px;
Text {
text: "Please add directories one per line";
horizontal-alignment: TextHorizontalAlignment.center;
}
TextEdit {
vertical-stretch: 1.0;
text <=> text-data;
}
HorizontalLayout {
min-height: 20px;
Button {
enabled: text-data != "";
text: "OK";
clicked => {
Callabler.added_manual_directories(bottom-panel.included-directories, text_data);
popup-item.close();
}
}
Button {
text: "Cancel";
clicked => {
popup-item.close();
}
}
}
}
}
}
}

}

set_console_text(text) => {
Expand Down
7 changes: 0 additions & 7 deletions krokiet/ui/settings.slint
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
export struct SettingsModel {
is_selected: bool,
}

export global Settings {
in-out property<SettingsModel> model;
in-out property<bool> checkbox_checked: false;

in-out property <[StandardListViewItem]> included_directories: [{text: "ABCD"}, {text: "BCDA"}];
in-out property <[StandardListViewItem]> excluded_directories: [{text: "ABCD"}, {text: "BCDA"}, {text: "CDFFF"}];

callback remove_item_directories(bool, int);
}

0 comments on commit 4f65c91

Please sign in to comment.