wxWidgets: integrate custom GTK+ widget - wxwidgets

Question:
How implement a custom wxSciter control properly and correctly place it inside standard wxWidgets controls?
(so it can behave like a browser window)
SOLVED:
I got it solved after provided suggestions with:
class NativeWindow : public wxNativeWindow
{
public:
explicit NativeWindow(wxWindow* parent)
: wxNativeWindow()
{
GtkWidget* widget = SAPI()->SciterCreateWindow(SW_CHILD, NULL, NULL, NULL, this->GetHandle());
g_object_ref_sink(widget);
// remove Sciter's GTK top-level container
// to prevent "Can't set a parent on widget which has a parent"
gtk_container_remove(GTK_CONTAINER(gwindow(widget)), widget);
SAPI()->SciterLoadFile(widget, WSTR("http://linux.org.ru/"));
(void)Create(parent, wxID_ANY, widget);
}
virtual ~NativeWindow()
{
Disown();
}
};

wxNativeWindow normally should allow you to do what you need with very little effort. You can find a fuller example of using it than the one given in the docs in the widgets sample, see its GTK-specific part.

Related

C# XAML page dependency injection on the fly with MVVM Light

I would like some feedback to see if I'm using SimpleIoc in the correct way.
The code below works, but I'm not sure if it's best practice.
I have an UWP XAML DocumentPage class on which I want to show an IRpcDocument.
I want to use the DocumentPage for both RpcDocumentA and RpcDocumentB. The user can navigate to both types of IRpcDocument. So the application should be able to switch between the two 'on the fly'.
So I wrote my DocumentPageViewModel
public class DocumentPageViewModel : ViewModelBase
{
public IRpcDocument RpcDocument;
public DocumentPageViewModel(IRpcDocument rpcDocument)
{
RpcDocument = rpcDocument;
}
}
And my ViewModelLocator
class ViewModelLocator
{
static ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Register<DocumentPageViewModel>();
}
public DocumentPageViewModel SimpleIoc.Default.Register<DocumentPageViewModel>
{
get
{
return ServiceLocator.Current.GetInstance<SimpleIoc.Default.Register<DocumentPageViewModel>>(Guid.NewGuid().ToString());
}
}
}
When I'm navigating to the DocumentPage I call:
SimpleIoc.Default.Register<IRpcDocument , RpcDocumentA>();
await NavigationService.NavigateAsync(typeof(DocumentPage), DocumentIdParameter);
The app then navigates to the DocumentPage, constructs the RpcDocumentA, makes the necessary RPC calls to fetch the data and shows the document.
The first line tells the IoC framework it should expect an RpcDocumentA in its constructor, the second one triggers navigation. So in this case, im not registering the interface in the static ViewModelLocator().
So for each time I navigate I call SimpleIoc.Default.Register<IRpcDocument , RpcDocumentA> or SimpleIoc.Default.Register<IRpcDocument , RpcDocumentB>
This works, but is this the right way to do this? I suspect it's not.

IntelliJ IDEA plugin: associating a source psi file with a icon in the package structure

I'm building a idea plugin which needs to create source file with the extension of ".java". I have created a file template and used it in an implementation of JavaCreateTemplateInPackageAction<PsiElement> class. In the constructor of the above mentioned class I called the constructor of the super class with a icon(which I loaded using IconLoader.getIcon before) like this
protected JavaCreateTemplateInPackageAction(String text, String description, Icon icon, boolean inSourceOnly) {
super(text, description, icon, inSourceOnly ? JavaModuleSourceRootTypes.SOURCES : null);
}
Finally I registered the implementation in plugin.xml as an action. The code works as a charm to create the source file with given template but the issue is in the package structure it doesn't shows the given custom icon, instead it shows the default icon for java classes(letter 'c'). But the given icon appears in the new menu when right click on the source package to create a source file. Can anybody help me out please.? Thanks.
PS: I tried to change the file extension something other than .java and it still doesn't show the expected icon but instead it shows the generic icon for java(letter 'j' icon)
The icon you provide in your JavaCreateTemplateInPackageAction is only used for that action. Icons in the project view can be overridden using an IconProvider, that you can register using the <iconProvider> tag in your plugin.xml:
<iconProvider implementation="org.intellij.plugins.ceylon.ide.presentation.CeylonIconProvider"/>
Java code:
public class CeylonIconProvider extends IconProvider {
#Nullable
#Override
public Icon getIcon(#NotNull PsiElement element, int flags) {
if (element instanceof CeylonFile) {
return ...
}
if (element instanceof CeyLightClass) {
...
}
return null;
}
}

How do I get Xtext's model from a different plugin?

