2018-06-26 14:09:39 +02:00
# include "CommandPage.hpp"
2018-01-12 23:09:05 +01:00
2018-05-06 00:32:45 +02:00
# include <QHeaderView>
2018-01-12 23:09:05 +01:00
# include <QLabel>
2018-04-27 01:11:09 +02:00
# include <QPushButton>
# include <QStandardItemModel>
# include <QTableView>
2018-01-12 23:09:05 +01:00
# include <QTextEdit>
2018-06-26 14:09:39 +02:00
# include "Application.hpp"
# include "controllers/commands/CommandController.hpp"
# include "controllers/commands/CommandModel.hpp"
# include "util/LayoutCreator.hpp"
# include "util/StandardItemHelper.hpp"
# include "widgets/helper/EditableModelView.hpp"
//#include "widgets/helper/ComboBoxItemDelegate.hpp"
2019-08-26 11:46:52 +02:00
# include "util/CombinePath.hpp"
2018-01-12 23:09:05 +01:00
2018-04-27 22:11:19 +02:00
# include <QLabel>
# include <QTextEdit>
2018-01-12 23:09:05 +01:00
// clang-format off
2019-08-26 14:07:21 +02:00
# define TEXT "{1} => first word {1+} => first word and after {{ => { <a href='https: //chatterino.com/help/commands'>more info</a>"
2018-01-12 23:09:05 +01:00
// clang-format on
namespace chatterino {
2019-08-26 11:46:52 +02:00
namespace {
QString c1settingsPath ( )
{
return combinePath ( qgetenv ( " appdata " ) ,
" Chatterino \\ Custom \\ Commands.txt " ) ;
}
} // namespace
2018-01-12 23:09:05 +01:00
CommandPage : : CommandPage ( )
2018-08-09 06:22:55 +02:00
: SettingsPage ( " Commands " , " :/settings/commands.svg " )
2018-01-12 23:09:05 +01:00
{
2018-04-28 13:48:49 +02:00
auto app = getApp ( ) ;
2018-04-27 01:11:09 +02:00
2018-06-26 17:06:17 +02:00
LayoutCreator < CommandPage > layoutCreator ( this ) ;
2018-01-13 00:04:47 +01:00
auto layout = layoutCreator . emplace < QVBoxLayout > ( ) . withoutMargin ( ) ;
2018-01-12 23:09:05 +01:00
2018-06-26 17:06:17 +02:00
EditableModelView * view =
2018-08-06 21:17:03 +02:00
layout . emplace < EditableModelView > ( app - > commands - > createModel ( nullptr ) )
. getElement ( ) ;
2018-04-29 23:25:49 +02:00
2018-05-06 00:32:45 +02:00
view - > setTitles ( { " Trigger " , " Command " } ) ;
view - > getTableView ( ) - > horizontalHeader ( ) - > setStretchLastSection ( true ) ;
view - > addButtonPressed . connect ( [ ] {
2018-11-03 13:37:09 +01:00
getApp ( ) - > commands - > items_ . appendItem (
2018-08-06 21:17:03 +02:00
Command { " /command " , " I made a new command HeyGuys " } ) ;
2018-05-06 00:32:45 +02:00
} ) ;
2018-04-27 01:11:09 +02:00
2019-08-26 11:46:52 +02:00
if ( QFile ( c1settingsPath ( ) ) . exists ( ) )
{
2019-08-26 14:07:21 +02:00
auto button = new QPushButton ( " Import commands from Chatterino 1 " ) ;
view - > addCustomButton ( button ) ;
2019-08-26 11:46:52 +02:00
2019-08-26 14:07:21 +02:00
QObject : : connect ( button , & QPushButton : : clicked , this , [ ] {
2019-08-26 11:46:52 +02:00
QFile c1settings = c1settingsPath ( ) ;
c1settings . open ( QIODevice : : ReadOnly ) ;
for ( auto line : QString ( c1settings . readAll ( ) )
. split ( QRegularExpression ( " [ \r \n ] " ) ,
QString : : SkipEmptyParts ) )
{
if ( int index = line . indexOf ( ' ' ) ; index ! = - 1 )
{
getApp ( ) - > commands - > items_ . insertItem (
Command ( line . mid ( 0 , index ) , line . mid ( index + 1 ) ) ) ;
}
}
} ) ;
}
2018-08-06 21:17:03 +02:00
layout . append (
this - > createCheckBox ( " Also match the trigger at the end of the message " ,
2018-08-12 12:56:28 +02:00
getSettings ( ) - > allowCommandsAtEnd ) ) ;
2018-01-12 23:09:05 +01:00
2018-06-22 12:34:33 +02:00
QLabel * text = layout . emplace < QLabel > ( TEXT ) . getElement ( ) ;
2018-04-27 01:11:09 +02:00
text - > setWordWrap ( true ) ;
text - > setStyleSheet ( " color: #bbb " ) ;
2019-08-26 14:07:21 +02:00
text - > setOpenExternalLinks ( true ) ;
2018-01-12 23:09:05 +01:00
// ---- end of layout
2018-07-06 19:23:47 +02:00
this - > commandsEditTimer_ . setSingleShot ( true ) ;
2018-01-12 23:09:05 +01:00
}
} // namespace chatterino