Ask to SaveAs just after creating a new calculator and improve the Save and SaveAs in certain situation.

This commit is contained in:
dgis 2019-12-06 00:15:40 +01:00
parent ea970cbed3
commit 2d1af254a1
3 changed files with 21 additions and 9 deletions

View file

@ -602,12 +602,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
} }
private void ensureDocumentSaved(Runnable continueCallback) {
ensureDocumentSaved(continueCallback, false);
}
private Runnable fileSaveAsCallback = null; private Runnable fileSaveAsCallback = null;
private void ensureDocumentSaved(Runnable continueCallback) {
ensureDocumentSaved(continueCallback, false, false);
}
private void ensureDocumentSaved(Runnable continueCallback, boolean forceRequest) { private void ensureDocumentSaved(Runnable continueCallback, boolean forceRequest) {
ensureDocumentSaved(continueCallback, forceRequest, false);
}
private void ensureDocumentSaved(Runnable continueCallback, boolean forceRequest, boolean simpleSave) {
if(NativeLib.isDocumentAvailable()) { if(NativeLib.isDocumentAvailable()) {
String currentFilename = NativeLib.getCurrentFilename(); String currentFilename = NativeLib.getCurrentFilename();
boolean hasFilename = (currentFilename != null && currentFilename.length() > 0); boolean hasFilename = (currentFilename != null && currentFilename.length() > 0);
@ -629,7 +631,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
}; };
if(!forceRequest && hasFilename && sharedPreferences.getBoolean("settings_autosave", true)) { if(simpleSave || (!forceRequest && hasFilename && sharedPreferences.getBoolean("settings_autosave", true))) {
onClickListener.onClick(null, DialogInterface.BUTTON_POSITIVE); onClickListener.onClick(null, DialogInterface.BUTTON_POSITIVE);
} else { } else {
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
@ -646,7 +648,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
// By default Port1 is set // By default Port1 is set
setPort1Settings(true, true); setPort1Settings(true, true);
ensureDocumentSaved(() -> showKMLPicker(false)); ensureDocumentSaved(() -> showKMLPicker(false) );
} }
private void newFileFromKML(String kmlScriptFilename) { private void newFileFromKML(String kmlScriptFilename) {
@ -655,11 +657,20 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
showCalculatorView(true); showCalculatorView(true);
displayFilename(""); displayFilename("");
showKMLLog(); showKMLLog();
suggestToSaveNewFile();
} else } else
showKMLLogForce(); showKMLLogForce();
updateNavigationDrawerItems(); updateNavigationDrawerItems();
} }
private void suggestToSaveNewFile() {
new AlertDialog.Builder(this)
.setMessage(getString(R.string.message_save_new_file))
.setPositiveButton(android.R.string.yes, (dialog, which) -> OnFileSaveAs())
.setNegativeButton(android.R.string.no, (dialog, which) -> {})
.show();
}
private void OnFileOpen() { private void OnFileOpen() {
ensureDocumentSaved(() -> { ensureDocumentSaved(() -> {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
@ -670,7 +681,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}); });
} }
private void OnFileSave() { private void OnFileSave() {
ensureDocumentSaved(null); ensureDocumentSaved(null, false, true);
} }
private void OnFileSaveAs() { private void OnFileSaveAs() {
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
@ -1228,7 +1239,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
private void showKMLLog() { private void showKMLLog() {
if(sharedPreferences.getBoolean("settings_alwaysdisplog", true)) { if(sharedPreferences.getBoolean("settings_alwaysdisplog", false)) {
showKMLLogForce(); showKMLLogForce();
} }
} }

View file

@ -71,6 +71,7 @@
<string name="message_open_security_retry_description">I hope now you could open again the state file.</string> <string name="message_open_security_retry_description">I hope now you could open again the state file.</string>
<string name="message_state_saved">State saved</string> <string name="message_state_saved">State saved</string>
<string name="message_do_you_want_to_save">Do you want to save changes?\n(BACK to cancel)</string> <string name="message_do_you_want_to_save">Do you want to save changes?\n(BACK to cancel)</string>
<string name="message_save_new_file">Do you want to save this new state file?\n(To avoid losing the state of the machine)</string>
<string name="message_yes">Yes</string> <string name="message_yes">Yes</string>
<string name="message_no">No</string> <string name="message_no">No</string>
<string name="message_ok">Ok</string> <string name="message_ok">Ok</string>

View file

@ -22,7 +22,7 @@
<SwitchPreference <SwitchPreference
android:key="settings_alwaysdisplog" android:key="settings_alwaysdisplog"
android:title="@string/settings_alwaysdisplog_title" android:title="@string/settings_alwaysdisplog_title"
android:defaultValue="true" /> android:defaultValue="false" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/settings_category_ui_title"> <PreferenceCategory android:title="@string/settings_category_ui_title">