On Sunday, 2. June 2013 12:28:23 Adrián Chaves Fernández wrote: > Thanks to both of you and Milian. I have it working already. > > Once I got the editor the right way, setting the syntax highlighting I > wanted was as easy as: > > document->setHighlightingMode("mediawiki");
Now as a 10 years kate developer I didn't see this simple solution, lol. Cheers, Dominik > O Domingo, 2 de Xuño de 2013 03:17:02 Dominik Haumann escribiu: > > On Wednesday, 29. May 2013 21:38:03 Adrián Chaves Fernández wrote: > > > Hi, > > > > > > I want to start an application with a text editor that provides a > > > specific > > > syntax highlighting, as the application is only going to support a > > > specific > > > type of files (MediaWiki). Then I plan to build some features > > > (auto-complete, etc.) on top of it. > > > > > > Not to reinvent the wheel, I wanted to reuse Kate’s text edition widget. > > > I’ve actually been working on improving the MediaWiki syntax > > > highlighting > > > support in Kate, so reusing that work for my app would be ideal. > > > > > > So I found myself copying and pasting the code in > > > http://techbase.kde.org/Development/Tutorials/Using_KParts > > > > It's correct that the KTextEditor interfaces implement KParts. > > There more straightforward way to get an editor component is to to follow > > http://api.kde.org/4.10-api/kdelibs-apidocs/interfaces/ktexteditor/html/kt > > e_howto.html> > > As you can see, creating an editor is simply done by: > > KTextEditor::Editor *editor = KTextEditor::EditorChooser::editor(); > > // error handling omitted > > m_document = editor->createDocument(0); > > m_view = m_document->createView(this); > > // hook this view into the gui somewhere > > > > // now XML gui stuff: > > setXMLFile("mainwindowui.rc"); > > guiFactory()->addClient(m_view); > > > > setXMLFile sets your gui.rc file. This is where you can control which > > actions of Kate appear in the gui, iirc. If in doubt, you can also look > > at the Kate application (kate/app/*). There we also solely use the > > interfaces to get the editor component instance. > > > > > Now I have a working KatePart. But I have no idea whatsoever about > > > interacting with it from code (such as getting an instance of > > > KateDocument). Any recommendation that puts me in the right direction to > > > set the KatePart syntax highlighting from code? > > > > One way of setting the syntax highlighting is: > > #include <commandinterface.h> > > > > KTextEditor::CommandInterface *iface = > > qobject_cast<KTextEditor::CommandInterface*>( editor ); if( iface ) { > > > > KTextEditor::Command * setHl = iface->queryCommand("set-highlight"); > > if (setHl) { > > > > QString error; > > setHl->exec(view, "set-highlight MediaWiki", error); > > > > } > > > > } > > > > You can get a list of commands by switching into the command line with F7 > > in Kate/Kwrte/KDevelop/Kile, ... Just start typing set- > > > > > Also, I want to manually define the context-menu items and any other > > > actions in the interface, so I’m not calling createGUI(m_part). Most > > > KatePart> > > Yes you can remove actions, see above with the XML file. > > > > > actions I don’t want to provide, so is KatePart the right choice for me > > > nonetheless? Or is there another way (without kparts) of reusing Kate’s > > > text edition widget that fits my use case better? > > > > You can set the context menu with View::setContextMenu: > > http://api.kde.org/4.10-api/kdelibs-apidocs/interfaces/ktexteditor/html/cl > > assKTextEditor_1_1View.html#aac67f3d61e2fcec8369fe31012f27fb0 > > > > You can also ask on kwrite-de...@kde.org for further help. > > > > Greetings > > Dominik >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<