Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support charset #50

Merged
merged 3 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

root = true

[*]
charset=utf-8
indent_style=space
indent_size=4
end_of_line=crlf
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ The EditorConfig Notepad++ plugin supports the following EditorConfig
* end_of_line
* trim_trailing_whitespace
* insert_final_newline
* charset
* root (only used by EditorConfig core)

## Bugs and Feature Requests
Expand Down
4 changes: 2 additions & 2 deletions init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $url = "https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$($pcre)/p
$output = "$dest\pcre-$($pcre).zip"

"Downloading pcre2 v$pcre sources" | Write-Host -ForegroundColor DarkGreen
Start-BitsTransfer -Source $url -Destination $output
Start-BitsTransfer -Source $url -Destination $output -Dynamic

"Extracting pcre2 v$pcre sources" | Write-Host -ForegroundColor DarkGreen
Expand-Archive -Path $output -DestinationPath $dest
Expand All @@ -33,7 +33,7 @@ $url = "https://github.com/editorconfig/editorconfig-core-c/archive/v$($edc).zip
$output = "$dest\editorconfig-core-c-$($edc).zip"

"Downloading editorconfig-core-c v$edc sources" | Write-Host -ForegroundColor DarkGreen
Start-BitsTransfer -Source $url -Destination $output
Start-BitsTransfer -Source $url -Destination $output -Dynamic

"Extracting editorconfig-core-c v$edc sources" | Write-Host -ForegroundColor DarkGreen
Expand-Archive -Path $output -DestinationPath $dest
Expand Down
331 changes: 266 additions & 65 deletions src/Notepad_plus_msgs.hpp

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/PluginDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ void onBeforeSave(HWND hWnd)
int trim_trailing_whitespace = NPPEC_BOOLVAL_UNSPECIFIED;
int insert_final_newline = NPPEC_BOOLVAL_UNSPECIFIED;
int end_of_line = 0;
int charset = 0;

int name_value_count = editorconfig_handle_get_name_value_count(eh);
for (int i = 0; i < name_value_count; ++i) {
Expand Down Expand Up @@ -318,6 +319,22 @@ void onBeforeSave(HWND hWnd)
end_of_line = IDM_FORMAT_TOMAC;
continue;
}

// Need to convert the charset of the document?
if (strcmp(name, "charset") == 0)
{
if (strcmp(value, "latin1") == 0)
charset = IDM_FORMAT_CONV2_ANSI;
else if (strcmp(value, "utf-8") == 0)
charset = IDM_FORMAT_CONV2_AS_UTF_8;
else if (strcmp(value, "utf-8-bom") == 0)
charset = IDM_FORMAT_CONV2_UTF_8;
else if (strcmp(value, "utf-16be") == 0)
charset = IDM_FORMAT_CONV2_UTF_16BE;
else if (strcmp(value, "utf-16le") == 0)
charset = IDM_FORMAT_CONV2_UTF_16LE;
continue;
}
}

// Save the folding behavior and set it to 0 to keep folds from opening
Expand All @@ -340,6 +357,10 @@ void onBeforeSave(HWND hWnd)
SendMessage(hWnd, NPPM_MENUCOMMAND, 0, end_of_line);
}

if (charset != 0) {
SendMessage(hWnd, NPPM_MENUCOMMAND, 0, charset);
}

// Restore the folding behavior
SendMessage(curScintilla, SCI_SETAUTOMATICFOLD, automatic_fold, 0);

Expand Down
61 changes: 21 additions & 40 deletions src/PluginInterface.hpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,34 @@
// This file is part of Notepad++ project
// Copyright (C)2003 Don HO <[email protected]>
//
// 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.
//
// Note that the GPL places important restrictions on "derived works", yet
// it does not provide a detailed definition of that term. To avoid
// misunderstandings, we consider an application to constitute a
// "derivative work" for the purpose of this license if it does any of the
// following:
// 1. Integrates source code from Notepad++.
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
// installer, such as those produced by InstallShield.
// 3. Links to a library or executes a program that does any of the above.
// Copyright (C)2021 Don HO <[email protected]>

// 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
// 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, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// along with this program. If not, see <https://www.gnu.org/licenses/>.


#ifndef PLUGININTERFACE_H
#define PLUGININTERFACE_H
#pragma once

#ifndef SCINTILLA_H
#include "Scintilla.hpp"
#endif //SCINTILLA_H

#ifndef NOTEPAD_PLUS_MSGS_H
#include "Notepad_plus_msgs.hpp"
#endif //NOTEPAD_PLUS_MSGS_H

const int nbChar = 64;

typedef const TCHAR * (__cdecl * PFUNCGETNAME)();

struct NppData
{
HWND _nppHandle;
HWND _scintillaMainHandle;
HWND _scintillaSecondHandle;
HWND _nppHandle = nullptr;
HWND _scintillaMainHandle = nullptr;
HWND _scintillaSecondHandle = nullptr;
};

typedef void (__cdecl * PFUNCSETINFO)(NppData);
Expand All @@ -56,19 +39,19 @@ typedef LRESULT (__cdecl * PMESSAGEPROC)(UINT Message, WPARAM wParam, LPARAM lPa

struct ShortcutKey
{
bool _isCtrl;
bool _isAlt;
bool _isShift;
UCHAR _key;
bool _isCtrl = false;
bool _isAlt = false;
bool _isShift = false;
UCHAR _key = 0;
};

struct FuncItem
{
TCHAR _itemName[nbChar];
PFUNCPLUGINCMD _pFunc;
int _cmdID;
bool _init2Check;
ShortcutKey *_pShKey;
TCHAR _itemName[nbChar] = { '\0' };
PFUNCPLUGINCMD _pFunc = nullptr;
int _cmdID = 0;
bool _init2Check = false;
ShortcutKey *_pShKey = nullptr;
};

typedef FuncItem * (__cdecl * PFUNCGETFUNCSARRAY)(int *);
Expand All @@ -83,5 +66,3 @@ extern "C" __declspec(dllexport) LRESULT messageProc(UINT Message, WPARAM wParam
// This API return always true now, since Notepad++ isn't compiled in ANSI mode anymore
extern "C" __declspec(dllexport) BOOL isUnicode();


#endif //PLUGININTERFACE_H
29 changes: 29 additions & 0 deletions src/Sci_Position.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Scintilla source code edit control
/** @file Sci_Position.h
** Define the Sci_Position type used in Scintilla's external interfaces.
** These need to be available to clients written in C so are not in a C++ namespace.
**/
// Copyright 2015 by Neil Hodgson <[email protected]>
// The License.txt file describes the conditions under which this software may be distributed.

#ifndef SCI_POSITION_H
#define SCI_POSITION_H

#include <stddef.h>

// Basic signed type used throughout interface
typedef ptrdiff_t Sci_Position;

// Unsigned variant used for ILexer::Lex and ILexer::Fold
typedef size_t Sci_PositionU;

// For Sci_CharacterRange which is defined as long to be compatible with Win32 CHARRANGE
typedef intptr_t Sci_PositionCR;

#ifdef _WIN32
#define SCI_METHOD __stdcall
#else
#define SCI_METHOD
#endif

#endif
Loading