Skip to content

Commit b2f1a01

Browse files
committed
Merge pull request #37 from chrisws/0_11_20
0 12 5
2 parents b48ea71 + 0355dd7 commit b2f1a01

File tree

15 files changed

+148
-25
lines changed

15 files changed

+148
-25
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2016-02-11
2+
Added export to mobile command (SDL)
3+
Added Desktop shortcut command (android)
4+
15
2015-12-05
26
Implemented loading recent files via ALT+1 .. ALT+9
37
Fix potential editor crash with empty support widget

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
77
dnl Download the GNU Public License (GPL) from www.gnu.org
88
dnl
99

10-
AC_INIT([smallbasic], [0.12.3])
10+
AC_INIT([smallbasic], [0.12.5])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

ide/android/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="net.sourceforge.smallbasic"
44
android:installLocation="preferExternal"
5-
android:versionCode="17"
6-
android:versionName="0.12.3">
5+
android:versionCode="19"
6+
android:versionName="0.12.5">
77
<!-- This is the platform API where NativeActivity was introduced. -->
88
<uses-sdk android:minSdkVersion="9"/>
99

@@ -64,5 +64,6 @@
6464
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6565
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
6666
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
67+
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
6768
</manifest>
6869

ide/android/assets/main.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ sub do_about()
5555
print "(_ ._ _ _.|||_) /\ (_ |/ "
5656
print "__)| | |(_||||_)/--\__)|\_"
5757
print
58-
print "Version 0.12.3"
58+
print "Version 0.12.5"
5959
print
6060
print "Copyright (c) 2002-2015 Chris Warren-Smith"
6161
print "Copyright (c) 1999-2006 Nic Christopoulos" + chr(10)

src/platform/android/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test: ant-build-test
1717
(cd ../../../ide/android && \
1818
adb -a logcat -c && \
1919
adb -a shell am start net.sourceforge.smallbasic/net.sourceforge.smallbasic.MainActivity && \
20-
adb -a logcat)
20+
adb -a logcat DEBUG:I smallbasic:I AndroidRuntime:E *:S)
2121

2222
clean-ant:
2323
(cd ../../../ide/android && ant -quiet clean)

