Enumerating MudTabpanels inside Mudtabs and activating/deactivating it - mudblazor

I have the following code
<MudTabs Elevation="4" Rounded="true" Centered="true" #ref="tabs" AlwaysShowScrollButtons="true" Color="Color.Info" Style="#($"color:{Colors.Pink.Darken1};")" #bind-ActivePanelIndex="activeIndex">
<MudTabPanel Text="Text1" Disabled="#isDisabled">
</MudTabPanel>
<MudTabPanel Text="Text2" Disabled="#isDisabled">
</MudTabPanel>
<MudTabPanel Text="Text3" Disabled="#isDisabled">
</MudTabPanel>
<MudTabPanel Text="Text4" Disabled="#isDisabled">
</MudTabPanel>
<MudTabPanel Text="Text5" Disabled="#isDisabled">
</MudTabPanel>
<MudTabPanel Text="Text6" Disabled="#isDisabled">
</MudTabPanel>
<MudTabPanel Text="Text7" Disabled="#isRiskSummaryDisabled">
</MudTabPanel>
<MudTabPanel Text="Text7" Disabled="#IsExceptionDisabled" ID="exctab">
</MudTabPanel>
#code
{
MudTabs tabs;
private void DisableAllTabsExceptExceptionTab(int _index)
{
try
{
var list = tabs.Panels
foreach(MudTabPanel mtp in list)
{
mtp.Disabled = true;
}
tabs.ActivatePanel(_index,true);
StateHasChanged();
}
catch
{
}
}
}
I am trying to disable all tabs except one. However the code is not disabling the tabs.

Your code doesn't compile and there are missing informations about what errors do you encounter.
Anyway, here you are a working example:
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="#(()=>DisableAllTabsExceptExceptionTab(6))">Disable All Tabs Except Last One</MudButton>
<MudTabs Elevation="4" Rounded="true" Centered="true" #ref="tabs" AlwaysShowScrollButtons="true" Color="Color.Info">
<MudTabPanel Text="Text1"></MudTabPanel>
<MudTabPanel Text="Text2"></MudTabPanel>
<MudTabPanel Text="Text3"></MudTabPanel>
<MudTabPanel Text="Text4"></MudTabPanel>
<MudTabPanel Text="Text5"></MudTabPanel>
<MudTabPanel Text="Text6"></MudTabPanel>
<MudTabPanel Text="Text7"></MudTabPanel>
</MudTabs>
#code {
MudTabs tabs;
private void DisableAllTabsExceptExceptionTab(int _index)
{
var list = tabs.Panels;
foreach(MudTabPanel mtp in list)
{
mtp.Disabled = true;
}
tabs.ActivatePanel(_index,true);
StateHasChanged();
}
}
You can try it here:
https://try.mudblazor.com/snippet/wOwdOvcBzeOlVVoT

Related

Setting variable outside a block from inside a block?

I have following code:
def test_callback_interface
with_temp_stdio do |stdin, stdout|
stdin.write("hello\n")
stdin.close
stdout.flush
line = nil
replace_stdio(stdin.path, stdout.path) {
Readline.handler_install("> ", true) { |l| line = l }
6.times { Readline.read_char }
Readline.handler_remove
}
assert_equal("hello", line) <------ FAIL here
assert_equal(true, line.tainted?)
stdout.rewind
assert_equal("> ", stdout.read(2))
assert_equal(1, Readline::HISTORY.length)
assert_equal("hello", Readline::HISTORY[0])
end
assert_equal(true, false)
end
it fails on the line assert_equal("hello", line) saying that the line is nil. However, I'm sure that the callback is called (I verified it by putting raise in there). So I must be missing something fundamental about scopes here. Could someone please enlighten me how to get the value of l to the line variable?
Thanks
EDIT:
How do I call the callback inside handler_install/read_char?
static VALUE readline_callback_ensure(VALUE val) {
free(readline_callback_line);
readline_callback_line = NULL;
return Qnil;
}
static VALUE readline_callback_call(VALUE line) {
VALUE proc = rb_attr_get(mReadline, read_char_cb_proc);
rb_funcall(proc, id_call, 1, line);
return Qnil;
}
static void readline_callback_callback(char * line) {
if (readline_callback_add_history && line) {
add_history(line);
}
readline_callback_line = line;
rb_ensure(
readline_callback_call, line ? rb_str_new_cstr(line) : Qnil,
readline_callback_ensure, Qnil
);
}
static VALUE readline_callback_handler_install(int argc, VALUE * argv, VALUE self) {
VALUE tmp, add_hist, block;
char * prompt = NULL;
rb_need_block();
if (rb_scan_args(argc, argv, "02&", &tmp, &add_hist, &block) > 0) {
prompt = RSTRING_PTR(tmp);
}
if (RTEST(add_hist)) {
readline_callback_add_history = true;
} else {
readline_callback_add_history = false;
}
rb_ivar_set(mReadline, read_char_cb_proc, block);
rl_callback_handler_install(prompt, readline_callback_callback);
return Qnil;
}
static VALUE readline_callback_read_char(VALUE self) {
VALUE proc = rb_attr_get(mReadline, read_char_cb_proc);
if (NIL_P(proc)) {
rb_raise(rb_eRuntimeError, "No handler installed.");
}
rl_callback_read_char();
return Qnil;
}
So basically read_char calls rl_callback_read_char (gnu readline function), which on detecting complete line invokes my installed handler readline_callback_callback which invoked stored block supplied by user.
Solved, not an scope issue. GNU Readline calls my code once more with NULL on EOF, complete forgot about that.

