AddChart() throws when presentation is opened with WithWindow = false - charts

I'm not sure if this is "intended", or if a workaround (other than showing the presentation) exists.
#if DEBUG
var withWindow = Microsoft.Office.Core.MsoTriState.msoTrue;
#else
// using msoTrue fixes the error
var withWindow = Microsoft.Office.Core.MsoTriState.msoFalse;
#endif
presentation = app.Presentations.Open(templateFileName,
Microsoft.Office.Core.MsoTriState.msoTrue, // readonly
Microsoft.Office.Core.MsoTriState.msoFalse, // untitled (?)
withWindow // with window: visible or not
);
// some time later...
slide.Shapes.AddChart(); // Error HRESULT E_FAIL has been returned from a call to a COM component. ErrorCode: -214747259
Not being able to have the PowerPoint presentation hidden when automating is pretty annoying. Are there any workarounds for this issue?

Related

Why does QQmlComponent::create() return nullptr?

Under what conditions does QQmlComponent::create(QQmlContext *) fail by returning nullptr? The documentation only says " Returns nullptr if creation failed" without further detail. My backend C++ code tries to instantiate a MessageDialog from the following qml:
import QtQuick 2.0
import QtQuick.Dialogs 1.1
MessageDialog {
id: messageDialog
title: "My message"
text: "Fill in this message from C++"
onAccepted: {
console.log("Knew you'd see it my way!")
// Hide the dialog
visible = false
}
Component.onCompleted: visible = true
}
And here's a fragment of my backend constructor:
QQmlApplicationEngine engine;
// Note that component resource is local file URL,
// not network - no need to wait before calling create()?
QQmlComponent *component =
new QQmlComponent(&engine,
QStringLiteral("ui-components/MessageDialog.qml"));
// Following call returns nullptr
QObject *childItem = component->create();
Anyone know why? Thanks!
I don't think it is finding your qml file. Presuming your "ui-components/MessageDialog.qml" is in a qrc file, try:
new QQmlComponent(&engine, QStringLiteral("qrc:/ui-components/MessageDialog.qml"));

MS Word VSTO Addin Find.Execute fires ContentControlOnEnter event

