feat(modulo): implement troubleshooting window

This commit is contained in:
Federico Terzi 2021-07-19 20:48:55 +02:00
parent aec2425b0b
commit 11edf080de
11 changed files with 1042 additions and 1 deletions

View File

@ -117,6 +117,8 @@ fn build_native() {
.file("src/sys/wizard/wizard_gui.cpp")
.file("src/sys/welcome/welcome.cpp")
.file("src/sys/welcome/welcome_gui.cpp")
.file("src/sys/troubleshooting/troubleshooting.cpp")
.file("src/sys/troubleshooting/troubleshooting_gui.cpp")
.flag("/EHsc")
.include(wx_include_dir)
.include(wx_include_msvc_dir)
@ -215,6 +217,8 @@ fn build_native() {
.file("src/sys/wizard/wizard_gui.cpp")
.file("src/sys/welcome/welcome.cpp")
.file("src/sys/welcome/welcome_gui.cpp")
.file("src/sys/troubleshooting/troubleshooting.cpp")
.file("src/sys/troubleshooting/troubleshooting_gui.cpp")
.file("src/sys/common/mac.mm");
build.flag("-std=c++17");
@ -353,7 +357,9 @@ fn build_native() {
.file("src/sys/wizard/wizard.cpp")
.file("src/sys/wizard/wizard_gui.cpp")
.file("src/sys/welcome/welcome.cpp")
.file("src/sys/welcome/welcome_gui.cpp");
.file("src/sys/welcome/welcome_gui.cpp")
.file("src/sys/troubleshooting/troubleshooting.cpp")
.file("src/sys/troubleshooting/troubleshooting_gui.cpp");
build.flag("-std=c++17");
for flag in cpp_flags {

View File

@ -22,6 +22,7 @@ extern crate lazy_static;
pub mod form;
pub mod search;
pub mod troubleshooting;
pub mod welcome;
pub mod wizard;
mod sys;

View File

@ -120,6 +120,8 @@ typedef struct WizardMetadata {
void (*on_completed)();
} WizardMetadata;
// WELCOME
typedef struct WelcomeMetadata {
const char *window_icon_path;
const char *tray_image_path;
@ -128,3 +130,30 @@ typedef struct WelcomeMetadata {
int (*dont_show_again_changed)(int);
} WelcomeMetadata;
// TROUBLESHOOTING
const int ERROR_METADATA_LEVEL_ERROR = 1;
const int ERROR_METADATA_LEVEL_WARNING = 2;
typedef struct ErrorMetadata {
const int level;
const char *message;
} ErrorMetadata;
typedef struct ErrorSetMetadata {
const char *file_path;
const ErrorMetadata * errors;
const int errors_count;
} ErrorSetMetadata;
typedef struct TroubleshootingMetadata {
const char *window_icon_path;
const int is_fatal_error;
const ErrorSetMetadata * error_sets;
const int error_sets_count;
// METHODS
int (*dont_show_again_changed)(int);
int (*open_file)(const char * file_name);
} TroubleshootingMetadata;

View File

@ -146,6 +146,38 @@ pub struct WelcomeMetadata {
pub dont_show_again_changed: extern fn(c_int),
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct TroubleshootingMetadata {
pub window_icon_path: *const c_char,
pub is_fatal_error: c_int,
pub error_sets: *const ErrorSetMetadata,
pub error_sets_count: c_int,
pub dont_show_again_changed: extern fn(c_int),
pub open_file: extern fn(*const c_char),
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ErrorSetMetadata {
pub file_path: *const c_char,
pub errors: *const ErrorMetadata,
pub errors_count: c_int,
}
pub const ERROR_METADATA_LEVEL_ERROR: c_int = 1;
pub const ERROR_METADATA_LEVEL_WARNING: c_int = 2;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ErrorMetadata {
pub level: c_int,
pub message: *const c_char,
}
// Native bindings
#[allow(improper_ctypes)]
@ -174,4 +206,7 @@ extern "C" {
// WELCOME
pub(crate) fn interop_show_welcome(metadata: *const WelcomeMetadata);
// TROUBLESHOOTING
pub(crate) fn interop_show_troubleshooting(metadata: *const TroubleshootingMetadata);
}

View File

@ -19,6 +19,7 @@
pub mod form;
pub mod search;
pub mod troubleshooting;
pub mod wizard;
pub mod welcome;

View File

@ -0,0 +1,176 @@
/*
* This file is part of modulo.
*
* Copyright (C) 2020-2021 Federico Terzi
*
* modulo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* modulo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with modulo. If not, see <https://www.gnu.org/licenses/>.
*/
use std::ffi::CStr;
use std::os::raw::{c_char, c_int};
use std::path::PathBuf;
use std::sync::Mutex;
use crate::sys::interop::{ErrorSetMetadata, TroubleshootingMetadata};
use crate::sys::troubleshooting::interop::{OwnedErrorSet};
use crate::sys::util::convert_to_cstring_or_null;
use crate::troubleshooting::{TroubleshootingHandlers, TroubleshootingOptions};
use anyhow::Result;
lazy_static! {
static ref HANDLERS: Mutex<Option<TroubleshootingHandlers>> = Mutex::new(None);
}
#[allow(dead_code)]
mod interop {
use crate::troubleshooting::{ErrorRecord, ErrorSet};
use super::interop::{ErrorMetadata, ErrorSetMetadata};
use super::super::interop::*;
use std::{
ffi::{CString},
os::raw::c_int,
};
pub(crate) struct OwnedErrorSet {
file_path: Option<CString>,
errors: Vec<OwnedErrorMetadata>,
pub(crate) _interop_errors: Vec<ErrorMetadata>,
}
impl OwnedErrorSet {
pub fn to_error_set_metadata(&self) -> ErrorSetMetadata {
let file_path_ptr = if let Some(file_path) = self.file_path.as_ref() {
file_path.as_ptr()
} else {
std::ptr::null()
};
ErrorSetMetadata {
file_path: file_path_ptr,
errors: self._interop_errors.as_ptr(),
errors_count: self._interop_errors.len() as c_int,
}
}
}
impl From<&ErrorSet> for OwnedErrorSet {
fn from(error_set: &ErrorSet) -> Self {
let file_path = if let Some(file_path) = &error_set.file {
Some(CString::new(file_path.to_string_lossy().to_string())
.expect("unable to convert file_path to CString"))
} else {
None
};
let errors: Vec<OwnedErrorMetadata> =
error_set.errors.iter().map(|item| item.into()).collect();
let _interop_errors: Vec<ErrorMetadata> =
errors.iter().map(|item| item.to_error_metadata()).collect();
Self {
file_path,
errors,
_interop_errors,
}
}
}
pub(crate) struct OwnedErrorMetadata {
level: c_int,
message: CString,
}
impl OwnedErrorMetadata {
fn to_error_metadata(&self) -> ErrorMetadata {
ErrorMetadata {
level: self.level,
message: self.message.as_ptr(),
}
}
}
impl From<&ErrorRecord> for OwnedErrorMetadata {
fn from(item: &ErrorRecord) -> Self {
let message =
CString::new(item.message.clone()).expect("unable to convert item message to CString");
Self {
level: match item.level {
crate::troubleshooting::ErrorLevel::Error => ERROR_METADATA_LEVEL_ERROR,
crate::troubleshooting::ErrorLevel::Warning => ERROR_METADATA_LEVEL_WARNING,
},
message,
}
}
}
}
pub fn show(options: TroubleshootingOptions) -> Result<()> {
let (_c_window_icon_path, c_window_icon_path_ptr) =
convert_to_cstring_or_null(options.window_icon_path);
let owned_error_sets: Vec<OwnedErrorSet> =
options.error_sets.iter().map(|set| set.into()).collect();
let error_sets: Vec<ErrorSetMetadata> = owned_error_sets
.iter()
.map(|set| set.to_error_set_metadata())
.collect();
extern "C" fn dont_show_again_changed(dont_show: c_int) {
let lock = HANDLERS
.lock()
.expect("unable to acquire lock in dont_show_again_changed method");
let handlers_ref = (*lock).as_ref().expect("unable to unwrap handlers");
if let Some(handler_ref) = handlers_ref.dont_show_again_changed.as_ref() {
let value = if dont_show == 1 { true } else { false };
(*handler_ref)(value);
}
}
extern "C" fn open_file(file_path: *const c_char) {
let lock = HANDLERS
.lock()
.expect("unable to acquire lock in open_file method");
let handlers_ref = (*lock).as_ref().expect("unable to unwrap handlers");
if let Some(handler_ref) = handlers_ref.open_file.as_ref() {
let c_string = unsafe { CStr::from_ptr(file_path) };
let string = c_string.to_string_lossy();
let path = PathBuf::from(string.to_string());
(*handler_ref)(&path);
}
}
{
let mut lock = HANDLERS.lock().expect("unable to acquire handlers lock");
*lock = Some(options.handlers)
}
let troubleshooting_metadata = TroubleshootingMetadata {
window_icon_path: c_window_icon_path_ptr,
is_fatal_error: if options.is_fatal_error { 1 } else { 0 },
error_sets: error_sets.as_ptr(),
error_sets_count: error_sets.len() as c_int,
dont_show_again_changed,
open_file,
};
unsafe {
super::interop::interop_show_troubleshooting(&troubleshooting_metadata);
}
Ok(())
}

View File

@ -0,0 +1,188 @@
/*
* This file is part of modulo.
*
* Copyright (C) 2020-2021 Federico Terzi
*
* modulo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* modulo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with modulo. If not, see <https://www.gnu.org/licenses/>.
*/
#define _UNICODE
#include "../common/common.h"
#include "../interop/interop.h"
#include "./troubleshooting_gui.h"
#include <vector>
#include <memory>
#include <unordered_map>
TroubleshootingMetadata *troubleshooting_metadata = nullptr;
// App Code
class TroubleshootingApp : public wxApp
{
public:
virtual bool OnInit();
};
// Custom controller to display an ErrorSet
class ErrorSetPanel : public wxPanel
{
private:
protected:
wxStaticText *filename_label;
wxButton *open_file_btn;
wxTextCtrl *error_text_ctrl;
const ErrorSetMetadata * error_set_metadata;
public:
ErrorSetPanel(wxWindow *parent, const ErrorSetMetadata * error_set_metadata) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
{
this->error_set_metadata = error_set_metadata;
wxBoxSizer *main_file_sizer;
main_file_sizer = new wxBoxSizer(wxVERTICAL);
main_file_sizer->SetMinSize(0, 150);
wxBoxSizer *header_sizer;
header_sizer = new wxBoxSizer(wxHORIZONTAL);
wxString path = wxString::FromUTF8(error_set_metadata->file_path);
wxString filename = wxString::Format(wxT("%s (%i errors)"), path, error_set_metadata->errors_count);
filename_label = new wxStaticText(this, wxID_ANY, filename, wxDefaultPosition, wxDefaultSize, 0);
filename_label->Wrap(-1);
filename_label->SetFont(wxFont(wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString));
header_sizer->Add(filename_label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
header_sizer->Add(0, 0, 1, wxEXPAND, 5);
open_file_btn = new wxButton(this, wxID_ANY, wxT("Open file"), wxDefaultPosition, wxDefaultSize, 0);
header_sizer->Add(open_file_btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
main_file_sizer->Add(header_sizer, 0, wxEXPAND, 5);
wxString errors_text = wxEmptyString;
for (int i = 0; i<error_set_metadata->errors_count; i++) {
wxString level = wxT("ERROR");
if (error_set_metadata->errors[i].level == ERROR_METADATA_LEVEL_WARNING) {
level = wxT("WARNING");
}
wxString error_text = wxString::Format(wxT("[%s] %s\n"), level, error_set_metadata->errors[i].message);
errors_text.Append(error_text);
}
error_text_ctrl = new wxTextCtrl(this, wxID_ANY, errors_text, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
main_file_sizer->Add(error_text_ctrl, 1, wxALL | wxEXPAND, 5);
this->SetSizer(main_file_sizer);
this->Layout();
main_file_sizer->Fit(this);
if (!this->error_set_metadata->file_path) {
filename_label->Hide();
open_file_btn->Hide();
}
open_file_btn->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ErrorSetPanel::on_open_file), NULL, this);
}
void ErrorSetPanel::on_open_file(wxCommandEvent &event)
{
if (troubleshooting_metadata->open_file && this->error_set_metadata->file_path) {
troubleshooting_metadata->open_file(this->error_set_metadata->file_path);
}
}
~ErrorSetPanel()
{
open_file_btn->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ErrorSetPanel::on_open_file), NULL, this);
}
};
// Frame
class DerivedTroubleshootingFrame : public TroubleshootingFrame
{
protected:
void on_dont_show_change(wxCommandEvent &event);
void on_ignore(wxCommandEvent &event);
public:
DerivedTroubleshootingFrame(wxWindow *parent);
};
DerivedTroubleshootingFrame::DerivedTroubleshootingFrame(wxWindow *parent)
: TroubleshootingFrame(parent)
{
if (troubleshooting_metadata->is_fatal_error) {
dont_show_checkbox->Hide();
ignore_button->Hide();
info_label->SetLabel(wxT("Espanso couldn't load some files due to configuration errors and won't be able to start until you fix them."));
title_label->SetLabel(wxT("Errors detected, action needed"));
}
for (int i = 0; i<troubleshooting_metadata->error_sets_count; i++) {
const ErrorSetMetadata * metadata = &troubleshooting_metadata->error_sets[i];
ErrorSetPanel *panel = new ErrorSetPanel(scrollview, metadata);
this->scrollview_sizer->Add(panel, 0, wxEXPAND | wxALL, 5);
}
}
void DerivedTroubleshootingFrame::on_dont_show_change(wxCommandEvent &event)
{
if (troubleshooting_metadata->dont_show_again_changed)
{
int value = this->dont_show_checkbox->IsChecked() ? 1 : 0;
troubleshooting_metadata->dont_show_again_changed(value);
}
}
void DerivedTroubleshootingFrame::on_ignore(wxCommandEvent &event)
{
Close(true);
}
bool TroubleshootingApp::OnInit()
{
DerivedTroubleshootingFrame *frame = new DerivedTroubleshootingFrame(NULL);
if (troubleshooting_metadata->window_icon_path)
{
setFrameIcon(troubleshooting_metadata->window_icon_path, frame);
}
frame->Show(true);
Activate(frame);
return true;
}
extern "C" void interop_show_troubleshooting(TroubleshootingMetadata *_metadata)
{
// Setup high DPI support on Windows
#ifdef __WXMSW__
SetProcessDPIAware();
#endif
troubleshooting_metadata = _metadata;
wxApp::SetInstance(new TroubleshootingApp());
int argc = 0;
wxEntry(argc, (char **)nullptr);
}

View File

@ -0,0 +1,421 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="15" />
<object class="Project" expanded="1">
<property name="class_decoration">; </property>
<property name="code_generation">C++</property>
<property name="disconnect_events">1</property>
<property name="disconnect_mode">source_name</property>
<property name="disconnect_php_events">0</property>
<property name="disconnect_python_events">0</property>
<property name="embedded_files_path">res</property>
<property name="encoding">UTF-8</property>
<property name="event_generation">connect</property>
<property name="file">troubleshooting_gui</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="indent_with_spaces"></property>
<property name="internationalize">0</property>
<property name="name">Troubleshooting</property>
<property name="namespace"></property>
<property name="path">.</property>
<property name="precompiled_header">#define _UNICODE</property>
<property name="relative_path">1</property>
<property name="skip_lua_events">1</property>
<property name="skip_php_events">1</property>
<property name="skip_python_events">1</property>
<property name="ui_table">UI</property>
<property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property>
<object class="Frame" expanded="1">
<property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg">wxSYS_COLOUR_WINDOW</property>
<property name="center">wxBOTH</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="enabled">1</property>
<property name="event_handler">impl_virtual</property>
<property name="extra_style"></property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">TroubleshootingFrame</property>
<property name="pos"></property>
<property name="size">841,544</property>
<property name="style">wxDEFAULT_FRAME_STYLE</property>
<property name="subclass">; ; forward_declare</property>
<property name="title">Troubleshooting</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL</property>
<property name="xrc_skip_sizer">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer1</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="spacer" expanded="0">
<property name="height">10</property>
<property name="permission">protected</property>
<property name="width">0</property>
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">10</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font">,90,92,20,70,0</property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Errors detected</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">title_label</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">10</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Espanso couldn&apos;t load some files due to configuration errors. Some snippets or settings might not be available until you fix them.</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">-1,-1</property>
<property name="moveable">1</property>
<property name="name">info_label</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size">-1,-1</property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND | wxALL</property>
<property name="proportion">5</property>
<object class="wxScrolledWindow" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">scrollview</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="scroll_rate_x">5</property>
<property name="scroll_rate_y">5</property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxHSCROLL|wxVSCROLL</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">scrollview_sizer</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">protected</property>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">10</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer2</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="0">
<property name="border">10</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="checked">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Don&apos;t show again for non-critical errors</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">dont_show_checkbox</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnCheckBox">on_dont_show_change</event>
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="spacer" expanded="0">
<property name="height">0</property>
<property name="permission">protected</property>
<property name="width">0</property>
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">10</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Ignore errors</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">ignore_button</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">on_ignore</event>
</object>
</object>
</object>
</object>
</object>
</object>
</object>
</wxFormBuilder_Project>

View File

@ -0,0 +1,77 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#define _UNICODE
#include "troubleshooting_gui.h"
///////////////////////////////////////////////////////////////////////////
TroubleshootingFrame::TroubleshootingFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer( wxVERTICAL );
bSizer1->Add( 0, 10, 0, wxEXPAND, 5 );
title_label = new wxStaticText( this, wxID_ANY, wxT("Errors detected"), wxDefaultPosition, wxDefaultSize, 0 );
title_label->Wrap( -1 );
title_label->SetFont( wxFont( 20, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) );
bSizer1->Add( title_label, 0, wxALL, 10 );
info_label = new wxStaticText( this, wxID_ANY, wxT("Espanso couldn't load some files due to configuration errors. Some snippets or settings might not be available until you fix them."), wxDefaultPosition, wxSize( -1,-1 ), 0 );
info_label->Wrap( -1 );
bSizer1->Add( info_label, 0, wxALL, 10 );
scrollview = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
scrollview->SetScrollRate( 5, 5 );
scrollview_sizer = new wxBoxSizer( wxVERTICAL );
scrollview->SetSizer( scrollview_sizer );
scrollview->Layout();
scrollview_sizer->Fit( scrollview );
bSizer1->Add( scrollview, 5, wxEXPAND | wxALL, 5 );
wxBoxSizer* bSizer2;
bSizer2 = new wxBoxSizer( wxHORIZONTAL );
dont_show_checkbox = new wxCheckBox( this, wxID_ANY, wxT("Don't show again for non-critical errors"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( dont_show_checkbox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 10 );
bSizer2->Add( 0, 0, 1, wxEXPAND, 5 );
ignore_button = new wxButton( this, wxID_ANY, wxT("Ignore errors"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( ignore_button, 0, wxALIGN_CENTER_VERTICAL|wxALL, 10 );
bSizer1->Add( bSizer2, 0, wxEXPAND, 10 );
this->SetSizer( bSizer1 );
this->Layout();
this->Centre( wxBOTH );
// Connect Events
dont_show_checkbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( TroubleshootingFrame::on_dont_show_change ), NULL, this );
ignore_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( TroubleshootingFrame::on_ignore ), NULL, this );
}
TroubleshootingFrame::~TroubleshootingFrame()
{
// Disconnect Events
dont_show_checkbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( TroubleshootingFrame::on_dont_show_change ), NULL, this );
ignore_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( TroubleshootingFrame::on_ignore ), NULL, this );
}

View File

@ -0,0 +1,57 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/sizer.h>
#include <wx/scrolwin.h>
#include <wx/checkbox.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/button.h>
#include <wx/frame.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class TroubleshootingFrame
///////////////////////////////////////////////////////////////////////////////
class TroubleshootingFrame : public wxFrame
{
private:
protected:
wxStaticText* title_label;
wxStaticText* info_label;
wxScrolledWindow* scrollview;
wxBoxSizer* scrollview_sizer;
wxCheckBox* dont_show_checkbox;
wxButton* ignore_button;
// Virtual event handlers, overide them in your derived class
virtual void on_dont_show_change( wxCommandEvent& event ) { event.Skip(); }
virtual void on_ignore( wxCommandEvent& event ) { event.Skip(); }
public:
TroubleshootingFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Troubleshooting"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 841,544 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
~TroubleshootingFrame();
};

View File

@ -0,0 +1,50 @@
/*
* This file is part of modulo.
*
* Copyright (C) 2020-2021 Federico Terzi
*
* modulo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* modulo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with modulo. If not, see <https://www.gnu.org/licenses/>.
*/
use std::path::{Path, PathBuf};
pub use crate::sys::troubleshooting::show;
pub struct TroubleshootingOptions {
pub window_icon_path: Option<String>,
pub error_sets: Vec<ErrorSet>,
pub is_fatal_error: bool,
pub handlers: TroubleshootingHandlers,
}
pub struct ErrorSet {
pub file: Option<PathBuf>,
pub errors: Vec<ErrorRecord>,
}
pub struct ErrorRecord {
pub level: ErrorLevel,
pub message: String,
}
pub enum ErrorLevel {
Error,
Warning,
}
pub struct TroubleshootingHandlers {
pub dont_show_again_changed: Option<Box<dyn Fn(bool) + Send>>,
pub open_file: Option<Box<dyn Fn(&Path) + Send>>,
}