aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2008-10-27 03:44:14 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2008-10-27 03:44:14 -0400
commita87d7403532c3a2be43e158e0cf3dd1e8e82f7ab (patch)
treefd710e6ba5286026f26a6a4e69dfd84dcc109f1f
parent99c71445d4892fb8d465dc33767ac2fbc769ec50 (diff)
downloadtextadept-a87d7403532c3a2be43e158e0cf3dd1e8e82f7ab.tar.gz
textadept-a87d7403532c3a2be43e158e0cf3dd1e8e82f7ab.zip
Updated Textadept to compile and run on OSX with native GTK framework.
-rw-r--r--core/init.lua25
-rw-r--r--init.lua10
-rw-r--r--osx.patch62
-rw-r--r--src/lua_interface.c3
-rw-r--r--src/textadept.c51
-rw-r--r--src/textadept.h18
6 files changed, 74 insertions, 95 deletions
diff --git a/core/init.lua b/core/init.lua
index 6b491583..84c0d4d6 100644
--- a/core/init.lua
+++ b/core/init.lua
@@ -11,7 +11,9 @@ _THEME = ''
require 'iface'
require 'events'
require 'file_io'
-require 'lua_dialog'
+if not MAC then
+ require 'lua_dialog'
+end
---
-- Checks if the buffer being indexed is the currently focused buffer.
@@ -36,10 +38,23 @@ end
-- used.
-- @return string CocoaDialog result.
function cocoa_dialog(kind, opts)
- local args = { kind }
+ local args = not MAC and { kind } or ''
for k, v in pairs(opts) do
- args[#args + 1] = '--'..k
- if type(v) == 'string' then args[#args + 1] = v end
+ if not MAC then
+ args[#args + 1] = '--'..k
+ if type(v) == 'string' then args[#args + 1] = v end
+ else
+ args = args..' --'..k
+ if type(v) == 'string' then args = args..' "'..v..'"' end
+ end
+ end
+ if not MAC then
+ return lua_dialog.run(args)
+ else
+ local cocoa_dialog = '/CocoaDialog.app/Contents/MacOS/CocoaDialog '
+ local p = io.popen(_HOME..cocoa_dialog..kind..args)
+ local out = p:read('*all')
+ p:close()
+ return out
end
- return lua_dialog.run(args)
end
diff --git a/init.lua b/init.lua
index 76dc9a05..bce765c8 100644
--- a/init.lua
+++ b/init.lua
@@ -26,10 +26,12 @@ if not RESETTING then
local base_dir = arg[0]:match('^.+/') or ''
local filepath
for _, filename in ipairs(arg) do
- if not filename:match('^~?/') then
- textadept.io.open(base_dir..filename)
- else
- textadept.io.open(filename)
+ if not MAC or not filename:match('^%-psn_0') then
+ if not filename:match('^~?/') then
+ textadept.io.open(base_dir..filename)
+ else
+ textadept.io.open(filename)
+ end
end
end
-- read only the Project Manager session settings
diff --git a/osx.patch b/osx.patch
deleted file mode 100644
index ca31c4f3..00000000
--- a/osx.patch
+++ /dev/null
@@ -1,62 +0,0 @@
-diff -r b49f6c4c060a core/init.lua
---- a/core/init.lua Tue Jun 24 18:43:59 2008 -0400
-+++ b/core/init.lua Wed Jun 25 14:44:26 2008 -0400
-@@ -6,7 +6,6 @@ require 'iface'
- require 'iface'
- require 'events'
- require 'file_io'
--require 'lua_dialog'
-
- ---
- -- Checks if the buffer being indexed is the currently focused buffer.
-@@ -31,10 +30,13 @@ end
- -- used.
- -- @return string CocoaDialog result.
- function cocoa_dialog(kind, opts)
-- local args = { kind }
-+ local args = ''
- for k, v in pairs(opts) do
-- args[#args + 1] = '--'..k
-- if type(v) == 'string' then args[#args + 1] = v end
-+ args = args..' --'..k
-+ if type(v) == 'string' then args = args..' "'..v..'"' end
- end
-- return lua_dialog.run(args)
-+ local p = io.popen('CocoaDialog '..kind..args)
-+ local out = p:read('*all')
-+ p:close()
-+ return out
- end
-diff -r b49f6c4c060a src/Makefile
---- a/src/Makefile Tue Jun 24 18:43:59 2008 -0400
-+++ b/src/Makefile Wed Jun 25 14:44:26 2008 -0400
-@@ -10,7 +10,7 @@ endif
- endif
- GTKFLAGS=$(shell pkg-config --cflags gtk+-2.0)
- GTKLIBS=$(shell pkg-config --libs gtk+-2.0 gthread-2.0)
--EXPORTLUASYMS=-rdynamic -Wl,--retain-symbols-file -Wl,lua.sym
-+EXPORTLUASYMS=
-
- all: textadept
-
-diff -r b49f6c4c060a src/textadept.c
---- a/src/textadept.c Tue Jun 24 18:43:59 2008 -0400
-+++ b/src/textadept.c Wed Jun 25 14:44:26 2008 -0400
-@@ -240,7 +240,7 @@ void new_scintilla_buffer(ScintillaObjec
- // Setup default styling and properties.
- SS(sci, SCI_STYLESETFONT, 32,
- reinterpret_cast<long>("!Bitstream Vera Sans Mono"));
-- SS(sci, SCI_STYLESETSIZE, 32, 8);
-+ SS(sci, SCI_STYLESETSIZE, 32, 11);
- SS(sci, SCI_STYLESETFORE, 32, 0xAA | (0xAA << 8) | (0xAA << 16));
- SS(sci, SCI_STYLESETBACK, 32, 0x33 | (0x33 << 8) | (0x33 << 16));
- SS(sci, SCI_SETSTYLEBITS, 8, 0);
-@@ -585,7 +585,7 @@ void set_default_editor_properties(Scint
- SS(sci, SCI_SETFOLDFLAGS, 16);
- SS(sci, SCI_SETMODEVENTMASK, SC_MOD_CHANGEFOLD);
-
-- SS(sci, SCI_SETMARGINWIDTHN, 0, 4 + 2 * // line number margin
-+ SS(sci, SCI_SETMARGINWIDTHN, 0, 4 + 3 * // line number margin
- SS(sci, SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast<long>("9")));
-
- SS(sci, SCI_SETMARGINWIDTHN, 1, 0); // marker margin invisible
diff --git a/src/lua_interface.c b/src/lua_interface.c
index dc5bfa0b..4ae435f0 100644
--- a/src/lua_interface.c
+++ b/src/lua_interface.c
@@ -114,6 +114,9 @@ bool l_init(int argc, char **argv, bool reinit) {
#ifdef WIN32
lua_pushboolean(lua, 1); lua_setglobal(lua, "WIN32");
#endif
+#ifdef MAC
+ lua_pushboolean(lua, 1); lua_setglobal(lua, "MAC");
+#endif
return l_load_script("core/init.lua");
}
diff --git a/src/textadept.c b/src/textadept.c
index eba730a1..a3c85189 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -50,21 +50,40 @@ GtkWidget *findbox, *find_entry, *replace_entry;
GtkWidget *fnext_button, *fprev_button, *r_button, *ra_button;
GtkWidget *match_case_opt, *whole_word_opt, /**incremental_opt,*/ *lua_opt;
GtkAttachOptions
- normal = static_cast<GtkAttachOptions>(GTK_SHRINK | GTK_FILL),
- expand = static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL);
+ ao_normal = static_cast<GtkAttachOptions>(GTK_SHRINK | GTK_FILL),
+ ao_expand = static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL);
static gbool fe_keypress(GtkWidget*, GdkEventKey *event, gpointer);
static gbool re_keypress(GtkWidget*, GdkEventKey *event, gpointer);
static void button_clicked(GtkWidget *button, gpointer);
+#if WIN32 || MAC
+char *textadept_home;
+#endif
+
/**
- * Runs Textadept.
+ * Runs Textadept in Linux or Mac.
* Inits the Lua State, creates the user interface, and loads the core/init.lua
* script.
* @param argc The number of command line params.
* @param argv The array of command line params.
*/
int main(int argc, char **argv) {
+#ifdef MAC
+ CFBundleRef bundle = CFBundleGetMainBundle();
+ if (bundle) {
+ char path[260];
+ CFURLRef bundle_url = CFBundleCopyBundleURL(bundle);
+ CFStringRef bundle_path =
+ CFURLCopyFileSystemPath(bundle_url, kCFURLPOSIXPathStyle);
+ CFStringGetCString(bundle_path, path, 260, kCFStringEncodingASCII);
+ char *resources_path = g_strconcat(path, "/Contents/Resources/", NULL);
+ textadept_home = static_cast<char*>(resources_path);
+ g_free(path);
+ CFRelease(bundle_url);
+ CFRelease(bundle_path);
+ } else textadept_home = "";
+#endif
gtk_init(&argc, &argv);
if (l_init(argc, argv, false)) {
create_ui();
@@ -76,8 +95,6 @@ int main(int argc, char **argv) {
}
#ifdef WIN32
-char *textadept_home;
-
/**
* Runs Textadept in Windows.
* Sets textadept_home according to the directory the executable is in before
@@ -824,18 +841,18 @@ GtkWidget *find_create_ui() {
gtk_label_set_mnemonic_widget(GTK_LABEL(rlabel), replace_entry);
//gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lua_opt), TRUE);
- attach(find_entry, 1, 2, 0, 1, expand, normal, 5, 0);
- attach(replace_entry, 1, 2, 1, 2, expand, normal, 5, 0);
- attach(flabel, 0, 1, 0, 1, normal, normal, 5, 0);
- attach(rlabel, 0, 1, 1, 2, normal, normal, 5, 0);
- attach(fnext_button, 2, 3, 0, 1, normal, normal, 0, 0);
- attach(fprev_button, 3, 4, 0, 1, normal, normal, 0, 0);
- attach(r_button, 2, 3, 1, 2, normal, normal, 0, 0);
- attach(ra_button, 3, 4, 1, 2, normal, normal, 0, 0);
- attach(match_case_opt, 4, 5, 0, 1, normal, normal, 5, 0);
- attach(whole_word_opt, 4, 5, 1, 2, normal, normal, 5, 0);
- //attach(incremental_opt, 5, 6, 0, 1, normal, normal, 5, 0);
- attach(lua_opt, 5, 6, 0, 1, normal, normal, 5, 0);
+ attach(find_entry, 1, 2, 0, 1, ao_expand, ao_normal, 5, 0);
+ attach(replace_entry, 1, 2, 1, 2, ao_expand, ao_normal, 5, 0);
+ attach(flabel, 0, 1, 0, 1, ao_normal, ao_normal, 5, 0);
+ attach(rlabel, 0, 1, 1, 2, ao_normal, ao_normal, 5, 0);
+ attach(fnext_button, 2, 3, 0, 1, ao_normal, ao_normal, 0, 0);
+ attach(fprev_button, 3, 4, 0, 1, ao_normal, ao_normal, 0, 0);
+ attach(r_button, 2, 3, 1, 2, ao_normal, ao_normal, 0, 0);
+ attach(ra_button, 3, 4, 1, 2, ao_normal, ao_normal, 0, 0);
+ attach(match_case_opt, 4, 5, 0, 1, ao_normal, ao_normal, 5, 0);
+ attach(whole_word_opt, 4, 5, 1, 2, ao_normal, ao_normal, 5, 0);
+ //attach(incremental_opt, 5, 6, 0, 1, ao_normal, ao_normal, 5, 0);
+ attach(lua_opt, 5, 6, 0, 1, ao_normal, ao_normal, 5, 0);
signal(find_entry, "key_press_event", fe_keypress);
signal(replace_entry, "key_press_event", re_keypress);
diff --git a/src/textadept.h b/src/textadept.h
index 4397b5f2..ad490cf2 100644
--- a/src/textadept.h
+++ b/src/textadept.h
@@ -12,17 +12,21 @@
#include <SciLexer.h>
#include <ScintillaWidget.h>
-#ifdef WIN32
-#include "Windows.h"
-#define strcasecmp _stricmp
-#endif
-
extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
+#ifdef WIN32
+#include "Windows.h"
+#define strcasecmp _stricmp
+#endif
+
+#ifdef MAC
+#include "CoreFoundation/CoreFoundation.h"
+#endif
+
// globals
extern GtkWidget
*window, *focused_editor, *command_entry,
@@ -31,7 +35,7 @@ extern GtkWidget
extern GtkEntryCompletion *command_entry_completion;
extern GtkTreeStore *cec_store, *pm_store;
extern lua_State *lua;
-#ifndef WIN32
+#if !(WIN32 || MAC)
static const char *textadept_home = "/usr/share/textadept/";
#else
extern char *textadept_home;
@@ -59,7 +63,7 @@ void pm_toggle_focus();
void pm_open_parent(GtkTreeIter *iter, GtkTreePath *path);
void pm_close_parent(GtkTreeIter *iter, GtkTreePath *path);
void pm_activate_selection();
-void pm_popup_context_menu(GdkEventButton *event, GCallback callback);
+void pm_popup_context_menu(GdkEventButton *event);
void pm_process_selected_menu_item(GtkWidget *menu_item);
GtkWidget *find_create_ui();