Would it be easier to rewrite it for one single cross-platform backend, like Qt, than maintain a mix of platform-specific code?
Re:Textmate2 Goes Open Source
by alastairpat on Thursday August 09, 2012 @05:53PM
(#4363468)
I think one of the appeals of TM1 was that it WAS a native Mac app and felt like one. Qt apps never 'feel' completely native, so if you went down that path you'd end up with an awkward, substandard, non-native text editor and might as well be using Sublime Text.
Re:Textmate2 Goes Open Source
by Sauerkrause on Friday August 10, 2012 @02:00AM
(#4365128)
as ugly as it may look, it seems like targeting something like GNUStep may help out with the portability issues. then you really only need to worry about the Mac-specific APIs.
The actual layout/folding code, for example, is in C++. When it needs to draw it calls Core Graphics C functions. A lot of the other things like commands are similarly abstracted. But the thing is, if you look in Frameworks/layout/src/layout.cc for example (the code that actually lays out the text), it looks like nice platform-independent C++ code. Ah, you think, this will be easy! Until you get to, say, CGRect layout_t::rect_for (row_tree_t::iterator rowIter). The return type is CGRect and it's calling CGRectMake. These are Mac-specific Core Graphics calls. The drawing code is similarly Mac-specific.
So the first thing you'd need to do is follow the architecture and start TRULY abstracting the core functionality into these C++ classes and, when they make a call to something platform-specific, you'll need to replace it with something platform-independent.
To do this, you'll need to:
- Make or move to an abstracted Graphics Context library. You could use something like Cairo or roll your own (which is what WebKit does).
- Further abstract the application structure away from the actual classes. So, for example, you would have platform neutral code to talk about the UI logically but then have each "MyWindow" C/C++ class hold a "PlatformWindowHandle" which, on Linux might be a GTKWindow pointer, on Win32 might be a Window HANDLE or COM object reference to a .NET Window, and on Mac be a pointer to an NSWindow. You'd obviously need similar platform-neutral library infrastructure to call into each of these with a similar API and translate to the platform actually running at the bottom. You could write this yourself, or you could maybe just use wxWidgets or some other library that's had a decade-long head start. You lose some control that way, though.
- Repeat with all other areas of the app that are still Mac-specific.
My opinion is this would be a good starting point for such a thing, and if you really wanted to make it happen you could. But you're NOT going to just go in there and replace NSWindows with GTKWindows and NSButtons with GTKButtons and call it a day. It will be MUCH more work than that.