I've written an Xtext-based plugin for some language. I'm now interested in creating a new independent view (as a separate plugin, though it requires my first plugin), which will interact with the currently-active DSL document - and specifically, interact with the model Xtext parsed (I think it's called the Ecore model?). How do I approach this?
I saw I can get an instance of XtextEditor if I do something like this when initializing my view:
getSite().getPage().addPartListener(new MyListener());
And then, in MyListener, override partActivated and partInputChanged to get an IWorkbenchPartReference, which is a reference to the XtextEditor. But what do I do from here? Is this even the right approach to this problem? Should I instead use some notification functionality from the Xtext side?
Found it out! First, you need an actual document:
IXtextDocument doc = editor.getDocument();
Then, if you want to access the model:
doc.modify(new IUnitOfWork.Void<XtextResource>() { // Can also use just IUnitOfWork
#Override public void process(XtextResource state) throws Exception {
...
}
});
And if you want to get live updates whenever it changes:
doc.addModelListener(new IXtextModelListener() {
#Override public void modelChanged(XtextResource resource) {
for (EObject model : resource.getContent()) {
...
}
}
});

Eclipse RCP disable a view from a dialog

I have a simple RCP application. I have a perspective and three views added to it. Initially one of the view will be disabled for the users. There is a toolbar item which launches a dialog. User authenticates himself in the dialog. After successful authentication, I want to make the view editable. I could get the reference of that specific view in my dialog.But I dont know how to enable it. I could not use selection listener as I am not selecting anything. Also I saw an example about using activities extension. But that opens/closes the view and not just enable/disable it. Can someone help me? Thanks.
As I understand you, you want to show the view in one of two states: either disabled if the user is not authenticated, or enabled when the user has been authenticated.
This is actually pretty easy :-) and I have made a small example application for you that illustrates the technique: so-edi.zip
UPDATED with new link
In RCP 3.x you have to expose the View's Control's enabled state in your implementation of ViewPart:
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.part.ViewPart;
public class View extends ViewPart {
private Control control;
#Override
public void createPartControl(Composite parent) {
control = new Composite(parent, SWT.NONE);
}
#Override
public void setFocus() {
}
public void setEnabled(boolean enabled) {
control.setEnabled(enabled);
}
public boolean isEnabled() {
return control.getEnabled()
}
}

Zend framework common code for all the controllers

I have a login button in the header of the website. This header's html is programmed into Zend framework views/layouts/home.phtml.
I have a hidden form in this layout that is triggered by jQuery thickbox inline content display integration. Reason, I dont want to make a ajax call to just fetch a small login form.
I create the form using Zend_Form and the problem is that I have to do it in all the controllers after checking if the user is logged in or not. I want to place this form generation in one single place, say in bootstrap and then have a logic in bootstrap to say that if user is logged in dont generate the form.
I don't know if bootstrap is the right place to do so or should I do it in some other place.
So, where should I instantiate the form so that its available everywhere if user is not logged in.
Create your own base controller which extends Zend_Controller_Action then have your controllers extend off of your base controller. I don't know what "jQuery thickbox inline content display integration" is...but you have several sections you can put it in depending when you need your code to run. init(), preDispatch(), postDispatch() etc... Just make sure when you extend off your base controller that you do sthing like:
parent::init()
parent::preDispatch()
parent::postDispatch()
etc... within each section so that the base code runs as well...
Be careful about Pradeep Sharma's solution (the answer he wrote himself and accepted below).
All the code code below is for ZF 1.12, and not ZF 2.0
In the bootstrap, Zend_Layout's MVC instance might not have been created yet. You should use Zend_Layout::startMvc() instead :
$view = Zend_Layout::startMvc()->getView() ;
And tbh I prefer executing this code in the preDispatch() function. New users of ZF might be interested in this :
application/plugins/HeaderForm.php :
class Application_Plugin_HeaderForm extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$view = Zend_Layout::startMvc()->getView() ;
$view->headerForm = new Application_Form_HeaderForm() ;
}
}
Calling new Application_Form_HeaderForm() will autoload by default into application/forms/ folder. You can also create the form directly into the plugin with new Zend_Form(), and addElement() etc. but it won't be reusable.
Of course, you need to register this plugin in your bootstrap!
application/Bootstrap.php :
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initPlugin()
{
$front = Zend_Controller_Front::getInstance() ;
$front->registerPlugin(new Application_Plugin_HeaderForm()) ;
}
}
Calling new Application_Plugin_HeaderForm() will autoload by default into application/plugins/ folder
I did it in a different way, extendingZend_Controller_Plugin_Abstract to implement a plugin and register it with front controller.
public function routeStartup(Zend_Controller_Request_Abstract $request) { }
generated the form inside the above mentioned method and by setting the form in $view object.
$view can be retrived using :
$view = Zend_Layout :: getMvcInstance()->getView();