Single Instance Window in Catel v4.0 - catel

If I have a button (bound to Command 'OpenOtherWindow') that opens a DataWindow by using IUIVisualizerService.Show(viewModel), how can I prevent another instance of said DataWindow to open?
I do not think that creating a Singleton ViewModel is the correct way to do it and having a boolean 'IsWindowOpen' in the ViewModel where my 'OpenOtherWindow' Command is located would not be very MVVM, although this is the current way we have done it.
How would I do it in Catel?

The key is to create a service that manages the state and instances of the windows. Then you never have to worry about the actual behavior and can change it in one place.
Then you can just call the following (pseudo) code:
_myFeatureService.Show();
In this service you can keep track if the window is already open and open the window if not. If you want to change this behavior in the future, you only have to do it in a single location: the service.

Related

Browser Window in each method of test case? Using coded ui

I am new to coded UI, is it good practice to initialize Browser Window in each method of test case. For example i have two methods in my test case, I am trying to find control in each method, for that i write browser window in each method, can i write like that.
I don't see an issue with that approach.
Are you trying to reduce code/setup statements?
It really depends, you could have a test class with many test methods. however have a method attributed with ClassInitialize to launch the browser one time (and set the option to not destroy the window after each test) and keep reusing the same window. Then, possibly, have a method to close the window attributed with ClassCleanup.
Then in a test, you should only potentially need to use the NavigateTo method at the start of your tests to be on the right page.
Do you have test requirements dealing with sessions or saved data?
You may need to actively close down a window after a test and programmatically empty caches. Then in this aspect, I would be using BrowserWindow.Launch typically and letting CodedUi automatically destroy the window if i forgot to call close on the window.

vspackage: how could I make a command in the context menu available for specific file type

in the solution explorer, there are projects and files. and I want my custom command only to show up when user right click on certain file type, let's say ".cs" or ".html". How could I make so happen?
Assuming your package is loaded, you can control the visible/enabled state of a command through the BeforeQueryStatus event of the OleMenuCommand.
In the event handler you set if the command is supported (OleMenuCommand.Supported property) the visible state (OleMenuCommand.Visible property) and enabled state (OleMenuCommand.Enabled property) etc. according to whichever conditions, such as the type of file selected in Solution Explorer.

Coded ui objects in UIMap

I have a question regarding coded ui UIMap.
Every time I record an action on the same application, coded ui generates a new object for the same window in the application.
It looks like:
UIAdminWindow
UIAdminWindow1
UIAdminWindow2
and so on...
every window class holds different buttons, even though it's the same window.
Thus it's very hard to keep code maintenance.
What i would like is that every time i perform actions and records on a window, even if not at the same time, the already generated class for this window, will be updated with the new controls.
any suggestions to why it happens?
Thanks a lot!
You can clean up your UIMaps by doing two things:
Use the UIMap Toolbox (from codeplex) to move controls within the UIMap so they are all under one control tree.
When you have duplicate UI controls, go to the properties for the action that references the duplicate control and change the UI Control property to point to the original control in the UIMap.
The duplicate trees should now be unreferenced and you can delete it from your map, keeping things clean.
And yes, it's a pain to do, but it's worth it for maintainability.
In UIMap.uitest you can change the action name and the control name for better maintenance.
For example: you can set UIAdminWindow as FirstAcessWindow or other name that will express comfortably the control or the action.
What I can guess is that there is some randomly generated content or element identification data such as class or title that may be causing it. This may be caused by different username for example. Also you can update the element from UI map element tree.

Creating a new NSManagedObject within an NSPersistentDocument refuses to save even though undo shows as possible

I have a CoreData / NSPersistentDoc app. It works fine.
I added a new entity to the MOM, and updated the version.
Now, when I create new instances of that Entity inside the MOC, the "Save" menu item remains disabled until/unless I create any instances of the old Entities that were already in the app.
The red dot button on titlebar correctly goes black to show that the document has changed - but OS X / NSDocument refuses to acknowledge this - it is impossible to do a Save.
Any ideas?
I found the cause / solution - it was my own bug, but this answer may help others with similar issues.
I was using Apple's official approach for enabling the Copy/Paste menu items (by implementing validateMenuItem), and returning true/false for copy and paste at the right times.
And I was returning NSPersistentDocument's implementation for everything else (which included Save, although I didn't see that).
Then, when I added my new NSManagedObject, I added a sub-view, and sub-view-controller, and I delegated the validateMenuItem to this - i.e. so that it could handle it's own copy/paste status.
...but I had no code path for "if it's not copy paste, and it's not handled by the child, and it's not handled by my NSPersistenDocument subclass ... then hand it to NSPersistentDocument to decide"...
...and so the Save menuitem was never being enabled.

Core data dirty flag not being set

I have a core data document based cocoa app that is working well except for one slightly odd problem.
For some reason, if I make a change to any of my fields the menu/window don't seem to recognize it - ie. the red close button doesn't get the black 'dirty' indicator and the File/Save menu item isn't enabled. However, if I attempt to close the application (via command-Q), I do get the popup asking me if I want to save my changes.
It seems that the document's dirty flag is being set, but the window/menu items aren't reacting to it. I am curious as to where I might look to see why this might be the case. I suspect that it may have something to do with my window not knowing about my ManagedObjectContext...
The only slightly atypical behaviour is that my document's makeWindowControllers method has been overridden and I am adding my window controllers using a call to my document's [self addWindowController:xxx] method. My window controllers subclass from NSWindowController so I had to add my own instance variable to each window controller to hold the ManagedObjectContext, but I suspect that this isn't getting passed to the window/menu. Not sure what the normal pattern is here...
Anyway, any thoughts would be much appreciated. Thanks
From the description it sounds like your UI elements are not actually bound to the document itself. If so, then the UI elements are not observing the document and are not reacting to changes in the document. Check the bindings.
Thanks in part to TechZen, and also re-reading my own question (in particular, where I said "I suspect that it may have something to do with my window not knowing about my ManagedObjectContext") I started to look at the bindings for my WindowController subclass.
As it turned out, I hadn't bound the window outlet for the File's Owner to my actual NSWindow. As soon as I did that, the black dirty dot and the window's menus started behaving correctly.

Resources