Author: kitone
Date: Sat Feb 6 23:37:25 2016
New Revision: 964
URL: http://svn.gna.org/viewcvs/subtitleeditor?rev=964&view=rev
Log:
Fix bug #19010 : subtitleeditor needs a style template system for all formats.
Added:
trunk/plugins/actions/template/
trunk/plugins/actions/template/Makefile.am
trunk/plugins/actions/template/dialog-template-save-as.ui (with props)
trunk/plugins/actions/template/template.cc
trunk/plugins/actions/template/template.se-plugin.in
Modified:
trunk/ChangeLog
trunk/configure.ac
trunk/plugins/actions/Makefile.am
Modified: trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/subtitleeditor/trunk/ChangeLog?rev=964&r1=963&r2=964&view=diff
==============================================================================
--- trunk/ChangeLog (original)
+++ trunk/ChangeLog Sat Feb 6 23:37:25 2016
@@ -1,3 +1,12 @@
+2016-02-06 kitone <[email protected]>
+
+ * configure.ac:
+ * plugins/actions/Makefile.am:
+ * plugins/actions/template/Makefile.am:
+ * plugins/actions/template/template.cc:
+ * plugins/actions/template/template.se-plugin.in:
+ Fix bug #19010 : subtitleeditor needs a style template system for all
formats.
+
2016-02-05 kitone <[email protected]>
* share/subtitleeditor.desktop.in:
Modified: trunk/configure.ac
URL:
http://svn.gna.org/viewcvs/subtitleeditor/trunk/configure.ac?rev=964&r1=963&r2=964&view=diff
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Sat Feb 6 23:37:25 2016
@@ -361,6 +361,7 @@
plugins/actions/stacksubtitles/Makefile
plugins/actions/styleeditor/Makefile
plugins/actions/stylize/Makefile
+plugins/actions/template/Makefile
plugins/actions/textcorrection/Makefile
plugins/actions/timemodemanagement/Makefile
plugins/actions/timingfromplayer/Makefile
Modified: trunk/plugins/actions/Makefile.am
URL:
http://svn.gna.org/viewcvs/subtitleeditor/trunk/plugins/actions/Makefile.am?rev=964&r1=963&r2=964&view=diff
==============================================================================
--- trunk/plugins/actions/Makefile.am (original)
+++ trunk/plugins/actions/Makefile.am Sat Feb 6 23:37:25 2016
@@ -38,6 +38,7 @@
styleeditor \
stylize \
stacksubtitles \
+ template \
textcorrection \
timemodemanagement \
timingfromplayer \
Added: trunk/plugins/actions/template/Makefile.am
URL:
http://svn.gna.org/viewcvs/subtitleeditor/trunk/plugins/actions/template/Makefile.am?rev=964&view=auto
==============================================================================
--- trunk/plugins/actions/template/Makefile.am (added)
+++ trunk/plugins/actions/template/Makefile.am Sat Feb 6 23:37:25 2016
@@ -0,0 +1,32 @@
+plugin_name = template
+pluginlibdir = $(PACKAGE_PLUGIN_LIB_DIR)/actions
+plugindescriptiondir = $(PACKAGE_PLUGIN_DESCRIPTION_DIR)/actions
+actionplugindevdir = $(abs_srcdir)
+uidir = $(PACKAGE_PLUGIN_SHARE_DIR)/$(plugin_name)
+
+INCLUDES = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/src \
+ $(SUBTITLEEDITOR_CFLAGS) \
+ -DSE_PLUGIN_PATH_DEV=\"$(actionplugindevdir)\" \
+ -DSE_PLUGIN_PATH_UI=\"$(uidir)\"
+
+pluginlib_LTLIBRARIES = \
+ libtemplate.la
+
+libtemplate_la_SOURCES = \
+ template.cc
+
+libtemplate_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
+libtemplate_la_LIBADD = $(SUBTITLEEDITOR_LIBS) -L$(top_srcdir)/src
-lsubtitleeditor
+
+plugindescription_in_files = template.se-plugin.in
+plugindescription_DATA = $(plugindescription_in_files:.se-plugin.in=.se-plugin)
+
+@INTLTOOL_SE_PLUGIN_RULE@
+
+ui_DATA = dialog-template-save-as.ui
+
+EXTRA_DIST = $(plugindescription_in_files) $(ui_DATA)
+
+CLEANFILES = $(plugindescription_DATA) Makefile.am~ *.cc~ *.h~ *.ui~ *.uip
*.uip.bak *.in~
Added: trunk/plugins/actions/template/dialog-template-save-as.ui
URL:
http://svn.gna.org/viewcvs/subtitleeditor/trunk/plugins/actions/template/dialog-template-save-as.ui?rev=964&view=auto
==============================================================================
Binary file - no diff available.
Propchange: trunk/plugins/actions/template/dialog-template-save-as.ui
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: trunk/plugins/actions/template/template.cc
URL:
http://svn.gna.org/viewcvs/subtitleeditor/trunk/plugins/actions/template/template.cc?rev=964&view=auto
==============================================================================
--- trunk/plugins/actions/template/template.cc (added)
+++ trunk/plugins/actions/template/template.cc Sat Feb 6 23:37:25 2016
@@ -0,0 +1,360 @@
+/*
+ * subtitleeditor -- a tool to create or edit subtitle
+ *
+ * http://home.gna.org/subtitleeditor/
+ * https://gna.org/projects/subtitleeditor/
+ *
+ * Copyright @ 2016, kitone
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <extension/action.h>
+#include <utility.h>
+#include <documentsystem.h>
+#include <memory>
+#include <gtkmm_utility.h>
+#include <gui/comboboxencoding.h>
+#include <gui/comboboxsubtitleformat.h>
+#include <gui/comboboxnewline.h>
+
+/*
+ */
+class DialogTemplate : public Gtk::Dialog
+{
+public:
+ DialogTemplate(BaseObjectType* cobj, const Glib::RefPtr<Gtk::Builder>&
xml)
+ :Gtk::Dialog(cobj)
+ {
+ utility::set_transient_parent(*this);
+
+ xml->get_widget("entry-name", m_entryName);
+ xml->get_widget_derived("combo-format", m_comboFormat);
+ xml->get_widget_derived("combo-encoding", m_comboEncoding);
+ xml->get_widget_derived("combo-newline", m_comboNewLine);
+
+ m_comboEncoding->show_auto_detected(false);
+
+ add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ add_button(Gtk::Stock::SAVE_AS, Gtk::RESPONSE_OK);
+
+ set_default_response(Gtk::RESPONSE_OK);
+ }
+
+ /*
+ */
+ void set_name(const Glib::ustring &name)
+ {
+ m_entryName->set_text(name);
+ }
+
+ /*
+ */
+ Glib::ustring get_name()
+ {
+ return m_entryName->get_text();
+ }
+
+ /*
+ */
+ void set_charset(const Glib::ustring &charset)
+ {
+ m_comboEncoding->set_value(charset);
+ }
+
+ /*
+ */
+ Glib::ustring get_charset()
+ {
+ return m_comboEncoding->get_value();
+ }
+
+ /*
+ */
+ void set_format(const Glib::ustring &format)
+ {
+ m_comboFormat->set_value(format);
+ }
+
+ /*
+ */
+ Glib::ustring get_format()
+ {
+ return m_comboFormat->get_value();
+ }
+
+ /*
+ */
+ void set_newline(const Glib::ustring &newline)
+ {
+ m_comboNewLine->set_value(newline);
+ }
+
+ /*
+ */
+ Glib::ustring get_newline()
+ {
+ return m_comboNewLine->get_value();
+ }
+
+public:
+ Gtk::Entry* m_entryName;
+ ComboBoxEncoding* m_comboEncoding;
+ ComboBoxSubtitleFormat* m_comboFormat;
+ ComboBoxNewLine* m_comboNewLine;
+};
+
+/*
+ */
+class TemplatePlugin : public Action
+{
+public:
+
+ TemplatePlugin()
+ {
+ activate();
+ update_ui();
+ }
+
+ ~TemplatePlugin()
+ {
+ deactivate();
+ }
+
+ /*
+ */
+ void activate()
+ {
+ se_debug(SE_DEBUG_PLUGINS);
+
+ // actions
+ action_group = Gtk::ActionGroup::create("TemplatePlugin");
+
+ action_group->add(
+ Gtk::Action::create("template",
_("_Template")));
+
+ action_group->add(
+ Gtk::Action::create("save-as-template",
Gtk::Stock::SAVE_AS, _("_Save As Template"), _("Save the current document as
template.")),
+ sigc::mem_fun(*this,
&TemplatePlugin::on_save_as_template));
+
+ // ui
+ Glib::RefPtr<Gtk::UIManager> ui = get_ui_manager();
+
+ ui->insert_action_group(action_group);
+
+ Glib::ustring submenu =
+ "<ui>"
+ " <menubar name='menubar'>"
+ " <menu name='menu-extensions'
action='menu-extensions'>"
+ " <placeholder
name='placeholder'>"
+ " <menu
name='template' action='template'>"
+ "
<menuitem action='save-as-template'/>"
+ "
<separator/>"
+ "
<placeholder name='template-files'/>"
+ " </menu>"
+ " </placeholder>"
+ " </menu>"
+ " </menubar>"
+ "</ui>";
+
+ ui_id = ui->add_ui_from_string(submenu);
+
+ rebuild_templates_menu();
+ }
+
+ /*
+ */
+ void deactivate()
+ {
+ se_debug(SE_DEBUG_PLUGINS);
+
+ Glib::RefPtr<Gtk::UIManager> ui = get_ui_manager();
+
+ if(action_group_templates)
+ {
+ ui->remove_ui(ui_id_templates);
+ ui->remove_action_group(action_group_templates);
+ }
+ ui->remove_ui(ui_id);
+ ui->remove_action_group(action_group);
+ }
+
+ /*
+ */
+ void update_ui()
+ {
+ se_debug(SE_DEBUG_PLUGINS);
+
+ bool visible = (get_current_document() != NULL);
+
+
action_group->get_action("save-as-template")->set_sensitive(visible);
+ }
+
+ /*
+ */
+ void rebuild_templates_menu()
+ {
+ Glib::RefPtr<Gtk::UIManager> ui = get_ui_manager();
+ // We clean the old ui and action_group
+ if(action_group_templates)
+ {
+ ui->remove_ui(ui_id_templates);
+ ui->remove_action_group(action_group_templates);
+ }
+ // Create new ui and action_group
+ action_group_templates =
Gtk::ActionGroup::create("TemplatePluginFiles");
+ ui->insert_action_group(action_group_templates);
+
+ ui_id_templates = ui->new_merge_id();
+
+ // Read the template directory
+ if(initialize_template_directory() == false)
+ return;
+
+ // For each files we create an entry
+ Glib::Dir dir(get_config_dir("plugins/template"));
+ std::vector<Glib::ustring> files(dir.begin(), dir.end());
+
+ for(unsigned int i=0; i< files.size(); ++i)
+ {
+ add_ui_from_file(i, files[i]);
+ }
+ // Update the ui
+ ui->ensure_update();
+ }
+
+ /*
+ */
+ void add_ui_from_file(const guint number, const Glib::ustring &filename)
+ {
+ // We extract from the filename the label and the charset
+ Glib::RefPtr<Glib::Regex> re =
Glib::Regex::create("^\\[(.*)\\]\\[(.*)\\]$");
+ if(re->match(filename) == false)
+ {
+ // Something wrong...
+ return;
+ }
+ std::vector<Glib::ustring> group = re->split(filename);
+
+ Glib::ustring label = group[1];
+ Glib::ustring charset = group[2];
+ Glib::ustring fullname =
Glib::build_filename(get_config_dir("plugins/template"), filename);
+
+ Glib::ustring action_name =
Glib::ustring::compose("template-file-%1", number);
+ Glib::ustring action_accel = "";//(number < 10) ?
Glib::ustring::compose("<alt>%1", (number+1) % 10) : "";
+
+ action_group_templates->add(
+ Gtk::Action::create(action_name, label),
Gtk::AccelKey(action_accel),
+ sigc::bind(
+ sigc::mem_fun(*this,
&TemplatePlugin::on_template_activate), fullname, charset));
+
+ get_ui_manager()->add_ui(
+ ui_id_templates,
+
"/menubar/menu-extensions/placeholder/template/template-files",
+ action_name,
+ action_name,
+ Gtk::UI_MANAGER_MENUITEM,
+ false);
+ }
+
+ /*
+ */
+ void on_template_activate(const Glib::ustring &path, const
Glib::ustring &charset)
+ {
+ Glib::ustring uri = Glib::filename_to_uri(path);
+
+ Document* doc = Document::create_from_file(uri, charset);
+ if(doc == NULL)
+ return;
+
+
doc->setFilename(DocumentSystem::getInstance().create_untitled_name());
+ doc->setCharset(charset);
+ DocumentSystem::getInstance().append(doc);
+ }
+
+ /*
+ */
+ void on_save_as_template()
+ {
+ Document* current = get_current_document();
+ g_return_if_fail(current);
+
+ // create dialog
+ std::auto_ptr<DialogTemplate> dialog(
+
gtkmm_utility::get_widget_derived<DialogTemplate>(
+ SE_DEV_VALUE(SE_PLUGIN_PATH_UI,
SE_PLUGIN_PATH_DEV),
+ "dialog-template-save-as.ui",
+ "dialog-template-save-as"));
+
+ dialog->set_name(current->getName());
+ dialog->set_format(current->getFormat());
+ dialog->set_newline(current->getNewLine());
+ dialog->set_charset(current->getCharset());
+
+ if(dialog->run() != Gtk::RESPONSE_OK)
+ return;
+
+ std::auto_ptr<Document> newdoc(new Document(*current));
+ newdoc->setName(dialog->get_name());
+ newdoc->setFormat(dialog->get_format());
+ newdoc->setNewLine(dialog->get_newline());
+ newdoc->setCharset(dialog->get_charset());
+
+ Glib::ustring uri = Glib::filename_to_uri(
+ Glib::build_filename(
+ get_config_dir("plugins/template"),
+ Glib::ustring::compose("[%1][%2]",
newdoc->getName(), newdoc->getCharset())));
+
+ if(newdoc->save(uri) == false)
+ return;
+
+ rebuild_templates_menu();
+ }
+
+
+ /*
+ * Check if the template directory exists
+ * Create if needed
+ */
+ bool initialize_template_directory()
+ {
+ se_debug(SE_DEBUG_PLUGINS);
+
+ // Read the template directory
+ Glib::ustring path = get_config_dir("plugins/template");
+ // Already there ?
+ if(Glib::file_test(path, Glib::FILE_TEST_EXISTS |
Glib::FILE_TEST_IS_DIR))
+ return true;
+ // Needs to be created
+ try
+ {
+ Glib::RefPtr<Gio::File> file =
Gio::File::create_for_path(path);
+ if(file && file->make_directory_with_parents())
+ return true;
+ }
+ catch(...)
+ {
+ }
+ return false;
+ }
+
+protected:
+ Gtk::UIManager::ui_merge_id ui_id;
+ Glib::RefPtr<Gtk::ActionGroup> action_group;
+
+ Gtk::UIManager::ui_merge_id ui_id_templates;
+ Glib::RefPtr<Gtk::ActionGroup> action_group_templates;
+};
+
+REGISTER_EXTENSION(TemplatePlugin)
Added: trunk/plugins/actions/template/template.se-plugin.in
URL:
http://svn.gna.org/viewcvs/subtitleeditor/trunk/plugins/actions/template/template.se-plugin.in?rev=964&view=auto
==============================================================================
--- trunk/plugins/actions/template/template.se-plugin.in (added)
+++ trunk/plugins/actions/template/template.se-plugin.in Sat Feb 6
23:37:25 2016
@@ -0,0 +1,8 @@
+[SubtitleEditor Extension]
+_Name=Template Management
+_Description=FIXME
+Categorie=action
+Hidden=true
+Type=module
+Module=template
+Authors=kitone <kitone at gna dot org>
_______________________________________________
Subtitleeditor-commits mailing list
[email protected]
https://mail.gna.org/listinfo/subtitleeditor-commits