Xcode error? Use of undeclared identifier [duplicate]

I have following snippets of code that fetches contacts by using block:
if (&ABAddressBookCreateWithOptions != NULL) {
CFErrorRef error = nil;
addressBook = ABAddressBookCreateWithOptions(NULL, &error);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
dispatch_sync(dispatch_get_main_queue(), ^{
if (error) {
//...
} else if (!granted) {
//...
} else {
// access granted
//...
}
});
});
It works fine on both 7.1.2 and 8.1.3 versions.
However when I try to change dispatch_get_main_queue to dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0) it works on 8.1.3 but crashes on 7.1.2
if (&ABAddressBookCreateWithOptions != NULL) {
CFErrorRef error = nil;
addressBook = ABAddressBookCreateWithOptions(NULL, &error);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
dispatch_sync(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ // BAD ACCESS
if (error) {
//...
} else if (!granted) {
//...
} else {
// access granted
//...
}
});
});
The QOS_CLASS_ identifiers were introduced in iOS 8. You need to use the DISPATCH_QUEUE_PRIORITY_ identifiers if you want to support iOS 7.

Realm crash when try [RLMRealm defaultRealm]

I added Realm pod to my tvos project. However it crash when I just try:
[RLMRealm defaultRealm]
It crash in simulator and device. I created a tvos empty project, added the Realms pod and it works. So I guess it's something related with the current project.
If the problem appear in the line 361 of RLMRealm file.
try {
realm->_realm = [self openSharedRealm:config error:error];
}
catch (SchemaMismatchException const& exception) {
if (configuration.deleteRealmIfMigrationNeeded) {
BOOL success = [[NSFileManager defaultManager] removeItemAtURL:configuration.fileURL error:nil];
if (success) {
realm->_realm = [self openSharedRealm:config error:error];
} else {
RLMSetErrorOrThrow(RLMMakeError(RLMException(exception)), error);
return nil;
}
} else {
RLMSetErrorOrThrow(RLMMakeError(RLMException(exception)), error);
return nil;
}
}
It executes RLMSetErrorOrThrow(RLMMakeError(RLMException(exception)), error); but the error is nil and it doesn't give me any extra information

ios9.1 gets UILocalNotification called twice in one post

