* Added ability to save a "styles" attribute for StyledEdit. This implements
ticket #4032. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31196 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+118
-33
@@ -15,10 +15,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <ByteOrder.h>
|
#include <ByteOrder.h>
|
||||||
|
#include <Entry.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <TextView.h>
|
||||||
|
|
||||||
|
|
||||||
#define CHARS_TABLE_MAXSIZE 10000
|
#define CHARS_TABLE_MAXSIZE 10000
|
||||||
@@ -618,7 +620,22 @@ Keymap::SaveAsSource(const char* name)
|
|||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
_SaveSourceText(file);
|
text_run_array* textRuns;
|
||||||
|
_SaveSourceText(file, &textRuns);
|
||||||
|
|
||||||
|
if (textRuns != NULL) {
|
||||||
|
ssize_t dataSize;
|
||||||
|
void* data = BTextView::FlattenRunArray(textRuns, &dataSize);
|
||||||
|
if (data != NULL) {
|
||||||
|
BNode node(name);
|
||||||
|
node.WriteAttr("styles", B_RAW_TYPE, 0, data, dataSize);
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
BTextView::FreeRunArray(textRuns);
|
||||||
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,7 +643,7 @@ Keymap::SaveAsSource(const char* name)
|
|||||||
status_t
|
status_t
|
||||||
Keymap::SaveAsSource(FILE* file)
|
Keymap::SaveAsSource(FILE* file)
|
||||||
{
|
{
|
||||||
_SaveSourceText(file);
|
_SaveSourceText(file, NULL);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1061,8 +1078,8 @@ Keymap::RestoreSystemDefault()
|
|||||||
|
|
||||||
path.Append("Key_map");
|
path.Append("Key_map");
|
||||||
|
|
||||||
BEntry ref(path.Path());
|
BEntry entry(path.Path());
|
||||||
ref.Remove();
|
entry.Remove();
|
||||||
|
|
||||||
_restore_key_map_();
|
_restore_key_map_();
|
||||||
#else // ! __BEOS__
|
#else // ! __BEOS__
|
||||||
@@ -1112,12 +1129,36 @@ Keymap::GetKey(char* chars, int32 offset, char* string)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Keymap::_SaveSourceText(FILE* file)
|
Keymap::_SaveSourceText(FILE* file, text_run_array** _textRuns)
|
||||||
{
|
{
|
||||||
fprintf(file, "#!/bin/keymap -l\n"
|
text_run_array* runs = NULL;
|
||||||
|
if (_textRuns != NULL) {
|
||||||
|
runs = BTextView::AllocRunArray(8);
|
||||||
|
*_textRuns = runs;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const rgb_color kCommentColor = (rgb_color){200, 92, 92, 255};
|
||||||
|
static const rgb_color kTextColor = (rgb_color){0, 0, 0, 255};
|
||||||
|
BFont font = *be_fixed_font;
|
||||||
|
|
||||||
|
if (runs != NULL) {
|
||||||
|
runs->runs[0].offset = 0;
|
||||||
|
runs->runs[0].font = font;
|
||||||
|
runs->runs[0].color = kCommentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bytes = fprintf(file, "#!/bin/keymap -l\n"
|
||||||
"#\n"
|
"#\n"
|
||||||
"#\tRaw key numbering for 101 keyboard...\n"
|
"#\tRaw key numbering for 101 keyboard...\n");
|
||||||
"# [sys] [brk]\n"
|
|
||||||
|
if (runs != NULL) {
|
||||||
|
runs->runs[1].offset = bytes;
|
||||||
|
runs->runs[1].font = font;
|
||||||
|
runs->runs[1].font.SetSize(9);
|
||||||
|
runs->runs[1].color = kCommentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes += fprintf(file, "# [sys] [brk]\n"
|
||||||
"# 0x7e 0x7f\n"
|
"# 0x7e 0x7f\n"
|
||||||
"# [esc] [ f1] [ f2] [ f3] [ f4] [ f5] [ f6] [ f7] [ f8] [ f9] [f10] [f11] [f12] [prn] [scr] [pau]\n"
|
"# [esc] [ f1] [ f2] [ f3] [ f4] [ f5] [ f6] [ f7] [ f8] [ f9] [f10] [f11] [f12] [prn] [scr] [pau]\n"
|
||||||
"# 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 K E Y P A D K E Y S\n"
|
"# 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 K E Y P A D K E Y S\n"
|
||||||
@@ -1135,8 +1176,15 @@ Keymap::_SaveSourceText(FILE* file)
|
|||||||
"# 0x4b 0x4c 0x4d 0x4e 0x4f 0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a 0x5b\n"
|
"# 0x4b 0x4c 0x4d 0x4e 0x4f 0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a 0x5b\n"
|
||||||
"#\n"
|
"#\n"
|
||||||
"# [ctr] [cmd] [ space ] [cmd] [ctr] [lft] [dwn] [rgt] [ 0 ] [ . ]\n"
|
"# [ctr] [cmd] [ space ] [cmd] [ctr] [lft] [dwn] [rgt] [ 0 ] [ . ]\n"
|
||||||
"# 0x5c 0x5d 0x5e 0x5f 0x60 0x61 0x62 0x63 0x64 0x65\n"
|
"# 0x5c 0x5d 0x5e 0x5f 0x60 0x61 0x62 0x63 0x64 0x65\n");
|
||||||
"#\n"
|
|
||||||
|
if (runs != NULL) {
|
||||||
|
runs->runs[2].offset = bytes;
|
||||||
|
runs->runs[2].font = font;
|
||||||
|
runs->runs[2].color = kCommentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes += fprintf(file, "#\n"
|
||||||
"#\tNOTE: On a Microsoft Natural Keyboard:\n"
|
"#\tNOTE: On a Microsoft Natural Keyboard:\n"
|
||||||
"#\t\t\tleft option = 0x66\n"
|
"#\t\t\tleft option = 0x66\n"
|
||||||
"#\t\t\tright option = 0x67\n"
|
"#\t\t\tright option = 0x67\n"
|
||||||
@@ -1147,20 +1195,37 @@ Keymap::_SaveSourceText(FILE* file)
|
|||||||
"#\t\t\tkeypad '=' = 0x6a\n"
|
"#\t\t\tkeypad '=' = 0x6a\n"
|
||||||
"#\t\t\tpower key = 0x6b\n");
|
"#\t\t\tpower key = 0x6b\n");
|
||||||
|
|
||||||
fprintf(file, "Version = %ld\n", fKeys.version);
|
if (runs != NULL) {
|
||||||
fprintf(file, "CapsLock = 0x%02lx\n", fKeys.caps_key);
|
runs->runs[3].offset = bytes;
|
||||||
fprintf(file, "ScrollLock = 0x%02lx\n", fKeys.scroll_key);
|
runs->runs[3].font = *be_fixed_font;
|
||||||
fprintf(file, "NumLock = 0x%02lx\n", fKeys.num_key);
|
runs->runs[3].color = kTextColor;
|
||||||
fprintf(file, "LShift = 0x%02lx\n", fKeys.left_shift_key);
|
}
|
||||||
fprintf(file, "RShift = 0x%02lx\n", fKeys.right_shift_key);
|
|
||||||
fprintf(file, "LCommand = 0x%02lx\n", fKeys.left_command_key);
|
bytes += fprintf(file, "Version = %ld\n"
|
||||||
fprintf(file, "RCommand = 0x%02lx\n", fKeys.right_command_key);
|
"CapsLock = 0x%02lx\n"
|
||||||
fprintf(file, "LControl = 0x%02lx\n", fKeys.left_control_key);
|
"ScrollLock = 0x%02lx\n"
|
||||||
fprintf(file, "RControl = 0x%02lx\n", fKeys.right_control_key);
|
"NumLock = 0x%02lx\n"
|
||||||
fprintf(file, "LOption = 0x%02lx\n", fKeys.left_option_key);
|
"LShift = 0x%02lx\n"
|
||||||
fprintf(file, "ROption = 0x%02lx\n", fKeys.right_option_key);
|
"RShift = 0x%02lx\n"
|
||||||
fprintf(file, "Menu = 0x%02lx\n", fKeys.menu_key);
|
"LCommand = 0x%02lx\n"
|
||||||
fprintf(file, "#\n"
|
"RCommand = 0x%02lx\n"
|
||||||
|
"LControl = 0x%02lx\n"
|
||||||
|
"RControl = 0x%02lx\n"
|
||||||
|
"LOption = 0x%02lx\n"
|
||||||
|
"ROption = 0x%02lx\n"
|
||||||
|
"Menu = 0x%02lx\n",
|
||||||
|
fKeys.version, fKeys.caps_key, fKeys.scroll_key, fKeys.num_key,
|
||||||
|
fKeys.left_shift_key, fKeys.right_shift_key, fKeys.left_command_key,
|
||||||
|
fKeys.right_command_key, fKeys.left_control_key, fKeys.right_control_key,
|
||||||
|
fKeys.left_option_key, fKeys.right_option_key, fKeys.menu_key);
|
||||||
|
|
||||||
|
if (runs != NULL) {
|
||||||
|
runs->runs[4].offset = bytes;
|
||||||
|
runs->runs[4].font = *be_fixed_font;
|
||||||
|
runs->runs[4].color = kCommentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes += fprintf(file, "#\n"
|
||||||
"# Lock settings\n"
|
"# Lock settings\n"
|
||||||
"# To set NumLock, do the following:\n"
|
"# To set NumLock, do the following:\n"
|
||||||
"# LockSettings = NumLock\n"
|
"# LockSettings = NumLock\n"
|
||||||
@@ -1168,15 +1233,29 @@ Keymap::_SaveSourceText(FILE* file)
|
|||||||
"# To set everything, do the following:\n"
|
"# To set everything, do the following:\n"
|
||||||
"# LockSettings = CapsLock NumLock ScrollLock\n"
|
"# LockSettings = CapsLock NumLock ScrollLock\n"
|
||||||
"#\n");
|
"#\n");
|
||||||
fprintf(file, "LockSettings = ");
|
|
||||||
if (fKeys.lock_settings & B_CAPS_LOCK)
|
if (runs != NULL) {
|
||||||
fprintf(file, "CapsLock ");
|
runs->runs[5].offset = bytes;
|
||||||
if (fKeys.lock_settings & B_NUM_LOCK)
|
runs->runs[5].font = *be_fixed_font;
|
||||||
fprintf(file, "NumLock ");
|
runs->runs[5].color = kTextColor;
|
||||||
if (fKeys.lock_settings & B_SCROLL_LOCK)
|
}
|
||||||
fprintf(file, "ScrollLock ");
|
|
||||||
fprintf(file, "\n");
|
bytes += fprintf(file, "LockSettings = ");
|
||||||
fprintf(file, "# Legend:\n"
|
if ((fKeys.lock_settings & B_CAPS_LOCK) != 0)
|
||||||
|
bytes += fprintf(file, "CapsLock ");
|
||||||
|
if ((fKeys.lock_settings & B_NUM_LOCK) != 0)
|
||||||
|
bytes += fprintf(file, "NumLock ");
|
||||||
|
if ((fKeys.lock_settings & B_SCROLL_LOCK) != 0)
|
||||||
|
bytes += fprintf(file, "ScrollLock ");
|
||||||
|
bytes += fprintf(file, "\n");
|
||||||
|
|
||||||
|
if (runs != NULL) {
|
||||||
|
runs->runs[6].offset = bytes;
|
||||||
|
runs->runs[6].font = *be_fixed_font;
|
||||||
|
runs->runs[6].color = kCommentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes += fprintf(file, "# Legend:\n"
|
||||||
"# n = Normal\n"
|
"# n = Normal\n"
|
||||||
"# s = Shift\n"
|
"# s = Shift\n"
|
||||||
"# c = Control\n"
|
"# c = Control\n"
|
||||||
@@ -1184,6 +1263,12 @@ Keymap::_SaveSourceText(FILE* file)
|
|||||||
"# o = Option\n"
|
"# o = Option\n"
|
||||||
"# Key n s c o os C Cs Co Cos \n");
|
"# Key n s c o os C Cs Co Cos \n");
|
||||||
|
|
||||||
|
if (runs != NULL) {
|
||||||
|
runs->runs[7].offset = bytes;
|
||||||
|
runs->runs[7].font = *be_fixed_font;
|
||||||
|
runs->runs[7].color = kTextColor;
|
||||||
|
}
|
||||||
|
|
||||||
for (int idx = 0; idx < 128; idx++) {
|
for (int idx = 0; idx < 128; idx++) {
|
||||||
char normalKey[32];
|
char normalKey[32];
|
||||||
char shiftKey[32];
|
char shiftKey[32];
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
#include <Entry.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
@@ -47,7 +47,8 @@ public:
|
|||||||
static void GetKey(char* chars, int32 offset, char* string);
|
static void GetKey(char* chars, int32 offset, char* string);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _SaveSourceText(FILE* file);
|
void _SaveSourceText(FILE* file,
|
||||||
|
text_run_array** _textRuns);
|
||||||
void _ComputeChars(const char* buffer,
|
void _ComputeChars(const char* buffer,
|
||||||
struct re_registers& regs, int i, int& offset);
|
struct re_registers& regs, int i, int& offset);
|
||||||
void _ComputeTables(const char* buffer,
|
void _ComputeTables(const char* buffer,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
|
||||||
#include "Keymap.h"
|
#include "Keymap.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -150,6 +152,7 @@ main(int argc, char **argv)
|
|||||||
if (argc > optind && input == NULL)
|
if (argc > optind && input == NULL)
|
||||||
input = argv[optind];
|
input = argv[optind];
|
||||||
|
|
||||||
|
BApplication app("application/x-vnd.Haiku-keymap-cli");
|
||||||
Keymap keymap;
|
Keymap keymap;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|||||||
Reference in New Issue
Block a user