我正在为Eclipse创建一个插件,每当用户按下与插件关联的撤消按钮时,我都希望利用内置的Eclipse'Undo'操作(org.eclipse.core.commands.operations).
理想情况下,它只会重现按下CTRL + Z时发生的情况,但我没有模拟按键工作.
我试过这些代码片段:
在工作台中执行撤消:
IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport();
IUndoContext context = operationSupport.getUndoContext();
IOperationHistory operationHistory = operationSupport.getOperationHistory();
IStatus status = operationHistory.undo(context, null, null);
Run Code Online (Sandbox Code Playgroud)
撤消在工作区中执行:
IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport();
IUndoContext context= (IUndoContext)ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class);
IOperationHistory operationHistory = operationSupport.getOperationHistory();
IStatus status = operationHistory.undo(context, null, null);
Run Code Online (Sandbox Code Playgroud)
类似地,我正在寻找的是这个,但它不起作用:
在编辑器/文档上执行撤消:
IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport();
IEditorPart currentEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IUndoContext context = (IUndoContext) currentEditor.getAdapter(IUndoContext.class);
IOperationHistory operationHistory = operationSupport.getOperationHistory();
IStatus status = operationHistory.undo(context, null, null);
Run Code Online (Sandbox Code Playgroud) 假设你有一个像这样的XML文档:
<root>
That was a <b boldness="very">very bold</b> move.
</root>
Run Code Online (Sandbox Code Playgroud)
假设它XmlPullParser位于root的开始标记上.是否有内读取所有文字一个方便的方法root来一个String,有点像innerHtml在DOM?
或者我是否必须自己编写一个实用程序方法来重新创建解析后的标记?这当然对我来说似乎是浪费时间.
String myDesiredString = "That was a <b boldness=\"very\">very bold</b> move."
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,其中设置了ImageView,可以单击以在库中打开.
默认情况下,我使用以下代码从外部存储器获取文件目录以存储我的jpegs:
File picsDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"MyCameraApp");
Run Code Online (Sandbox Code Playgroud)
但!假设外部存储器未安装或根本不存在(Galaxy Nexus),这不起作用.所以我围绕它编写了一个if语句,并将内部缓存目录作为后退.
String state = Environment.getExternalStorageState()
if(Environment.MEDIA_MOUNTED.equals(state)){
File picsDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"MyCameraApp");
}else{
context.getCacheDir();
}
Run Code Online (Sandbox Code Playgroud)
图像在ImageView中显示得很好,但是在我的意图启动时却没有显示出来.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(imgFile), "image/jpeg");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
图库被加载,但显示黑屏.大概是因为画廊无法访问我的应用程序的缓存目录中的文件.
作为替代方案,我尝试使用使用的媒体内容提供程序MediaStore.Images.Media.INTERNAL_CONTENT_URI,但这会在尝试插入图像时导致错误:
java.lang.UnsupportedOperationException: Writing to internal storage is not supported.
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
关于这个问题有很多问题,但大多数都太专业了,不能回答我的问题.
我有一个GoogleMap我告诉它适合它的相机到某些界限.也许不是很令人惊讶,我收到一个错误:
java.lang.IllegalStateException: Map size should not be 0. Most likely, layout has not yet occured for the map view.
所以让我们把这个问题抽象给任何人View.
这个'布局'事件何时实际发生?onMeasure()例如,未显示在" 活动生命周期"中.何时可以安全地调用我需要布局的方法?
Android _id在BaseColumns界面中指定了超级便利的列,在这个问题中使用了很好的解释,但是用途是什么_count?在一个目录中的行数,什么目录?
public interface BaseColumns
{
/**
* The unique ID for a row.
* <P>Type: INTEGER (long)</P>
*/
public static final String _ID = "_id";
/**
* The count of rows in a directory.
* <P>Type: INTEGER</P>
*/
public static final String _COUNT = "_count";
}
Run Code Online (Sandbox Code Playgroud) WebView我的应用程序中有一个加载动态内容,我希望视图在设备轮换时保持不变.所以我写了以下几行代码:
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mWebView.saveState(outState);
}
Run Code Online (Sandbox Code Playgroud)
在我的onCreate()中:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (savedInstanceState != null) {
if(D.bug){
Log.i(TAG, "Restoring browser state");
}
mWebView.restoreState(savedInstanceState);
} else {
if(D.bug){
Log.i(TAG, "Not restoring browser state");
}
mWebView.loadUrl("file:///android_asset/html/browser_3col.html");
}
return mWebView;
}
Run Code Online (Sandbox Code Playgroud)
但这有效地重新加载了页面.我想传递动态生成的HTML.
我正在考虑通过a将整个文档HTML转储JavascriptInterface,将其存储在outState中,然后再通过它重置它JavascriptInterface.
这会是一个好方法吗?有没有方法WebView可以让我得到它的内在HTML?
在我的Rails应用程序中,我想将位置列字段的地理边界存储在数据库中.例如,纽约的边界表示为多边形:数组数组.
我已经声明我的模型来序列化多边形,但我不确定我是否应该像这样存储它们.这些序列化多边形的大小很容易超过100,000个字符,MySQL只能在标准TEXT字段中存储大约65000个字符.
现在我知道MySQL也有一个LONGTEXT字段.但我真的希望我的应用程序与数据库无关.Rails如何自己处理这个问题?它会自动切换到LONGTEXT字段吗?当我开始使用PostgreSQL时呢?
我在GAE中使用JDO使用以下方法批处理持久化对象:
public void makePersistent(PersistenceManager pm,
List<Regeling> makePersistent) {
Transaction tx = pm.currentTransaction();
try {
// Start the transaction
tx.begin();
// Persist to the datastore
// pm.makePersistentAll(makePersistent);
for (int i = 0; i < makePersistent.size(); i += BATCH_SIZE) {
int last = i + BATCH_SIZE;
last = last > makePersistent.size() ? makePersistent.size()
: last;
pm.makePersistentAll(makePersistent.subList(i, last));
pm.flush();
System.out.println("Made "+last+" items persistent.");
}
// Commit the transaction, flushing the object to the datastore
tx.commit();
} catch (Exception e) {
e.printStackTrace();
} finally …Run Code Online (Sandbox Code Playgroud) 假设您有一个JSON对象:
{
"mappings": {
"s54dsf45fzd324": "135sdq13sod1tt3",
"21sm24dsfp2ds2": "123sd56f4gt4ju4"
}
}
Run Code Online (Sandbox Code Playgroud)
您对映射对象唯一了解的是它将字符串映射到字符串,但您不知道键值.
是否可以使用GSON解析此对象并循环键/值对?
我有一个使用 Webpack 构建的 Vue 站点。我有一个包含组件的 TypeScript 文件:
// my-component.ts
import Vue = require('vue');
export default Vue.component("my-component", {
template: "<div>I am a component</div>"
});
Run Code Online (Sandbox Code Playgroud)
当我尝试使用此组件时,我收到以下警告:
您正在使用 Vue 的仅运行时构建,其中模板选项不可用。要么将模板预编译为渲染函数,要么使用包含编译器的构建。
现在:我如何预编译这个模板?我知道我可以定义一个.vue文件,甚至可以在里面使用 TypeScript <script></script>,但我宁愿在纯 TypeScript 中定义我的组件,以便在 WebStorm 中获得良好的 TypeScript 支持。
这可能吗?
(我知道我也可以通过为包含编译器的构建创建别名来使用第二个选项,vue/dist/vue.js但我觉得这会给我带来性能损失。至少,它为我的构建增加了 20kb。)