{"id":1997,"date":"2016-09-25T19:56:23","date_gmt":"2016-09-25T10:56:23","guid":{"rendered":"http:\/\/mattyan.net\/blog\/?p=1997"},"modified":"2016-09-25T19:56:23","modified_gmt":"2016-09-25T10:56:23","slug":"windows%e3%81%abgedit%e3%82%92%e5%85%a5%e3%82%8c%e3%81%a6%e3%81%bf%e3%81%9f%e3%80%82%e3%81%a4%e3%81%84%e3%81%a7%e3%81%ab%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e6%9b%b8%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"https:\/\/mattyan.net\/blog\/?p=1997","title":{"rendered":"windows\u306bgedit\u3092\u5165\u308c\u3066\u307f\u305f\u3002\u3064\u3044\u3067\u306b\u30d7\u30e9\u30b0\u30a4\u30f3\u66f8\u3044\u3066\u307f\u305f"},"content":{"rendered":"<p>Ubuntu\u306e\u3068\u304d\u306b\u4f7f\u3063\u3066\u3044\u305f\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u306e<a href=\"https:\/\/wiki.gnome.org\/Apps\/Gedit\">Gedit<\/a>\u306bWindows\u7248\u304c\u3042\u3063\u305f\u304b\u3089\u3001Atom\u306e\u91cd\u3055\u306b\u30ad\u30ec\u3066\u6d88\u3057\u305f\u305f\u3064\u3044\u3067\u306b\u5165\u308c\u3066\u307f\u305f\u3002<br \/>\n<!--more--><br \/>\n\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u30fc\u62fe\u3063\u3066\u304d\u3066\u5b9f\u884c\u3057\u3066\u7d42\u4e86\u3002<br \/>\n\u30dc\u30c8\u30e0\u30da\u30a4\u30f3\u304c\u51fa\u3066\u3053\u306a\u3044\u306e\u306f\u306a\u3093\u3067\u3060\u308d\u3046\u2026Python\u30b3\u30f3\u30bd\u30fc\u30eb\u4f7f\u3044\u305f\u3044\u2026<\/p>\n<hr \/>\n<p>\u3064\u3044\u3067\u306a\u3093\u3067\u30d7\u30e9\u30b0\u30a4\u30f3\u66f8\u3044\u3066\u307f\u305f\u3002<br \/>\nAtom\u306epretty-json\u307f\u305f\u3044\u306a\u3082\u306e\u304c\u6b32\u3057\u304b\u3063\u305f\u306e\u3067\u3001Gedit\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u5b66\u7fd2\u304c\u3066\u3089\u66f8\u3044\u3066\u307f\u305f\u3002<br \/>\n\u3060\u3044\u305f\u3044\u306e\u3053\u3068\u306f<a href=\"http:\/\/palepoli.skr.jp\/tips\/gedit\/plugin312.php\">Gedit \u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u4f5c\u308a\u65b9(v3.12 \u4ee5\u964d)<\/a>\u3092\u30b3\u30d4\u30fc\u3057\u3064\u3064\u4fee\u6b63<br \/>\njsonformat.plugin<\/p>\n<pre><code class=\"\" data-line=\"\">\n    [Plugin]\n    Loader=python3\n    Module=jsonformat\n    IAge=3\n    Name=Json format\n    Name[ja]=Json \u30d5\u30a9\u30fc\u30de\u30c3\u30c8\n    Description=Json format\n    Description[ja]=Json\u3092\u898b\u3084\u3059\u304f\n    Authors=mattyan &lt;mattyan@gmail.com&gt;\n    Copyright=Copyright \u00a9 2016 mattyan &lt;mattyan@gmail.com&gt;\n    Website=https:\/\/mattyan.net\/\n<\/code><\/pre>\n<p>\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb<br \/>\njsonformat\/__init__.py<br \/>\n[python]<br \/>\nimport gi<br \/>\ngi.require_version(&quot;Gtk&quot;, &quot;3.0&quot;)<br \/>\ngi.require_version(&quot;Gedit&quot;, &quot;3.0&quot;)<br \/>\nfrom .appactivatable import AppActivatable<br \/>\nfrom .windowactivatable import WindowActivatable<br \/>\n[\/python]<br \/>\nAppActivate\u3068WindowActivate\u3092\u8aad\u307f\u8fbc\u307f<br \/>\njsonformat\/appactivate.py<br \/>\n[python]<br \/>\nfrom gi.repository import GObject, Gedit, Gtk, Gio<br \/>\nclass AppActivatable(GObject.Object, Gedit.AppActivatable):<br \/>\n\tapp = GObject.property(type = Gedit.App)<br \/>\n\tdef __init__(self):<br \/>\n\t\tGObject.Object.__init__(self)<br \/>\n\tdef do_activate(self):<br \/>\n\t\titem = Gio.MenuItem.new(&#8216;JsonFormat&#8217;, &#8216;win.JsonFormatAction&#8217;)<br \/>\n\t\tself.menu_extend = self.extend_menu(&#8216;tools-section&#8217;)<br \/>\n\t\tself.menu_extend.append_menu_item(item)<br \/>\n\tdef do_deactivate(self):<br \/>\n\t\tpass<br \/>\n[\/python]<br \/>\n\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u521d\u671f\u8a2d\u5b9a\u3002do_activate()\u3067\u306f\u30e1\u30fc\u30cb\u30e5\u30fc\u306e\u8a2d\u5b9a\u3092\u3057\u3066\u3044\u308b\u3002<br \/>\njsonformat\/windowactivate.py<br \/>\n[python]<br \/>\nfrom gi.repository import GObject, Gedit, Gtk, Gio<br \/>\nimport json<br \/>\nclass WindowActivatable(GObject.Object, Gedit.WindowActivatable):<br \/>\n\t__gtype_name__ = &#8216;WindowActivatable&#8217;<br \/>\n\twindow = GObject.property(type = Gedit.Window)<br \/>\n\tdef __init__(self):<br \/>\n\t\tGObject.Object.__init__(self)<br \/>\n\tdef do_activate(self):<br \/>\n\t\taction = Gio.SimpleAction.new(&#8216;JsonFormatAction&#8217;, None)<br \/>\n\t\taction.connect(&#8216;activate&#8217;, self.on_click_format)<br \/>\n\t\tself.window.add_action(action)<br \/>\n\t\tpass<br \/>\n\tdef do_deactivate(self):<br \/>\n\t\tself.window.remove_action(&#8216;JsonFormatAction&#8217;)<br \/>\n\t\tpass<br \/>\n\tdef do_update_state(self):<br \/>\n\t\tpass<br \/>\n\tdef on_click_format(self, action, data = None):<br \/>\n\t\tdoc = self.window.get_active_document()<br \/>\n\t\ttry:<br \/>\n\t\t\tdata = json.loads(doc.get_start_iter().get_text(doc.get_end_iter()))<br \/>\n\t\t\tdoc.set_text(json.dumps(data, indent = 4))<br \/>\n\t\texcept Exception as e:<br \/>\n\t\t\tpass<br \/>\n[\/python]<br \/>\n\u30a4\u30d9\u30f3\u30c8\u306e\u8a2d\u5b9a\u3068\u5b9f\u884c\u3002do_activate()\u3067\u30a4\u30d9\u30f3\u30c8\u306e\u8a2d\u5b9a\u3092\u3057\u3066on_click_format()\u3067\u5b9f\u969b\u306e\u51e6\u7406\u3002<br \/>\n\u9762\u5012\u306a\u3093\u3067\u5b9f\u884c\u4e2d\u306e\u4f8b\u5916\u306f\u5168\u90e8\u63e1\u308a\u3064\u3076\u3057\u3066\u308b\u3002<br \/>\n\u3042\u3068\u305f\u3076\u3093Gtk\u306e\u4ed5\u69d8\u306a\u3093\u3060\u308d\u3046\u3051\u3069\u3001\u30a2\u30af\u30c6\u30a3\u30d6\u30bf\u30b0\u306e\u30c6\u30ad\u30b9\u30c8\u53d6\u5f97\u304c\u3061\u3087\u3063\u3068\u9762\u5012\u3002<br \/>\n\u8a2d\u5b9a\u306f<br \/>\n[python]<br \/>\ndoc = self.window.get_active_document()<br \/>\ndoc.set_text(&#8216;text&#8217;)<br \/>\n[\/python]<br \/>\n\u3067\u3044\u3044\u306e\u306b\u8aad\u307f\u8fbc\u307f\u306f<br \/>\n[python]<br \/>\ndoc = self.window.get_active_document()<br \/>\ndata = doc.get_start_iter().get_text(doc.get_end_iter())<br \/>\n[\/python]<br \/>\n\u3068\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306e\u958b\u59cb\u30a4\u30c6\u30ec\u30fc\u30bf\u30fc\u3092\u53d6\u5f97\u3057\u3066\u304b\u3089\u305d\u308c\u306eget_text\u3092\u547c\u3076\u307f\u305f\u3044\u3002\u3088\u304f\u308f\u304b\u3089\u3093\u2026<br \/>\n\u3042\u3068Windows\u7248Gedit\u306f\u6a19\u6e96\u51fa\u529b\u3084\u6a19\u6e96\u30a8\u30e9\u30fc\u306b\u51fa\u529b\u3057\u306a\u3044\u304b\u3089\u30d7\u30e9\u30b0\u30a4\u30f3\u5b9f\u88c5\u4e2d\u306b\u30d0\u30b0\u3063\u3066\u3082\u4f55\u3082\u308f\u304b\u3089\u3093\u2026VirtualBox\u306bUbuntu\u5165\u308c\u3066\u305d\u3063\u3061\u3067\u30c7\u30d0\u30c3\u30b0\u3057\u305f\u3051\u3069\u9762\u5012\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ubuntu\u306e\u3068\u304d\u306b\u4f7f\u3063\u3066\u3044\u305f\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u306eGedit\u306bWindows\u7248\u304c\u3042\u3063\u305f\u304b\u3089\u3001Atom\u306e\u91cd\u3055\u306b\u30ad\u30ec\u3066\u6d88\u3057\u305f\u305f\u3064\u3044\u3067\u306b\u5165\u308c\u3066\u307f\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,1],"tags":[],"class_list":["post-1997","post","type-post","status-publish","format-standard","hentry","category-3","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1997","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1997"}],"version-history":[{"count":0,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1997\/revisions"}],"wp:attachment":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}