UILocalNotificaiton gets called twice in one post.
Does anybody know the reason?
I found it in iOS9.1. But in iOS8.0 it works normally.
Below is my code:
extension UILocalNotification {
class func postNotification(message : String!, soundName : String?) {
dispatch_async(dispatch_get_main_queue()) { () -> Void in
let localNotification : UILocalNotification = UILocalNotification()
localNotification.fireDate = NSDate().dateByAddingTimeInterval(1)
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.alertBody = message
localNotification.repeatInterval = NSCalendarUnit(rawValue: 0)
if soundName != nil {
localNotification.soundName = soundName
} else {
localNotification.soundName = UILocalNotificationDefaultSoundName
}
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
}
}

Very unusual Xcode compile behaviour

Since the release of Xcode 6.1 and iOS 8.1, one of my apps stopped functioning.
I managed to reproduce the problem only if I did "RUN" on my device with a scheme of "Release" instead of "Debug".
Now for the problem. This works fine in Debug mode:
import Foundation
class CategoryParser {
var categoriesSettingsDictionary : [String: AnyObject]?
init() {
let categoriesURL = NSBundle.mainBundle().URLForResource("CategoriesSettings", withExtension: "plist")
categoriesSettingsDictionary = NSDictionary(contentsOfURL: categoriesURL!) as? Dictionary<String, AnyObject>
}
}
But it crashes in "Release" mode when I instantiate an Object of the CategoryParser type. After many trials and errors, I figured that to stop it from doing the problem I could place the dictionary initialisation between two println() statements. Why would those make any difference?
import Foundation
class CategoryParser {
var categoriesSettingsDictionary : [String: AnyObject]?
init() {
let categoriesURL = NSBundle.mainBundle().URLForResource("CategoriesSettings", withExtension: "plist")
println("_")
categoriesSettingsDictionary = NSDictionary(contentsOfURL: categoriesURL!) as? Dictionary<String, AnyObject>
println("_")
}
}
It must be a bug around optimizations in Swift compiler. I think, it's around bridging NSDictionary to Dictionary<String,AnyObject>.
I reproduced the problem with following setup.
Environment: Xcode 6.1 (6A1052d) / iPhone 6 / iOS 8.1
Template: Single View Application
CategoriesSettings.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ct1</key>
<string>test</string>
</dict>
</plist>
AppDelegate.swift
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let result = loadPlist()
println("result: \(result)")
return true
}
func loadPlist() -> [String: AnyObject]? {
let categoriesURL = NSBundle.mainBundle().URLForResource("CategoriesSettings", withExtension: "plist")
let dict = NSDictionary(contentsOfURL: categoriesURL!)
println(dict)
let result = dict as? [String:AnyObject]
return result
}
}
// EOF
outputs (with -O):
Optional({
ct1 = test;
})
result: nil
outputs (with -Onone):
Optional({
ct1 = test;
})
result: Optional(["ct1": test])
I don't know the best workaround, though.
Maybe this works:
class CategoryParser {
var categoriesSettingsDictionary : [String: AnyObject]?
init() {
let categoriesURL = NSBundle.mainBundle().URLForResource("CategoriesSettings", withExtension: "plist")
categoriesSettingsDictionary = NSDictionary(contentsOfURL: categoriesURL!) as? Dictionary<String, AnyObject>
if categoriesSettingsDictionary == nil {
// NOTICE: to other developers about this workaround
println("_")
println("_")
}
}
}
Encapsulating them in autoreleasepool also works:
class CategoryParser {
var categoriesSettingsDictionary : [String: AnyObject]?
init() {
autoreleasepool {
let categoriesURL = NSBundle.mainBundle().URLForResource("CategoriesSettings", withExtension: "plist")
self.categoriesSettingsDictionary = NSDictionary(contentsOfURL: categoriesURL!) as? Dictionary<String, AnyObject>
}
}
}
But, as of now, I think, you should use NSDictionary as is, because as long as you only read from it, there is almost no practical difference between NSDictionary and Dictionary<String,AnyObject> in most cases.
class CategoryParser {
var categoriesSettingsDictionary : NSDictionary?
init() {
let categoriesURL = NSBundle.mainBundle().URLForResource("CategoriesSettings", withExtension: "plist")
categoriesSettingsDictionary = NSDictionary(contentsOfURL: categoriesURL!)
}
}
OR, this may be too aggressive, but you can implement your own NSDictionary → Dictionary converter.
extension Dictionary {
init?(nsDictionaryOrNil:NSDictionary?) {
if let dict = nsDictionaryOrNil? {
self = [Key:Value](minimumCapacity: dict.count)
for (k,v) in dict {
if let key = k as? Key {
if let val = v as? Value {
self[key] = val
continue
}
}
return nil
}
}
else {
return nil
}
}
}
class CategoryParser {
var categoriesSettingsDictionary : [String:AnyObject]?
init() {
let categoriesURL = NSBundle.mainBundle().URLForResource("CategoriesSettings", withExtension: "plist")
let dict = NSDictionary(contentsOfURL: categoriesURL!)
categoriesSettingsDictionary = [String:AnyObject](nsDictionaryOrNil: dict)
}
}

Resources