It seems that if Find.Execute finds a result inside a ContentControl, it will cause the ContentControlOnEnter and ContentControlOnExit events to fire. It's particularly annoying because the exit event fires even if the selection is still in the content control, so any code which sets the states of buttons dependent upon a content control being active will appear to be in the incorrect state.
Given a document containing a single content control with the word "test", and the following code:
// In setup
Application.ActiveDocument.ContentControlOnEnter += ActiveDocument_ContentControlOnEnter;
private void ActiveDocument_ContentControlOnEnter(Word.ContentControl ContentControl)
{
var selRange = _Application.Selection.Range;
_logger.Debug(m => m("Selection: {0}-{1}", selRange.Start, selRange.End));
}
//Later in another method
var finder = _Application.ActiveDocument.Range().Find;
_logger.Debug("Find.Execute start");
finder.Execute("test);
_logger.Debug("Find.Execute end");
The following gets logged:
38137 [VSTA_Main] DEBUG - Find.Execute start
38141 [VSTA_Main] DEBUG - Selection: 1-5
38149 [VSTA_Main] DEBUG - Find.Execute end
We have a lot of code that handles ContentControlOnEnter and ContentControlOnExit events, and having the find operation cause them to be called is really causing problems!
Is there any way to use Find.Execute without having it trigger these events? Failing that, is there a good way to distinguish between the Find-triggered ones and the genuine user ones? I have tried using the time between the enter and exit events, but this is not reliable.
I had similar problems in Word, though it was about the Selection event. I tried many solutions, but only one helped. In your case, make a new field bool _skipEnterAndExitEvents and set it true before calling
finder.Execute("test) and false after calling. And in the enter and exit event handlers check this field, if the field is true then just skip. This solutions is not beautiful, looks like a hack, but other solutions are even uglier and don't really work.
I think I found a decent solution:
private bool _doIgnoreNextExit = false;
private void ActiveDocument_ContentControlOnEnter(Word.ContentControl ContentControl)
{
if (Application.Selection.Find.Found)
{
_logger.Debug("Ignoring CC enter event caused by Find operation");
_doIgnoreNextExit = true;
return;
}
// Do things
}
private void ActiveDocument_ContentControlOnExit(Word.ContentControl ContentControl)
{
if(_doIgnoreNextExit)
{
_logger.Debug("Ignoring fake exit");
_doIgnoreNextExit = false;
return;
}
// Do things
}

Open a new window and get its location after loading

I am using this code to open a new window:
Window w = window.open('example2.com', 'example2'); // Consisder than my domain
// is example1.com
This part of code works ok and succesfully opens a new window. Than i am trying to call my function after loading finishes.
w.onLoad.listen(locationGetter);
This is a code of locationGetter() function:
locationGetter(Event e) {
Location currentLocation = w.location;
currentHref = currentLocation.href; // currentHref is var defined
} // in main() function
But this code doesn't work well. Every time when I run my script both currentLocation and currentHref is null. At the beginning i thought that problem was in onLoad event, so i tried to call w.location exacly after opening a window:
Window w = window.open('example2.com', 'example2');
Location currentLocation = w.location; // still null
I am pretty sure that both Window and WindowBase has location property. Please help me with my problem or provide alternative solution of this task.
I don't think this is a Dart issue.
Seems you run into this
http://blog.carbonfive.com/2012/08/17/cross-domain-browser-window-messaging-with-html5-and-javascript/
CORS prevents accessing windows of other domains, you can use postMessage instead.

Using a javascript XPCOM component to create a custom autocomplete box in a FireFox add-on

I've spent a few days reading over all manner of tutorials, MDN entries, and S.O. posts, and I've come to suspect that I'm missing something obvious, but I'm too inexperienced with XPCOM to spot it. I'm about 80% sure there error is somewhere in my custom component (components/fooLogin.js).
Problem: When the add-on initializes (when I call loadData() from chrome/content/foologin.js), I get an error saying:
TypeError: Components.classes['#foo.com/foologinautocomplete;1'] is undefined
Am I maybe trying to create the component before the class has been registered? Is there something else I need to do to register it? Any tips would be appreciated.
Relevant Code: (happy to supply any additional code, if need be)
components/fooLogin.js:
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function fooLoginAutoComplete(){
this.wrappedJSObject = this;
}
fooLoginAutoComplete.prototype = {
classID: Components.ID("loginac#foo.com"),
contractID: "#foo.com/foologinautocomplete;1",
classDescription: "Auto complete for foo",
QueryInterface: XPCOMUtils.generateQI([]),
complete: function(str){ // Autocomplete functionality will in this function
return null;
}
};
var NSGetFactory = XPCOMUtils.generateNSGetFactory([fooLoginAutoComplete]);
chrome/content/foologin.js:
let fooLogin = {
dataLoaded : false,
searchFilter = null,
...
loadData : function(){
...
try{
alert(1); // This alert fires
this.searchFilter = Components.classes['#foo.com/foologinautocomplete;1']
.getService().wrappedJSObject;
alert(2); // I get the error before this alert
}catch(e){alert(e);}
this.dataLoaded = true;
}
}
window.addEventListener("load", function(){
if(!fooLogin.dataLoaded) fooLogin.loadData();
}
chrome.manifest:
content foologin chrome/content/
content foologin chrome/content/ contentaccessible=yes
skin foologin classic chrome/skin/
locale foologin en-US chrome/locale/en-US/
component loginac#foo.com components/fooLogin.js
contract #foo.com/foologinautocomplete;1 loginac#foo.com
overlay chrome://browser/content/browser.xul chrome://foologin/content/foologin.xul
In your chrome.manifest, you have this:
component loginac#foo.com components/fooLogin.js
contract #foo.com/foologinautocomplete;1 loginac#foo.com
and in fooLogin.js you have:
classID: Components.ID("loginac#foo.com"),
loginac#foo.com is not a valid class ID for a component.
They have to be of the form:
{00000000-0000-0000-0000-000000000000}
Only add-ons can have a foo#bar.com format.

How to load an accelerators map from a file using GTK3 in Vala?

I'm making a text editor using GTK3 in Vala. I have a Gtk.MenuBar in a Gtk.Window and I want to use accelerators to easily activate its Gtk.MenuItems. But I want the user to be able to change the key combinations, so I'm loading the accelerators specifications from a file using the method Gtk.AccelMap.load("accels"). However, after calling this method, the accelerators are not loaded: the menu items don't have AccelLabels and are not activated when I press the key combinations. Here are the two files I'm working on. The first file contains a small version of my application (to show what I'm trying to do) and the second one is the accels file from which I load the accels specifications, and they must be in the same directory.
main.vala
// Compile me with: valac main.vala -o main --pkg gtk+-3.0
public class MyWindow: Gtk.Window {
public MyWindow() {
this.set_default_size(500, 500);
var main_box = new Gtk.VBox(false, 0);
this.add(main_box);
var accel_group = new Gtk.AccelGroup();
this.add_accel_group(accel_group);
// Load the accelerators from the file
Gtk.AccelMap.load("accels");
// Create the action
var quit_action = new Gtk.Action("file-quit", "Quit", "Quit the application", null);
quit_action.activate.connect(()=>{
Gtk.main_quit();
});
quit_action.set_accel_group(accel_group);
quit_action.set_accel_path("<MyWindow>/File/Quit");
// Menubar
var menubar = new Gtk.MenuBar();
main_box.pack_start(menubar, false, false, 0);
var file = new Gtk.MenuItem.with_label("File");
menubar.add(file);
var file_menu = new Gtk.Menu();
file.set_submenu(file_menu);
var quit_mi = (Gtk.MenuItem)quit_action.create_menu_item();
file_menu.append(quit_mi);
// Label
var label = new Gtk.Label("My Window");
main_box.pack_start(label, true, true, 0);
this.destroy.connect(Gtk.main_quit);
}
}
int main(string[] args) {
Gtk.init(ref args);
var win = new MyWindow();
win.show_all();
Gtk.main();
return 0;
}
"accels" file
; main GtkAccelMap rc-file -*- scheme -*-
; this file is an automated accelerator map dump
;
; (gtk_accel_path "<MyWindow>/File/Quit" "<Control>q")
So, why is this not working? What do I have to do before or after loading the accel file?
PS: I don't want to use a Gtk.UIManager.
See : https://docs.xfce.org/faq#keyboard_related
"
This functionality has been disabled since GTK3 which means that Xfce apps that have migrated to GTK3 (such as xfce4-terminal) do not support it.
Refer to specific app's documentation to learn how to configure its shortcuts.
"