Skip to content

Commit 771d0f5

Browse files
committed
Synchronize settings and disable patching during batch mode
1 parent 6823036 commit 771d0f5

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

PasteIntoFile/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
<setting name="updateChecksEnabled" serializeAs="String">
5050
<value>True</value>
5151
</setting>
52+
<setting name="continuousMode" serializeAs="String">
53+
<value>False</value>
54+
</setting>
5255
</PasteIntoFile.Properties.Settings>
5356
</userSettings>
5457
</configuration>

PasteIntoFile/Dialog.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace PasteIntoFile {
1515
public partial class Dialog : MasterForm {
1616
private ClipboardContents clipData = new ClipboardContents();
17-
private bool continuousMode = false;
1817
private int saveCount = 0;
1918

2019
private SharpClipboard _clipMonitor;
@@ -33,6 +32,10 @@ protected override void OnFormClosed(FormClosedEventArgs e) {
3332

3433

3534
public Dialog(string location = null, string filename = null, bool? showDialogOverwrite = null, bool? clearClipboardOverwrite = null, bool overwriteIfExists = false) {
35+
Settings.Default.Reload(); // load modifications made from other instance
36+
Settings.Default.continuousMode = false; // always start in normal mode
37+
Settings.Default.Save();
38+
3639
// Fallback to default path
3740
location = (location ?? ExplorerUtil.GetActiveExplorerPath() ??
3841
Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
@@ -92,7 +95,7 @@ public Dialog(string location = null, string filename = null, bool? showDialogOv
9295
if (saveIntoSubdir) location += @"\" + formatFilenameTemplate(Settings.Default.subdirTemplate);
9396
txtCurrentLocation.Text = location;
9497
chkClrClipboard.Checked = clearClipboardOverwrite ?? Settings.Default.clrClipboard;
95-
chkContinuousMode.Checked = continuousMode;
98+
chkContinuousMode.Checked = Settings.Default.continuousMode;
9699
updateSavebutton();
97100
chkAutoSave.Checked = Settings.Default.autoSave;
98101

@@ -217,7 +220,7 @@ private void ClipboardChanged(Object sender, SharpClipboard.ClipboardChangedEven
217220
readClipboard();
218221

219222
// continuous batch mode
220-
if (continuousMode) {
223+
if (Settings.Default.continuousMode) {
221224
var ignore = false;
222225
// ignore duplicate updates within 100ms
223226
ignore |= (clipData.Timestamp - previousClipboardTimestamp).TotalMilliseconds <= 100;
@@ -308,8 +311,8 @@ private void updateContentPreview() {
308311

309312

310313
private void updateSavebutton() {
311-
btnSave.Enabled = txtFilename.Enabled = !continuousMode;
312-
btnSave.Text = continuousMode ? string.Format(Resources.str_n_saved, saveCount) : Resources.str_save;
314+
btnSave.Enabled = txtFilename.Enabled = !Settings.Default.continuousMode;
315+
btnSave.Text = Settings.Default.continuousMode ? string.Format(Resources.str_n_saved, saveCount) : Resources.str_save;
313316
}
314317

315318
private void btnSave_Click(object sender, EventArgs e) {
@@ -425,7 +428,8 @@ private void chkContinuousMode_CheckedChanged(object sender, EventArgs e) {
425428
chkContinuousMode.Checked = false;
426429
}
427430

428-
continuousMode = chkContinuousMode.Checked;
431+
Settings.Default.continuousMode = chkContinuousMode.Checked;
432+
Settings.Default.Save();
429433
updateSavebutton();
430434

431435
}

PasteIntoFile/Main.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ static int Main(string[] args) {
105105
// not perfect, but probably as good as it can be: https://stackoverflow.com/a/11058118
106106
AttachConsole(ATTACH_PARENT_PROCESS);
107107

108+
Settings.Default.continuousMode = false; // always start in normal mode
109+
Settings.Default.Save();
110+
108111
if (!Settings.Default.upgradePerformed) {
109112
// New version installed with default settings (upgradePerformed == false)
110113
// https://stackoverflow.com/a/534335/13324744
@@ -272,6 +275,9 @@ static int RunTray(ArgsTray args = null) {
272275
bool skipFirst = true;
273276
void PatchClipboard(object s, SharpClipboard.ClipboardChangedEventArgs e) {
274277
if (skipFirst) { skipFirst = false; return; }
278+
Settings.Default.Reload(); // load modifications made from other instance
279+
if (!Settings.Default.trayPatchingEnabled) return; // allow to temporarily disable
280+
if (Settings.Default.continuousMode) return; // don't interfere with batch mode
275281
if (PatchedClipboardContents() is IDataObject data) {
276282
// TODO: This is experimental (might impact performance, might break proprietary formats used internally by other programs, not 100% stable)
277283
// Temporarily pausing monitoring seams unstable with the SharpClipboard library, so close and re-create the monitor instead

PasteIntoFile/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PasteIntoFile/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
<Setting Name="updateChecksEnabled" Type="System.Boolean" Scope="User">
4242
<Value Profile="(Default)">True</Value>
4343
</Setting>
44+
<Setting Name="continuousMode" Type="System.Boolean" Scope="User">
45+
<Value Profile="(Default)">False</Value>
46+
</Setting>
4447
</Settings>
4548
</SettingsFile>
4649

PasteIntoFile/Wizard.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace PasteIntoFile {
99
public partial class Wizard : MasterForm {
1010
public Wizard() {
1111
InitializeComponent();
12+
Settings.Default.Reload(); // load modifications made from other instance
1213

1314

1415
foreach (Control element in GetAllChild(this)) {

0 commit comments

Comments
 (0)