Commit 67455a3e authored by Atsuhito Kohda's avatar Atsuhito Kohda

Imported Upstream version 0.5~svn1035

parent 75d29a2a
......@@ -222,17 +222,41 @@ void CompletingEdit::mouseMoveEvent(QMouseEvent *e)
if (action != Qt::IgnoreAction) {
dropCursor.setPosition(droppedOffset);
dropCursor.setPosition(droppedOffset + droppedLength, QTextCursor::KeepAnchor);
if (action == Qt::MoveAction && (this == drag->target() || this->isAncestorOf(drag->target()))) {
if (droppedOffset >= sourceStart && droppedOffset <= sourceEnd) {
if (action == Qt::MoveAction) {
// If we successfully completed a "Move" action, we
// need to make sure that the source text is removed
// (inserting the text in the target has already
// been completed at this point)
bool insideWindow = (drag->target() && (this == drag->target() || this->isAncestorOf(drag->target())));
bool insideSelection = (insideWindow && droppedOffset >= sourceStart && droppedOffset <= sourceEnd);
if (insideSelection) {
// The text was dropped into the same window at
// an overlapping position.
// First, remove everything that is left from
// the source text *after* the inserted text
// (note that every position after droppedOffset
// needs to be translated by droppedLength)
source.setPosition(droppedOffset + droppedLength);
source.setPosition(sourceEnd + droppedLength, QTextCursor::KeepAnchor);
source.removeSelectedText();
// Second, remove everything that is left from
// the source text *before* the inserted text
source.setPosition(sourceStart);
source.setPosition(droppedOffset, QTextCursor::KeepAnchor);
source.removeSelectedText();
}
else
else {
// Otherwise, simply remove the source text
source.removeSelectedText();
}
if (!insideWindow) {
// The selection was moved to a different window,
// so dropCursor has no sensible data here. Thus,
// we collapse the cursor to where the selection
// was before the move action.
dropCursor.setPosition(sourceStart);
}
}
}
textCursor().endEditBlock();
......
/*
This is part of TeXworks, an environment for working with TeX documents
Copyright (C) 2007-2013 Jonathan Kew, Stefan Löffler, Charlie Sharpsteen
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 2 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/>.
For links to further information, or to contact the authors,
see <http://www.tug.org/texworks/>.
*/
#ifndef DefaultPrefs_H
#define DefaultPrefs_H
const int kDefault_LaunchOption = 1;
const int kDefault_ToolBarIcons = 2;
const bool kDefault_ToolBarText = false;
const int kDefault_Locale = 0;
const bool kDefault_OpenPDFwithTeX = true;
const int kDefault_SyntaxColoring = 0;
const int kDefault_IndentMode = 0;
const int kDefault_QuotesMode = 0;
const int kDefault_SpellcheckLanguage = 0;
const bool kDefault_LineNumbers = false;
const bool kDefault_WrapLines = true;
const int kDefault_TabWidth = 32;
const int kDefault_HideConsole = 1;
const bool kDefault_HighlightCurrentLine = true;
const bool kDefault_AutocompleteEnabled = true;
const bool kDefault_AllowScriptFileReading = false;
const bool kDefault_AllowScriptFileWriting = false;
const bool kDefault_EnableScriptingPlugins = false;
const bool kDefault_AllowSystemCommands = false;
const bool kDefault_ScriptDebugger = false;
#endif // !defined(DefaultPrefs_H)
......@@ -20,6 +20,7 @@
*/
#include "PrefsDialog.h"
#include "DefaultPrefs.h"
#include "TWApp.h"
#include "PDFDocument.h"
#include "TeXHighlighter.h"
......@@ -291,6 +292,7 @@ void PrefsDialog::restoreDefaults()
showText->setChecked(kDefault_ToolBarText);
switch (kDefault_LaunchOption) {
case 1:
default:
blankDocument->setChecked(true);
break;
case 2:
......@@ -300,8 +302,8 @@ void PrefsDialog::restoreDefaults()
openDialog->setChecked(true);
break;
}
blankDocument->setChecked(true);
localePopup->setCurrentIndex(0);
localePopup->setCurrentIndex(kDefault_Locale);
openPDFwithTeX->setChecked(kDefault_OpenPDFwithTeX);
break;
case 1:
......@@ -312,10 +314,12 @@ void PrefsDialog::restoreDefaults()
fontSize->setValue(font.pointSize());
}
tabWidth->setValue(kDefault_TabWidth);
lineNumbers->setChecked(kDefault_LineNumbers);
wrapLines->setChecked(kDefault_WrapLines);
syntaxColoring->setCurrentIndex(kDefault_SyntaxColoring);
autoIndent->setCurrentIndex(kDefault_IndentMode);
smartQuotes->setCurrentIndex(kDefault_QuotesMode);
language->setCurrentIndex(kDefault_SpellcheckLanguage);
encoding->setCurrentIndex(encoding->findText("UTF-8"));
highlightCurrentLine->setChecked(kDefault_HighlightCurrentLine);
autocompleteEnabled->setChecked(kDefault_AutocompleteEnabled);
......@@ -366,8 +370,11 @@ void PrefsDialog::restoreDefaults()
case 4:
// Scripts
allowSystemCommands->setChecked(false);
scriptDebugger->setChecked(false);
allowScriptFileReading->setChecked(kDefault_AllowScriptFileReading);
allowScriptFileWriting->setChecked(kDefault_AllowScriptFileWriting);
enableScriptingPlugins->setChecked(kDefault_EnableScriptingPlugins);
allowSystemCommands->setChecked(kDefault_AllowSystemCommands);
scriptDebugger->setChecked(kDefault_ScriptDebugger);
break;
}
}
......@@ -477,6 +484,7 @@ QDialog::DialogCode PrefsDialog::doPrefsDialog(QWidget *parent)
dlg.openDialog->setChecked(true);
break;
}
dlg.openPDFwithTeX->setChecked(settings.value("openPDFwithTeX", kDefault_OpenPDFwithTeX).toBool());
QString oldLocale = settings.value("locale").toString();
// System and English are predefined at index 0 and 1 (see constants above)
......@@ -578,14 +586,14 @@ QDialog::DialogCode PrefsDialog::doPrefsDialog(QWidget *parent)
dlg.autoHideOutput->setCurrentIndex(hideConsoleSetting.toInt());
// Scripts
dlg.allowScriptFileReading->setChecked(settings.value("allowScriptFileReading", false).toBool());
dlg.allowScriptFileWriting->setChecked(settings.value("allowScriptFileWriting", false).toBool());
dlg.allowSystemCommands->setChecked(settings.value("allowSystemCommands", false).toBool());
dlg.enableScriptingPlugins->setChecked(settings.value("enableScriptingPlugins", false).toBool());
dlg.allowScriptFileReading->setChecked(settings.value("allowScriptFileReading", kDefault_AllowScriptFileReading).toBool());
dlg.allowScriptFileWriting->setChecked(settings.value("allowScriptFileWriting", kDefault_AllowScriptFileWriting).toBool());
dlg.allowSystemCommands->setChecked(settings.value("allowSystemCommands", kDefault_AllowSystemCommands).toBool());
dlg.enableScriptingPlugins->setChecked(settings.value("enableScriptingPlugins", kDefault_EnableScriptingPlugins).toBool());
// there is always at least JSScriptInterface
if (TWApp::instance()->getScriptManager()->languages().size() <= 1)
dlg.enableScriptingPlugins->setEnabled(false);
dlg.scriptDebugger->setChecked(settings.value("scriptDebugger", false).toBool());
dlg.scriptDebugger->setChecked(settings.value("scriptDebugger", kDefault_ScriptDebugger).toBool());
#if QT_VERSION < 0x040500
dlg.scriptDebugger->setEnabled(false);
#endif
......@@ -633,6 +641,8 @@ QDialog::DialogCode PrefsDialog::doPrefsDialog(QWidget *parent)
launchOption = 3;
settings.setValue("launchOption", launchOption);
settings.setValue("openPDFwithTeX", dlg.openPDFwithTeX->isChecked());
if (dlg.localePopup->currentIndex() != oldLocaleIndex) {
switch (dlg.localePopup->currentIndex()) {
case kSystemLocaleIndex: // system locale
......
......@@ -30,19 +30,6 @@
#include "ui_PrefsDialog.h"
#include "ui_ToolConfig.h"
const int kDefault_LaunchOption = 1;
const int kDefault_ToolBarIcons = 2;
const bool kDefault_ToolBarText = false;
const int kDefault_SyntaxColoring = 0;
const int kDefault_IndentMode = -1;
const int kDefault_QuotesMode = -1;
const bool kDefault_LineNumbers = false;
const bool kDefault_WrapLines = true;
const int kDefault_TabWidth = 32;
const int kDefault_HideConsole = 1;
const bool kDefault_HighlightCurrentLine = true;
const bool kDefault_AutocompleteEnabled = true;
class QListWidgetItem;
class PrefsDialog : public QDialog, private Ui::PrefsDialog
......
......@@ -30,54 +30,85 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_general">
<attribute name="title">
<string>General</string>
</attribute>
<layout class="QGridLayout">
<item row="0" column="0" rowspan="2">
<widget class="QGroupBox" name="groupBox">
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_11">
<property name="title">
<string>Toolbar buttons</string>
<string>Interface</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QRadioButton" name="smallIcons">
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Small icons</string>
<string>Locale:</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mediumIcons">
<property name="text">
<string>Medium icons</string>
<item row="0" column="1">
<widget class="QComboBox" name="localePopup">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="largeIcons">
<property name="text">
<string>Large icons</string>
<property name="maxVisibleItems">
<number>20</number>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showText">
<item row="1" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Show text as well as icons</string>
<string>Toolbar buttons:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QRadioButton" name="smallIcons">
<property name="text">
<string>Small icons</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mediumIcons">
<property name="text">
<string>Medium icons</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="largeIcons">
<property name="text">
<string>Large icons</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showText">
<property name="text">
<string>Show text as well as icons</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="0" column="1" colspan="2">
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>When launched, show</string>
......@@ -104,46 +135,29 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="openPDFwithTeX">
<property name="text">
<string>Open corresponding PDF preview with TeX files</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="2" rowspan="3">
<spacer>
<item row="1" column="1">
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>111</width>
<height>311</height>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Interface locale:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="localePopup">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxVisibleItems">
<number>20</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<spacer>
<property name="orientation">
......@@ -151,8 +165,8 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>242</width>
<height>271</height>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
......@@ -1035,6 +1049,8 @@
</layout>
</widget>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>localePopup</tabstop>
<tabstop>smallIcons</tabstop>
<tabstop>mediumIcons</tabstop>
<tabstop>largeIcons</tabstop>
......@@ -1042,7 +1058,7 @@
<tabstop>blankDocument</tabstop>
<tabstop>templateDialog</tabstop>
<tabstop>openDialog</tabstop>
<tabstop>localePopup</tabstop>
<tabstop>openPDFwithTeX</tabstop>
<tabstop>editorFont</tabstop>
<tabstop>fontSize</tabstop>
<tabstop>tabWidth</tabstop>
......@@ -1054,6 +1070,7 @@
<tabstop>language</tabstop>
<tabstop>encoding</tabstop>
<tabstop>highlightCurrentLine</tabstop>
<tabstop>autocompleteEnabled</tabstop>
<tabstop>actualSize</tabstop>
<tabstop>fitWidth</tabstop>
<tabstop>fitWindow</tabstop>
......@@ -1077,13 +1094,12 @@
<tabstop>toolRemove</tabstop>
<tabstop>defaultTool</tabstop>
<tabstop>autoHideOutput</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>tabWidget</tabstop>
<tabstop>allowScriptFileReading</tabstop>
<tabstop>allowScriptFileWriting</tabstop>
<tabstop>allowSystemCommands</tabstop>
<tabstop>enableScriptingPlugins</tabstop>
<tabstop>scriptDebugger</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
<include location="../res/resources.qrc"/>
......
#define SVN_REVISION 1031
#define SVN_REVISION_STR "1031"
#define SVN_REVISION 1035
#define SVN_REVISION_STR "1035"
......@@ -24,6 +24,7 @@
#include "TeXDocument.h"
#include "PDFDocument.h"
#include "PrefsDialog.h"
#include "DefaultPrefs.h"
#include "TemplateDialog.h"
#include "TWSystemCmd.h"
......@@ -1278,7 +1279,7 @@ QMap<QString, QVariant> TWApp::openFileFromScript(const QString& fileName, QObje
// for absolute paths and full reading permissions, we don't have to care
// about peculiarities of the script; in that case, this even succeeds
// if no valid scriptApi is passed; otherwise, we need to investigate further
if (fi.isRelative() || !settings.value("allowScriptFileReading", false).toBool()) {
if (fi.isRelative() || !settings.value("allowScriptFileReading", kDefault_AllowScriptFileReading).toBool()) {
if (!scriptApi)
return retVal;
script = qobject_cast<TWScript*>(scriptApi->GetScript());
......
......@@ -22,6 +22,7 @@
#include "TWScript.h"
#include "TWScriptAPI.h"
#include "ConfigurableApp.h"
#include "DefaultPrefs.h"
#include <QTextStream>
#include <QMetaObject>
......@@ -458,7 +459,7 @@ bool TWScript::mayReadFile(const QString& filename, QObject * context) const
QVariant targetFile;
QDir targetDir;
if (settings.value("allowScriptFileReading", false).toBool())
if (settings.value("allowScriptFileReading", kDefault_AllowScriptFileReading).toBool())
return true;
// even if global reading is disallowed, some exceptions may apply
......
......@@ -29,7 +29,7 @@
#include "PDFDocument.h"
#include "ConfirmDelete.h"
#include "HardWrapDialog.h"
#include "PrefsDialog.h"
#include "DefaultPrefs.h"
#include <QCloseEvent>
#include <QFileDialog>
......@@ -296,13 +296,13 @@ void TeXDocument::init()
++index;
}
// FIXME: This does not respect kDefault_SyntaxColoring defined in
// PrefsDialog.h. ATM, that is irrelevant because kDefault_SyntaxColoring = 0
// DefaultPrefs.h. ATM, that is irrelevant because kDefault_SyntaxColoring = 0
// corresponds to None (i.e., ""). In the future, this may change, though.
// However, it would require some additional logic here (e.g., handling the
// case that kDefault_SyntaxColoring points to an invalid index).
setSyntaxColoringMode(settings.value("syntaxColoring").toString());
// kDefault_TabWidth is defined in PrefsDialog.h
// kDefault_TabWidth is defined in DefaultPrefs.h
textEdit->setTabStopWidth(settings.value("tabWidth", kDefault_TabWidth).toInt());
// It is VITAL that this connection is queued! Calling showMessage directly
......@@ -1092,14 +1092,20 @@ void TeXDocument::loadFile(const QString &fileName, bool asTemplate, bool inBack
lastModified = QDateTime();
}
else {
QSETTINGS_OBJECT(settings);
setCurrentFile(fileName);
if (!inBackground) {
if (!inBackground && settings.value("openPDFwithTeX", kDefault_OpenPDFwithTeX).toBool()) {
openPdfIfAvailable(false);
// Note: openPdfIfAvailable() enables/disables actionGo_to_Preview
// automatically.
}
else {
QString previewFileName;
actionGo_to_Preview->setEnabled(getPreviewFileName(previewFileName));
}
// set openDialogDir after openPdfIfAvailable as we want the .tex file's
// path to end up in that variable (which might be touched/changed when
// loading the pdf
QSETTINGS_OBJECT(settings);
QFileInfo info(fileName);
settings.setValue("openDialogDir", info.canonicalPath());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment