Skip to content

Commit

Permalink
option to dismiss picker on focus loss
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed Sep 6, 2024
1 parent d81e7eb commit 5e4860f
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 43 deletions.
4 changes: 2 additions & 2 deletions bt/app/app_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace fs = std::filesystem;

namespace bt {

const string FileName = "log.txt";
const string AppLogFileName = "log.txt";
app_log app_log::i;

app_log::app_log() :
path{config::get_data_file_path(FileName)},
path{config::get_data_file_path(AppLogFileName)},
stream(path, ofstream::out | ofstream::app | ofstream::ate) {
}

Expand Down
58 changes: 32 additions & 26 deletions bt/app/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,30 @@ using namespace std;
namespace fs = std::filesystem;

namespace bt {
const string FileName = "config.ini";
const string settings_root = string("SOFTWARE\\") + APP_LONG_NAME;
const string IIDKeyName = "iid";
const string BrowserPrefix = "browser";
const string FirefoxContainerModeKey = "firefox_container_mode";
const string LogRuleHitsKey = "log_rule_hits";
const string LogAppKey = "log_app";
const string PersistPopularityKey = "persist_popularity";
const string ShowHiddenBrowsersKey = "browsers_show_hidden";
const string UnshortEnabledKey = "unshort_enabled";
const string PickerSectionName = "picker";
const string PipelineSectionName = "pipeline";
const string PipelineSubstKeyName = "subst";
const string PipelineUnwrapO365Key = "unwrap_o365";
const string PipelineUnshortenKey = "unshorten";
const string PipelineSubstituteKey = "substitute";
const string PipelineScriptKey = "script";
const string PipeVisualiserSectionName = "pipevis";

config::config() : cfg{config::get_data_file_path(FileName)} {
#define ConfigFileName "config.ini"
#define settings_root "SOFTWARE\\" APP_LONG_NAME
#define IIDKeyName "iid"
#define BrowserPrefix "browser"
#define FirefoxContainerModeKey "firefox_container_mode"
#define LogRuleHitsKey "log_rule_hits"
#define LogAppKey "log_app"
#define PersistPopularityKey "persist_popularity"
#define ShowHiddenBrowsersKey "browsers_show_hidden"
#define UnshortEnabledKey "unshort_enabled"
#define PickerSectionName "picker"
#define PickerOnKeyCS "on_key_cs"
#define PickerOnKeyCA "on_key_ca"
#define PickerOnKeyAS "on_key_as"
#define PickerCloseOnFocusLoss "close_on_focus_loss"
#define PipelineSectionName "pipeline"
#define PipelineSubstKeyName "subst"
#define PipelineUnwrapO365Key "unwrap_o365"
#define PipelineUnshortenKey "unshorten"
#define PipelineSubstituteKey "substitute"
#define PipelineScriptKey "script"
#define PipeVisualiserSectionName "pipevis"

config::config() : cfg{config::get_data_file_path(ConfigFileName)} {
migrate();
ensure_instance_id();
load();
Expand Down Expand Up @@ -119,12 +123,13 @@ namespace bt {
default_profile_long_id = cfg.get_value("default_profile");

// picker
picker_on_key_cs = cfg.get_bool_value("on_key_cs", true, PickerSectionName);
picker_on_key_ca = cfg.get_bool_value("on_key_ca", false, PickerSectionName);
picker_on_key_as = cfg.get_bool_value("on_key_as", false, PickerSectionName);
picker_on_key_cs = cfg.get_bool_value(PickerOnKeyCS, true, PickerSectionName);
picker_on_key_ca = cfg.get_bool_value(PickerOnKeyCA, false, PickerSectionName);
picker_on_key_as = cfg.get_bool_value(PickerOnKeyAS, false, PickerSectionName);
picker_on_conflict = cfg.get_bool_value("on_conflict", true, PickerSectionName);
picker_on_no_rule = cfg.get_bool_value("on_no_rule", false, PickerSectionName);
picker_always = cfg.get_bool_value("always", false, PickerSectionName);
picker_close_on_focus_loss = cfg.get_bool_value(PickerCloseOnFocusLoss, false, PickerSectionName);

// pipeline
pipeline_unwrap_o365 = cfg.get_bool_value(PipelineUnwrapO365Key, true, PipelineSectionName);
Expand All @@ -150,12 +155,13 @@ namespace bt {
cfg.set_value("default_profile", default_profile_long_id);

// picker
cfg.set_bool_value("on_key_cs", picker_on_key_cs, PickerSectionName);
cfg.set_bool_value("on_key_ca", picker_on_key_ca, PickerSectionName);
cfg.set_bool_value("on_key_as", picker_on_key_as, PickerSectionName);
cfg.set_bool_value(PickerOnKeyCS, picker_on_key_cs, PickerSectionName);
cfg.set_bool_value(PickerOnKeyCA, picker_on_key_ca, PickerSectionName);
cfg.set_bool_value(PickerOnKeyAS, picker_on_key_as, PickerSectionName);
cfg.set_bool_value("on_conflict", picker_on_conflict, PickerSectionName);
cfg.set_bool_value("on_no_rule", picker_on_no_rule, PickerSectionName);
cfg.set_bool_value("always", picker_always, PickerSectionName);
cfg.set_bool_value(PickerCloseOnFocusLoss, picker_close_on_focus_loss, PickerSectionName);

// pipeline
cfg.set_bool_value(PipelineUnwrapO365Key, pipeline_unwrap_o365, PipelineSectionName);
Expand Down
1 change: 1 addition & 0 deletions bt/app/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace bt {
bool picker_on_no_rule;
// whether to always show the picker, regardless of other settings above (they are kept to restore old behavior when you un-tick)
bool picker_always;
bool picker_close_on_focus_loss;

// pipeline
bool pipeline_unwrap_o365;
Expand Down
4 changes: 2 additions & 2 deletions bt/app/rule_hit_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace fs = std::filesystem;

namespace bt {

const string FileName = "hit_log.csv";
const string HitLogFileName = "hit_log.csv";
rule_hit_log rule_hit_log::i;

rule_hit_log::rule_hit_log() :
path{config::get_data_file_path(FileName)},
path{config::get_data_file_path(HitLogFileName)},
stream(path, ofstream::out | ofstream::app | ofstream::ate),
writer(stream) {
if(stream.tellp() == 0) {
Expand Down
2 changes: 2 additions & 0 deletions bt/app/ui/config_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ namespace bt::ui {
}

if(w::menu m{"Picker"}; m) {
w::small_checkbox("Close on focus loss", g_config.picker_close_on_focus_loss);

w::sep("Manual invocation");
w::small_checkbox("Ctrl + Shift + Left Click", g_config.picker_on_key_cs);
w::small_checkbox("Ctrl + Alt + Left Click", g_config.picker_on_key_ca);
Expand Down
5 changes: 3 additions & 2 deletions bt/app/url_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ namespace bt {

void url_pipeline::clean(std::string& s) {
// remove custom protocol prefix
if(s.starts_with(CustomProtoName) && s.size() > CustomProtoName.size() + 3) {
s = s.substr(CustomProtoName.size() + 3);
size_t sz = string(CustomProtoName).size();
if(s.starts_with(CustomProtoName) && s.size() > sz + 3) {
s = s.substr(sz + 3);
}

// Firefox for some reason removes ':' when opening custom protocol links, so we need to add it back
Expand Down
17 changes: 8 additions & 9 deletions bt/globals.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
#pragma once
#include <string>
#include "app/url_pipeline.h"
#include "app/config.h"
#include "app/script_site.h"
#include "../common/ext/alg_tracker.h"

const std::string ProtoName = "BrowserTamerHTM";
#define ProtoName "BrowserTamerHTM"

const std::string PdfProtoName = "BrowserTamerPDF";
#define PdfProtoName "BrowserTamerPDF"

const std::string CustomProtoName = "x-bt";
#define CustomProtoName "x-bt"

const std::string ContributeUrl = "https://github.com/aloneguid/bt#contributing";
#define ContributeUrl "https://github.com/aloneguid/bt#contributing"

const std::string ArgSplitter = "|";
#define ArgSplitter "|"

constexpr std::string_view PortableMarkerName = ".portable";
#define PortableMarkerName ".portable"

constexpr std::string_view LuaRulePrefix = "rule_";
#define LuaRulePrefix "rule_"

constexpr std::string_view LuaPipelinePrefix = "ppl_";
#define LuaPipelinePrefix "ppl_"

extern alg::tracker t;

Expand Down
5 changes: 4 additions & 1 deletion docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## 4.1.1

⌨️ Keyboard is back, but it's even better now. Picker can be [controlled with keyboaard keys](https://aloneguid.github.io/bt/picker.html#keyboard-navigation).
### Improvements
- ⌨️ Keyboard is back, but it's even better now. Picker can be [controlled with keyboaard keys](https://aloneguid.github.io/bt/picker.html#keyboard-navigation). Thanks to @aaronransley.
- Picker window can be optionally dismissed on focus loss, the option is off by default and can be enabled from the `Picker` menu. Thanks to @rp1231 in #86.


## 4.1.0

Expand Down
2 changes: 1 addition & 1 deletion grey

0 comments on commit 5e4860f

Please sign in to comment.