src/platform/android/jni/runtime.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void handleCommand(android_app *app, int32_t cmd) {
8989
case APP_CMD_GAINED_FOCUS:
9090
trace("gainedFocus");
9191
runtime->setFocus(true);
92+
runtime->redraw();
9293
break;
9394
case APP_CMD_LOST_FOCUS:
9495
trace("lostFocus");
@@ -138,7 +139,7 @@ extern "C" JNIEXPORT void JNICALL Java_net_sourceforge_smallbasic_MainActivity_r
138139

139140
extern "C" JNIEXPORT void JNICALL Java_net_sourceforge_smallbasic_MainActivity_onResize
140141
(JNIEnv *env, jclass jclazz, jint width, jint height) {
141-
if (runtime != NULL && runtime->isActive() && os_graphics) {
142+
if (runtime != NULL && !runtime->isClosing() && runtime->isActive() && os_graphics) {
142143
runtime->onResize(width, height);
143144
}
144145
}
@@ -176,6 +177,10 @@ Runtime::~Runtime() {
176177
pthread_mutex_destroy(&_mutex);
177178
}
178179

180+
void Runtime::addShortcut(const char *path) {
181+
setString("addShortcut", path);
182+
}
183+
179184
void Runtime::alert(const char *title, const char *message) {
180185
logEntered();
181186

@@ -200,8 +205,7 @@ void Runtime::alert(const char *title, bool longDuration) {
200205
_app->activity->vm->AttachCurrentThread(&env, NULL);
201206
jstring titleString = env->NewStringUTF(title);
202207
jclass clazz = env->GetObjectClass(_app->activity->clazz);
203-
jmethodID method = env->GetMethodID(clazz, "showToast",
204-
"(Ljava/lang/String;Z)V");
208+
jmethodID method = env->GetMethodID(clazz, "showToast", "(Ljava/lang/String;Z)V");
205209
env->CallVoidMethod(_app->activity->clazz, method, titleString, longDuration);
206210
env->DeleteLocalRef(clazz);
207211
env->DeleteLocalRef(titleString);

src/platform/android/jni/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct Runtime : public System {
2121
Runtime(android_app *app);
2222
virtual ~Runtime();
2323

24+
void addShortcut(const char *path);
2425
void alert(const char *title, const char *message);
2526
void alert(const char *title, bool longDuration=true);
2627
int ask(const char *title, const char *prompt, bool cancel);

src/platform/android/src/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ public class MainActivity extends NativeActivity {
8484
public static native void onResize(int width, int height);
8585
public static native void runFile(String fileName);
8686

87+
public void addShortcut(final String path) {
88+
Intent shortcut = new Intent(getApplicationContext(), MainActivity.class);
89+
shortcut.setAction(Intent.ACTION_MAIN);
90+
shortcut.setData(Uri.parse("smallbasic://" + path));
91+
Intent intent = new Intent();
92+
int index = path.lastIndexOf('/');
93+
String name = (index == -1) ? path : path.substring(index + 1);
94+
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
95+
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
96+
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
97+
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
98+
R.drawable.ic_launcher));
99+
intent.putExtra("duplicate", false);
100+
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
101+
getApplicationContext().sendBroadcast(intent);
102+
}
103+
87104
public int ask(final String title, final String prompt, final boolean cancel) {
88105
final AskResult result = new AskResult();
89106
final Activity activity = this;

src/platform/sdl/editor.cpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
#include "config.h"
1010

1111
#include "common/sbapp.h"
12+
#include "common/fs_socket_client.h"
1213
#include "ui/textedit.h"
1314
#include "platform/sdl/runtime.h"
1415
#include "platform/sdl/settings.h"
1516

1617
using namespace strlib;
1718

19+
String g_exportAddr;
20+
String g_exportToken;
21+
1822
void onlineHelp(Runtime *runtime, TextEditInput *widget) {
1923
char path[100];
2024
const char *nodeId = widget->getNodeId();
@@ -60,6 +64,27 @@ void showRecentFiles(TextEditHelpWidget *helpWidget, String &loadPath) {
6064
helpWidget->setText(fileList);
6165
}
6266

67+
void exportBuffer(AnsiWidget *out, const char *text, String &dest, String &token) {
68+
char buffer[PATH_MAX];
69+
dev_file_t f;
70+
memset(&f, 0, sizeof(dev_file_t));
71+
72+
sprintf(f.name, "SOCL:%s\n", dest.c_str());
73+
if (dest.indexOf(':', 0) != -1 && sockcl_open(&f)) {
74+
sprintf(buffer, "# %s\n", token.c_str());
75+
sockcl_write(&f, (byte *)buffer, strlen(buffer));
76+
if (!sockcl_write(&f, (byte *)text, strlen(text))) {
77+
sprintf(buffer, "Failed to write: %s", dest.c_str());
78+
} else {
79+
sprintf(buffer, "Exported file to %s", dest.c_str());
80+
}
81+
sockcl_close(&f);
82+
} else {
83+
sprintf(buffer, "Failed to open: %s", dest.c_str());
84+
}
85+
out->setStatus(buffer);
86+
}
87+
6388
void System::editSource(String &loadPath) {
6489
logEntered();
6590

@@ -73,6 +98,9 @@ void System::editSource(String &loadPath) {
7398
TextEditInput *widget = editWidget;
7499
String dirtyFile;
75100
String cleanFile;
101+
enum InputMode {
102+
kInit, kExportAddr, kExportToken
103+
} inputMode = kInit;
76104

77105
setupStatus(dirtyFile, cleanFile, loadPath);
78106
_modifiedTime = getModifiedTime();
@@ -124,7 +152,6 @@ void System::editSource(String &loadPath) {
124152
}
125153

126154
switch (event.key) {
127-
case SB_KEY_F(3):
128155
case SB_KEY_F(8):
129156
case SB_KEY_F(10):
130157
case SB_KEY_F(11):
@@ -168,6 +195,22 @@ void System::editSource(String &loadPath) {
168195
redraw = false;
169196
onlineHelp((Runtime *)this, editWidget);
170197
break;
198+
case SB_KEY_F(4):
199+
if (editWidget->getTextLength() && g_exportAddr.length() && g_exportToken.length()) {
200+
exportBuffer(_output, editWidget->getText(), g_exportAddr, g_exportToken);
201+
break;
202+
}
203+
// else fallthru to F3 handler
204+
case SB_KEY_F(3):
205+
if (editWidget->getTextLength()) {
206+
saveFile(editWidget, loadPath);
207+
_output->setStatus("Export to mobile SmallBASIC. Enter <IP>:<Port>");
208+
widget = helpWidget;
209+
helpWidget->createLineEdit(g_exportAddr);
210+
helpWidget->show();
211+
inputMode = kExportAddr;
212+
}
213+
break;
171214
case SB_KEY_F(5):
172215
saveFile(editWidget, loadPath);
173216
_output->setStatus("Debug. F6=Step, F7=Continue, Esc=Close");
@@ -269,6 +312,25 @@ void System::editSource(String &loadPath) {
269312
if (helpWidget->replaceMode()) {
270313
_output->setStatus("Replace string with. Esc=Close");
271314
dirty = editWidget->isDirty();
315+
} else if (helpWidget->lineEditMode() && helpWidget->getTextLength()) {
316+
switch (inputMode) {
317+
case kExportAddr:
318+
g_exportAddr = helpWidget->getText();
319+
inputMode = kExportToken;
320+
helpWidget->createLineEdit(g_exportToken);
321+
_output->setStatus("Enter token. Esc=Close");
322+
break;
323+
case kExportToken:
324+
g_exportToken = helpWidget->getText();
325+
inputMode = kInit;
326+
widget = editWidget;
327+
exportBuffer(_output, editWidget->getText(), g_exportAddr, g_exportToken);
328+
helpWidget->hide();
329+
break;
330+
default:
331+
break;
332+
}
333+
redraw = true;
272334
} else if (helpWidget->closeOnEnter() && helpWidget->isVisible()) {
273335
if (helpWidget->replaceDoneMode()) {
274336
_output->setStatus(dirtyFile);

src/platform/sdl/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct Runtime : public System {
2121
Runtime(SDL_Window *window);
2222
virtual ~Runtime();
2323

24+
void addShortcut(const char *) {}
2425
void alert(const char *title, const char *message);
2526
int ask(const char *title, const char *prompt, bool cancel);
2627
void browseFile(const char *url);

0 commit comments

Comments
 (0)